network_w2_picture_snn.m
来自「神经网络的工具箱, 神经网络的工具箱,」· M 代码 · 共 108 行
M
108 行
function network_w2_picture_snn(net1, net2);%NETWORK_W2_PICTURE_SNN Draw picture of 2 combined neural networks.L = net1.numLayers+1;units = zeros(1, L);for l = 1:L-1 units(l) = size(net1.weights{l}, 2);endunits(L) = size(net1.weights{L-1},1);maxw = max(max(abs(net1.weights{1})));for l = 2:L-1 tmpmax = max(max(abs(net1.weights{l}))); if (tmpmax > maxw) maxw = tmpmax; endendmaxw = max(maxw, max(max(abs(net2.weights{L-1}))));limw = [0 maxw];cm = summer;m = size(cm,1);cla;set(gca, 'Units', 'normalized');hold on;%L = size(units, 2);dx = 0.9/(L-1);nmax = max(max(units),2);for l = 1:L-1 dy = 0.9/(sqrt(nmax*units(l))-1); x{l} = 0.5 + dx*(l - (L+1)/2); y{l} = 0.5 + dy*([1:units(l)] - (units(l)+1)/2); enddy = 0.5 * 0.9/(sqrt(nmax*units(L))-1);x{L} = 0.5 + dx*(L - (L+1)/2); yL1 = 0.25 + 0.5 + dy*([1:units(L)] - (units(L)+1)/2); yL2 = -0.25 + 0.5 + dy*([1:units(L)] - (units(L)+1)/2); nmax = max(max(units(1), units(L)), 2);y{1} = 0.5 + (0.9/(nmax - 1))*([1:units(1)] - (units(1)+1)/2);y{L} = 0.5 + (0.9/(nmax - 1))*([1:units(L)] - (units(L)+1)/2);for l = 2:L-1 for u = 1:units(l) for i = 1:units(l-1) if (abs(net1.weights{l-1}(u,i)) < 1e-10) cl = cm(1,:); else w = net1.weights{l-1}(u,i); cl = cm(ceil(abs(w/(limw(2)-limw(1))*m)),:); end if (w > 0) line([x{l}, x{l-1}], [y{l}(u), y{l-1}(i)], 'Color', cl); else line([x{l}, x{l-1}], [y{l}(u), y{l-1}(i)], 'Color', cl, ... 'LineStyle', '--'); end end draw_circle(x{l}, y{l}(u), 0.01, 0.01, 'r-'); endendfor u = 1:units(L) for i = 1:units(L-1) if (abs(net1.weights{L-1}(u,i)) < 1e-10) cl = cm(1,:); else w = net1.weights{L-1}(u,i); cl = cm(ceil(abs(w/(limw(2)-limw(1))*m)),:); end if (w > 0) line([x{L}, x{L-1}], [yL1(u), y{L-1}(i)], 'Color', cl); else line([x{L}, x{L-1}], [yL1(u), y{L-1}(i)], 'Color', cl, ... 'LineStyle', '--'); end if (abs(net2.weights{L-1}(u,i)) < 1e-10) cl = cm(1,:); else w = net2.weights{L-1}(u,i); cl = cm(ceil(abs(w/(limw(2)-limw(1))*m)),:); end if (w > 0) line([x{L}, x{L-1}], [yL2(u), y{L-1}(i)], 'Color', cl); else line([x{L}, x{L-1}], [yL2(u), y{L-1}(i)], 'Color', cl, ... 'LineStyle', '--'); end end draw_circle(x{L}, yL1(u), 0.01, 0.01, 'r-'); draw_circle(x{L}, yL2(u), 0.01, 0.01, 'r-');endfor u = 1:units(1) draw_circle(x{1}, y{1}(u), 0.01, 0.01, 'r-');endaxis([0 1 0 1]);axis('off');hold off;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?