Search in sources :

Example 26 with PartitionGetParam

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam in project angel by Tencent.

the class SampleNodeFeatParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] partitions = meta.getPartitionKeys();
    // sample (count / partNum + 1) in every partition randomly
    int eachSize = count / partitions.length + 1;
    // Generate rpc params
    List<PartitionGetParam> partParams = new ArrayList<>(partitions.length);
    for (int i = 0; i < partitions.length; i++) {
        partParams.add(new PartSampleNodeFeatParam(matrixId, partitions[i], eachSize));
    }
    return partParams;
}
Also used : MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Example 27 with PartitionGetParam

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam in project angel by Tencent.

the class GetNodesParam method split.

@Override
public List<PartitionGetParam> split() {
    // Get matrix meta
    MatrixMeta meta = PSAgentContext.get().getMatrixMetaManager().getMatrixMeta(matrixId);
    PartitionKey[] partitions = meta.getPartitionKeys();
    isHash = meta.isHash();
    List<PartitionGetParam> params = new ArrayList<>();
    Map<Integer, PartitionKey> pkeys = new HashMap<>();
    for (PartitionKey pkey : partitions) {
        pkeys.put(pkey.getPartitionId(), pkey);
    }
    for (int i = 0; i < partitionIds.length; i++) {
        params.add(new PartGetNodesParam(matrixId, pkeys.get(partitionIds[i]), isHash));
    }
    return params;
}
Also used : HashMap(java.util.HashMap) MatrixMeta(com.tencent.angel.ml.matrix.MatrixMeta) ArrayList(java.util.ArrayList) PartitionKey(com.tencent.angel.PartitionKey) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)

Example 28 with PartitionGetParam

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam in project angel by Tencent.

the class SampleNeighbor method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    Int2ObjectArrayMap<PartitionGetResult> partIdToResultMap = new Int2ObjectArrayMap<>(partResults.size());
    for (PartitionGetResult result : partResults) {
        partIdToResultMap.put(((PartSampleNeighborResult) result).getPartId(), result);
    }
    SampleNeighborParam param = (SampleNeighborParam) getParam();
    long[] nodeIds = param.getNodeIds();
    List<PartitionGetParam> partParams = param.getPartParams();
    Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
    for (PartitionGetParam partParam : partParams) {
        int start = ((PartSampleNeighborParam) partParam).getStartIndex();
        int end = ((PartSampleNeighborParam) partParam).getEndIndex();
        PartSampleNeighborResult partResult = (PartSampleNeighborResult) (partIdToResultMap.get(partParam.getPartKey().getPartitionId()));
        long[][] results = partResult.getNodeIdToNeighbors();
        for (int i = start; i < end; i++) {
            nodeIdToNeighbors.put(nodeIds[i], results[i - start]);
        }
    }
    return new SampleNeighborResult(nodeIdToNeighbors);
}
Also used : Int2ObjectArrayMap(it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Example 29 with PartitionGetParam

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam in project angel by Tencent.

the class SampleNodeFeatsParam method split.

@Override
public List<PartitionGetParam> split() {
    List<PartitionGetParam> params = new ArrayList<>();
    List<PartitionKey> parts = PSAgentContext.get().getMatrixMetaManager().getPartitions(matrixId);
    int eachSize = size / parts.size() + 1;
    for (PartitionKey key : parts) {
        params.add(new SampleNodeFeatsPartParam(matrixId, key, eachSize));
    }
    return params;
}
Also used : ArrayList(java.util.ArrayList) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) PartitionKey(com.tencent.angel.PartitionKey)

Example 30 with PartitionGetParam

use of com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam in project angel by Tencent.

the class SampleNeighbor method merge.

@Override
public GetResult merge(List<PartitionGetResult> partResults) {
    Int2ObjectArrayMap<PartitionGetResult> partIdToResultMap = new Int2ObjectArrayMap<>(partResults.size());
    for (PartitionGetResult result : partResults) {
        partIdToResultMap.put(((PartSampleNeighborResult) result).getPartId(), result);
    }
    SampleNeighborParam param = (SampleNeighborParam) getParam();
    long[] nodeIds = param.getNodeIds();
    List<PartitionGetParam> partParams = param.getPartParams();
    Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
    for (PartitionGetParam partParam : partParams) {
        int start = ((PartSampleNeighborParam) partParam).getStartIndex();
        int end = ((PartSampleNeighborParam) partParam).getEndIndex();
        PartSampleNeighborResult partResult = (PartSampleNeighborResult) (partIdToResultMap.get(partParam.getPartKey().getPartitionId()));
        long[][] results = partResult.getNodeIdToNeighbors();
        for (int i = start; i < end; i++) {
            nodeIdToNeighbors.put(nodeIds[i], results[i - start]);
        }
    }
    return new SampleNeighborResult(nodeIdToNeighbors);
}
Also used : Int2ObjectArrayMap(it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap) PartitionGetParam(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) PartitionGetResult(com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)

Aggregations

PartitionGetParam (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetParam)35 PartitionKey (com.tencent.angel.PartitionKey)28 ArrayList (java.util.ArrayList)28 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)13 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)9 PartitionGetResult (com.tencent.angel.ml.matrix.psf.get.base.PartitionGetResult)6 Int2ObjectArrayMap (it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap)6 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)5 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)4 HashMap (java.util.HashMap)3 KeyValuePart (com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)2 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)1 ScalarAggrResult (com.tencent.angel.ml.matrix.psf.aggr.enhance.ScalarAggrResult)1 GetParam (com.tencent.angel.ml.matrix.psf.get.base.GetParam)1 GetResult (com.tencent.angel.ml.matrix.psf.get.base.GetResult)1 PartitionGetRowsParam (com.tencent.angel.ml.matrix.psf.get.getrows.PartitionGetRowsParam)1 FutureResult (com.tencent.angel.psagent.matrix.transport.FutureResult)1 MatrixTransportClient (com.tencent.angel.psagent.matrix.transport.MatrixTransportClient)1 MapResponseCache (com.tencent.angel.psagent.matrix.transport.response.MapResponseCache)1 ResponseCache (com.tencent.angel.psagent.matrix.transport.response.ResponseCache)1