-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathexample_use.py
55 lines (43 loc) · 1.35 KB
/
example_use.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example_use.py
# Jim Bagrow
# Last Modified: 2018-04-22
import sys, os
import itertools
import networkx as nx
import numpy as np
from portrait_divergence import portrait_divergence
# make n ER graphs and n BA graphs:
n = 10
list_ER = [ nx.erdos_renyi_graph(100, 3/99) for _ in range(n) ]
list_BA = [ nx.barabasi_albert_graph(100, 3) for _ in range(n) ]
# compare every pair of ER graphs:
Djs_sameER = []
for ERi, ERj in itertools.combinations(list_ER, 2):
Djs = portrait_divergence(ERi, ERj)
Djs_sameER.append(Djs)
# compare every pair of BA graphs:
Djs_sameBA = []
for BAi, BAj in itertools.combinations(list_BA, 2):
Djs = portrait_divergence(BAi, BAj)
Djs_sameBA.append(Djs)
# compare every ER with every BA:
Djs_ERvBA = []
for ER, BA in itertools.product(list_ER, list_BA):
Djs = portrait_divergence(ER, BA)
Djs_ERvBA.append(Djs)
try:
import matplotlib.pyplot as plt
except ImportError:
sys.exit(0)
# plot histograms:
hargs = dict(bins='auto', density=True, histtype='stepfilled')
plt.hist(Djs_sameER, label='Same ER', alpha=0.7, **hargs)
plt.hist(Djs_sameBA, label='Same BA', alpha=0.6, **hargs)
plt.hist(Djs_ERvBA, label='ER vs. BA', alpha=0.7, **hargs)
plt.xlabel("Portrait divergence $D_\mathrm{JS}$")
plt.ylabel("Prob. density")
plt.legend()
plt.tight_layout()
plt.show()