### allow nodes to be in both half d-graph

parent e8a2652e
 ... ... @@ -12,7 +12,7 @@ def deconvolve(G,node): # Extract neighbors from the graph G_neighbors = nx.Graph(G.subgraph(neighbors)) communities = get_communities(G_neighbors) communities = get_communities(G_neighbors, node=="273:597_148") # Continue only if something need to be splited. if len(communities) == 1: ... ... @@ -33,26 +33,30 @@ def deconvolve(G,node): print("splitted into", len(communities), "parts\n") def get_communities(G): def get_communities(G, max_overlap=2, verbose=False): # Half d-graphs are cliques. So compute max cliques cliques = list(nx.find_cliques(G)) if verbose: for clq in cliques: print(clq, "\n") candidate_d_graphs = [] # d-graphs are composed of 2 cliques related by the current node. # The overlapp between the 2 cliques determine the node order in the d-graph. # The overlap between the 2 cliques determine the node order in the d-graph. for idx, clq1 in enumerate(cliques): to_compare = cliques[idx+1:] for clq2 in to_compare: # TO REMOVE : Temporary only check for distinct cliques jump = False # Test if d-graphs only if there are less than max overlapping nodes # between the two half overlap = 0 for val in clq1: if val in clq2: jump = True break if jump: continue # / TO REMOVE overlap += 1 if overlap > max_overlap: continue # Check for d-graph candidates d_graph = compute_d_graph(clq1, clq2, G) ... ... @@ -67,13 +71,13 @@ def get_communities(G): if len(minimal_d_graphes) == 0: return [list(G.nodes())] # TODO : !!! Concatenation not possible if the same node can be in both side communites = [d_graph+d_graph for d_graph in minimal_d_graphes] communites = [list(set(d_graph+d_graph)) for d_graph in minimal_d_graphes] return communites """ This function take two cliques in the graph G and try to find if they are 2 halfes of a d-graph. 1 - The algorithm compute overlapp between nodes from first clique to the second and from the """ This function take two cliques in the graph G and try to find if they are 2 halfes of a d-graph. 1 - The algorithm compute overlap between nodes from first clique to the second and from the second to the first. 2 - Filter the clique pairs that have less than n*(n-1)/2 traversing edges (necessary critera to be considered as d-graph). ... ... @@ -83,7 +87,7 @@ def get_communities(G): @param G the graph of the neighbors of the central node (not present). @return A pair of lists that are the 2 halves of the d-graph ordered from the center. """ def compute_d_graph(clq1, clq2, G): def compute_d_graph(clq1, clq2, G, verbose=False): # Compute the arities between the cliques arities1 = {name:0 for name in clq1} arities2 = {name:0 for name in clq2} ... ... @@ -107,19 +111,25 @@ def compute_d_graph(clq1, clq2, G): arities2[node2] += 1 sum_edges += 1 if verbose: print(clq1, clq2) print(arities1, arities2, "\n") # Reject if not enought edges if sum_edges < min_clq_size * (min_clq_size-1) / 2: return None # print(clq1, clq2) # print(arities1, arities2, "\n") # if verbose: # print(clq1, clq2) # print(arities1, arities2, "\n") # order lists lst1 = [key for key, value in sorted(arities1.items(), key=lambda tup: -tup)] lst2 = [key for key, value in sorted(arities2.items(), key=lambda tup: -tup)] # print(min_clq_size) # print(lst1, "\n", lst2, "\n") if verbose: print(min_clq_size) print(lst1, "\n", lst2, "\n") # Return the 2 halves of the d-graph return lst1, lst2 ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!