Commit e8142332 authored by Yoann Dufresne's avatar Yoann Dufresne
Browse files

allow nodes to be in both half d-graph

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