【复杂网络python】有向加权网络紧密中心性计算(权重是否有影响).pdfVIP

  • 7
  • 0
  • 约3.62千字
  • 约 10页
  • 2023-08-04 发布于湖北
  • 举报

【复杂网络python】有向加权网络紧密中心性计算(权重是否有影响).pdf

【复杂⽹络python】有向加权⽹络紧密中⼼性计算 (权重是否有影响) 学习复杂⽹络陷⼊误区, 直在思考度中⼼性是否需要加权?误认为中⼼性指标仅计算了度 (⽆向⽹络中的度),没有考虑权重。结果忽略 了中⼼性指标都是基于最短路径计算的 (紧密中⼼性和中介中⼼性)。对此使⽤紧密中⼼性指标计算⽆权⽹络、加权⽹络、加权有向⽹络在 数据基本 致的情况,该项指标是否有计算权重。 、⽆向⽆权⽹络 ( )数据 1.节点数据 (节点数据没有变化) (2)边数据 (⽆权) (edge- 11.txt) (⼆)代码 import networkx as nx import matplotlib.pyplot as plt column1 = [] with open(node-9.txt,r as f : line = f.readline( # 读取 ⾏ while line: txt_data = eval(line # 可将字符串变为元组 column1.append(txt_data # 列表增加 line = f.readline( # 读取下 ⾏ #print(column1 edge = [] with open(edge-11.txt,r as f : line = f.readline( # 读取 ⾏ while line: txt_data = eval(line # 可将字符串变为元组 edge.append(txt_data # 列表增加 line = f.readline( # 读取下 ⾏ #print(edge G = nx.Graph( G.add_ nodes_from(column1 G.add_edges_from(edge nx.draw_ networkx(G,pos=nx.shell_ layout(G ,node_size=20,node_shape=o,width=1,style=solid,font_size=8 plt.show( #计算紧密中⼼度 (⽆权重⽆向) print(⽆权重⽆向Closeness centrality c = nx.closeness_centrality(G for v in G.nodes( : print(v, c[v] 结果 ⼆、⽆向加权⽹络 ( )数据 1.节点数据 (节点数据没有变化) (2)边数据 (加权) (edge- 10.txt) (⼆)代码 import networkx as nx import matplotlib.pyplot as plt column1 = [] with open(node-9.txt,r as f : line = f.readline( # 读取 ⾏ while line: txt_data = eval(line # 可将字符串变为元组 column1.append(txt_data # 列表增加 line = f.readline( # 读取下 ⾏ #print(column1 edge = [] with open(edge-10.txt,r as f : line = f.readline( # 读取 ⾏ while line: txt_data = eval(line # 可将字符串变为元组 edge.append(txt_data # 列表增加 line = f.readline( # 读取下 ⾏ #print(edge G = nx.Graph( G.add_ nodes_from(column1 G.add_weighted_edges_from(edge nx.draw_ networkx(G,pos=nx.shell_ layout(G ,node_size=20,node_shape=o,width=1,style=solid,font_size=8 plt.show( ####紧密中⼼性######### #计算紧密中⼼度 (有权重⽆向) print(⽆向加权C

文档评论(0)

1亿VIP精品文档

相关文档