use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.
the class EigenvectorCentralityTest method testWeight.
/**
* Some weighted relationships.
*/
@Test
public void testWeight() {
/*
* Layout
* ------- 0.1 ---------
* / \
* / --- 0.1 ---
* v v \
* (a) - 1.0 -> (b) - 1.0 -> (c) - 1.0 -> (d)
*/
graph.makeEdgeChain("a,b", "cost", 1.0);
graph.makeEdgeChain("b,c", "cost", 1.0);
graph.makeEdgeChain("c,d", "cost", 1.0);
graph.makeEdgeChain("c,b", "cost", 0.1);
graph.makeEdgeChain("c,a", "cost", 0.1);
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator("cost"), graph.getAllNodes(), graph.getAllEdges(), 0.01);
assertApproximateCentrality(eigenvectorCentrality, "a", 0.0851, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.244, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.456, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.852, 0.02);
}
use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.
the class EigenvectorCentralityTest method shouldHandleTargetNodeBeingOrphan.
@Test
public void shouldHandleTargetNodeBeingOrphan() {
graph.makeNode("o");
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.BOTH, new CostEvaluator<Double>() {
@Override
public Double getCost(Relationship relationship, Direction direction) {
return 1d;
}
}, graph.getAllNodes(), graph.getAllEdges(), 0.01);
assertApproximateCentrality(eigenvectorCentrality, "o", 0d, 0.02);
}
use of org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality in project neo4j by neo4j.
the class EigenvectorCentralityTest method testWeightAndDirection.
/**
* Same network as above, but with direction BOTH and weights in different
* directions are given by a map.
*/
@Test
public void testWeightAndDirection() {
graph.makeEdgeChain("a,b");
graph.makeEdgeChain("b,c");
graph.makeEdgeChain("c,d");
graph.makeEdgeChain("c,a");
final Map<String, Double> costs = new HashMap<String, Double>();
costs.put("a,b", 1.0);
costs.put("b,c", 1.0);
costs.put("c,d", 1.0);
costs.put("c,b", 0.1);
costs.put("c,a", 0.1);
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.BOTH, new CostEvaluator<Double>() {
public Double getCost(Relationship relationship, Direction direction) {
String start = graph.getNodeId(relationship.getStartNode());
String end = graph.getNodeId(relationship.getEndNode());
if (direction == Direction.INCOMING) {
// swap
String tmp = end;
end = start;
start = tmp;
}
Double value = costs.get(start + "," + end);
if (value == null) {
return 0.0;
}
return value;
}
}, graph.getAllNodes(), graph.getAllEdges(), 0.01);
assertApproximateCentrality(eigenvectorCentrality, "a", 0.0851, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.244, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.456, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.852, 0.02);
}
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 graphdb by neo4j-attic.
the class EigenvectorCentralityTest method testWeight.
/**
* Some weighted relationships.
*/
@Test
public void testWeight() {
graph.makeEdgeChain("a,b", "cost", 1.0);
graph.makeEdgeChain("b,c", "cost", 1.0);
graph.makeEdgeChain("c,d", "cost", 1.0);
graph.makeEdgeChain("c,b", "cost", 0.1);
graph.makeEdgeChain("c,a", "cost", 0.1);
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator("cost"), graph.getAllNodes(), graph.getAllEdges(), 0.01);
// eigenvectorCentrality.setMaxIterations( 100 );
assertApproximateCentrality(eigenvectorCentrality, "a", 0.0851, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.244, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.456, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.852, 0.01);
}
Aggregations