📄 nnd14cl.m
字号:
% REFRESH
set(big_circle,'facecolor',nnltyell);
set(big_cross,'color',nndkblue);
for j=1:3
if j ~= i
set(WV(j),'color',colors(j,:));
end
end
a = compet(W*P);
[ai,aj] = find(a);
for i=1:size(ai,1)
set(PV(i),'color',colors(ai(i),:));
end
% NEW INPUT VECTOR
else
pv = plot(x,y,'.',...
'color',nndkblue,...
'markersize',25,...
'erasemode','none');
PV = [PV; pv];
P = [P [x; y]];
% REFRESH
set(big_circle,'facecolor',nnltyell);
set(big_cross,'color',nndkblue);
for i=1:3
set(WV(i),'color',colors(i,:));
end
a = compet(W*P);
[ai,aj] = find(a);
for i=1:size(ai,1)
set(PV(i),'color',colors(ai(i),:));
end
end
end
% SET DATA
set(fig,'nextplot','new')
set(PV_ptr,'userdata',PV);
set(P_ptr,'userdata',P);
set(WV_ptr,'userdata',WV);
set(W_ptr,'userdata',W);
%==================================================================
% Button up.
%
% ME('up')
%==================================================================
elseif strcmp(cmd,'up') & (fig) & (nargin == 2)
% INDEX
i = arg1;
% FIND CLICK POSITION
axes(big_axis)
pt = get(big_axis,'currentpoint');
x = pt(1);
y = pt(3);
length = sqrt(x^2 + y^2);
% GET DATA
PV = get(PV_ptr,'userdata');
P = get(P_ptr,'userdata');
WV = get(WV_ptr,'userdata');
W = get(W_ptr,'userdata');
set(fig,'nextplot','add')
axes(big_axis);
% NORMALIZE
angle = atan2(y,x);
deg5 = 5*pi/180;
angle = round(angle/deg5)*deg5;
length = sqrt(sum(x^2 + y^2));
if length < 1.1
length = min(length,1);
end
x = cos(angle)*length;
y = sin(angle)*length;
p = [x;y];
if length <= 1
delete(WV(i));
W(i,:) = [x y];
WV(i) = nndrwvec(W(i,1),W(i,2),2,0.05,colors(i,:),'','none');
else
set(WV(i),'color',colors(i,:));
end
set(fig,...
'windowbuttonupfcn','',...
'pointer','arrow')
% REFRESH
set(big_circle,'facecolor',nnltyell);
set(big_cross,'color',nndkblue);
for i=1:3
set(WV(i),'color',colors(i,:));
end
a = compet(W*P);
[ai,aj] = find(a);
for i=1:size(ai,1)
set(PV(i),'color',colors(ai(i),:));
end
% SET DATA
set(fig,'nextplot','new')
set(PV_ptr,'userdata',PV);
set(WV_ptr,'userdata',WV);
set(W_ptr,'userdata',W);
%==================================================================
% Button down.
%
% ME('learn')
%==================================================================
elseif strcmp(cmd,'learn') & (fig) & (nargin == 1)
% GET DATA
PV = get(PV_ptr,'userdata');
P = get(P_ptr,'userdata');
WV = get(WV_ptr,'userdata');
W = get(W_ptr,'userdata');
axes(big_axis);
set(fig,'nextplot','add')
lr = get(lr_bar,'value');
i = floor(rand*size(PV,1))+1;
p = P(:,i);
% SHOW INPUT
nnpause(0.5);
set(fig,'nextplot','add');
temp_circle = plot(p(1),p(2),'.',...
'color',nndkblue,...
'markersize',32,...
'erasemode','none');
set(PV(i),'color',nnwhite);
nnpause(0.5);
% CALCULATE NEW WEIGHT
a = compet(W*p);
i = find(a);
newW = W + (lr*a*ones(1,2)).*(ones(3,1)*p'-W);
temp1 = plot([W(i,1) p(1)],[W(i,2) p(2)],'--',...
'color',nndkblue,...
'erasemode','none');
temp2 = nndrwvec([W(i,1) newW(i,1)],[W(i,2) newW(i,2)],2,0.05,nndkblue,'','none');
nnpause(0.5);
W = newW;
% MOVE WEIGHT
set(WV(i),'color',nnltyell);
set(temp1,'color',nnltyell);
set(temp2,'color',nnltyell);
delete(WV(i));
delete(temp1);
delete(temp2);
set(big_cross,'color',nndkblue);
WV(i) = nndrwvec(W(i,1),W(i,2),2,0.05,colors(i,:),'','none');
nnpause(0.5);
% REFRESH
delete(temp_circle);
set(big_circle,'facecolor',nnltyell);
set(big_cross,'color',nndkblue);
for i=1:3
set(WV(i),'color',colors(i,:));
end
a = compet(W*P);
[ai,aj] = find(a);
for i=1:size(ai,1)
set(PV(i),'color',colors(ai(i),:));
end
% SET DATA
set(fig,'nextplot','new')
set(WV_ptr,'userdata',WV);
set(W_ptr,'userdata',W);
%==================================================================
% Button down.
%
% ME('train')
%==================================================================
elseif strcmp(cmd,'train') & (fig) & (nargin == 1)
nnpause(0.5);
for xx=1:5
% GET DATA
PV = get(PV_ptr,'userdata');
P = get(P_ptr,'userdata');
WV = get(WV_ptr,'userdata');
W = get(W_ptr,'userdata');
axes(big_axis);
set(fig,'nextplot','add')
lr = get(lr_bar,'value');
i = floor(rand*size(PV,1))+1;
p = P(:,i);
% SHOW INPUT
set(fig,'nextplot','add');
temp_circle = plot(p(1),p(2),'.',...
'color',nndkblue,...
'markersize',32,...
'erasemode','none');
set(PV(i),'color',nnwhite);
nnpause(1);
% CALCULATE NEW WEIGHT
a = compet(W*p);
i = find(a);
newW = W + (lr*a*ones(1,2)).*(ones(3,1)*p'-W);
temp1 = plot([W(i,1) p(1)],[W(i,2) p(2)],'--',...
'color',nndkblue,...
'erasemode','none');
temp2 = nndrwvec([W(i,1) newW(i,1)],[W(i,2) newW(i,2)],2,0.05,nndkblue,'','none');
nnpause(0.5);
W = newW;
% MOVE WEIGHT
set(WV(i),'color',nnltyell);
set(temp1,'color',nnltyell);
set(temp2,'color',nnltyell);
delete(WV(i));
delete(temp1);
delete(temp2);
set(big_cross,'color',nndkblue);
WV(i) = nndrwvec(W(i,1),W(i,2),2,0.05,colors(i,:),'','none');
nnpause(0.5);
% REFRESH
delete(temp_circle);
set(big_circle,'facecolor',nnltyell);
set(big_cross,'color',nndkblue);
for i=1:3
set(WV(i),'color',colors(i,:));
end
a = compet(W*P);
[ai,aj] = find(a);
for i=1:size(ai,1)
set(PV(i),'color',colors(ai(i),:));
end
% SET DATA
set(fig,'nextplot','new')
set(WV_ptr,'userdata',WV);
set(W_ptr,'userdata',W);
nnpause(0.5);
set(fig,'nextplot','new');
end
%==================================================================
% Respond to learning rate slider.
%
% ME('lr')
%==================================================================
elseif strcmp(cmd,'lr')
lr = get(lr_bar,'value');
set(lr_text,'string',sprintf('%5.2f',round(lr*10)*0.1))
%==================================================================
% Clear input vectors.
%
% ME('random')
%==================================================================
elseif strcmp(cmd,'random') & (fig) & (nargin == 1)
% GET DATA
PV = get(PV_ptr,'userdata');
P = get(P_ptr,'userdata');
WV = get(WV_ptr,'userdata');
axes(big_axis);
set(fig,'nextplot','add')
delete(WV);
set(big_circle,'facecolor',nnltyell);
set(big_cross,'color',nndkblue);
set(PV,'color',nndkblue);
angle = rand(1,3)*2*pi;
WV = [];
for i=1:3
W(i,:) = [cos(angle(i)) sin(angle(i))];
WV(i) = nndrwvec(W(i,1),W(i,2),2,0.05,colors(i,:),'','none');
set(WV(i),'color',colors(i,:));
end
% REFRESH
set(big_circle,'facecolor',nnltyell);
set(big_cross,'color',nndkblue);
for i=1:3
set(WV(i),'color',colors(i,:));
end
a = compet(W*P);
[ai,aj] = find(a);
for i=1:size(ai,1)
set(PV(i),'color',colors(ai(i),:));
end
% SET DATA
set(fig,'nextplot','new')
set(W_ptr,'userdata',W);
set(WV_ptr,'userdata',WV);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -