Search in sources :

Example 6 with GraphNode

use of com.tencent.angel.graph.data.GraphNode in project angel by Tencent.

the class NnzFeature method processRow.

@Override
public double processRow(ServerRow row) {
    LongElementStorage storage = ((ServerLongAnyRow) row).getStorage();
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = storage.iterator();
    long size = 0;
    while (it.hasNext()) {
        GraphNode node = (GraphNode) (it.next().getValue());
        if (node.getFeats() != null) {
            size++;
        }
    }
    return size;
}
Also used : LongElementStorage(com.tencent.angel.ps.storage.vector.storage.LongElementStorage) GraphNode(com.tencent.angel.graph.data.GraphNode) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 7 with GraphNode

use of com.tencent.angel.graph.data.GraphNode in project angel by Tencent.

the class NnzEdge method processRow.

@Override
public double processRow(ServerRow row) {
    LongElementStorage storage = ((ServerLongAnyRow) row).getStorage();
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = storage.iterator();
    long size = 0;
    while (it.hasNext()) {
        GraphNode node = (GraphNode) (it.next().getValue());
        if (node.getNeighbors() != null) {
            size += node.getNeighbors().length;
        }
    }
    return size;
}
Also used : LongElementStorage(com.tencent.angel.ps.storage.vector.storage.LongElementStorage) GraphNode(com.tencent.angel.graph.data.GraphNode) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 8 with GraphNode

use of com.tencent.angel.graph.data.GraphNode in project angel by Tencent.

the class NnzNeighbor method processRow.

@Override
public double processRow(ServerRow row) {
    LongElementStorage storage = ((ServerLongAnyRow) row).getStorage();
    ObjectIterator<Long2ObjectMap.Entry<IElement>> it = storage.iterator();
    int size = 0;
    while (it.hasNext()) {
        GraphNode node = (GraphNode) (it.next().getValue());
        if (node.getNeighbors() != null) {
            size++;
        }
    }
    return size;
}
Also used : LongElementStorage(com.tencent.angel.ps.storage.vector.storage.LongElementStorage) GraphNode(com.tencent.angel.graph.data.GraphNode) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 9 with GraphNode

use of com.tencent.angel.graph.data.GraphNode in project angel by Tencent.

the class SampleUtils method sampleEdgeFeat.

public static Tuple2<Long2ObjectOpenHashMap<long[]>, Long2ObjectOpenHashMap<IntFloatVector[]>> sampleEdgeFeat(ServerRow row, int count, long[] nodeIds, long seed) {
    Random r = new Random(seed);
    Long2ObjectOpenHashMap<long[]> nodeId2SampleNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
    Long2ObjectOpenHashMap<IntFloatVector[]> nodeId2SampleEdgeFeats = new Long2ObjectOpenHashMap<>(nodeIds.length);
    for (long nodeId : nodeIds) {
        long[] sampleNeighbors;
        IntFloatVector[] edgeFeats;
        // Get node neighbor number
        GraphNode graphNode = (GraphNode) ((ServerLongAnyRow) row).get(nodeId);
        if (graphNode == null) {
            sampleNeighbors = new long[0];
            edgeFeats = new IntFloatVector[0];
        } else {
            long[] nodeNeighbors = graphNode.getNeighbors();
            IntFloatVector[] nodeEdgeFeats = graphNode.getEdgeFeatures();
            if (nodeNeighbors == null || nodeNeighbors.length == 0) {
                sampleNeighbors = new long[0];
                edgeFeats = new IntFloatVector[0];
            } else if (count <= 0 || nodeNeighbors.length <= count) {
                sampleNeighbors = nodeNeighbors;
                if (nodeEdgeFeats == null || nodeEdgeFeats.length == 0) {
                    edgeFeats = new IntFloatVector[0];
                } else {
                    edgeFeats = nodeEdgeFeats;
                }
            } else {
                sampleNeighbors = new long[count];
                edgeFeats = new IntFloatVector[count];
                // If the neighbor number > count, just copy a range of neighbors to
                // the result array, the copy position is random
                int startPos = Math.abs(r.nextInt()) % nodeNeighbors.length;
                if (startPos + count <= nodeNeighbors.length) {
                    System.arraycopy(nodeNeighbors, startPos, sampleNeighbors, 0, count);
                    System.arraycopy(nodeEdgeFeats, startPos, edgeFeats, 0, count);
                } else {
                    System.arraycopy(nodeNeighbors, startPos, sampleNeighbors, 0, nodeNeighbors.length - startPos);
                    System.arraycopy(nodeNeighbors, 0, sampleNeighbors, nodeNeighbors.length - startPos, count - (nodeNeighbors.length - startPos));
                    // sample types
                    System.arraycopy(nodeEdgeFeats, startPos, edgeFeats, 0, nodeEdgeFeats.length - startPos);
                    System.arraycopy(nodeEdgeFeats, 0, edgeFeats, nodeEdgeFeats.length - startPos, count - (nodeEdgeFeats.length - startPos));
                }
            }
        }
        nodeId2SampleNeighbors.put(nodeId, sampleNeighbors);
        nodeId2SampleEdgeFeats.put(nodeId, edgeFeats);
    }
    return new Tuple2<>(nodeId2SampleNeighbors, nodeId2SampleEdgeFeats);
}
Also used : Random(java.util.Random) Tuple2(scala.Tuple2) GraphNode(com.tencent.angel.graph.data.GraphNode) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) IntFloatVector(com.tencent.angel.ml.math2.vector.IntFloatVector)

