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()))
In [6]:
g = list(nx.connected_component_subgraphs(g))[0]
In [7]:
print(len(g), len(g.edges()))
In [8]:
weight_sr = pd.Series([attrs["weight"] for s, t, attrs in g.edges(data=True)])
weight_sr.describe()
Out[8]:
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]:
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]))
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])
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])
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]))
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])
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])