Académique Documents
Professionnel Documents
Culture Documents
function nnd2n1(cmd,arg1,arg2,arg3)
%NND2N1 One-input neuron demonstration.
%
% This demonstration requires either the MININNET functions
% on the NND disk or the Neural Network Toolbox.
% $Revision: 1.7 $
% Copyright 1994-2002 PWS Publishing Company and The MathWorks, Inc.
% First Version, 8-31-95.
%==================================================================
% CONSTANTS
me = 'nnd2n1';
max_t = 0.5;
w_max = 2;
p_max = 4;
% FLAGS
change_func = 0;
% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); 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('')
%==================================================================
%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================
% CONSTANTS
w = 1;
b = 0;
p = 0;
f = 'purelin';
n = w*p+b;
a = feval(f,n);
title_str = 'Neuron Model Demonstration';
chapter_str = 'Chapter 2';
a_lim = [-2 2];
P = [-p_max:0.1:p_max];
[R,Q] = size(P);
A = feval(f,w*P+b*ones(1,Q));
ind = find(A >= -p_max & A <= p_max);
P = P(ind);
A = A(ind);
% ICON
nndicon(2,458,363,'shadow')
% NEURON DIAGRAM
x = 60;
y = 340;
plot(x+[0 100],y-[50 50],...
'linewidth',4,...
'color',nnred);
plot(x+[100 100],y-[49 91],...
'linewidth',4,...
'color',nnred);
nndicon(100,x+100,y-50)
plot(x+[125 185],y-[50 50],...
'linewidth',4,...
'color',nnred);
plot(x+[200 250],y-[50 50],...
'linewidth',4,...
'color',nnred);
plot(x+[240 250 240],y-[40 50 60],...
'linewidth',4,...
'color',nnred);
nndicon(101,x+200,y-50)
fill(x+[90 110 110 90],y-[115 115 95 95],nnltyell,...
'edgecolor',nndkblue)
text(x+101,y-106,'1',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center');
text(x-10,y-50,'p',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center',...
'erasemode','none');
text(x+40,y-40,'w',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center',...
'erasemode','none');
text(x+115,y-85,'b',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center',...
'erasemode','none');
text(x+265,y-50,'a',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center',...
'erasemode','none');
deg = pi/180;
angle = [0:5:90]*deg;
xc = cos(angle)*10;
yc = sin(angle)*10;
plot(x-20-xc,y-20+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[-20 0],y-[10 10],...
'linewidth',3,...
'color',nndkblue);
plot(x+xc,y-20+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x-20-xc,y-115-yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[-20 0],y-[125 125],...
'linewidth',3,...
'color',nndkblue);
plot(x+xc,y-115-yc,...
'linewidth',3,...
'color',nndkblue);
text(x-10,y+5,'Input',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center');
plot(x+30-xc,y-20+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[30 280],y-[10 10],...
'linewidth',3,...
'color',nndkblue);
plot(x+280+xc,y-20+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+30-xc,y-115-yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[30 280],y-[125 125],...
'linewidth',3,...
'color',nndkblue);
plot(x+280+xc,y-115-yc,...
'linewidth',3,...
'color',nndkblue);
f_text = text(x+155,y+5,'Linear Neuron: a = purelin(w*p+b)',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center',...
'erasemode','none');
% PARAMETERS
y = 160;
x = 40;
text(x+40,y-100,'F:',...
'fontname','helvetica',...
'fontweight','bold',...
'color',nndkblue,...
'horiz','center',...
'fontsize',12)
w_axis = nnsfo('a2','w','','');
set(w_axis, ...
'units','points',...
'position',[x y 70 20],...
'color',nnmdgray,...
'ylim',[-0.3 1.3],...
'ytick',[],...
'xlim',[-1.3 1.3]*w_max,...
'xtick',[-1 -0.5 0 0.5 1]*w_max,...
'xticklabel',str2mat(num2str(-w_max),'','0','',num2str(w_max)))
b_axis = nnsfo('a2','b','','');
set(b_axis, ...
'units','points',...
'position',[x y-65 70 20],...
'color',nnmdgray,...
'ylim',[-0.3 1.3],...
'ytick',[],...
'xlim',[-1.3 1.3]*w_max,...
'xtick',[-1 -0.5 0 0.5 1]*w_max,...
'xticklabel',str2mat(num2str(-w_max),'','0','',num2str(w_max)))
% NEURON FUNCTION
y = 40;
x = 200;
a_axis = nnsfo('a2','','p','a');
set(get(a_axis,'xlabel'),...
'fontsize',12)
set(get(a_axis,'ylabel'),...
'fontsize',12)
set(a_axis, ...
'units','points',...
'position',[x y 140 140],...
'color',nnltyell,...
'xlim',[-1.05 1.05]*p_max,...
'xtick',[-4 -2 0 2 4],...
'ylim',[-1.05 1.05]*p_max,...
'ytick',[-4 -2 0 2 4])
cross = plot([-p_max p_max NaN 0 0],[0 0 NaN -p_max p_max],':',...
'color',nndkblue,...
'erasemode','none');
p_line = plot([p p],[-p_max p_max],'--',...
'color',nnred,...
'erasemode','none');
a = feval(f,w*p+b);
a_line = line([-p_max p],[a a],...
'color',nnred,...
'erasemode','none');
A_line = line(P,A,...
'color',nndkblue,...
'erasemode','none',...
'linewidth',2);
p_axis = nnsfo('a2','','','');
set(p_axis, ...
'units','points',...
'position',[x y+140 140 15],...
'color',nnltyell,...
'xlim',[-1.05 1.05]*p_max,...
'xtick',[-4 -2 0 2 4],...
'ylim',[-0.1 1.1],...
'ytick',[])
axis('off')
p_ind = fill([0 0.125 -0.125]*p_max+p,[0 1 1],nnred,...
'edgecolor',nndkblue,...
'erasemode','none');
% BUTTONS
drawnow % Let everything else appear before buttons
uicontrol(...
'units','points',...
'position',[400 110 60 20],...
'string','Contents',...
'callback','nndtoc')
uicontrol(...
'units','points',...
'position',[400 75 60 20],...
'string','Close',...
'callback',[me '(''close'')'])
% DATA POINTERS
meters = [w_axis b_axis p_axis a_axis];
indicators = [w_ind b_ind p_ind];
lines = [p_line a_line A_line];
w_ptr = uicontrol('visible','off'); set(w_ptr,'userdata',w);
b_ptr = uicontrol('visible','off'); set(b_ptr,'userdata',b);
f_ptr = uicontrol('visible','off'); set(f_ptr,'userdata',f);
p_ptr = uicontrol('visible','off'); set(p_ptr,'userdata',p);
% INSTRUCTION TEXT
feval(me,'instr');
% LOCK WINDOW
set(fig,...
'nextplot','new',...
'color',nnltgray);
nnchkfs;
%==================================================================
% Display the instructions.
%
% ME('instr')
%==================================================================
%==================================================================
% Respond to mouse down.
%
% ME('down')
%==================================================================
q = 0;
for i=1:3
pt = get(meters(i),'currentpoint');
x = pt(1);
y = pt(3);
if (i <= 2)
if (x >= -1.3*w_max) & (x <= 1.3*w_max) & (y >= 0) & (y <= 1)
q = i;
z_max = w_max;
z = x;
hide_color = nnmdgray;
width = 0.2;
break;
end
else
if (x >= -1.1*p_max) & (x <= 1.1*p_max) & (y >= 0) & (y <= 1)
q = i;
z_max = p_max;
z = x;
hide_color = nnltgray;
width = 0.125;
break;
end
end
end
if (q)
set(fig,'pointer','crosshair')
z = min(z_max,max(-z_max,z));
set(indicators(q),...
'facecolor',hide_color,...
'edgecolor',hide_color)
set(indicators(q),...
'xdata',[0 1 -1]*width*z_max+z,...
'facecolor',nnred,...
'edgecolor',nndkblue)
set(fig,'WindowButtonMotionFcn',[me '(''down'')']);
set(fig,'WindowButtonUpFcn',[me '(''up'')']);
% ALTER VARIABLES
if (q == 1)
set(w_ptr,'userdata',z);
change_func = 1;
elseif (q == 2)
set(b_ptr,'userdata',z);
change_func = 1;
else
set(p_ptr,'userdata',z);
end
cmd = 'update';
else
set(fig,'pointer','arrow')
end
%==================================================================
% Respond to mouse up.
%
% ME('up')
%==================================================================
set(fig,...
'WindowButtonMotionFcn','',...
'pointer','arrow')
%==================================================================
% Respond to function menu.
%
% ME('function')
%==================================================================
v = get(f_menu,'value');
%==================================================================
end
%==================================================================
% Respond to request to update displays.
%
% ME('update')
%==================================================================
if strcmp(cmd,'update') & (fig)
% GET DATA
w = get(w_ptr,'userdata');
b = get(b_ptr,'userdata');
f = get(f_ptr,'userdata');
p = get(p_ptr,'userdata');
% UPDATE OUTPUT
n = w*p+b;
if strcmp(f,'satlin')
a = (~((n < 0) | (n > 1))).*n + (n > 1);
elseif strcmp(f,'satlins')
a = (~((n < -1) | (n > 1))).*n + (n > 1) - (n < -1);
else
a = feval(f,n);
end
% HIDE LINES
set(lines(1:2),...
'color',nnltyell)
% $Revision: 1.7 $
% Copyright 1994-2002 PWS Publishing Company and The MathWorks, Inc.
% First Version, 8-31-95.
%==================================================================
% CONSTANTS
me = 'nnd2n2';
max_t = 0.5;
w_max = 2;
p_max = 1;
n_max = 6;
a_max = 6;
% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); 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('')
%==================================================================
%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================
% CONSTANTS
w = [0.5 -0.5]*w_max;
b = [0];
p = [0; 0];
f = 'purelin';
n = w*p+b;
a = feval(f,n);
title_str = 'Neuron Model Demonstration';
chapter_str = 'Chapter 2';
% ICON
nndicon(2,458,363,'shadow')
% NEURON DIAGRAM
x = 60;
y = 230;
plot(x+[0 100 0],y-[0 50 100],...
'linewidth',4,...
'color',nnred);
plot(x+[100 100],y-[49 112],...
'linewidth',4,...
'color',nnred);
nndicon(100,x+100,y-50)
plot(x+[125 136],y-[50 50],...
'linewidth',4,...
'color',nnred);
plot(x+[160 185],y-[50 50],...
'linewidth',4,...
'color',nnred);
plot(x+[200 250],y-[50 50],...
'linewidth',4,...
'color',nnred);
plot(x+[240 250 240],y-[40 50 60],...
'linewidth',4,...
'color',nnred);
nndicon(101,x+200,y-50)
deg = pi/180;
angle = [0:5:90]*deg;
xc = cos(angle)*10;
yc = sin(angle)*10;
plot(x-20-xc,y+70+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[-20 0],y+[80 80],...
'linewidth',3,...
'color',nndkblue);
plot(x+xc,y+70+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x-20-xc,y-160-yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[-20 0],y-[170 170],...
'linewidth',3,...
'color',nndkblue);
plot(x+xc,y-160-yc,...
'linewidth',3,...
'color',nndkblue);
text(x-10,y+95,'Input',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center');
plot(x+30-xc,y+70+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[30 280],y+[80 80],...
'linewidth',3,...
'color',nndkblue);
plot(x+280+xc,y+70+yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+30-xc,y-160-yc,...
'linewidth',3,...
'color',nndkblue);
plot(x+[30 280],y-[170 170],...
'linewidth',3,...
'color',nndkblue);
plot(x+280+xc,y-160-yc,...
'linewidth',3,...
'color',nndkblue);
f_text = text(x+155,y+95,'Linear Neuron',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center',...
'erasemode','none');
func_str = sprintf('a = %s(w*p+b) = %g',f,a);
f_text2 = text(x+155,y-190,'a = purelin(w*p+b)',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center',...
'erasemode','none');
text(x+155,y+45,'F',...
'fontname','helvetica',...
'fontweight','bold',...
'color',nndkblue,...
'horiz','center',...
'fontsize',12)
% SIGNALS
p1_axis = nnsfo('a2','p(1)','','');
set(p1_axis, ...
'units','points',...
'position',[x-20 y-35 20 70],...
'color',nnltyell,...
'xlim',[-0.3 1.3],...
'xtick',[],...
'ylim',[-1.3 1.3]*p_max,...
'ytick',[-1 -0.5 0 0.5 1]*p_max,...
'yticklabel',str2mat(num2str(-p_max),'','0','',num2str(p_max)))
p1_ind = fill([0 1 1],[0 0.2 -0.2]*p_max+p(1),nnred,...
'edgecolor',nndkblue,...
'erasemode','none');
p2_axis = nnsfo('a2','p(2)','','');
set(p2_axis, ...
'units','points',...
'position',[x-20 y-135 20 70],...
'color',nnltyell,...
'xlim',[-0.3 1.3],...
'xtick',[],...
'ylim',[-1.3 1.3]*p_max,...
'ytick',[-1 -0.5 0 0.5 1]*p_max,...
'yticklabel',str2mat(num2str(-p_max),'','0','',num2str(p_max)))
p2_ind = fill([0 1 1],[0 0.2 -0.2]*p_max+p(2),nnred,...
'edgecolor',nndkblue,...
'erasemode','none');
n_axis = nnsfo('a2','n','','');
set(n_axis, ...
'units','points',...
'position',[x+140 y-85 20 70],...
'color',nnltyell,...
'xlim',[-0.3 1.3],...
'xtick',[],...
'ylim',[-1.3 1.3]*n_max,...
'ytick',-n_max:2:n_max,...
'yticklabel',str2mat(num2str(-n_max),'','','','','',num2str(n_max)))
n_ind = fill([0 1 1],[0 0.2 -0.2]*n_max+n,nndkblue,...
'edgecolor','none',...
'erasemode','none');
a_axis = nnsfo('a2','a','','');
set(a_axis, ...
'units','points',...
'position',[x+270 y-120 20 140],...
'color',nnltyell,...
'xlim',[-0.3 1.3],...
'xtick',[],...
'ylim',[-1.15 1.15]*a_max,...
'ytick',[-a_max:1:a_max],...
'yticklabel',...
['-6';' ';'-4';' ';'-2';' ';'0 ';' ';'2 ';' ';'4 ';' ';'6 '])
a_ind = fill([0 1 1],[0 0.2 -0.2]*a_max/2+a,nndkblue,...
'edgecolor','none',...
'erasemode','none');
bi_axis = nnsfo('a2','','','');
set(bi_axis, ...
'units','points',...
'position',[x+90 y-135 20 20],...
'color',nnltyell,...
'xlim',[-1 1],...
'xtick',[],...
'ylim',[-1 1],...
'ytick',[])
bi_ind = text(0,0,'1',...
'color',nndkblue,...
'fontweight','bold',...
'horiz','center');
% PARAMETERS
w1_axis = nnsfo('a2','w(1,1)','','');
set(w1_axis, ...
'units','points',...
'position',[x+10 y+15 70 20],...
'color',nnmdgray,...
'ylim',[-0.3 1.3],...
'ytick',[],...
'xlim',[-1.3 1.3]*w_max,...
'xtick',[-1 -0.5 0 0.5 1]*w_max,...
'xticklabel',str2mat(num2str(-w_max),'','0','',num2str(w_max)))
w1_ind = fill([0 0.2 -0.2]*w_max+w(1),[0 1 1],nnred,...
'edgecolor',nndkblue,...
'erasemode','none');
w2_axis = nnsfo('a2','w(1,2)','','');
set(w2_axis, ...
'units','points',...
'position',[x+10 y-135 70 20],...
'color',nnmdgray,...
'ylim',[-0.3 1.3],...
'ytick',[],...
'xlim',[-1.3 1.3]*w_max,...
'xtick',[-1 -0.5 0 0.5 1]*w_max,...
'xticklabel',str2mat(num2str(-w_max),'','0','',num2str(w_max)))
w2_ind = fill([0 0.2 -0.2]*w_max+w(2),[0 1 1],nnred,...
'edgecolor',nndkblue,...
'erasemode','none');
b_axis = nnsfo('a2','b','','');
set(b_axis, ...
'units','points',...
'position',[x+120 y-135 70 20],...
'color',nnmdgray,...
'ylim',[-0.3 1.3],...
'ytick',[],...
'xlim',[-1.3 1.3]*w_max,...
'xtick',[-1 -0.5 0 0.5 1]*w_max,...
'xticklabel',str2mat(num2str(-w_max),'','0','',num2str(w_max)))
b_ind = fill([0 0.2 -0.2]*w_max+b,[0 1 1],nnred,...
'edgecolor',nndkblue,...
'erasemode','none');
f_menu = uicontrol(...
'units','points',...
'position',[x+115 y+15, 80 20],...
'style','popupmenu',...
'string','Hardlim|Hardlims|Purelin|Satlin|Satlins|Logsig|Tansig',...
'background',nnmdgray,...
'callback',[me '(''function'')'],...
'value',3);
% SLIDE BARS
drawnow % Let everything else appear before buttons
% BUTTONS
uicontrol(...
'units','points',...
'position',[400 110 60 20],...
'string','Contents',...
'callback','nndtoc')
uicontrol(...
'units','points',...
'position',[400 75 60 20],...
'string','Close',...
'callback',[me '(''close'')'])
% DATA POINTERS
meters = [p1_axis p2_axis w1_axis w2_axis b_axis n_axis a_axis];
indicators = [p1_ind p2_ind w1_ind w2_ind b_ind n_ind a_ind];
w_ptr = uicontrol('visible','off'); set(w_ptr,'userdata',w);
b_ptr = uicontrol('visible','off'); set(b_ptr,'userdata',b);
f_ptr = uicontrol('visible','off'); set(f_ptr,'userdata',f);
p_ptr = uicontrol('visible','off'); set(p_ptr,'userdata',p);
% INSTRUCTION TEXT
feval(me,'instr');
% LOCK WINDOW
set(fig,...
'nextplot','new',...
'color',nnltgray);
nnchkfs;
%==================================================================
% Display the instructions.
%
% ME('instr')
%==================================================================
%==================================================================
% Respond to mouse down.
%
% ME('down')
%==================================================================
q = 0;
for i=1:5
pt = get(meters(i),'currentpoint');
x = pt(1);
y = pt(3);
if (i <= 2)
if (y >= -1.3*p_max) & (y <= 1.3*p_max) & (x >= 0) & (x <= 1)
q = i;
data = 'ydata';
z_max = p_max;
z = y;
hide_color = nnltyell;
break;
end
else
if (x >= -1.3*w_max) & (x <= 1.3*w_max) & (y >= 0) & (y <= 1)
q = i;
data = 'xdata';
z_max = w_max;
z = x;
hide_color = nnmdgray;
break;
end
end
end
if (q)
set(fig,'pointer','crosshair')
z = min(z_max,max(-z_max,z));
set(indicators(q),...
'facecolor',hide_color,...
'edgecolor',hide_color)
set(indicators(q),...
data,[0 0.2 -0.2]*z_max+z,...
'facecolor',nnred,...
'edgecolor',nndkblue)
set(fig,'WindowButtonMotionFcn',[me '(''down'')']);
set(fig,'WindowButtonUpFcn',[me '(''up'')']);
% ALTER VARIABLES
if (q <= 2)
p = get(p_ptr,'userdata');
p(q) = z;
set(p_ptr,'userdata',p);
elseif (q <= 4)
w = get(w_ptr,'userdata');
w(q-2) = z;
set(w_ptr,'userdata',w);
else
set(b_ptr,'userdata',z);
end
cmd = 'update';
else
set(fig,'pointer','arrow')
end
%==================================================================
% Respond to mouse up.
%
% ME('up')
%==================================================================
set(fig,...
'WindowButtonMotionFcn','',...
'pointer','arrow')
%==================================================================
% Respond to function menu.
%
% ME('function')
%==================================================================
v = get(f_menu,'value');
set(f_text,...
'color',nnltgray);
set(f_text,...
'string',new_text,...
'color',nndkblue);
set(f_text2,...
'color',nnltgray);
set(f_text2,...
'string',['a = ' f '(w*p+b)'],...
'color',nndkblue)
set(f_ptr,'userdata',f);
cmd = 'update';
%==================================================================
end
%==================================================================
% Respond to request to update displays.
%
% ME('update')
%==================================================================
% GET DATA
w = get(w_ptr,'userdata');
b = get(b_ptr,'userdata');
f = get(f_ptr,'userdata');
p = get(p_ptr,'userdata');
% UPDATE OUTPUT
n = w*p+b;
if strcmp(f,'satlin')
a = (~((n < 0) | (n > 1))).*n + (n > 1);
elseif strcmp(f,'satlins')
a = (~((n < -1) | (n > 1))).*n + (n > 1) - (n < -1);
else
a = feval(f,n);
end
set(indicators(7),...
'facecolor',nnltyell)
set(indicators(7),...
'ydata',[0 0.2 -0.2]*a_max/2+a,...
'facecolor',nndkblue)
end
hasil output
decision boundaries
function nnd4db(cmd,arg1,arg2,arg3)
%NND4DB Decision boundaries demonstration.
%
% This demonstration requires either the MININNET functions
% on the NND disk or the Neural Network Toolbox.
% $Revision: 1.7 $
% Copyright 1994-2002 PWS Publishing Company and The MathWorks, Inc.
% First Version, 8-31-95.
%==================================================================
% CONSTANTS
me = 'nnd4db';
p_max = 3;
% FLAGS
change_func = 0;
% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); 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('')
%==================================================================
%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================
% CONSTANTS
pt1 = [-1 0];
pt2 = [0 -2];
pt = [pt1; pt2];
w_dir = [pt(1,2)-pt(2,2),pt(2,1)-pt(1,1)];
w = w_dir/sqrt(sum(sum(w_dir.^2)))*2;
b = -w*pt(1,:)';
P = [0 0; 0 1; 1 0; 1 1]';
T = [0 0 0 1];
% ICON
nndicon(4,458,363,'shadow')
% VALUES
bracket_x = [1 0 0 1]*10;
bracket_y = [0 0 1 1]*10;
text(55,40,'W=',...
'fontsize',20,...
'fontweight','bold',...
'color',nndkblue,...
'horiz','right')
plot(bracket_x+60,bracket_y*4+20,'color',nndkblue,'linewidth',3);
plot(-bracket_x+190,bracket_y*4+20,'color',nndkblue,'linewidth',3);
w1_text = text(95,40,sprintf('%5.3g',w(1)),...
'fontsize',16,...
'fontweight','normal',...
'color',nndkblue,...
'horiz','center',...
'erasemode','none');
w2_text = text(150,40,sprintf('%5.3g',w(2)),...
'fontsize',16,...
'fontweight','normal',...
'color',nndkblue,...
'horiz','center',...
'erasemode','none');
text(255,40,'b=',...
'fontsize',20,...
'fontweight','bold',...
'color',nndkblue,...
'horiz','right')
plot(bracket_x+270,bracket_y*4+20,'color',nndkblue,'linewidth',3);
plot(-bracket_x+340,bracket_y*4+20,'color',nndkblue,'linewidth',3);
b_text = text(305,40,sprintf('%5.3g',b),...
'fontsize',16,...
'fontweight','normal',...
'color',nndkblue,...
'horiz','center',...
'erasemode','none');
% VECTOR DIAGRAM
v_axis = nnsfo('a2','','','');
set(v_axis,...
'position',[90 90 240*1.05 240*1.05],...
'xlim',[-p_max p_max]*1.05,...
'xtick',-p_max:p_max,...
'ylim',[-p_max p_max]*1.05,...
'ytick',-p_max:p_max)
% OBJECTS
zz1 = [-p_max:0.5:p_max];
zz2 = zz1*0;
cross = plot([zz1 NaN zz2],[zz2 NaN zz1],'.',...
'color',nndkblue,...
'erasemode','none');
[R,Q] = size(P);
A = hardlim(w*P+b*ones(1,Q));
if all(A == T)
col = nndkgray;
else
col = nnred;
end
w_arrow = nndrwvec(w(1),w(2),2,0.2,col,'W','none');
if (w(1) ~= 0)
pp2 = [-p_max p_max];
pp1 = -(w(2)*pp2+b)/w(1);
elseif (w(2) ~= 0)
pp1 = [-p_max p_max];
pp2 = -(w(1)*pp1+b)/w(2);
else
pp1 = [0 0];
pp2 = [0 0];
end
db_line = plot(pp1,pp2,...
'linewidth',2,...
'color',nndkblue,...
'erasemode','none');
db1 = plot(pt1(1),pt1(2),'o',...
'color',nndkblue,...
'markersize',10,...
'erasemode','none');
db2 = plot(pt2(1),pt2(2),'o',...
'color',nndkblue,...
'markersize',10,...
'erasemode','none');
q = length(T);
deg = pi/180;
angle = [0:5:360]*deg;
cx = cos(angle)*0.15;
cy = sin(angle)*0.15;
dots = zeros(1,q);
for i=1:q
a = hardlim(w*P(:,i)+b);
if (a == T(i))
col = nndkgray;
else
col = nnred;
end
dots(i) = fill(cx+P(1,i),cy+P(2,i),[1 1 1]-T(i),...
'edgecolor',col,...
'erasemode','none',...
'linewidth',2);
end
% TARGET AXES
t1_axis = nnsfo('a2','','','');
set(t1_axis,...
'position',[30 230 20*1.05 20*1.05],...
'xlim',[-.16 .16],...
'ylim',[-.16 .16])
axis('off')
fill(cx,cy,[0 0 0],...
'edgecolor',nndkgray,...
'linewidth',2)
t2_axis = nnsfo('a2','','','');
set(t2_axis,...
'position',[30 180 20*1.05 20*1.05],...
'xlim',[-.16 .16],...
'ylim',[-.16 .16])
axis('off')
fill(cx,cy,[1 1 1],...
'edgecolor',nndkgray,...
'linewidth',2)
% BUTTONS
drawnow % Let everything else appear before buttons
uicontrol(...
'units','points',...
'position',[400 110 60 20],...
'string','Contents',...
'callback','nndtoc')
uicontrol(...
'units','points',...
'position',[400 75 60 20],...
'string','Close',...
'callback',[me '(''close'')'])
% DATA POINTERS
w_ptr = uicontrol('visible','off'); set(w_ptr,'userdata',w);
b_ptr = uicontrol('visible','off'); set(b_ptr,'userdata',b);
pt_ptr = uicontrol('visible','off'); set(pt_ptr,'userdata',pt);
w_arrow_ptr = uicontrol('visible','off');
set(w_arrow_ptr,'userdata',w_arrow);
P_ptr = uicontrol('visible','off'); set(P_ptr,'userdata',P);
T_ptr = uicontrol('visible','off'); set(T_ptr,'userdata',T);
dots_ptr = uicontrol('visible','off'); set(dots_ptr,'userdata',dots);
dot_ptr = uicontrol('visible','off'); set(dot_ptr,'userdata',[]);
% INSTRUCTION TEXT
feval(me,'instr');
% LOCK WINDOW
set(fig,...
'nextplot','new',...
'color',nnltgray);
nnchkfs;
%==================================================================
% Display the instructions.
%
% ME('instr')
%==================================================================
%==================================================================
% Respond to mouse down.
%
% ME('down')
%==================================================================
pt = get(v_axis,'currentpoint');
x = pt(1);
y = pt(3);
% GET DATA
pt = get(pt_ptr,'userdata');
w_arrow = get(w_arrow_ptr,'userdata');
set(fig,...
'pointer','circle',...
'WindowButtonMotionFcn',[me '(''movept1'')'],...
'WindowButtonUpFcn',[me '(''setpt1'')'])
set(fig,...
'pointer','circle',...
'WindowButtonMotionFcn',[me '(''movept2'')'],...
'WindowButtonUpFcn',[me '(''setpt2'')'])
set(dots(i),...
'facecolor',nnltyell,...
'edgecolor',nnltyell);
set(db_line,...
'color',nndkblue)
A = hardlim(w*P+b*ones(1,q));
if all(A == T)
col = nndkgray;
else
col = nnred;
end
set(w_arrow,...
'color',col)
set(db1,...
'color',nndkblue)
set(db2,...
'color',nndkblue)
set(cross,...
'color',nndkblue)
delete(dots(i));
t = T(i);
T(i) = [];
P(:,i) = [];
dots(i) = [];
for i=1:length(T)
set(dots(i),...
'facecolor',[1 1 1]-T(i))
end
set(T_ptr,'userdata',T);
set(P_ptr,'userdata',P);
set(dots_ptr,'userdata',dots);
set(fig,...
'pointer','circle',...
'WindowButtonUpFcn',[me '(''setdot'')'])
set(dot_ptr,'userdata',t);
break;
end
end
end
% NEW DOTS
else
pt = get(t1_axis,'currentpoint');
x = pt(1);
y = pt(3);
% BLACK DOT
if (x >= -.15) & (x <= .15) & (y >= -.15) & (y <= .15)
set(fig,...
'pointer','circle',...
'WindowButtonUpFcn',[me '(''setdot'')'])
set(dot_ptr,'userdata',1);
else
pt = get(t2_axis,'currentpoint');
x = pt(1);
y = pt(3);
% WHITE DOT
if (x >= -.15) & (x <= .15) & (y >= -.15) & (y <= .15)
set(fig,...
'pointer','circle',...
'WindowButtonUpFcn',[me '(''setdot'')'])
set(dot_ptr,'userdata',0);
end
end
end
%==================================================================
% Set decision dot.
%
% ME('setdot')
%==================================================================
pt = get(v_axis,'currentpoint');
x = pt(1);
x = round(x*2)/2;
y = pt(3);
y = round(y*2)/2;
dot = get(dot_ptr,'userdata');
if (x >= -p_max) & (x <= p_max) & (y >= -p_max) & (y <= p_max)
P = get(P_ptr,'userdata');
T = get(T_ptr,'userdata');
w = get(w_ptr,'userdata');
b = get(b_ptr,'userdata');
dots = get(dots_ptr,'userdata');
q = length(dots)+1;
deg = pi/180;
angle = [0:5:360]*deg;
cx = cos(angle)*0.15;
cy = sin(angle)*0.15;
set(fig,'nextplot','add');
axes(v_axis);
a = hardlim(w*[x;y]+b);
if (a == dot)
col = nndkgray;
else
col = nnred;
end
set(P_ptr,'userdata',P);
set(T_ptr,'userdata',T);
set(dots_ptr,'userdata',dots);
cmd = 'update';
end
set(fig,...
'pointer','arrow',...
'WindowButtonUpFcn','')
%==================================================================
% Move decision boundary point #1.
%
% ME('movept1')
%==================================================================
pt = get(v_axis,'currentpoint');
x = pt(1);
x = round(x*4)/4;
y = pt(3);
y = round(y*4)/4;
%==================================================================
% Respond to set decision boundary point #1.
%
% ME('setpt1')
%==================================================================
set(fig,...
'WindowButtonMotionFcn','',...
'WindowButtonUpFcn','',...
'pointer','arrow')
pt = get(pt_ptr,'userdata');
set(db1,...
'xdata',pt(1,1),...
'ydata',pt(1,2),...
'color',nndkblue)
cmd = 'update';
%==================================================================
% Move decision boundary point #1.
%
% ME('movept2')
%==================================================================
pt = get(v_axis,'currentpoint');
x = pt(1);
x = round(x*4)/4;
y = pt(3);
y = round(y*4)/4;
% MOVE DECISION POINT #1
if (x >= -p_max) & (x <= p_max) & (y >= -p_max) & (y <= p_max)
pt = get(pt_ptr,'userdata');
pt(2,:) = [x y];
set(pt_ptr,'userdata',pt);
end
%==================================================================
% Respond to set decision boundary point #2.
%
% ME('setpt2')
%==================================================================
set(fig,...
'WindowButtonMotionFcn','',...
'WindowButtonUpFcn','',...
'pointer','arrow')
pt = get(pt_ptr,'userdata');
set(db2,...
'xdata',pt(2,1),...
'ydata',pt(2,2),...
'color',nndkblue)
cmd = 'update';
%==================================================================
end
%==================================================================
% Respond to request to update displays.
%
% ME('update')
%==================================================================
if strcmp(cmd,'update')
% GET DATA
b = get(b_ptr,'userdata');
pt = get(pt_ptr,'userdata');
P = get(P_ptr,'userdata');
T = get(T_ptr,'userdata');
if (w(1) ~= 0)
pp2 = [-p_max p_max];
pp1 = -(w(2)*pp2+b)/w(1);
elseif (w(2) ~= 0)
pp1 = [-p_max p_max];
pp2 = -(w(1)*pp1+b)/w(2);
else
pp1 = [0 0];
pp2 = [0 0];
end
% NEW BOUNDARY
set(db_line,...
'xdata',pp1,...
'ydata',pp2,...
'color',nndkblue)
% REFRESH DOTS
dots = get(dots_ptr,'userdata');
T = get(T_ptr,'userdata');
for i=1:length(T)
a = hardlim(w*P(:,i)+b);
if (a == T(i))
col = nndkgray;
else
col = nnred;
end
set(dots(i),...
'facecolor',[1 1 1]-T(i),...
'edgecolor',col)
end
hasil output
% $Revision: 1.7.2.2 $
% Copyright 1994-2005 PWS Publishing Company and The MathWorks, Inc.
% First Version, 8-31-95.
%==================================================================
% CONSTANTS
me = 'nnd4pr';
p_max = 3;
max_epoch = 5;
% FLAGS
change_func = 0;
% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); 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('')
%==================================================================
%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================
% CONSTANTS
pt1 = [-1 0];
pt2 = [0 -2];
pt = [pt1; pt2];
w = [1 -0.8];
b = 0;
P = [1 2; -1 2; 0 -1]';
T = [1 0 0];
% ICON
nndicon(4,458,363,'shadow')
% VALUES
bracket_x = [1 0 0 1]*10;
bracket_y = [0 0 1 1]*10;
text(55,40,'W=',...
'fontsize',20,...
'fontweight','bold',...
'color',nndkblue,...
'horiz','right')
plot(bracket_x+60,bracket_y*4+20,'color',nndkblue,'linewidth',3);
plot(-bracket_x+190,bracket_y*4+20,'color',nndkblue,'linewidth',3);
w1_text = text(95,40,sprintf('%5.3g',w(1)),...
'fontsize',16,...
'fontweight','normal',...
'color',nndkblue,...
'horiz','center',...
'erasemode','none');
w2_text = text(150,40,sprintf('%5.3g',w(2)),...
'fontsize',16,...
'fontweight','normal',...
'color',nndkblue,...
'horiz','center',...
'erasemode','none');
text(255,40,'b=',...
'fontsize',20,...
'fontweight','bold',...
'color',nndkblue,...
'horiz','right')
plot(bracket_x+285,bracket_y*4+20,'color',nndkblue,'linewidth',3);
plot(-bracket_x+355,bracket_y*4+20,'color',nndkblue,'linewidth',3);
b_text = text(320,40,sprintf('%5.3g',b),...
'fontsize',16,...
'fontweight','normal',...
'color',nndkblue,...
'horiz','center',...
'erasemode','none');
% VECTOR DIAGRAM
v_axis = nnsfo('a2','','','');
set(v_axis,...
'position',[105 90 240*1.05 240*1.05],...
'xlim',[-p_max p_max]*1.05,...
'xtick',-p_max:p_max,...
'ylim',[-p_max p_max]*1.05,...
'ytick',-p_max:p_max)
% OBJECTS
zz1 = [-p_max p_max];
zz2 = zz1*0;
cross = plot([zz1 NaN zz2],[zz2 NaN zz1],':',...
'color',nndkblue,...
'erasemode','none');
if (w(1) ~= 0)
pp2 = [-p_max p_max];
pp1 = -(w(2)*pp2+b)/w(1);
elseif (w(2) ~= 0)
pp1 = [-p_max p_max];
pp2 = -(w(1)*pp1+b)/w(2);
else
pp1 = [0 0];
pp2 = [0 0];
end
[R,Q] = size(P);
if all(T == hardlim(w*P+b*ones(1,Q)))
col = nndkblue;
else
col = nnred;
end
db_line = plot(pp1,pp2,...
'linewidth',2,...
'color',col,...
'erasemode','none');
q = length(T);
deg = pi/180;
angle = [0:5:360]*deg;
cx = cos(angle)*0.15;
cy = sin(angle)*0.15;
dots = zeros(1,q);
for i=1:q
a = hardlim(w*P(:,i)+b);
if (a == T(i))
col = nndkgray;
else
col = nnred;
end
dots(i) = fill(cx+P(1,i),cy+P(2,i),[1 1 1]-T(i),...
'edgecolor',col,...
'erasemode','none',...
'linewidth',2);
end
% TARGET AXES
t1_axis = nnsfo('a2','','','');
set(t1_axis,...
'position',[40 320 20*1.05 20*1.05],...
'xlim',[-.16 .16],...
'ylim',[-.16 .16])
axis('off')
fill(cx,cy,[0 0 0],...
'edgecolor',nndkgray,...
'linewidth',2)
t2_axis = nnsfo('a2','','','');
set(t2_axis,...
'position',[40 270 20*1.05 20*1.05],...
'xlim',[-.16 .16],...
'ylim',[-.16 .16])
axis('off')
fill(cx,cy,[1 1 1],...
'edgecolor',nndkgray,...
'linewidth',2)
% BUTTONS
drawnow % Let everything else appear before buttons
uicontrol(...
'units','points',...
'position',[20 220 60 20],...
'string','Learn',...
'callback',[me '(''learn'')'])
uicontrol(...
'units','points',...
'position',[20 185 60 20],...
'string','Train',...
'callback',[me '(''train'')'])
uicontrol(...
'units','points',...
'position',[20 150 60 20],...
'string','Random',...
'callback',[me '(''random'')'])
bias = uicontrol(...
'units','points',...
'position',[20 115 70 20],...
'string','Bias',...
'callback',[me '(''bias'')'],...
'style','radio',...
'value',0,...
'back',nnltgray);
no_bias = uicontrol(...
'units','points',...
'position',[20 85 70 20],...
'string','No Bias',...
'callback',[me '(''nobias'')'],...
'style','radio',...
'value',1,...
'back',nnltgray);
uicontrol(...
'units','points',...
'position',[400 110 60 20],...
'string','Contents',...
'callback','nndtoc')
uicontrol(...
'units','points',...
'position',[400 75 60 20],...
'string','Close',...
'callback',[me '(''close'')'])
% DATA POINTERS
w_ptr = uicontrol('visible','off','userdata',w);
b_ptr = uicontrol('visible','off','userdata',b);
pt_ptr = uicontrol('visible','off','userdata',pt);
P_ptr = uicontrol('visible','off','userdata',P);
T_ptr = uicontrol('visible','off','userdata',T);
dots_ptr = uicontrol('visible','off','userdata',dots);
dot_ptr = uicontrol('visible','off','userdata',[]);
index_ptr = uicontrol('visible','off','userdata',1);
% INSTRUCTION TEXT
feval(me,'instr');
% LOCK WINDOW
set(fig,...
'nextplot','new',...
'color',nnltgray);
nnchkfs;
%==================================================================
% Display the instructions.
%
% ME('instr')
%==================================================================
%==================================================================
% Respond to mouse down.
%
% ME('down')
%==================================================================
pt = get(v_axis,'currentpoint');
x = pt(1);
y = pt(3);
set(dots(i),...
'facecolor',nnltyell,...
'edgecolor',nnltyell);
delete(dots(i));
t = T(i);
T(i) = [];
P(:,i) = [];
dots(i) = [];
[R,Q] = size(P);
if all(T == hardlim(w*P+b*ones(1,Q)))
col = nndkblue;
else
col = nnred;
end
set(db_line,...
'color',col)
set(cross,...
'color',nndkblue)
for i=1:length(T)
set(dots(i),...
'facecolor',[1 1 1]-T(i))
end
set(T_ptr,'userdata',T);
set(P_ptr,'userdata',P);
set(dots_ptr,'userdata',dots);
set(fig,...
'pointer','circle',...
'WindowButtonUpFcn',[me '(''setdot'')'])
set(dot_ptr,'userdata',t);
break;
end
end
% NEW DOTS
else
pt = get(t1_axis,'currentpoint');
x = pt(1);
y = pt(3);
% BLACK DOT
if (x >= -.15) & (x <= .15) & (y >= -.15) & (y <= .15)
set(fig,...
'pointer','circle',...
'WindowButtonUpFcn',[me '(''setdot'')'])
set(dot_ptr,'userdata',1);
else
pt = get(t2_axis,'currentpoint');
x = pt(1);
y = pt(3);
% WHITE DOT
if (x >= -.15) & (x <= .15) & (y >= -.15) & (y <= .15)
set(fig,...
'pointer','circle',...
'WindowButtonUpFcn',[me '(''setdot'')'])
set(dot_ptr,'userdata',0);
end
end
end
%==================================================================
% Set decision dot.
%
% ME('setdot')
%==================================================================
pt = get(v_axis,'currentpoint');
x = pt(1);
x = round(x*2)/2;
y = pt(3);
y = round(y*2)/2;
dot = get(dot_ptr,'userdata');
if (x >= -p_max) & (x <= p_max) & (y >= -p_max) & (y <= p_max)
P = get(P_ptr,'userdata');
T = get(T_ptr,'userdata');
w = get(w_ptr,'userdata');
b = get(b_ptr,'userdata');
dots = get(dots_ptr,'userdata');
q = length(dots)+1;
deg = pi/180;
angle = [0:5:360]*deg;
cx = cos(angle)*0.15;
cy = sin(angle)*0.15;
set(fig,'nextplot','add');
axes(v_axis);
P = [P [x;y]];
T = [T dot];
[R,Q] = size(P);
if all(T == hardlim(w*P+b*ones(1,Q)))
col = nndkblue;
else
col = nnred;
end
set(db_line,...
'color',col);
a = hardlim(w*[x;y]+b);
if (a == dot)
col = nndkgray;
else
col = nnred;
end
dots(q) = fill(cx+x,cy+y,[1 1 1]-dot,...
'edgecolor',col,...
'erasemode','none',...
'linewidth',2);
set(fig,'nextplot','new');
set(P_ptr,'userdata',P);
set(T_ptr,'userdata',T);
set(dots_ptr,'userdata',dots);
end
set(fig,...
'pointer','arrow',...
'WindowButtonUpFcn','')
%==================================================================
% Learn.
%
% ME('learn')
%==================================================================
elseif strcmp(cmd,'learn')
max_epoch = 1;
cmd = 'train';
%==================================================================
% Bias.
%
% ME('bias')
%==================================================================
elseif strcmp(cmd,'bias')
set(no_bias,'value',0);
%==================================================================
% Bias.
%
% ME('bias')
%==================================================================
elseif strcmp(cmd,'nobias')
set(bias,'value',0);
w = get(w_ptr,'userdata');
b = 0;
P = get(P_ptr,'userdata');
T = get(T_ptr,'userdata');
dots = get(dots_ptr,'userdata');
if (w(1) ~= 0)
pp2 = [-p_max p_max];
pp1 = -(w(2)*pp2+b)/w(1);
if (pp1(1) < -p_max | pp1(1) > p_max)
pp1(1) = p_max*sign(pp1(1));
pp2(1) = -(w(1)*pp1(1)+b)/w(2);
end
if (pp1(2) < -p_max | pp1(2) > p_max)
pp1(2) = p_max*sign(pp1(2));
pp2(2) = -(w(1)*pp1(2)+b)/w(2);
end
elseif (w(2) ~= 0)
pp1 = [-p_max p_max];
pp2 = -(w(1)*pp1+b)/w(2);
else
pp1 = [0 0];
pp2 = [0 0];
end
% NEW BOUNDARY
set(db_line,...
'color',nnltyell)
set(cross,...
'color',nndkblue);
[R,Q] = size(P);
if all(T == hardlim(w*P+b*ones(1,Q)))
col = nndkblue;
else
col = nnred;
end
set(db_line,...
'xdata',pp1,...
'ydata',pp2,...
'color',col)
% REFRESH DOTS
for k=1:length(T)
a = hardlim(w*P(:,k)+b);
if (a == T(k))
col = nndkgray;
else
col = nnred;
end
set(dots(k),...
'facecolor',[1 1 1]-T(k),...
'edgecolor',col)
end
set(b_ptr,'userdata',b);
%==================================================================
% Random weights.
%
% ME('random')
%==================================================================
elseif strcmp(cmd,'random')
[w,b] = feval('rands',1,2);
if get(no_bias,'value'), b = 0; end
P = get(P_ptr,'userdata');
T = get(T_ptr,'userdata');
dots = get(dots_ptr,'userdata');
if (w(1) ~= 0)
pp2 = [-p_max p_max];
pp1 = -(w(2)*pp2+b)/w(1);
if (pp1(1) < -p_max | pp1(1) > p_max)
pp1(1) = p_max*sign(pp1(1));
pp2(1) = -(w(1)*pp1(1)+b)/w(2);
end
if (pp1(2) < -p_max | pp1(2) > p_max)
pp1(2) = p_max*sign(pp1(2));
pp2(2) = -(w(1)*pp1(2)+b)/w(2);
end
elseif (w(2) ~= 0)
pp1 = [-p_max p_max];
pp2 = -(w(1)*pp1+b)/w(2);
else
pp1 = [0 0];
pp2 = [0 0];
end
% NEW BOUNDARY
set(db_line,...
'color',nnltyell)
set(cross,...
'color',nndkblue);
[R,Q] = size(P);
if all(T == hardlim(w*P+b*ones(1,Q)))
col = nndkblue;
else
col = nnred;
end
set(db_line,...
'xdata',pp1,...
'ydata',pp2,...
'color',col)
% REFRESH DOTS
for k=1:length(T)
a = hardlim(w*P(:,k)+b);
if (a == T(k))
col = nndkgray;
else
col = nnred;
end
set(dots(k),...
'facecolor',[1 1 1]-T(k),...
'edgecolor',col)
end
% NEW PARAMETER VALUES
set(w1_text,...
'color',nnltgray)
set(w2_text,...
'color',nnltgray)
set(b_text,...
'color',nnltgray)
nntxtchk;
set(w1_text,...
'string',sprintf('%5.3g',w(1)),...
'color',nndkblue)
set(w2_text,...
'string',sprintf('%5.3g',w(2)),...
'color',nndkblue)
set(b_text,...
'string',sprintf('%5.3g',b),...
'color',nndkblue)
nntxtchk;
set(w_ptr,'userdata',w);
set(b_ptr,'userdata',b);
%==================================================================
end
%==================================================================
% Train.
%
% ME('train')
%==================================================================
if strcmp(cmd,'train')
% GET DATA
w = get(w_ptr,'userdata');
b = get(b_ptr,'userdata');
P = get(P_ptr,'userdata');
T = get(T_ptr,'userdata');
dots = get(dots_ptr,'userdata');
bf = get(bias,'value');
j = get(index_ptr,'userdata');
q = length(T);
if (q == 0)
return
end
for i=1:max_epoch
if (j > q), j = 1; end
if all(T == hardlim(w*P+b*ones(1,q))), break, end
dot_col = get(dots(j),'facecolor');
set(dots(j),...
'facecolor',nngreen)
nnpause(0.5);
set(dots(j),...
'facecolor',nnltyell)
nnpause(0.5);
set(dots(j),...
'facecolor',nngreen)
nnpause(0.5);
a = hardlim(w*P(:,j)+b);
e = T(:,j) - a;
dw = e*P(:,j)';
db = e;
w = w + dw;
if bf, b = b + db; end
% NEW BOUNDARY
set(db_line,...
'color',nnltyell)
set(cross,...
'color',nndkblue);
[R,Q] = size(P);
if all(T == hardlim(w*P+b*ones(1,Q)))
col = nndkblue;
else
col = nnred;
end
set(db_line,...
'xdata',pp1,...
'ydata',pp2,...
'color',col)
% REFRESH DOTS
for k=1:length(T)
a = hardlim(w*P(:,k)+b);
if (a == T(k))
col = nndkgray;
else
col = nnred;
end
set(dots(k),...
'facecolor',[1 1 1]-T(k),...
'edgecolor',col)
end
% NEW PARAMETER VALUES
set(w1_text,...
'color',nnltgray)
set(w2_text,...
'color',nnltgray)
set(b_text,...
'color',nnltgray)
nntxtchk;
set(w1_text,...
'string',sprintf('%5.3g',w(1)),...
'color',nndkblue)
set(w2_text,...
'string',sprintf('%5.3g',w(2)),...
'color',nndkblue)
set(b_text,...
'string',sprintf('%5.3g',b),...
'color',nndkblue)
nntxtchk;
end
set(dots(j),...
'facecolor',dot_col)
j = j + 1;
end
set(w_ptr,'userdata',w);
set(b_ptr,'userdata',b);
set(index_ptr,'userdata',j);
end
hasil output