【发布时间】:2018-08-14 03:10:54
【问题描述】:
我正在尝试在 MLP 网络中绘制特定的权重连接。我想要实现的是
简单的 graphviz 绘制 倾斜 图表 w.r.t.绘制边缘
from graphviz import Graph
graph = Graph(directory='graphs', format='png',
graph_attr=dict(ranksep='2', rankdir='LR', color='white', splines='line'),
node_attr=dict(label='', shape='circle', width='0.1'))
def draw_cluster(name, length):
with graph.subgraph(name=f'cluster_{name}') as c:
c.attr(label=name)
for i in range(length):
c.node(f'{name}_{i}')
draw_cluster('input', 10)
draw_cluster('output', 4)
source_active = [0, 1, 2, 3]
sink_active = [2, 3]
for i_input in source_active:
for i_output in sink_active:
graph.edge(f'input_{i_input}', f'output_{i_output}')
graph.view()
如果我在未连接的权重之间添加不可见的边,我会强制我的图形居中。
for i_input in set(range(10)).difference(source_active):
for i_output in set(range(4)).difference(sink_active):
graph.edge(f'input_{i_input}', f'output_{i_output}', style='invis')
但是要付出什么代价!我的层可以有超过 1000 个神经元,只有几十个连接。或许networkx能帮上忙,我没玩过。
对我没有帮助的类似问题:
【问题讨论】:
-
使用networkx,您可以创建字典
pos,以便pos[node]是node的(x,y)坐标。然后用nx.draw(G, pos)画出来。