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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations