cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Running closeness centrality with or without directions

I have the following graph

MERGE (a:Node{id:"A"})
MERGE (b:Node{id:"B"})
MERGE (c:Node{id:"C"})
MERGE (d:Node{id:"D"})
MERGE (e:Node{id:"E"})

MERGE (a)-[:LINK]->(b)
MERGE (b)-[:LINK]->(c)
MERGE (d)-[:LINK]->(c)
MERGE (e)-[:LINK]->(d);

which is a directed version of the graph in https://neo4j.com/docs/graph-algorithms/current/labs-algorithms/closeness-centrality/

If I want undirected, unweighted version of closeness centrality, I use

CALL algo.closeness.stream(
 'MATCH (n:Node) RETURN id(n) AS id',
  "MATCH (n)-[:LINK]-(m:Node) RETURN id(n) AS source, id(m) AS target",
  {graph: "cypher"})
YIELD nodeId, centrality

RETURN algo.asNode(nodeId).id AS node, centrality

which is indeed correct - the directionality is taken care in the cypher projection, but not with the option "direction: "BOTH" - if the option is available.
On the other hand, if I need directed, unweighted option, using cypher projection or not, using

CALL algo.closeness.stream(
 'MATCH (n:Node) RETURN id(n) AS id',
  "MATCH (n)-[:LINK]->(m:Node) RETURN id(n) AS source, id(m) AS target",
  {graph: "cypher", direction: "OUTGOING"})
YIELD nodeId, centrality

RETURN algo.asNode(nodeId).id AS node, centrality
ORDER BY centrality DESC
LIMIT 20;

returns

node centrality
"B" 1.0
"D" 1.0
"C" 0.0
"E" 0.0
"A" 0.0

which needs some explanation from the algorithms team. They are not reflective of "directed paths" either. Using any variation of the code, dropping "direction:" parameter in the above code - all return the same answer.

1 REPLY 1

This issue is related to Difference between calling "algo.closeness.stream" and "algo.closeness" for large graphs

Looking forward for clarifications.

Thanks,
Lavanya