Search in sources :

Example 6 with EigenvectorCentrality

use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.

the class EigenvectorCentralityTest method testDirection.

/**
     * Same as above, but inverted direction.
     */
@Test
public void testDirection() {
    graph.makeEdgeChain("d,c,b,a");
    graph.makeEdges("a,b,a,c");
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.INCOMING, new CostEvaluator<Double>() {

        public Double getCost(Relationship relationship, Direction direction) {
            return 1.0;
        }
    }, graph.getAllNodes(), graph.getAllEdges(), 0.01);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0.693, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0.523, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.395, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.298, 0.02);
}
Also used : Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) Test(org.junit.Test)

Example 7 with EigenvectorCentrality

use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.

the class EigenvectorCentralityTest method shouldHandleFirstNodeBeingOrphan.

@Test
public void shouldHandleFirstNodeBeingOrphan() {
    /*
         * Layout
         *
         * (o)
         *     ___________  _____
         *   v            \v     \
         * (a) -> (b) -> (c) -> (d)
         */
    // Degree 0
    Node orphan = graph.makeNode("o");
    Node a = graph.makeNode("a");
    Node b = graph.makeNode("b");
    Node c = graph.makeNode("c");
    Node d = graph.makeNode("d");
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.add(orphan);
    nodeSet.add(a);
    nodeSet.add(b);
    nodeSet.add(c);
    nodeSet.add(d);
    Set<Relationship> relSet = new HashSet<>();
    relSet.add(graph.makeEdge("a", "b"));
    relSet.add(graph.makeEdge("b", "c"));
    relSet.add(graph.makeEdge("c", "d"));
    relSet.add(graph.makeEdge("d", "c"));
    relSet.add(graph.makeEdge("c", "a"));
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {

        @Override
        public Double getCost(Relationship relationship, Direction direction) {
            return 1d;
        }
    }, nodeSet, relSet, 0.01);
    assertApproximateCentrality(eigenvectorCentrality, "o", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0.481, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0.363, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.637, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.481, 0.02);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with EigenvectorCentrality

use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.

the class EigenvectorCentralityTest method shouldHandleFirstNodeBeingOrphanInRelationshipSet.

@Test
public void shouldHandleFirstNodeBeingOrphanInRelationshipSet() {
    /*
         * Layout
         *
         * (o)
         *  ^
         *  |
         *  x
         *  |  ___________  _____
         *  |v            \v     \
         * (a) -> (b) -> (c) -> (d)
         */
    Node orphan = graph.makeNode("o");
    Node a = graph.makeNode("a");
    Node b = graph.makeNode("b");
    Node c = graph.makeNode("c");
    Node d = graph.makeNode("d");
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.add(orphan);
    nodeSet.add(a);
    nodeSet.add(b);
    nodeSet.add(c);
    nodeSet.add(d);
    Set<Relationship> relSet = new HashSet<>();
    relSet.add(graph.makeEdge("a", "b"));
    relSet.add(graph.makeEdge("b", "c"));
    relSet.add(graph.makeEdge("c", "d"));
    relSet.add(graph.makeEdge("d", "c"));
    relSet.add(graph.makeEdge("c", "a"));
    // Edge not included in rel set
    graph.makeEdge("a", "o");
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {

        @Override
        public Double getCost(Relationship relationship, Direction direction) {
            return 1d;
        }
    }, nodeSet, relSet, 0.01);
    assertApproximateCentrality(eigenvectorCentrality, "o", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0.481, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0.363, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.637, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.481, 0.02);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with EigenvectorCentrality

use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.

the class EigenvectorCentralityTest method shouldHandleIsolatedCommunities.

@Test
public void shouldHandleIsolatedCommunities() {
    /*
         * Layout
         *
         * (a) -> (b)
         *
         *   ___________   _____
         *  v            \v     \
         * (c) -> (d) -> (e) -> (f)
         *
         */
    Set<Node> nodeSet = new HashSet<>();
    nodeSet.add(graph.makeNode("a"));
    nodeSet.add(graph.makeNode("b"));
    nodeSet.add(graph.makeNode("c"));
    nodeSet.add(graph.makeNode("d"));
    nodeSet.add(graph.makeNode("e"));
    nodeSet.add(graph.makeNode("f"));
    Set<Relationship> relSet = new HashSet<>();
    relSet.add(graph.makeEdge("a", "b"));
    relSet.add(graph.makeEdge("c", "d"));
    relSet.add(graph.makeEdge("d", "e"));
    relSet.add(graph.makeEdge("e", "f"));
    relSet.add(graph.makeEdge("e", "c"));
    relSet.add(graph.makeEdge("f", "e"));
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {

        @Override
        public Double getCost(Relationship relationship, Direction direction) {
            return 1d;
        }
    }, nodeSet, relSet, 0.001);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0d, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.48, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.36, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "e", 0.64, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "f", 0.48, 0.02);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with EigenvectorCentrality

use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.

the class EigenvectorCentralityTest method simpleTest.

@Test
public void simpleTest() {
    /*
         * Layout
         *     ___________
         *   v             \
         *  (a) -> (b) -> (c) -> (d)
         *   ^     /
         *    ----
         */
    graph.makeEdgeChain("a,b,c,d");
    graph.makeEdges("b,a,c,a");
    EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {

        public Double getCost(Relationship relationship, Direction direction) {
            return 1.0;
        }
    }, graph.getAllNodes(), graph.getAllEdges(), 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "a", 0.693, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "b", 0.523, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "c", 0.395, 0.02);
    assertApproximateCentrality(eigenvectorCentrality, "d", 0.298, 0.02);
}
Also used : Relationship(org.neo4j.graphdb.Relationship) EigenvectorCentrality(org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality) Direction(org.neo4j.graphdb.Direction) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 EigenvectorCentrality (org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality)12 Direction (org.neo4j.graphdb.Direction)10 Relationship (org.neo4j.graphdb.Relationship)10 HashSet (java.util.HashSet)3 Node (org.neo4j.graphdb.Node)3 HashMap (java.util.HashMap)2