Beispiel #1
0
def test_omega():
    Gl = nx.connected_watts_strogatz_graph(50, 6, 0, seed=rng)
    Gr = nx.connected_watts_strogatz_graph(50, 6, 1, seed=rng)
    Gs = nx.connected_watts_strogatz_graph(50, 6, 0.1, seed=rng)
    omegal = omega(Gl, niter=1, nrand=1, seed=rng)
    omegar = omega(Gr, niter=1, nrand=1, seed=rng)
    omegas = omega(Gs, niter=1, nrand=1, seed=rng)
    print("omegas, omegal, omegar")
    print(omegas, omegal, omegar)
    assert_true(omegal < omegas and omegas < omegar)
Beispiel #2
0
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)
Beispiel #3
0
def get_omega(nx_G):
    is_connected = nx.is_connected(nx_G)
    print("is connected :{}".format(is_connected))
    components = list(nx.connected_components(nx_G))
    print("count of cc:{}".format(len(components)))

    if len(components) == 1:
        G = nx_G
    else:
        G = nx.Graph()
        node2id = dict()
        for id, node in enumerate(components[0]):
            node2id[node] = id

        for node1 in components[0]:
            for node2 in nx_G.adj[node1]:
                G.add_edge(node2id[node1], node2id[node2])

    avg_cluster = nx.average_clustering(G)
    print("clustering coefficient:{:.5f}".format(avg_cluster))
    short_path_length = nx.average_shortest_path_length(G)
    print("average shortest path length:{:.5f}".format(short_path_length))

    print("computing omega...")
    omega = nx.omega(G, niter=1, nrand=1)
    print("omega={:.5f}".format(omega))
    return omega
    def print_small_world_measure(self):
        """ Computes the small-world measure and prints it. The small-world
         measure (omega) ranges between -1 and 1. Values close to 0 mean the
         graph features small-world characteristics. Values close to -1 mean the
         graph has a lattice shape whereas values close to 1 mean it is a random graph."""

        omega = nx.omega(self.graph)
        print("Small World Measure: " + str(omega))
Beispiel #5
0
    def compute_features(self):

        # omega metric
        self.add_feature(
            "omega",
            lambda graph: nx.omega(graph),
            "The small world coefficient omega",
            InterpretabilityScore(4),
        )
 def small_world_omega(self,graph):
     """
     Returns the small-world coefficient (omega) of a graph : omega = Lr/L - C/Cl
     where:
     C = average clustering coefficient
     L = average shortest path length of G
     Lr = the average shortest path length of an equivalent random graph
     Cl = the average clustering coefficient of an equivalent lattice graph
     """
     return nx.omega(graph)
Beispiel #7
0
        g_dic['Gen_type'].append(g_df['Gen_type'].unique()[0])
        g_dic['No. Nodes'].append(nx.number_of_nodes(temp_g))
        g_dic['No. Edges'].append(nx.number_of_edges(temp_g))
        g_dic['Density'].append(nx.density(temp_g))
        g_dic['Av. Degree'].append(round(sum(dict(temp_g.degree()).values())/float(nx.number_of_nodes(temp_g)), 2))
        g_dic['Degree Cent'].append(round(sum(dict(nx.degree_centrality(temp_g)).values())/float(nx.number_of_nodes(temp_g)), 2))
        g_dic['Node Conn'].append(nx.node_connectivity(temp_g))
        g_dic['Clustering'].append(nx.average_clustering(temp_g))
        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()