Search in sources :

Example 1 with LongArrayElement

use of com.tencent.angel.ps.storage.vector.element.LongArrayElement in project angel by Tencent.

the class InitNeighbor method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    PartInitNeighborParam param = (PartInitNeighborParam) 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<long[]>> iter = param.getNodeIdToNeighborIndices().long2ObjectEntrySet().iterator();
    row.startWrite();
    try {
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<long[]> entry = iter.next();
            row.set(entry.getLongKey(), new LongArrayElement(entry.getValue()));
        }
    } finally {
        row.endWrite();
    }
}
Also used : ServerMatrix(com.tencent.angel.ps.storage.matrix.ServerMatrix) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) RowBasedPartition(com.tencent.angel.ps.storage.partition.RowBasedPartition) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 2 with LongArrayElement

use of com.tencent.angel.ps.storage.vector.element.LongArrayElement in project angel by Tencent.

the class InitWalkPath method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    InitWalkPathPartitionParam pparam = (InitWalkPathPartitionParam) partParam;
    PartitionKey partKey = pparam.getPartKey();
    ServerLongAnyRow walkPath = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(partKey, 0);
    ServerLongAnyRow rowNeighbor = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(pparam.getNeighborMatrixId(), 0, partKey.getPartitionId());
    Random rand = new Random();
    ObjectIterator<Long2ObjectMap.Entry<IElement>> iter = rowNeighbor.iterator();
    walkPath.startWrite();
    walkPath.clear();
    PathQueue.init(partKey.getPartitionId());
    PathQueue.setThreshold(pparam.getThreshold());
    PathQueue.setKeepProba(pparam.getKeepProba());
    PathQueue.setNumParts(pparam.getNumParts());
    PathQueue.setIsTrunc(pparam.isTrunc());
    try {
        int count = 0;
        int batchSize = 1024;
        ArrayList<WalkPath> batchPath = new ArrayList<>();
        while (iter.hasNext()) {
            Long2ObjectMap.Entry<IElement> entry = iter.next();
            long key = entry.getLongKey() + partKey.getStartCol();
            LongArrayElement value = (LongArrayElement) entry.getValue();
            long[] neighbor = value.getData();
            long neigh = neighbor[rand.nextInt(neighbor.length)];
            WalkPath wPath = new WalkPath(pparam.getWalkLength(), key, neigh);
            walkPath.set(key, wPath);
            batchPath.add(wPath);
            count++;
            if (count % batchSize == 0) {
                PathQueue.initPushBatch(partKey.getPartitionId(), batchPath);
                batchPath.clear();
            }
        }
        if (!batchPath.isEmpty()) {
            PathQueue.initPushBatch(partKey.getPartitionId(), batchPath);
            batchPath.clear();
        }
    } finally {
        walkPath.endWrite();
    }
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) ArrayList(java.util.ArrayList) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) Random(java.util.Random) PartitionKey(com.tencent.angel.PartitionKey) WalkPath(com.tencent.angel.graph.client.node2vec.data.WalkPath)

Example 3 with LongArrayElement

use of com.tencent.angel.ps.storage.vector.element.LongArrayElement in project angel by Tencent.

the class PullNeighbor method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    PartitionGetParamWithIds pparam = (PartitionGetParamWithIds) partParam;
    long[] keyIds = pparam.getKeyIds();
    ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(pparam.getPartKey(), 0);
    Long2ObjectOpenHashMap<long[]> partResult = new Long2ObjectOpenHashMap<long[]>(keyIds.length);
    boolean isTrunc = PathQueue.isIsTrunc();
    if (PathQueue.getKeepProba() < 1.0 - 1e-6 && PathQueue.getKeepProba() > 1e-6) {
        double selectThred = PathQueue.getThreshold() / (1 - PathQueue.getKeepProba());
        for (long keyId : keyIds) {
            LongArrayElement longArrayElement = (LongArrayElement) row.get(keyId);
            long[] neighs = longArrayElement.getData();
            if (isTrunc && neighs.length > selectThred) {
                partResult.put(keyId, Arrays.copyOf(neighs, (int) selectThred));
            } else {
                partResult.put(keyId, neighs);
            }
        }
    } else {
        for (long keyId : keyIds) {
            LongArrayElement longArrayElement = (LongArrayElement) row.get(keyId);
            long[] neighs = longArrayElement.getData();
            partResult.put(keyId, neighs);
        }
    }
    return new PullNeighborPartitionResult(partResult);
}
Also used : PartitionGetParamWithIds(com.tencent.angel.graph.client.node2vec.params.PartitionGetParamWithIds) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 4 with LongArrayElement

use of com.tencent.angel.ps.storage.vector.element.LongArrayElement in project angel by Tencent.

the class PullMinDegree method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    ServerLongAnyRow row = (ServerLongAnyRow) psContext.getMatrixStorageManager().getRow(partParam.getPartKey(), 0);
    int partResult = Integer.MAX_VALUE;
    ObjectIterator<Long2ObjectMap.Entry<IElement>> iter = row.iterator();
    while (iter.hasNext()) {
        Long2ObjectMap.Entry<IElement> entry = iter.next();
        LongArrayElement value = (LongArrayElement) entry.getValue();
        int length = value.getData().length;
        if (length < partResult) {
            partResult = length;
        }
    }
    return new PullMinDegreePartitionResult(partResult);
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) Long2ObjectMap(it.unimi.dsi.fastutil.longs.Long2ObjectMap) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 5 with LongArrayElement

use of com.tencent.angel.ps.storage.vector.element.LongArrayElement in project angel by Tencent.

the class InitDynamicNbrs method partitionUpdate.

@Override
public void partitionUpdate(PartitionUpdateParam partParam) {
    GeneralPartUpdateParam initParam = (GeneralPartUpdateParam) partParam;
    ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, initParam);
    // Get nodes and features
    ILongKeyAnyValuePartOp split = (ILongKeyAnyValuePartOp) initParam.getKeyValuePart();
    long[] nodeIds = split.getKeys();
    IElement[] neighbors = split.getValues();
    row.startWrite();
    try {
        for (int i = 0; i < nodeIds.length; i++) {
            LongArrayElement data = (LongArrayElement) neighbors[i];
            DynamicNeighborElement ele = (DynamicNeighborElement) row.get(nodeIds[i]);
            if (ele == null) {
                ele = new DynamicNeighborElement();
                ele.add(data.getData());
                row.set(nodeIds[i], ele);
            } else {
                ele.add(data.getData());
            }
        }
    } finally {
        row.endWrite();
    }
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) GeneralPartUpdateParam(com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam) DynamicNeighborElement(com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement) LongArrayElement(com.tencent.angel.ps.storage.vector.element.LongArrayElement) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow) ILongKeyAnyValuePartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyAnyValuePartOp)

Aggregations

ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)8 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)8 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)5 IElement (com.tencent.angel.ps.storage.vector.element.IElement)4 ServerMatrix (com.tencent.angel.ps.storage.matrix.ServerMatrix)2 RowBasedPartition (com.tencent.angel.ps.storage.partition.RowBasedPartition)2 Random (java.util.Random)2 PartitionKey (com.tencent.angel.PartitionKey)1 WalkPath (com.tencent.angel.graph.client.node2vec.data.WalkPath)1 PartitionGetParamWithIds (com.tencent.angel.graph.client.node2vec.params.PartitionGetParamWithIds)1 DynamicNeighborElement (com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement)1 GeneralPartUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam)1 ServerPartition (com.tencent.angel.ps.storage.partition.ServerPartition)1 ILongKeyAnyValuePartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyAnyValuePartOp)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1 ArrayList (java.util.ArrayList)1