我正在编写一个基本的神经网络,并想将其绘制成图片。为此,我创建了我需要的所有节点和边。
for l, j in zip(self.layers, range(len(self.layers))):
for n, i in zip(l.neurons, range(len(l.neurons))):
fixed_positions[n.identifier] = (j, i)
for l in self.layers:
for n in l.neurons:
for c, w in zip(n.inconnections, n.inconnectionweights):
g.add_edge(n.identifier, c.identifier)
fixed_nodes = fixed_positions.keys()
pos = nx.spring_layout(g, pos=fixed_positions, fixed=fixed_nodes)
蓝点(想象它们在所有边缘上)是我想在边缘上添加标签的地方,但我不知道该怎么做。它应该适用于任何合理的网络大小,即它也适用于相应层中的 4、3 和 2 个神经元。
原文由 Eumel 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是一个在networkx中绘制边标签的例子,希望对你有帮助。