Advertisement

matlab显示神经网络结构图,matlab画神经网络的结构 neural network

阅读量:

在作神经网络的一些东西,想通过权重看哪一个输入起的作用比较大。

0818b9ca8b590ca3270a3433284dd417.png

主程序:

复制代码
    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)];

else

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,'','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,['',mat2str(i)],'Interpreter','latex','FontSize',fon_siz_mm)

end

text( x_output(1) , y_output(end)+1,'','Interpreter','latex','FontSize',fon_siz_mm)

axis off

h=gcf;

set(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

全部评论 (0)

还没有任何评论哟~