Example 10 with GraphNode

use of com.tencent.angel.graph.data.GraphNode in project angel by Tencent.

the class SampleUtils method sampleWithType.

public static Tuple2<Long2ObjectOpenHashMap<long[]>, Long2ObjectOpenHashMap<int[]>> sampleWithType(ServerRow row, long[] nodeIds, SampleType sampleType, long[] filterWithNeighKeys, long[] filterWithoutNeighKeys, long seed) {
    Long2ObjectOpenHashMap<long[]> nodeId2SampleNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
    Long2ObjectOpenHashMap<int[]> nodeId2SampleNeighborsType = new Long2ObjectOpenHashMap<>(nodeIds.length);
    for (int i = 0; i < nodeIds.length; i++) {
        ArrayList<Long> sampleNeighbors;
        ArrayList<Integer> neighborsTypes;
        // Get node neighbor number
        GraphNode graphNode = (GraphNode) ((ServerLongAnyRow) row).get(nodeIds[i]);
        if (graphNode == null) {
            sampleNeighbors = new ArrayList<>();
            neighborsTypes = new ArrayList<>();
        } else {
            long[] nodeNeighbors = graphNode.getNeighbors();
            int[] nodeNeighborsTypes;
            if (sampleType == SampleType.NODE) {
                nodeNeighborsTypes = graphNode.getTypes();
            } else {
                nodeNeighborsTypes = graphNode.getEdgeTypes();
            }
            if (nodeNeighbors == null || nodeNeighbors.length == 0) {
                sampleNeighbors = new ArrayList<>();
                neighborsTypes = new ArrayList<>();
            } else {
                sampleNeighbors = new ArrayList<>();
                neighborsTypes = new ArrayList<>();
                for (int j = 0; j < nodeNeighbors.length; j++) {
                    if (filterWithoutNeighKeys != null && nodeNeighbors[j] != filterWithoutNeighKeys[i]) {
                        sampleNeighbors.add(nodeNeighbors[j]);
                        neighborsTypes.add(nodeNeighborsTypes[j]);
                    } else if (filterWithoutNeighKeys == null) {
                        if (!sampleNeighbors.contains(nodeNeighbors[j])) {
                            sampleNeighbors.add(nodeNeighbors[j]);
                            neighborsTypes.add(nodeNeighborsTypes[j]);
                        }
                    }
                    if (filterWithNeighKeys != null) {
                        for (int k = 0; k < filterWithNeighKeys.length; k++) {
                            if (nodeNeighbors[j] == filterWithNeighKeys[k] && !sampleNeighbors.contains(filterWithNeighKeys[k])) {
                                sampleNeighbors.add(nodeNeighbors[j]);
                                neighborsTypes.add(nodeNeighborsTypes[j]);
                            }
                        }
                    } else {
                        if (!sampleNeighbors.contains(nodeNeighbors[j])) {
                            sampleNeighbors.add(nodeNeighbors[j]);
                            neighborsTypes.add(nodeNeighborsTypes[j]);
                        }
                    }
                }
            }
        }
        nodeId2SampleNeighbors.put(nodeIds[i], sampleNeighbors.stream().mapToLong(x -> x).toArray());
        nodeId2SampleNeighborsType.put(nodeIds[i], neighborsTypes.stream().mapToInt(x -> x).toArray());
    }
    return new Tuple2<>(nodeId2SampleNeighbors, nodeId2SampleNeighborsType);
}
Also used : GraphNode(com.tencent.angel.graph.data.GraphNode) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Tuple2(scala.Tuple2)

Aggregations

GraphNode (com.tencent.angel.graph.data.GraphNode)16 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)11 GeneralPartUpdateParam (com.tencent.angel.ml.matrix.psf.update.base.GeneralPartUpdateParam)7 IElement (com.tencent.angel.ps.storage.vector.element.IElement)7 ILongKeyAnyValuePartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyAnyValuePartOp)7 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)5 Random (java.util.Random)4 LongElementStorage (com.tencent.angel.ps.storage.vector.storage.LongElementStorage)3 Tuple2 (scala.Tuple2)3 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)1 IndexPartGetLongResult (com.tencent.angel.ml.matrix.psf.get.indexed.IndexPartGetLongResult)1 Long2ObjectMap (it.unimi.dsi.fastutil.longs.Long2ObjectMap)1 Entry (it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry)1 LongArrayList (it.unimi.dsi.fastutil.longs.LongArrayList)1 Tuple3 (scala.Tuple3)1