Search in sources :

Example 6 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class RangeRouterUtils method splitStream.

/**
 * Split keys by matrix partition
 *
 * @param matrixMeta matrix meta data
 * @param vectors Matrix vectors
 * @return partition key to key partition map
 */
public static CompStreamKeyValuePart[] splitStream(MatrixMeta matrixMeta, Vector[] vectors) {
    CompStreamKeyValuePart[] dataParts = new CompStreamKeyValuePart[matrixMeta.getPartitionNum()];
    KeyValuePart[][] subDataParts = new KeyValuePart[vectors.length][];
    for (int i = 0; i < vectors.length; i++) {
        subDataParts[i] = split(matrixMeta, vectors[i]);
    }
    for (int i = 0; i < dataParts.length; i++) {
        dataParts[i] = new CompStreamKeyValuePart(vectors.length);
        for (int j = 0; j < vectors.length; j++) {
            dataParts[i].add(subDataParts[j][i]);
        }
    }
    return dataParts;
}
Also used : CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)

Example 7 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class AnyKeysUpdateParam method split.

@Override
public List<PartitionUpdateParam> split() {
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = meta.getPartitionKeys();
    KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, neighbors);
    assert parts.length == splits.length;
    List<PartitionUpdateParam> partParams = new ArrayList<>(parts.length);
    for (int i = 0; i < parts.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            partParams.add(new GeneralPartUpdateParam(matrixId, parts[i], splits[i]));
        }
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) PartitionUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam) ArrayList(java.util.ArrayList) GeneralPartUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam) PartitionKey(com.tencent.angel.PartitionKey) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)

Example 8 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class IntKeysUpdateParam method split.

@Override
public List<PartitionUpdateParam> split() {
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = meta.getPartitionKeys();
    KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, neighbors);
    assert parts.length == splits.length;
    List<PartitionUpdateParam> partParams = new ArrayList<>(parts.length);
    for (int i = 0; i < parts.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            partParams.add(new GeneralPartUpdateParam(matrixId, parts[i], splits[i]));
        }
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) PartitionUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam) ArrayList(java.util.ArrayList) GeneralPartUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam) PartitionKey(com.tencent.angel.PartitionKey) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)

Example 9 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class LongKeysUpdateParam method split.

@Override
public List<PartitionUpdateParam> split() {
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] parts = meta.getPartitionKeys();
    KeyValuePart[] splits = RouterUtils.split(meta, 0, nodeIds, neighbors);
    assert parts.length == splits.length;
    List<PartitionUpdateParam> partParams = new ArrayList<>(parts.length);
    for (int i = 0; i < parts.length; i++) {
        if (splits[i] != null && splits[i].size() > 0) {
            partParams.add(new GeneralPartUpdateParam(matrixId, parts[i], splits[i]));
        }
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) PartitionUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam) ArrayList(java.util.ArrayList) GeneralPartUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam) PartitionKey(com.tencent.angel.PartitionKey) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)

Example 10 with KeyValuePart

use of com.tencent.angel.psagent.matrix.transport.router.KeyValuePart in project angel by Tencent.

the class GetNeighborsWithCount method partitionGetWithCount.

public static PartitionGetResult partitionGetWithCount(PSContext psContext, PartitionGetParam partParam) {
    PartGetNeighborWithCountParam param = (PartGetNeighborWithCountParam) partParam;
    KeyValuePart keyValuePart = param.getIndicesPart();
    // Long type node id
    long[] nodeIds = ((ILongKeyIntValuePartOp) keyValuePart).getKeys();
    int[] count = ((ILongKeyIntValuePartOp) keyValuePart).getValues();
    long[][] neighbors = new long[nodeIds.length][];
    Random r = new Random();
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
    for (int i = 0; i < nodeIds.length; i++) {
        long nodeId = nodeIds[i];
        // Get node neighbor number
        NeighborsAliasTableElement element = (NeighborsAliasTableElement) (row.get(nodeId));
        if (element == null) {
            neighbors[i] = null;
        } else {
            long[] nodeNeighbors = element.getNeighborIds();
            if (nodeNeighbors == null || nodeNeighbors.length == 0 || count[i] <= 0) {
                neighbors[i] = null;
            } else {
                neighbors[i] = new long[count[i]];
                // start sampling by alias table for count times
                float[] accept = element.getAccept();
                int[] alias = element.getAlias();
                for (int j = 0; j < count[i]; j++) {
                    // int index = Math.abs(r.nextInt()) % nodeNeighbors.length;
                    int index = r.nextInt(nodeNeighbors.length);
                    // float ac = Math.abs(r.nextFloat());
                    float ac = r.nextFloat();
                    if (ac < accept[index]) {
                        neighbors[i][j] = nodeNeighbors[index];
                    } else {
                        neighbors[i][j] = nodeNeighbors[alias[index]];
                    }
                }
            }
        }
    }
    return new PartGetNeighborWithCountResult(nodeIds, neighbors);
}
Also used : KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyIntValuePartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyIntValuePartOp) Random(java.util.Random)

Aggregations

KeyValuePart (com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)12 PartitionKey (com.tencent.angel.PartitionKey)9 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)7 ArrayList (java.util.ArrayList)7 PartitionUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.PartitionUpdateParam)5 GeneralPartUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam)4 CompStreamKeyValuePart (com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)4 PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)2 IntDoubleVector (com.tencent.angel.ml.math2.vector.IntDoubleVector)1 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)1 IntIntVector (com.tencent.angel.ml.math2.vector.IntIntVector)1 IntLongVector (com.tencent.angel.ml.math2.vector.IntLongVector)1 LongDoubleVector (com.tencent.angel.ml.math2.vector.LongDoubleVector)1 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)1 LongIntVector (com.tencent.angel.ml.math2.vector.LongIntVector)1 LongLongVector (com.tencent.angel.ml.math2.vector.LongLongVector)1 RowType (com.tencent.angel.ml.matrix.RowType)1 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)1 KeyHash (com.tencent.angel.psagent.matrix.transport.router.KeyHash)1 RouterType (com.tencent.angel.psagent.matrix.transport.router.RouterType)1