Python code for computing portrait divergences, a simple, general-purpose tool for comparing networks.
Please see the paper for more details:
An information-theoretic, all-scales approach to comparing networks
James P. Bagrow and Erik M. Bollt, 2018
arXiv:1804.03665
The output of each calculation is a float between 0 and 1 describing how similar the two networks are (0 = identical, 1 = maximally different, according to this measure).
Portrait divergences can be computed at the command line or within Python scripts:
-
Basic example:
python portrait_divergence.py data/net1.edgelist data/net2.edgelist
-
Networks stored in GraphML files:
python portrait_divergence.py -graphml digraph_time1.graphml digraph_time2.graphml
-
Use faster C++ code (assuming it's installed):
python portrait_divergence.py --cpp big_g.edgelist big_h.edgelist
-
Let's get crazy:
python portrait_divergence.py --weighted=strength -b 10 --graphml g.graphml h.graphml
The code supports directed and weighted networks.
See the help string for more: python portrait_divergence.py -h
Here's a script to compare Erdős-Rényi and Barabási-Albert graphs:
import networkx as nx
from portrait_divergence import portrait_divergence
Ger1 = nx.erdos_renyi_graph(100, 3/99)
Ger2 = nx.erdos_renyi_graph(100, 3/99)
Gba1 = nx.barabasi_albert_graph(100, 3)
Gba2 = nx.barabasi_albert_graph(100, 3)
print("Djs(ER1,ER2) =", portrait_divergence(Ger1, Ger2))
print("Djs(ER1,BA1) =", portrait_divergence(Ger1, Gba1))
print("Djs(ER1,BA2) =", portrait_divergence(Ger1, Gba2))
print("Djs(BA1,BA2) =", portrait_divergence(Gba1, Gba2))
Result:
Djs(ER1,ER2) = 0.139438811433
Djs(ER1,BA1) = 0.831004770397
Djs(ER1,BA2) = 0.864124658944
Djs(BA1,BA2) = 0.214176902159
- Python 3.x with packages:
A recent install of Anaconda Python should come with everything you need.
If you use Portrait Divergence, please cite our paper:
James P. Bagrow and Erik M. Bollt, An information-theoretic, all-scales approach to comparing networks (2018) arXiv:1804.03665
Here is a bibtex key:
@article{bagrow2018information,
title={An information-theoretic, all-scales approach to comparing networks},
author={Bagrow, James P and Bollt, Erik M},
journal={arXiv preprint arXiv:1804.03665},
year={2018}
}
Portraits of Complex Networks — the original paper and idea behind Portrait Divergence.