Compute discrete Ricci curvatures and Ricci flow on NetworkX graphs.
Project description
GraphRicciCurvature
A Python library to compute Discrete Ricci curvature and Ricci flow on NetworkX graph.
This work computes the Ollivier-Ricci Curvature[Ni], Ollivier-Ricci Flow[Ni2,Ni3] and Forman-Ricci Curvature(or Forman curvature)[Sreejith].
Curvature is a geometric property to describe the local shape of an object. If we draw two parallel paths on a surface with positive curvature like a sphere, these two paths move closer to each other while for a negative curved surface like saddle, these two paths tend to be apart.
In [Ni], we observe that the edge Ricci curvature play an important role in graph structure. An edge with positive curvature represents an edge within a cluster, while a negatively curved edge tents to be a bridge within clusters. Also, negatively curved edges are highly related to graph connectivity, with negatively curved edges removed from a connected graph, the graph soon become disconnected.
Ricci flow is a process to uniformized the edge Ricci curvature of the graph. For a given graph, the Ricci flow gives a "Ricci flow metric" on each edge as edge weights, such that under these edge weights, the Ricci curvature of the graph is mostly equal everywhere. In [Ni3], this "Ricci flow metric" is shown to be able to detect communities.
Both Ricci curvature and Ricci flow metric can be act as a graph fingerprint for graph classification. Different graph gives different edge Ricci curvature distributions and different Ricci flow metric.
Video demonstration of Ricci flow for community detection:
Package Requirement
- NetworkX (Based Graph library)
- NetworKit > 6.01 (Pairwise bidirectional dijkstra algorithm)
- CVXPY (LP solver for Optimal transportation)
- NumPy (CVXPY support)
- POT (For approximate Optimal transportation distance)
Installation
Installing via pip
pip3 install [--user] GraphRicciCurvature
- From version 0.4.0, in order to support larger graph, we switch to NetworKit's pairwise bidirectional dijkstra algorithm for density distribution (NetworKit>6.0 is required). If the installation of NetworKit failed, please refer to NetworKit' Installation instructions. In most of the cast build this package from source is recommended.
Getting Started
- See the jupyter notebook tutorial on nbviewer or github for a walk through for the basic usage of Ricci curvature, Ricci flow, and Ricci flow for community detection.
- Or you can run it in directly on binder (no account required) or Google colab (Faster but Google account required).
- Check the Documentations.
Simple Example
import networkx as nx
from GraphRicciCurvature.OllivierRicci import OllivierRicci
from GraphRicciCurvature.FormanRicci import FormanRicci
print("\n- Import an example NetworkX karate club graph")
G = nx.karate_club_graph()
print("\n===== Compute the Ollivier-Ricci curvature of the given graph G =====")
# compute the Ollivier-Ricci curvature of the given graph G
orc = OllivierRicci(G, alpha=0.5, verbose="INFO")
orc.compute_ricci_curvature()
print("Karate Club Graph: The Ollivier-Ricci curvature of edge (0,1) is %f" % orc.G[0][1]["ricciCurvature"])
print("\n===== Compute the Forman-Ricci curvature of the given graph G =====")
frc = FormanRicci(G)
frc.compute_ricci_curvature()
print("Karate Club Graph: The Forman-Ricci curvature of edge (0,1) is %f" % frc.G[0][1]["formanCurvature"])
# -----------------------------------
print("\n===== Compute Ricci flow metric - Optimal Transportation Distance =====")
G = nx.karate_club_graph()
orc_OTD = OllivierRicci(G, alpha=0.5, method="OTD", verbose="INFO")
orc_OTD.compute_ricci_flow(iterations=10)
More example in example.py.
Contact
Please contact Chien-Chun Ni.
Reference
[Ni]: Ni, C.-C., Lin, Y.-Y., Gao, J., Gu, X., and Saucan, E. 2015. "Ricci curvature of the Internet topology" (Vol. 26, pp. 2758–2766). Presented at the 2015 IEEE Conference on Computer Communications (INFOCOM), IEEE. arXiv
[Ni2]: Ni, C.-C., Lin, Y.-Y., Gao, J., and Gu, X. 2018. "Network Alignment by Discrete Ollivier-Ricci Flow", Graph Drawing 2018, arXiv
[Ni3]: Ni, C.-C., Lin, Y.-Y., Luo, F. and Gao, J. 2019. "Community Detection on Networks with Ricci Flow", Scientific Reports, arXiv
[Sreejith]: Sreejith, R. P., Karthikeyan Mohanraj, Jürgen Jost, Emil Saucan, and Areejit Samal. 2016. “Forman Curvature for Complex Networks.” Journal of Statistical Mechanics: Theory and Experiment 2016 (6). IOP Publishing: 063206. arxiv
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for GraphRicciCurvature-0.4.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bd7ac4ebab2989068f9151b9fae583dff45643eb483277a17937ace11f3c220 |
|
MD5 | 50690a5642d87973216abf2261767c17 |
|
BLAKE2b-256 | f72ca782285a9cfaca708e165a532f027dcd37f869a23ad013e5481e7001d0aa |
Hashes for GraphRicciCurvature-0.4.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcf4058a9c75c519b41d8d702ecdd502273eab137e751058a8ce7f7eea1bfe7f |
|
MD5 | f15937c9bb6ebd31324139c96c4bb4f3 |
|
BLAKE2b-256 | b01f1f6562a994a941397ac01ace9246f59108c1684e8df96f9efdee5bff7867 |