print(adjac) print(Z) new_graph.add_edges_from(adjac) # Draw the resulting graph nx.draw(new_graph, with_labels=True, font_weight='bold') S = [6, 7, 13] T = [4, 15, 8, 14, 3, 11, 1, 10, 0] # Conductance sumOfCond = [] for i in range(len(cluster)): sumOfCond.append(conductance(new_graph, cluster[i])) condScoreS = conductance(new_graph, S) condScoreT = conductance(new_graph, T) overallCond = min(sumOfCond) # Modularity Communities barbMod = list(greedy_modularity_communities(new_graph)) # Modularity Score barbModScore = qu.modularity(new_graph, barbMod) # edge_betweenness_centrality barbedgeBetweenness = nx.edge_betweenness_centrality(new_graph, None, False) barbaverageEdge = sum(barbedgeBetweenness.values()) / len(barbedgeBetweenness) barbtotalEdge = sum(barbedgeBetweenness.values())
barbaverageEdge = sum( barbedgeBetweenness.values()) / len(barbedgeBetweenness) barbtotalEdge = sum(barbedgeBetweenness.values()) print("\n") print("\n") print("Scores for Cut Distance: ", cutDistance[a]) print("\n") # print sets of nodes, one for each community. print("Communities: ", barbMod) print("\n") # Modularity Score print("Modularity: ", barbModScore) print("\n") # Conductance Score sumOfCond = [] for i in range(len(clusterL)): if clusterL[i] == []: # catch Division by zero continue # calculate Cond for current Cluster in list of Clusters currentCond = conductance(new_graph, clusterL[i]) sumOfCond.append(currentCond) print("Conductance for: ", clusterL[i], " = ", currentCond) overallCond = min(sumOfCond) print("Overall Conductance: ", overallCond) print("\n") # edge_betweenness_centrality print("Edge Betweenness Centrality Score: ", barbaverageEdge)
from networkx.algorithms.cuts import conductance from networkx.algorithms.community import quality as qu # barbell_graph barb = nx.barbell_graph(4, 0) nx.draw(barb, with_labels=True, font_weight='bold') S = [0, 1, 2, 3] T = [4, 5, 6, 7] cluster = [[0, 1, 2, 3], [4, 5, 6, 7]] # Conductance sumOfCond = [] for i in range(len(cluster)): sumOfCond.append(conductance(barb, cluster[i])) condScoreS = conductance(barb, S) condScoreT = conductance(barb, T) overallCond = min(sumOfCond) # Modularity Communities barbMod = list(greedy_modularity_communities(barb)) # Modularity Score barbModScore = qu.modularity(barb, barbMod) # edge_betweenness_centrality barbedgeBetweenness = nx.edge_betweenness_centrality(barb, None, False) barbaverageEdge = sum(barbedgeBetweenness.values()) / len(barbedgeBetweenness) barbtotalEdge = sum(barbedgeBetweenness.values())
# Modularity Score print("Modularity: ", ModScore) print("\n") modularityEnsemble.update({cutDistance[a]: ModScore}) # Conductance Score sumOfCond = [] for i in range(len(clusterL)): if clusterL[i] == []: # catch Division by zero continue if nx.volume(original_graph, clusterL[i]) == 0: continue # calculate Cond for current Cluster in list of Clusters currentCond = conductance(original_graph, clusterL[i]) sumOfCond.append(currentCond) print("Conductance for: ", clusterL[i], " = ", currentCond) overallCond = min(sumOfCond) print("Overall Conductance: ", overallCond) print("\n") conductanceEnsemble.update({cutDistance[a]: overallCond}) # edge betweenness centrality Score print("Edge Betweenness Centrality Score: ", averageEdge) print("Edge Betweenness Centrality Score: ", totalEdge) edgeEnsemble.update({cutDistance[a]: totalEdge}) bestModCut = max(modularityEnsemble, key=modularityEnsemble.get)
# Draw the resulting graph nx.draw(my_graph, with_labels=True, font_weight='bold') # Modularity Communities c = list(greedy_modularity_communities(my_graph)) # Modularity Score modScore = qu.modularity(my_graph, c) # Conductance # S (sequence) – A sequence of nodes in my_graph. # T (sequence) – A sequence of nodes in my_graph. S = [0, 1] T = [2, 3, 4] condScore = conductance(my_graph, S, T) # edge_betweenness_centrality edgeBetweenness = nx.edge_betweenness_centrality(my_graph) averageEdge = sum(edgeBetweenness.values()) / len(edgeBetweenness) totalEdge = sum(edgeBetweenness.values()) # print sets of nodes, one for each community. print("Communities: ", c) # Modularity Score print("Modularity: ", modScore) # Conductance Score print("Conductance: ", condScore)
import networkx.algorithms.cuts as cuts import networkx.algorithms.community as community # Generally, the lower value of # conductance the better quality the cluster is (Cai 2011). conductance_list_M = [] part_set_M = [] for i in range(len(prS_modified)): p = i while p < len(prS_modified): conductance_list_M.append( cuts.conductance(G2, prS_modified[i], prS_modified[p])) p += 1 conductance_list = [] for i in range(len(prS)): p = i + 1 while p < len(prS): conductance_list.append( cuts.conductance(G2, prS[i], prS[p])) p += 1 print(sum(conductance_list_M)) print(sum(conductance_list))