matlab画神经网络的结构 neural network

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



主程序:</p><p></p><p><pre name="code" class="html">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,'$$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;
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




  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值