我有一个networkx
对象和一个pd.Series
对象形式的输入加热列表。我想计算当热量通过定向网络扩散时产生的热量。我在文档中找不到关于此的任何内容,因此我正在与社区联系。有办法计算吗?也许有另一个包裹?
可以使用哪些算法,其中包括:(1)节点属性的输入热量; (2)通过有向图连接节点的边缘权重?
我期望的是代表整体扩散的网络单个值,或者是每个终端节点通过网络扩散后的值。是否存在?
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# Construct graph
ebunch = [("input","y1", {"weight":1.0}),('y1', 'y3', {'weight': 0.00411138}), ('y1', 'y2', {'weight': 0.0421627}), ('y3', 'y4', {'weight': 0.0701581}), ('y3', 'attr_5', {'weight': 0.161067}), ('y2', 'attr_4', {'weight': 0.123016}), ('y2', 'attr_1', {'weight': 0.123016}), ('y4', 'attr_3', {'weight': 0.0909091}), ('y4', 'attr_2', {'weight': 0.0909091})]
graph = nx.DiGraph(name="test_network")
graph.add_edges_from(ebunch)
with plt.style.context("seaborn-white"):
fig, ax = plt.subplots()
nx.draw_networkx(graph, pos=nx.nx_agraph.graphviz_layout(graph, "dot", root="y1"), with_labels=True, node_size=1000, node_color="lightgray", ax=ax)
ax.set_title(graph.name, fontsize=15)
ax.axis("off")
# Synthesize test input heats
u = np.random.RandomState(0).randint(0,1000,size=5)
terminal_nodes = [*filter(lambda x: graph.out_degree(x)==0 and graph.in_degree(x)==1, graph.nodes())]
test_heat_input = pd.Series(u/u.sum(),index=terminal_nodes )
# attr_5 0.235943
# attr_4 0.192825
# attr_1 0.216971
# attr_3 0.066230
# attr_2 0.288030
# dtype: float64