In [1]:
import networkx as nx
import matplotlib.pyplot as plt
import glob
from IPython.display import display, Markdown
In [2]:
def influence_graph(bnet):
    g = nx.DiGraph()
    with open(bnet) as fp:
        for line in fp.read().splitlines():
            dest, origs = line.split(",")
            dest = dest.strip()
            origs = set(origs.strip().replace("(","").replace(")","")\
                    .replace("&"," ").replace("|"," ").replace("!", "").split(" "))
            g.add_node(dest)
            g.add_edges_from([(dest, orig) for orig in origs])
    return g
In [3]:
def plot_scatter_degree(g):
    nodes = list(g.nodes())
    ins = [i for _,i in g.in_degree(nodes)]
    outs = [i for _,i in g.out_degree(nodes)]
    plt.plot(ins, outs, linestyle='none', marker='o')
    plt.xlabel("in-degree")
    plt.ylabel("out-degree")
    plt.show()
In [4]:
for filename in sorted(glob.glob("random-*.bnet"), key=lambda f: (len(f), f)):
    display(Markdown(f"### {filename}"))
    g = influence_graph(filename)
    plot_scatter_degree(g)

random-1000-1.bnet

random-1000-2.bnet

random-1000-3.bnet

random-1000-4.bnet

random-2000-1.bnet

random-2000-2.bnet

random-2000-3.bnet

random-2000-4.bnet

random-5000-1.bnet

random-5000-2.bnet

random-5000-3.bnet

random-5000-4.bnet

random-10000-1.bnet

random-10000-2.bnet

random-10000-3.bnet

random-10000-4.bnet

random-20000-1.bnet

random-20000-2.bnet

random-20000-3.bnet

random-20000-4.bnet

random-50000-1.bnet

random-50000-2.bnet

random-50000-3.bnet

random-50000-4.bnet

random-100000-1.bnet

random-100000-2.bnet

random-100000-3.bnet

random-100000-4.bnet

In [ ]: