Skip to content

Latest commit

 

History

94 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graph_ricci_curvature

Calculate the Ricci curvature tensor for a networkx graph. Both Ollivier [1] and Forman [3] discretizations of Ricci curvature are implemented (see [4] for comparison of methods).

Installation

From Source

  • Clone the repository and cd into the top level directory
  • Install python's build: python -m pip install build
  • Build the project: python -m build
  • Install the project with pip: python -m pip install dist/[file name].whl

For testing the installation, you need pytest. Run pytest in the top level directory to run the full test suite.

Download the .whl from Releases

After download, install the wheel via pip: python -m pip install [file name].whl

From PyPi

Not available yet

Usage

After installation:

from graph_ricci_curvature.ollivier_ricci_curvature import OllivierRicciCurvature
import networkx as nx

#setting up a simple graph
G = nx.Graph()
G.add_nodes_from([1, 2, 3])
G.add_edges_from([(1, 2), (1, 3)])

#create an object and calculate the values of the tensor and its contractions
g = OllivierRicciCurvature(G)
g.calculate_ricci_curvature()

#print results of calculation
print(list(g.G.edges.data()))
print(list(g.G.nodes.data()))
print(g.G.graph["graph_ricci_curvature"], g.G.graph["norm_graph_ricci_curvature"])

Output:

#edge curvature data
[
(1, 2, {"weight": 1.0, "ricci_curvature": 0.5}),
(1, 3, {"weight": 1.0, "ricci_curvature": 0.5}),
]

#node curvature data
[
(1, {"weight": 1.0, "ricci_curvature": 0.5}),
(2, {"weight": 1.0, "ricci_curvature": 0.5}),
(3, {"weight": 1.0, "ricci_curvature": 0.5})
]

#graph curvature data
1.5 0.5

Manual

You can see the manual here which is in docs/_build/latex. Or, after installation, can run the following with python

import graph_ricci_curvature as grc
grc.__manual__

to obtain the link to the pdf in the github repository.

References

About

Calculate Ricci Curvature for a networkx graph

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages