Search in sources :

Example 36 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.

the class InitNeighborAliasTable method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartInitNeighborAliasTableParam param = (PartInitNeighborAliasTableParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) part.getRow(0);
    ObjectIterator<Long2ObjectMap.Entry<NeighborsAliasTableElement>> iter = param.getNodeId2Neighbors().long2ObjectEntrySet().iterator();
    row.startWrite();
    try {
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<NeighborsAliasTableElement> entry = iter.next();
            NeighborsAliasTableElement element = entry.getValue();
            if (element == null) {
                row.set(entry.getLongKey(), null);
            } else {
                row.set(entry.getLongKey(), new NeighborsAliasTableElement(element.getNeighborIds(), element.getAccept(), element.getAlias()));
            }
        }
    } finally {
        row.endWrite();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) NeighborsAliasTableElement(com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)

Example 37 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.

the class GetNeighborAliasTable method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartGetNeighborAliasTableParam param = (PartGetNeighborAliasTableParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    ServerPartition part = matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongAnyRow row = (ServerLongAnyRow) (((RowBasedPartition) part).getRow(0));
    long[] nodeIds = param.getNodeIds();
    long[][] neighbors = new long[nodeIds.length][];
    int[] count = param.getCount();
    Random r = new Random();
    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 = r.nextInt(nodeNeighbors.length);
                    float ac = r.nextFloat();
                    if (ac < accept[index]) {
                        neighbors[i][j] = nodeNeighbors[index];
                    } else {
                        neighbors[i][j] = nodeNeighbors[alias[index]];
                    }
                }
            }
        }
    }
    return new PartGetNeighborAliasTableResult(part.getPartitionKey().getPartitionId(), neighbors);
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) Random(java.util.Random) ServerPartition(com.tencent.angel.ps.storage.partition.ServerPartition)

Example 38 with RowBasedPartition

use of com.tencent.angel.ps.storage.partition.RowBasedPartition in project angel by Tencent.

the class InitOutDegreeFunc method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartInitOutDegreeParam param = (PartInitOutDegreeParam) partParam;
    ServerMatrix matrix = psContext.getMatrixStorageManager().getMatrix(partParam.getMatrixId());
    RowBasedPartition part = (RowBasedPartition) matrix.getPartition(partParam.getPartKey().getPartitionId());
    ServerLongIntRow row = (ServerLongIntRow) part.getRow(0);
    ObjectIterator<Long2IntMap.Entry> iter = param.getNodeIdToOutDegree().long2IntEntrySet().iterator();
    row.startWrite();
    try {
        while (iter.hasNext()) {
            Long2IntMap.Entry entry = iter.next();
            row.set(entry.getLongKey(), entry.getIntValue());
        }
    } finally {
        row.endWrite();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2IntMap(it.unimi.dsi.fastutil.longs.Long2IntMap) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongIntRow(com.tencent.angel.ps.storage.vector.ServerLongIntRow)

Aggregations

RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)38 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)28 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)20 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)15 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)6 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)5 ServerIntAnyRow (com.tencent.angel.ps.storage.vector.ServerIntAnyRow)4 Random (java.util.Random)4 ServerLongIntRow (com.tencent.angel.ps.storage.vector.ServerLongIntRow)3 Vector (com.tencent.angel.ml.math2.vector.Vector)2 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)2 ServerAnyAnyRow (com.tencent.angel.ps.storage.vector.ServerAnyAnyRow)2 ServerLongLongRow (com.tencent.angel.ps.storage.vector.ServerLongLongRow)2 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)2 AngelException (com.tencent.angel.exception.AngelException)1 Node (com.tencent.angel.graph.data.Node)1 DynamicNeighborElement (com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement)1 NeighborsAliasTableElement (com.tencent.angel.graph.psf.neighbors.samplebyaliastable.samplealiastable.NeighborsAliasTableElement)1 CompIntDoubleVector (com.tencent.angel.ml.math2.vector.CompIntDoubleVector)1 CompIntFloatVector (com.tencent.angel.ml.math2.vector.CompIntFloatVector)1