matlab显⽰神经⽹络结构图,matlab画神经⽹络的结构
neuralnetwork
在作神经⽹络的⼀些东西,想通过权重看哪⼀个输⼊起的作⽤⽐较⼤。
主程序:
clear all
clc
clf
%% outline
% plot network topology
% -------------------------------
% inputs :
% 01 : n_layer,
% 02 : connect relationship
% 03 : hidden layer weights
醉卧沙场君莫笑% 04 : certain input
% -------------------------------
% outputs :
% 01 : figure handle
%% main
% -------------------------------
% ann topology sturcture.
n_input = 20;
n_hidden = [ 16 10 6];
n_output = 3;
fon_siz_mm = 20;
n_hid = length(n_hidden);
thre_val=0.8;
n_layer = [ n_input n_output n_hidden ];
h_mean = (max(n_layer) + 1) /2 ;
% -------------------------------
wei_mat{1} = rand(n_input,n_hidden(1));
for i= 1 : (n_hid-1)
wei_mat{i+1} = rand(n_hidden(i),n_hidden(i+1));
end
wei_mat{n_hid+1}= rand(n_hidden(n_hid),n_output) ;
x_input=ones(n_input,1);
y_input=[1:n_input]-n_input/2-0.5+h_mean;
for i=1:n_hid
x_hid=(1+i)*ones(n_hidden(i),1);
if n_hidden(i)==max(n_layer)
y_hid=[1:n_hidden(i)];
el
y_hid=[1:n_hidden(i)]-n_hidden(i)/2-0.5+h_mean;
end
x_hid_mat{i}=x_hid;
y_hid_mat{i}=y_hid;
% plot(x_hid,y_hid,'o','MarkerSize',30);
end
x_output = length(n_layer)*ones(n_output,1);
y_output = [1:n_output]-n_output/2-0.5+h_mean;钢铁侠的简笔画
x1 = x_input';
y1 = y_input;
x2 = x_hid_mat{1}';
y2 = y_hid_mat{1};
wei = wei_mat{1};
col_mm=cool(n_input);
thre = 0.6;
hold on
[ h ] = fun_plot_layer_mm( x1,y1,x2,y2,wei,col_mm,thre); for k=1:(n_hid-1)
x1=x_hid_mat{k}';
y1=y_hid_mat{k};
x2=x_hid_mat{k+1}';
y2=y_hid_mat{k+1};
wei=wei_mat{k+1};
col_mm=winter(n_hidden(k));
size(col_mm)
[ h ] = fun_plot_layer_mm( x1,y1,x2,y2,wei,col_mm,thre);
end
col_mm=winter(n_hidden(end));
x1=x_hid_mat{end}';
y1=y_hid_mat{end};
x2=x_output';
y2=y_output;
wei=wei_mat{4};
[ h ] = fun_plot_layer_mm( x1,y1,x2,y2,wei,col_mm,thre);
col_mm=autumn(n_output);
[ h ] = fun_plot_node_mm(x_output',y_output,col_mm);
% for k=1:n_output
% plot(x_output(k),y_output(k),'o','MarkerSize',30,'MarkerFaceColor',col_mm(k,:))
% end
axis([0 6 0 max(n_layer)+3])测试工程师职责
text( x_input(1) , y_input(end)+1,'$$Input$$','Interpreter','latex','FontSize',fon_siz_mm)
for i = 1 : (n_hid)
tm=x_hid_mat{i};x_str=tm(1);
tm=y_hid_mat{i};y_str=tm(end);
text( x_str ,y_str+1,['$$Hidden \, Layer $$',mat2str(i)],'Interpreter','latex','FontSize',fon_siz_mm) end
text( x_output(1) , y_output(end)+1,'$$Output$$','Interpreter','latex','FontSize',fon_siz_mm)
axis off
h=gcf;
t(h, 'Position', [100, 100, 1024, 800]);
fig_na=['fig_network_topology_structure'];
雪橇狗
fun_work_li_035_myfig_out(h,fig_na,3);
%% logs
% mod : 2015年 08⽉ 08⽇ 星期六 10:16:55 CST
函数01.
fun_plot_layer_mm.m
function [ h ] = fun_plot_layer_mm( x1,y1,x2,y2,wei,col_mm,thre)
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
n_in = length(x1);
n_out = length(x2);郁金香属
for i=1:n_in
龙舟比赛wei_col= wei(i,:);
size(wei_col);
size(x2);
arrayfun(@(x2_var,y2_var,wei_var)...
line([x1(i) x2_var],[y1(i) y2_var],...
如何灭蟑螂'linewidth',1+2*wei_var,'color',col_mm(i,:)),...
x2,y2,wei_col);
% line([x1(i) x2(j)],[y1(i) y2(j)],...
% 'linewidth',1+2*wei(i,j),...
% 'color',col_mm(i,:));
% end
% end
end
h=fun_plot_node_mm(x1,y1,col_mm);
end
fun02。画节点
fun_plot_node_mm.m
function [ h ] = fun_plot_node_mm(x1,y1,col_mm)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
size(x1')
size(y1')
arrayfun(@(x,y,colr,colg,colb)plot(x,y,'o','MarkerSize',30,... 'MarkerFaceColor',[colr colg colb]),...
x1',y1',col_mm(:,1),col_mm(:,2),col_mm(:,3));
淘宝新风尚
h=gcf;
end