In [1]:
%matplotlib inline

In [2]:
import networkx as nx
import pandas as pd
import projx as px
import matplotlib.pyplot as plt
import seaborn as sns

In [3]:
plt.rcParams['figure.figsize'] = (12, 7)

In [4]:
g = nx.read_gexf("projections/onemode.gexf")

In [5]:
print(len(g), len(g.edges()))


(318, 2212)

In [6]:
g = list(nx.connected_component_subgraphs(g))[0]

In [7]:
print(len(g), len(g.edges()))


(305, 2174)

In [8]:
weight_sr = pd.Series([attrs["weight"] for s, t, attrs in g.edges(data=True)])
weight_sr.describe()


Out[8]:
count    2174.000000
mean        0.203542
std         0.197535
min         0.052632
25%         0.111455
50%         0.142857
75%         0.200000
max         2.602381
dtype: float64

In [17]:
font = {'family' : 'normal',
        'weight' : 'bold',
        'size'   : 22}

plt.rc('font', **font)
plt.savefig("img/article/figure6.eps", format='eps', dpi=1000)
cutoffs, densities = px.proj_density(g, 0.0, 0.01, 100)
plt.plot(cutoffs, densities)
plt.ylabel('network density', size=18)
plt.xlabel('deight', size=18)
plt.savefig("img/article/figure6.eps", format='eps', dpi=1000)



In [30]:
cutoffs, densities = px.proj_density(g, 0.0, 0.01, 20)
plt.plot(cutoffs, densities)
plt.savefig("img/cutlines_detail.png")



In [9]:
weight_sr.quantile(0.10)


Out[9]:
0.090909090909100002

In [15]:
fourteen_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.14))
nx.write_gexf(fourteen_percent_cut, "projections/fourteen_percent_cut.gexf")
subgraphs = list(nx.connected_component_subgraphs(fourteen_percent_cut))
print([len(sub) for sub in subgraphs])
print(nx.density(subgraphs[0]))


[288, 5, 8]
0.0457075106465

In [10]:
ten_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.10))
nx.write_gexf(ten_percent_cut, "projections/ten_percent_cut.gexf")
subgraphs = list(nx.connected_component_subgraphs(ten_percent_cut))
print([len(sub) for sub in subgraphs])


[297, 5, 8]

In [11]:
twentyfive_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.25))
nx.write_gexf(twentyfive_percent_cut, "projections/twenty_percent_cut.gexf")
subgraphs = list(nx.connected_component_subgraphs(twentyfive_percent_cut))
print([len(sub) for sub in subgraphs])


[271, 5, 8]

In [31]:
fifty_percent_cut = px.remove_edges(g.copy(), 0.14)
nx.write_gexf(fifty_percent_cut, "projections/fifty_percent_cut.gexf")
subgraphs = list(nx.connected_component_subgraphs(fifty_percent_cut))
print([len(sub) for sub in subgraphs])
print(len(subgraphs[0].edges())) / float(2212)
print(nx.density(subgraphs[0]))


[236]
0.557414104882
0.0444644789037

In [13]:
sixty_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.6))
subgraphs = list(nx.connected_component_subgraphs(sixty_percent_cut))
print([len(sub) for sub in subgraphs])


[198, 5, 2]

In [14]:
seventy_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.7))
subgraphs = list(nx.connected_component_subgraphs(seventy_percent_cut))
print([len(sub) for sub in subgraphs])


[167, 5, 2]

In [15]:
seventyfive_percent_cut = px.remove_edges(g.copy(), 0.2)
subgraphs = list(nx.connected_component_subgraphs(seventyfive_percent_cut))
print([len(sub) for sub in subgraphs])


[167, 5, 2]

In [16]:
eighty_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.8))
subgraphs = list(nx.connected_component_subgraphs(eighty_percent_cut))
print([len(sub) for sub in subgraphs])


[139, 5, 2]

In [17]:
ninety_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.9))
nx.write_gexf(ninety_percent_cut, "projections/ninety_percent_cut.gexf")
subgraphs = list(nx.connected_component_subgraphs(ninety_percent_cut))
print([len(sub) for sub in subgraphs])


[76, 4, 5, 2, 2]

In [18]:
ninetyone_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.91))
subgraphs = list(nx.connected_component_subgraphs(ninetyone_percent_cut))
print([len(sub) for sub in subgraphs])


[74, 4, 2, 2, 2]

In [19]:
ninetytwo_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.92))
subgraphs = list(nx.connected_component_subgraphs(ninetytwo_percent_cut))
print([len(sub) for sub in subgraphs])


[57, 4, 2, 12, 2]

In [20]:
ninetythree_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.93))
subgraphs = list(nx.connected_component_subgraphs(ninetythree_percent_cut))
print([len(sub) for sub in subgraphs])


[49, 4, 2, 12, 2]

In [21]:
ninetyfour_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.94))
subgraphs = list(nx.connected_component_subgraphs(ninetyfour_percent_cut))
print([len(sub) for sub in subgraphs])


[47, 4, 5, 4, 2]

In [22]:
ninetyfive_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.95))
nx.write_gexf(ninetyfive_percent_cut, "projections/ninetyfive_percent_cut.gexf")
subgraphs = list(nx.connected_component_subgraphs(ninetyfive_percent_cut))
print([len(sub) for sub in subgraphs])


[44, 4, 5, 4, 2]

In [23]:
ninetysix_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.96))
subgraphs = list(nx.connected_component_subgraphs(ninetysix_percent_cut))
print([len(sub) for sub in subgraphs])


[37, 4, 5, 4, 2]

In [24]:
ninetyseven_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.97))
subgraphs = list(nx.connected_component_subgraphs(ninetyseven_percent_cut))
print([len(sub) for sub in subgraphs])


[32, 5, 3]

In [25]:
ninetyeight_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.98))
subgraphs = list(nx.connected_component_subgraphs(ninetyeight_percent_cut))
print([len(sub) for sub in subgraphs])


[25, 4, 3, 2]

In [26]:
ninetynine_percent_cut = px.remove_edges(g.copy(), weight_sr.quantile(0.99))
nx.write_gexf(ninetynine_percent_cut, "projections/ninetynine_percent_cut.gexf")
subgraphs = list(nx.connected_component_subgraphs(ninetynine_percent_cut))
print([len(sub) for sub in subgraphs])


[18, 3, 2, 2]