function [ret1,ret2,ret3,ret4]=nnd11bc(cmd,arg1,arg2,arg3,arg4,arg5)
%NND11BC Backpropagation calculation demonstration.
%
% This demonstration requires the Neural Network Toolbox.
%
% NND11BC runs this demo.
%
% NND11BC('set',W1,b1,W2,b2)
% sets the network's weight and bias values.
%
% [W1,b1,W2,b2] = NND11BC('get')
% gets the network's weight and bias values.
% First Version, 8-31-95.
%==================================================================
% CONSTANTS
me = 'nnd11bc';
max_t = 0.5;
w_max = 10;
p_max = 2;
box_len = 40;
box_x = [0 1 1 0 0]*box_len;
box_y = [-1 -1 1 1 -1]*10;
pause_time = 1;
% FLAGS
change_func = 0;
% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); end
% FIND WINDOW IF IT EXISTS
fig = nnfgflag(me);
if length(get(fig,'children')) == 0, fig = 0; end
% GET WINDOW DATA IF IT EXISTS
if fig
H = get(fig,'userdata');
fig_axis = H(1); % window axis
desc_text = H(2); % handle to first line of text sequence
W1_ptr = H(3);
b1_ptr = H(4);
W2_ptr = H(5);
b2_ptr = H(6);
p_name = H(7);
W11_box = H(8);
W11_text = H(9);
W11_name = H(10);
W12_box = H(11);
W12_text = H(12);
W12_name= H(13);
b11_box = H(14);
b11_text = H(15);
b11_name = H(16);
b12_box = H(17);
b12_text = H(18);
b12_name = H(19);
a11_name = H(20);
a12_name = H(21);
W21_box = H(22);
W21_text = H(23);
W21_name = H(24);
W22_box = H(25);
W22_text = H(26);
W22_name = H(27);
b2_box = H(28);
b2_text = H(29);
b2_name = H(30);
a2_name = H(31);
t_name = H(32);
e_name = H(33);
vars = H(34+[0:10]);
vals = H(45+[0:10]);
fp1_marker = H(56);
fp2_marker = H(57);
fp3_marker = H(58);
bp1_marker = H(59);
bp2_marker = H(60);
W1_marker = H(61);
b1_marker = H(62);
W2_marker = H(63);
b2_marker = H(64);
p_marker = H(65);
t_marker = H(66);
state_ptr = H(67);
p_ptr = H(68);
a1_ptr = H(69);
a2_ptr = H(70);
e_ptr = H(71);
s1_ptr = H(72);
s2_ptr = H(73);
t_ptr = H(74);
go_button = H(75);
s11_name = H(76);
s12_name = H(77);
s2_name = H(78);
blip_ptr = H(79);
bloop_ptr = H(80);
blp_ptr = H(81);
state1 = H(82);
state2 = H(83);
state3 = H(84);
state4 = H(85);
go_box = H(86);
last_text = H(87);
p_edit = H(88);
state = get(state_ptr,'userdata');
blip = get(blip_ptr,'userdata');
bloop = get(bloop_ptr,'userdata');
blp = get(blp_ptr,'userdata');
end
%==================================================================
% Activate the window.
%
% ME() or ME('')
%==================================================================
if strcmp(cmd,'')
if fig
figure(fig)
set(fig,'visible','on')
else
feval(me,'init')
end
%==================================================================
% Close the window.
%
% ME() or ME('')
%==================================================================
elseif strcmp(cmd,'close') & (fig)
delete(fig)
%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================
elseif strcmp(cmd,'init') & (~fig)
% CHECK FOR NNT
if ~nntexist(me), return, end
% CONSTANTS
W1 = [-0.27; -0.41];
b1 = [-0.48; -0.13];
W2 = [0.09 -0.17];
b2 = [0.48];
%%%%%%%% Copied from NNDEMOF2
s2 = 'DESIGN';
s3 = 'Backpropagation Calculation';
s4 = '';
s5 = 'Chapter 11';
fig = nnbg(me);
set(fig,'nextplot','add')
H = get(fig,'userdata');
h1 = H(1);
text(25,380,'Neural Network', ...
'color',nnblack, ...
'fontname','times', ...
'fontsize',16, ...
'fontangle','italic', ...
'fontweight','bold');
text(135,380,s2, ...
'color',nnblack, ...
'fontname','times', ...
'fontsize',16, ...
'fontweight','bold');
text(415,380,s3,...
'color',nnblack, ...
'fontname','times', ...
'fontsize',16, ...
'fontweight','bold',...
'HorizontalAlignment','right');
nndrwlin([0 415],[365 365],4,nndkblue);
h2 = text(390,315,'',...
'color',nnblack, ...
'fontname','helvetica', ...
'fontsize',10);
text1 = h2;
for i=1:30
text2 = text(390,315-6*i,'',...
'color',nnblack, ...
'fontname','helvetica', ...
'fontsize',10);
set(text1,'userdata',text2);
text1 = text2;
end
set(text1,'userdata','end');
text(410,54,s4, ...
'color',nnblack, ...
'fontname','times', ...
'fontsize',12, ...
'fontweight','bold');
text(410,38,s5, ...
'color',nnblack, ...
'fontname','times', ...
'fontsize',12, ...
'fontweight','bold');
nndrwlin([410 501],[24 24],4,nndkblue);
set(fig,'userdata',[h1 h2])
set(fig,'color',nndkgray,'color',nnltgray)
%%%%%%%%
set(fig, ...
'windowbuttondownfcn',nncallbk(me,'down'), ...
'BackingStore','off');
H = get(fig,'userdata');
fig_axis = H(1);
desc_text = H(2);
% ICON
nndicon(11,458,363,'shadow')
% NETWORK POSITIONS
x1 = 30; % input
x2 = x1+85; % 1st layer sum
x3 = x2+70; % 1st layer transfer function
x4 = x3+125; % 2nd layer sum
x5 = x4+55; % 2nd layer transfer function
x6 = x5+50; % output
y1 = 305; % top neuron
y2 = y1-20; % input & output neuron
y3 = y1-40; % bottom neuron
sz = 15; % size of icons
wx = 50; % weight horizontal offset (from 1st layer)
wy = 40; % weight vertical offset (from middle)
% NETWORK INPUT
p_name = nndtext(x1-10,y2,'p');
set(p_name,'fontsize',10);
% TOP NEURON: WEIGHT
plot([x1 x1+20],[y2 y1],'linewidth',2,'color',nnred);
W11_box = fill(x1+20+box_x,y1+box_y,nnltgray,...
'linewidth',2,...
'edgecolor',nnred,...
'erasemode','none');
W11_text = nndtext(x1+20+box_len/2,y1,sprintf('%5.3f',W1(1)));
set(W11_text,'fontsize',10);
plot([x1+20+box_len x2-sz],[y1 y1],'linewidth',2,'color',nnred);
W11_name = nndtext(x2-wx,y2+wy,'W1(1,1)');
set(W11_name,'fontsize',10);
% TOP NEURON: BIAS
plot([x2 x2 x3],[y1+sz*2 y1 y1],'linewidth',2,'color',nnred);
b11_box = fill(x2-box_len/2+box_x,y1+sz*2+10+box_y,nnltgray,...
'linewidth',2,...
'edgecolor',nnred,...
'erasemode','none');
b11_text = nndtext(x2,y1+sz*2+10,sprintf('%5.3f',b1(1)));
set(b11_text,'fontsize',10);
b11_name = nndtext(x2+25,y1+sz*2+10,'b1(1)','left');
set(b11_name,'fontsize',10);
% TOP NEURON: BODY
nndsicon('sum',x2,y1,sz)
n11_name = nndtext(x2+sz+20,y1+10,'n1(1)');
set(n11_name,'fontsize',10);
nndsicon('logsig',x3,y1,sz)
s11_name = nndtext(x2+sz+75,y1+40,'s1(1)');
set(s11_name,'fontsize',10);
plot(x2+sz+[30 60],y1+[18 32],'--',...
'color',nnred,...
'linewidth',2,...
'erasemode','none')
a11_name = nndtext(x3+sz+20,y1+10,'a1(1)');
set(a11_name,'fontsize',10);
% BOTTOM NEURON: WEIGHT
plot([x1 x1+20],[y2 y3],'linewidth',2,'color',nnred);
W12_box = fill(x1+20+box_x,y3+box_y,nnltgray,...
'linewidth',2,...
'edgecolor',nnred,...
'erasemode','none');
W12_text = nndtext(x1+20+box_len/2,y3,sprintf('%5.3f',W1(2)));
set(W12_text,'fontsize',10);
plot([x1+20+box_len x2-sz],[y3 y3],'linewidth',2,'color',nnred);
W12_name = nndtext(x2-wx,y2-wy,'W1(2,1)');
set(W12_name,'fontsize',10);
% BOTTOM NEURON: BIAS
plot([x2 x2 x3],[y3-sz*2 y3 y3],'linewidth',2,'color',nnred);
b12_box = fill(x2-box_len/2+box_x,y3-sz*2-10+box_y,nnltgray,...
'linewidth',2,...
'edgecolor',nnred,...
'erasemode','none');
b12_text = nndtext(x2,y3-sz*2-10,sprintf('%5.3f',b1(2)));
set(b12_text,'fontsize',10);
b12_name = nndtext(x2+25,y3-sz*2-10,'b1(2)','left');
set(b12_name,'fontsize',10);
% BOTTOM NEURON: BODY
nndsicon('sum',x2,y3,sz)
n12_name = nndtext(x2+sz+20,y3-10,'n1(2)');
set(n12_name,'fontsize',10);
nndsicon('logsig',x3,y3,sz)
s12_name = nndtext(x2+sz+75,y3-40,'s1(2)');
set(s12_name,'fontsize',10)
评论0