network_weights_picture_snn.m

来自「神经网络的工具箱, 神经网络的工具箱,」· M 代码 · 共 77 行

M
77
字号
function network_weights_picture_snn(net);%NETWORK_WEIGHTS_PICTURE_SNN Draw a picture of a net_struct neural%                            network.%% See also%%   NET_STRUCT_SNN%L = net.numLayers+1;units = zeros(1, L);for l = 1:L-1  units(l) = size(net.weights{l}, 2);endunits(L) = size(net.weights{L-1},1);maxw = max(max(abs(net.weights{1})));for l = 2:L-1    tmpmax = max(max(abs(net.weights{l})));    if (tmpmax > maxw)       maxw = tmpmax;    endendlimw = [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    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);  endnmax = 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    for u = 1:units(l)        for i = 1:units(l-1)	    if (abs(net.weights{l-1}(u,i)) < 1e-10)               cl = cm(1,:);	    else	       w = net.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(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 + -
显示快捷键?