neo4j-contrib / neo4j-graph-algorithms

Efficient Graph Algorithms for Neo4j
https://github.com/neo4j/graph-data-science/
GNU General Public License v3.0
767 stars 196 forks source link

Directed random walks #925

Closed cbobed closed 4 years ago

cbobed commented 4 years ago

Hi all,

when calling randomWalk procedure with a direction which is not BOTH (either using random or node2vec modes) I get the following null pointer exception:

2020-01-23 10:56:28.224+0000 INFO ======== Neo4j 3.5.14 ======== 2020-01-23 10:56:28.234+0000 INFO Starting... 2020-01-23 10:56:38.563+0000 INFO Bolt enabled on 127.0.0.1:7687. 2020-01-23 10:56:39.915+0000 INFO Started. 2020-01-23 10:56:40.642+0000 INFO Remote interface available at http://localhost:7474/ 2020-01-23 10:56:48.323+0000 INFO [node-importer] LOADING 1% Memory usage: 0 Bytes 2020-01-23 10:56:49.311+0000 INFO [neo4j.BoltWorker-5 [bolt] [/127.0.0.1:61238] ] LOADING 100% Memory usage: 30 MiB Exception in thread "Thread-16" java.lang.NullPointerException at org.neo4j.graphalgo.core.heavyweight.AdjacencyMatrix.degree(AdjacencyMatrix.java:274) at org.neo4j.graphalgo.core.heavyweight.HeavyGraph.degree(HeavyGraph.java:90) at org.neo4j.graphalgo.impl.walking.NodeWalker$RandomNextNodeStrategy.getNextNode(NodeWalker.java:143) at org.neo4j.graphalgo.impl.walking.NodeWalker.doWalk(NodeWalker.java:87) at org.neo4j.graphalgo.impl.walking.NodeWalker.lambda$randomWalk$0(NodeWalker.java:60) at org.neo4j.graphalgo.core.utils.ParallelUtil.runWithConcurrency(ParallelUtil.java:689) at org.neo4j.graphalgo.core.utils.ParallelUtil.runWithConcurrency(ParallelUtil.java:428) at org.neo4j.graphalgo.impl.walking.NodeWalker.lambda$randomWalk$1(NodeWalker.java:65) at java.lang.Thread.run(Unknown Source)

s1ck commented 4 years ago

RandomWalk only supports undirected graphs at the moment. Anything besides BOTH will lead to NPEs on the underlying graph.

That being said, I'd recommend using the new version of this library which you can find at https://github.com/neo4j/graph-data-science

The direction limitation is still the case in the ported version of RandomWalk, please check the docs for more details: https://github.com/neo4j/graph-data-science/blob/master/doc/asciidoc/algorithms/alpha/alpha-random-walk.adoc for more details on the algo in the new library.

What's your use case for directed random walks? Maybe we can consider prioritizing work on that particular algorithm if there is a lot of benefit in supporting directions.

cbobed commented 4 years ago

Hi, in fact, I didn't need directed random walks for my use case. I'm working just in obtaining a semantic kernel of the graph following node2vec, so, in the end, I can reconstruct the sampling taking into account the original structure (not so costly).

It was just to note that it didn't work with the directed parameter. This said, I'd add the comment in the library documentation to avoid confusion :)

Thank you!