This library provides efficiently implemented, parallel versions of common graph algorithms for Neo4j 3.x, exposed as Cypher procedures.
You can find documentation at neo4j.com/docs/graph-algorithms
Amy Hodler and Mark Needham recently finished writing the O’Reilly Graph Algorithms Book. For a limited time only, you can download your free copy from neo4j.com/graph-algorithms-book
Graph algorithms are used to compute metrics for graphs, nodes, or relationships.
They can provide insights on relevant entities in the graph (centralities, ranking), or inherent structures like communities (community-detection, graph-partitioning, clustering).
Many graph algorithms are iterative approaches that frequently traverse the graph for the computation using random walks, breadth-first or depth-first searches, or pattern matching.
Due to the exponential growth of possible paths with increasing distance, many of the approaches also have high algorithmic complexity.
Fortunately, optimized algorithms exist that utilize certain structures of the graph, memoize already explored parts, and parallelize operations. Whenever possible, we’ve applied these optimizations.
The library supports the following algorithms:
These algorithms determine the importance of distinct nodes in a network:
-
PageRank (
algo.pageRank
) -
ArticleRank (
algo.articleRank
) -
Betweenness Centrality (
algo.betweenness
) -
Closeness Centrality (
algo.closeness
) -
Harmonic Centrality (
algo.closeness.harmonic
) -
Eigenvector Centrality (
algo.eigenvector
) -
Degree Centrality (
algo.degree
)
These algorithms evaluate how a group is clustered or partitioned, as well as its tendency to strengthen or break apart:
-
Louvain (
algo.louvain
) -
Label Propagation (
algo.labelPropagation
) -
Connected Components (
algo.unionFind
) -
Strongly Connected Components (
algo.scc
) -
Triangle Counting / Clustering Coefficient (
algo.triangleCount
) -
Balanced Triads (
algo.balancedTriads
)
These algorithms help find the shortest path or evaluate the availability and quality of routes:
-
Minimum Weight Spanning Tree (
algo.mst
) -
Shortest Path (
algo.shortestPath
) -
Single Source Shortest Path (
algo.shortestPath.deltastepping
) -
All Pairs Shortest Path (
algo.allShortestPaths
) -
A* (
algo.shortestPath.astar
) -
Yen’s K-shortest paths (
algo.kShortestPaths
) -
Random Walk (
algo.randomWalk
)
These algorithms help calculate the similarity of nodes:
-
Jaccard Similarity (
algo.similarity.jaccard
) -
Cosine Similarity (
algo.similarity.cosine
) -
Pearson Similarity (
algo.similarity.pearson
) -
Euclidean Distance (
algo.similarity.euclidean
) -
Overlap Similarity (
algo.similarity.overlap
)
These algorithms can be used as part of Link Prediction solution:
-
Adamic Adar (
algo.linkprediction.adamicAdar
) -
Common Neighbors (
algo.linkprediction.commonNeighbors
) -
Preferential Attachment (
algo.linkprediction.preferentialAttachment
) -
Resource Allocation (
algo.linkprediction.resourceAllocation
) -
Same Community (
algo.linkprediction.sameCommunity
) -
Total Neighbors (
algo.linkprediction.totalNeighbors
)
These are utility functions and procedures that transform data for use further along the data pipeline:
-
One Hot Encoding (
algo.ml.oneHotEncoding
)
If we are using the Neo4j Desktop, the library can be installed from the 'Plugins' tab of a database.
The installer will download a copy of the graph algorithms library and place it in the 'plugins' directory of the database. It will also add the following entry to the settings file:
dbms.security.procedures.unrestricted=algo.*
If we are using a standalone Neo4j Server, the library will need to be installed and configured manually.
-
Download
graph-algorithms-algo-[version].jar
from the matching release and copy it into the$NEO4J_HOME/plugins
directory. We can work out which release to download by referring to the versions file. -
Add the following to your
$NEO4J_HOME/conf/neo4j.conf
file:dbms.security.procedures.unrestricted=algo.*
We need to give the library unrestricted access because the algorithms use the lower level Kernel API to read from, and to write to Neo4j.
-
Restart Neo4j
Once we’ve installed the library, to see a list of all the algorithms, run the following query:
CALL algo.list()
You can also see the full list in the documentation.
These algorithms are exposed as Neo4j procedures. They can be called directly from Cypher in your Neo4j Browser, from cypher-shell, or from your client code.
For most algorithms there are two procedures:
-
algo.<name>
- this procedure writes results back to the graph as node-properties, and reports statistics. -
algo.<name>.stream
- this procedure returns a stream of data. For example, node-ids and computed values.For large graphs, the streaming procedure might return millions, or even billions of results. In this case it may be more convenient to store the results of the algorithm, and then use them with later queries.
We’d love your feedback, so please try out these algorithms and let us know how well they work for your use-case. Also please note things that are missing from the installation instructions or documentation.
Please raise GitHub issues for anything you encounter or join the Neo4j Community forum and ask in the Graph Algorithms Category