Search in sources :

Example 11 with IElement

use of com.tencent.angel.ps.storage.vector.element.IElement 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 12 with IElement

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

the class InitNodeFeats method partitionUpdate.

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

Example 13 with IElement

use of com.tencent.angel.ps.storage.vector.element.IElement 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 14 with IElement

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

the class GetNodeAttrs method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int resultSize = 0;
    for (PartitionGetResult result : partResults) {
        resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
    }
    Long2ObjectOpenHashMap<float[]> nodeIdToAttrs = new Long2ObjectOpenHashMap<>(resultSize);
    for (PartitionGetResult result : partResults) {
        PartGeneralGetResult partResult = (PartGeneralGetResult) result;
        long[] nodeIds = partResult.getNodeIds();
        IElement[] attrs = partResult.getData();
        for (int i = 0; i < nodeIds.length; i++) {
            if (attrs[i] != null) {
                nodeIdToAttrs.put(nodeIds[i], ((FloatArrayElement) attrs[i]).getData());
            } else {
                nodeIdToAttrs.put(nodeIds[i], emptyFloats);
            }
        }
    }
    return new GetFloatsResult(nodeIdToAttrs);
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) PartGeneralGetResult(com.tencent.angel.graph.model.general.get.PartGeneralGetResult) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) GetFloatsResult(com.tencent.angel.graph.common.psf.result.GetFloatsResult) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 15 with IElement

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

the class GeneralGet method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    int resultSize = 0;
    for (PartitionGetResult result : partResults) {
        resultSize += ((PartGeneralGetResult) result).getNodeIds().length;
    }
    Long2ObjectOpenHashMap nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(resultSize);
    for (PartitionGetResult result : partResults) {
        PartGeneralGetResult getResult = (PartGeneralGetResult) result;
        long[] nodeIds = getResult.getNodeIds();
        IElement[] objs = getResult.getData();
        for (int i = 0; i < nodeIds.length; i++) {
            nodeIdToNeighbors.put(nodeIds[i], objs[i]);
        }
    }
    return new GetElementResult(nodeIdToNeighbors);
}
Also used : IElement(com.tencent.angel.ps.storage.vector.element.IElement) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult) GetElementResult(com.tencent.angel.graph.common.psf.result.GetElementResult)

Aggregations

IElement (com.tencent.angel.ps.storage.vector.element.IElement)38 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)19 ILongKeyAnyValuePartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyAnyValuePartOp)13 GeneralPartUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam)12 GraphNode (com.tencent.angel.graph.data.GraphNode)7 PartGeneralGetResult (com.tencent.angel.graph.model.general.get.PartGeneralGetResult)6 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)6 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)6 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)6 LongArrayElement (com.tencent.angel.ps.storage.vector.element.LongArrayElement)4 Entry (java.util.Map.Entry)4 GetLongsResult (com.tencent.angel.graph.common.psf.result.GetLongsResult)3 DynamicNeighborElement (com.tencent.angel.graph.model.neighbor.dynamic.DynamicNeighborElement)3 Object2ObjectMap (it.unimi.dsi.fastutil.objects.Object2ObjectMap)2 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)1 PartitionKey (com.tencent.angel.PartitionKey)1 AngelException (com.tencent.angel.exception.AngelException)1 WalkPath (com.tencent.angel.graph.client.node2vec.data.WalkPath)1 GetElementResult (com.tencent.angel.graph.common.psf.result.GetElementResult)1 GetFloatsResult (com.tencent.angel.graph.common.psf.result.GetFloatsResult)1