Пример #1
0
 def connected_component_subgraphs(self, subgraph):
     return components.connected_component_subgraphs(
         subgraph._g.to_undirected(), copy=False)
    def cohesive_blocking(self,
                          G,
                          conn,
                          emb=0,
                          blocks=[],
                          i=0,
                          highest_conn=1):

        #get the node sets and a single minimal os cut
        A, B = self.get_node_sets(G)
        cut = self.get_os_cut(G, A, B)

        #if component has the highest conn seen so far, append to blocks
        if conn == highest_conn:
            blocks.append([G, conn, emb])

        #if the current graph component is complete, return that component,
        #its connectivity, and its nestedness
        if (conn == len(B)) or (conn == 0):
            # component terminated. Going back..
            return

        #create copy of current graph component before node removal
        G_original = G.copy()

        #remove the nodes in the cut
        for node in cut:
            if node in G.nodes():
                G.remove_node(node)

        #get all of the new components as a result of the removed cut
        comps = list(components.connected_component_subgraphs(G))

        #iterate over new components
        for c in comps:

            #get every component with the latest cut added back in
            removed_edges = self.get_removed_edges(c, cut, G_original)
            c.add_nodes_from(list(cut), bipartite=1)
            c.add_edges_from(removed_edges)

            #remove pendants chains
            to_remove = self.get_pendants(c)

            while to_remove:
                for n in to_remove:
                    c.remove_node(n)
                to_remove = self.get_pendants(c)

            A, B = self.get_node_sets(c)
            cur_conn = self.get_os_conn(c, A, B)

            #Recurse:
            #if current component has a higher connectivity that all of its
            #ancestors, increase embeddedness and append to parents list.
            #Otherwise, just recurse normally
            if cur_conn > highest_conn:
                self.parents.append(G_original)
                self.cohesive_blocking(c, cur_conn, emb + 1, blocks, i + 1,
                                       cur_conn)
            else:
                self.cohesive_blocking(c, cur_conn, emb, blocks, i + 1,
                                       highest_conn)

        return blocks
Пример #3
0
def get_cc(G):
    cc = connected_component_subgraphs(G)
    cc_list = list(cc)
    print("cc completed")
    return cc_list
Пример #4
0
 def connected_component_subgraphs(self, subgraph):
     return components.connected_component_subgraphs(
         subgraph._g.to_undirected(), copy=False)
Пример #5
0
    # return gt_stats.vertex_hist(g, gt.pagerank(g))
    return gt.pagerank(g).get_array()

def variance(g):
    degree_hist = gt_stats.vertex_hist(g, 'total')[0] / g.num_vertices()
    second_m = np.sum(degree_hist * (np.arange(len(degree_hist)) ** 2))
    return second_m - avg_degree(g) ** 2

if __name__ == '__main__':
    nx_g = barabasi_albert_graph(int(1e3), 2)
    nx_apl = average_shortest_path_length(nx_g)
    nx_ad = 2 * nx_g.number_of_edges() / nx_g.number_of_nodes()
    nx_gcc = transitivity(nx_g)
    nx_lcc = average_clustering(nx_g)
    nx_md = len(degree_histogram(nx_g)) - 1
    nx_drogc = max(connected_component_subgraphs(nx_g), key=len).number_of_nodes() / nx_g.number_of_nodes()
    second_m = np.sum(np.array(degree_histogram(nx_g)) * (np.arange(len(degree_histogram(nx_g))) ** 2))
    nx_v = math.sqrt(second_m - nx_ad ** 2)
    nx_ap = degree_pearson_correlation_coefficient(nx_g)
    nx_aknn = np.flip(np.array(
        [it[1] for it in sorted(
            average_degree_connectivity(nx_g).items(), reverse=True
        )]
    ))

    nx_dh = np.array(degree_histogram(nx_g)) / nx_g.number_of_nodes()
    nx_cdh = np.flip(np.flip(
        (np.array(degree_histogram(nx_g)) / nx_g.number_of_nodes())
        , 0
    ).cumsum(),0)