def analyze_small_world(): # Small-world sigma = nx.sigma(G) omega = nx.omega(G) table = prettytable.PrettyTable(['sigma', 'omega']) table.add_row([sigma, omega]) print(table)
def small_world_sigma(self,graph): """ Returns the small-world coefficient (sigma) of the given graph. sigma = C/Cr / L/Lr where: C = the average clustering coefficient L = the average shortest path length of G Cr = the average clustering coefficient Lr = average shortest path length of an equivalent random graph. """ return nx.sigma(graph)
def test_sigma(): Gs = nx.connected_watts_strogatz_graph(50, 6, 0.1, seed=rng) Gr = nx.connected_watts_strogatz_graph(50, 6, 1, seed=rng) sigmas = sigma(Gs, niter=1, nrand=2, seed=rng) sigmar = sigma(Gr, niter=1, nrand=2, seed=rng) assert_true(sigmar < sigmas)
def test_sigma(): Gs = nx.connected_watts_strogatz_graph(100, 6, 0.1) Gr = nx.connected_watts_strogatz_graph(100, 6, 1) sigmas = sigma(Gs, niter=1, nrand=2) sigmar = sigma(Gr, niter=1, nrand=2) assert_true(sigmar < sigmas)
import pandas as pd import networkx as nx actors_edges = pd.read_csv('actor_edge.csv') # actors_nodes = pd.read_csv('actor_nodes.csv') #init Graph G = nx.Graph() G = nx.from_pandas_edgelist(actors_edges, "Source", "Target") #betweenness centrality bet_centrality = nx.betweenness_centrality(G, k=1000) #small-world sigma = nx.sigma(G) print("Small world sigma is " + sigma)
g_dic['Clustering_W'].append(nx.average_clustering(temp_g, weight = 'STTC_rec')) if nx.is_connected(temp_g) == True: g_dic['Char Path'].append(nx.average_shortest_path_length(temp_g)) g_dic['Char Path_w'].append(nx.average_shortest_path_length(temp_g, weight = 'STTC_rec')) g_dic['Global Eff'].append(nx.global_efficiency(temp_g)) g_dic['Major C'].append(nx.number_of_nodes(temp_g)/nx.number_of_nodes(temp_g)*100) g_dic['Sigma'].append(nx.(temp_g)) g_dic['Omega'].append(nx.omega(temp_g)) else: print(ii, 'is not connected') Gc = max(nx.connected_component_subgraphs(temp_g), key=len) g_dic['Char Path'].append(nx.average_shortest_path_length(Gc)) g_dic['Char Path_w'].append(nx.average_shortest_path_length(Gc, weight = 'STTC_rec')) g_dic['Global Eff'].append(nx.global_efficiency(Gc)) g_dic['Major C'].append(nx.number_of_nodes(Gc)/nx.number_of_nodes(temp_g)*100) g_dic['Sigma'].append(nx.sigma(Gc)) g_dic['Omega'].append(nx.omega(Gc)) g_df = pd.DataFrame(g_dic) g_df = g_df.drop(24) # outlier, only 10 nodes # PROPORTION OF CONNECTED AND FRAGMENTED GRPAHS wt_con = g_df['Gen_type'][(g_df['Major C']== 100) & (g_df['Gen_type'] == 'WT')].count() wt_disc = g_df['Gen_type'][(g_df['Major C']< 100) & (g_df['Gen_type'] == 'WT')].count() ko_con = g_df['Gen_type'][(g_df['Major C']== 100) & (g_df['Gen_type'] == 'KO')].count() ko_disc = g_df['Gen_type'][(g_df['Major C']< 100) & (g_df['Gen_type'] == 'KO')].count() cont_tab = np.array([[wt_con, wt_disc], [ko_con, ko_disc]]) sp.stats.fisher_exact(cont_tab) disconnected_Nxs = (g_df['Gen_type'][(g_df['Major C']< 100) & (g_df['Gen_type'] == 'WT')].count()/g_df['Gen_type'][g_df['Gen_type'] == 'WT'].count()).round(2), (g_df['Gen_type'][(g_df['Major C']< 100) & (g_df['Gen_type'] == 'KO')].count()/g_df['Gen_type'][g_df['Gen_type'] == 'KO'].count()).round(2)