社区检测 Louvain 算法的模块化在添加边缘权重时不会改变

问题描述

当向我的图中添加边权重时,与没有边权重相比,Louvain 算法的模块化分数不会改变(它保持在大约 0.8)。我将权重计算为连接节点之间的欧几里德相似度分数,因此它们的范围在 0 到 1 之间。

我对社区检测很陌生,那么可能是什么导致了这个问题?

编辑:

import community
import networkx as nx 
from community import best_partition
from community import modularity

#Reduced dictionary explanation: the key(eg. BIDU) is one node,#the nested key(eg: 865326452400504832) is the second node,#and the value is the edge weight computed as the average 
#Euclidean similarity (based on a feature vector) of the
# nested key with all other nested keys within the same 
#key(eg.0.7885422115698439 = vector similarity between 865326452400504832 and 865326457001697280)

similarity_reduced = {"BIDU": {865326452400504832: 0.7885422115698439,865326457001697280: 0.7885422115698439},'JD':{865326452400504832: 0.6138829308835345,865326457001697280: 0.6259871779548237,869811004955389952: 0.4513278972685143},'TCEHY':{865326452400504832: 0.6020128491158321,865326457001697280: 0.6078782014152254,869528165076447232: 0.42134883896121356}}

  
def create_graph():
  G = nx.Graph()
  for keys,values in similarity_reduced.items():
    G.add_node(keys)
    for key,value in values.items():
      G.add_edge(keys,key,weight = value)
      if key in G.nodes():
          continue
      else :
          G.add_node(key)
  return G

G = create_graph()
nx.set_node_attributes(G,attributes)
print(nx.info(G))

Returns:
Name: 
Type: Graph
Number of nodes: 7
Number of edges: 8
Average degree:   2.2857

#These are all the edges in the graph
list(G.edges(data=True))

Returns:
"[('BIDU',865326452400504832,{'weights': 0.7885422115698439}),('BIDU',865326457001697280,(865326452400504832,'JD',{'weights': 0.6138829308835345}),'TCEHY',{'weights': 0.6020128491158321}),(865326457001697280,{'weights': 0.6259871779548237}),{'weights': 0.6078782014152254}),('JD',869811004955389952,{'weights': 0.4513278972685143}),('TCEHY',869528165076447232,{'weights': 0.42134883896121356})]
"

partitions = best_partition(G,weight="weight")
mod = modularity(partitions,G,weight="weight")
mod
Returns:
"0.1484375"

´´´

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)