📄 nnd3hopc.m
字号:
% MOVE DATA FROM SCANNER TO NETWORK & DISPLAY
xx = [157 188 NaN 162 188 NaN 167 188 NaN, ...
142 140 140 NaN 137 130 130 NaN 132 120 120];
yy = [90 90 NaN 80 80 NaN 70 70 NaN, ...
90 90 110 NaN 80 80 110 NaN 70 70 110];
set(fig,'nextplot','add')
nnsound(blip,Fs);
data = plot(xx,yy,...
'color',[1 1 1],...
'erasemode','none',...
'linewidth',2);
for j=1:3
if j == 1, str = 'SHAPE: ';
elseif j == 2, str = 'TEXTURE: ';
else str = 'WEIGHT: '; end
if p(j) >= 0
sign = '+';
else
sign = '-';
end
set(p_text(j),...
'color',nndkblue)
set(p_text(j),...
'string',[str,sign,num2str(abs(p(j)))],...
'color',nngreen)
end
nnpause(0.25);
nnsound(bloop,Fs);
set(data,...
'color',nndkblue)
delete(data);
% CLASSIFY FRUIT
nnpause(0.25)
nnsound(blip,Fs);
set(nnet(1),...
'edgecolor',[1 1 1],...
'facecolor',nndkblue)
set(nnet(2:3),...
'color',[1 1 1])
axes(fig_axis);
nnpause(0.25)
nnsound(bloop,Fs);
set(nnet(1),...
'edgecolor',[1 0 0],...
'facecolor',nndkblue)
set(nnet(2:3),...
'color',[0 1 0])
% CALL CLASSIFICATION ROUTINE
t1 = clock;
nnsound(classify,Fs);
while etime(clock,t1) < 1, end
feval(me,'classify')
nnpause(0.25)
% MOVE DATA FROM NETWORK TO EXIT
xx = [252 268];
yy = [80 80];
set(fig,'nextplot','add')
nnsound(blip,Fs);
data = plot(xx,yy,...
'color',[1 1 1],...
'erasemode','none',...
'linewidth',2);
set(indicators(fruit_id+1),...
'color',[1 1 1])
axes(fig_axis)
if fruit_id == 1
box_x = 84;
else
box_x = 62;
end
box = plot([0 62 62 0 0]+314,[0 0 14 14 0]+box_x,...
'color',[1 1 1],...
'erasemode','none');
nnpause(0.25);
nnsound(bloop,Fs);
set(data,...
'color',nndkblue)
delete(data);
% MOVE FRUIT TO EXIT
for dx=70:10:200
t1 = clock;
nnsound(blp,Fs);
while etime(clock,t1) < 0.05, end
set(fruit, ...
'facecolor',nnltgray, ...
'edgecolor',nnltgray);
set(fruit, ...
'facecolor',fruit_c, ...
'edgecolor',fruit_c*0.5, ...
'xdata',fruit_x + x + dx)
angle = angle + 20;
adata = [0 pi]-angle*deg;
xdata = cos(adata)*8;
ydata = sin(adata)*8+30;
set(lines,'color',nnred);
set(lines(1),...
'xdata',xdata+50,...
'ydata',ydata,...
'color',nndkblue)
set(lines(2),...
'xdata',xdata+330,...
'ydata',ydata,...
'color',nndkblue)
end
% REMOVE FRUIT
nnpause(0.5)
nnsound(blip,Fs);
set(fruit,...
'facecolor',nnltgray,...
'edgecolor',nnltgray);
delete(fruit)
set(arrows(2),...
'facecolor',nnred)
nnsound(wind,Fs);
set(arrows(2),...
'facecolor',nndkblue)
% UNLIGHT APPROPRIATE INDICATOR
nnpause(0.5)
nnsound(bloop,Fs);
set(indicators(fruit_id+1),...
'color',fruit_c)
set(box,...
'color',nndkblue)
delete(box)
set(fig,'nextplot','new')
% SAVE DATA
set(angle_ptr,'userdata',angle);
set(fruit_ptr,'userdata',fruit);
set(id_ptr,'userdata',fruit_id);
%==================================================================
% Remove previous fruit (activated by hitting "Clear" button).
%
% ME('remove')
%==================================================================
elseif strcmp(cmd,'remove') & (fig) & (nargin == 1)
% GET DATA
wind = get(sounds(1),'userdata');
blip = get(sounds(5),'userdata');
bloop = get(sounds(6),'userdata');
fruit = get(fruit_ptr,'userdata');
fruit_id = get(id_ptr,'userdata');
axes(fig_axis);
% GET RID OF PREVIOUS FRUIT
if length(fruit) > 0
% FRUIT COLOR
if (fruit_id == 1)
fruit_c = [1 0.5 0];
else
fruit_c = [1 0 0];
end
% UNLIGHT APPROPRIATE INDICATOR
nnpause(0.5)
nnsound(bloop,Fs);
set(indicators(fruit_id+1),...
'color',fruit_c)
% CLEAR VALUES
set(p_text,...
'color',nndkblue)
set(p_text(1),...
'string','SHAPE: ?',...
'color',nnltgray)
set(p_text(2),...
'string','TEXTURE: ?',...
'color',nnltgray)
set(p_text(3),...
'string','WEIGHT: ?',...
'color',nnltgray)
% CLEAR NETWORK DEPENDENT STUFF
feval(me,'clear')
% STORE DATA
set(fruit_ptr,'userdata',[]);
end
%==================================================================
% Setup network specific parts of window.
%
% ME('setup')
%==================================================================
elseif strcmp(cmd,'setup') & (fig) & (nargin == 1)
set(fig,'nextplot','add')
% EXPRESSION
x = 220;
text(x,340,'W = [.2 0 0; 0 1.2 0; 0 0 .2]',...
'color',nndkblue,...
'fontweight','bold',...
'fontsize',10)
text(x,304,'b1 = [0.9; 0; -0.9]',...
'color',nndkblue,...
'fontweight','bold',...
'fontsize',10)
line1 = text(x,268,'p = [?; ?; ?]',...
'color',nnltgray,...
'erasemode','none',...
'fontweight','bold',...
'fontsize',10);
line2 = text(x,232,'a(0) = p',...
'color',nnltgray,...
'erasemode','none',...
'fontweight','bold',...
'fontsize',10);
line3 = text(x,196,'a(0) = [?; ?; ?]',...
'color',nnltgray,...
'erasemode','none',...
'fontweight','bold',...
'fontsize',10);
line4 = text(x,160,'Fruit = ?',...
'color',nnltgray,...
'erasemode','none',...
'fontweight','bold',...
'fontsize',10);
% INPUT SPACE AXES
ext = 1.25;
input_axis = nnsfo('a4','Input Space','shape','texture','weight');
set(input_axis,...
'xlim',[-1 1]*ext,'xtick',[-1 1],...
'ylim',[-1 1]*ext,'ytick',[-1 1],...
'zlim',[-1 1]*ext,'ztick',[-1 1],...
'pos',[48 175 140 140],...
'box','off');
view(3)
% EDGE
edge = plot3([-1 -1 -1 1 1 1 -1]*ext,[-1 1 1 1 -1 -1 -1]*ext,...
[-1 -1 1 1 1 -1 -1]*ext,...
'color',nndkblue,...
'erasemode','none');
% BOX
box1 = plot3([-1 1 1 -1 -1],[-1 -1 -1 -1 -1],[-1 -1 1 1 -1],':',...
'color',nndkblue,...
'erasemode','none');
box2 = plot3([-1 1 1 -1 -1],[1 1 1 1 1],[-1 -1 1 1 -1],':',...
'color',nndkblue,...
'erasemode','none');
box3 = plot3([-1 -1 -1 -1 -1],[-1 1 1 -1 -1],[-1 -1 1 1 -1],':',...
'color',nndkblue,...
'erasemode','none');
box4 = plot3([1 1 1 1 1],[-1 1 1 -1 -1],[-1 -1 1 1 -1],':',...
'color',nndkblue,...
'erasemode','none');
boundary = plot3([-1 1 1 -1 -1],[0 0 0 0 0],[-1 -1 1 1 -1],...
'color',nndkblue,...
'erasemode','none');
% PROTOTYPE ORANGE
orange_dot = plot3(1,-1,-1,'.',...
'markersize',25,...
'color',[1 0.5 0],...
'erasemode','none');
% PROTOTYPE APPLE
apple_dot = plot3(1,1,-1,'.',...
'markersize',25,...
'color',[1 0 0],...
'erasemode','none');
% STORE DATA
p_mark_ptr = uicontrol('visible','off','userdata',[]);
lines_ptr = uicontrol('visible','off','userdata',...
[line1 line2 line3 line4]);
H = [input_axis, ...
orange_dot apple_dot,...
edge box1 box2 box3 box4 boundary,...
lines_ptr,...
p_mark_ptr];
set(net_ptr,'userdata',H);
set(fig,'nextplot','new')
%==================================================================
% Classify fruit with network.
%
% ME('classify')
%==================================================================
elseif strcmp(cmd,'classify') & (fig) & (nargin == 1)
% GET DATA
p = get(p_ptr,'userdata');
H = get(net_ptr,'userdata');
input_axis = H(1); % handle to input space axis
dots = H(2:3); % handles to orange & apple dots
frame = H(4:9); % frame & boundary
lines_ptr = H(10);
p_mark_ptr = H(11); % pointer to input marks
lines = get(lines_ptr,'userdata');
axes(input_axis);
set(fig,'nextplot','add')
% SHOW INPUT LINES
p1 = p(1);
p2 = p(2);
p3 = p(3);
p_marks = plot3([p1 p1 NaN p1 p1 NaN -1 1],[p2 p2 NaN -1 1 NaN p2 p2],...
[-1 1 NaN p3 p3 NaN p3 p3],'-',...
'color',nngreen,...
'erasemode','none',...
'markersize',15);
% FLASH INPUT LINES
for i=1:8
nnpause(0.075)
set(p_marks,...
'color',nnltyell)
set(dots(1),...
'color',[1 0.5 0])
set(dots(2),...
'color',[1 0 0])
set(frame,...
'color',nndkblue)
nnpause(0.05)
set(p_marks,...
'color',nngreen)
end
% PERFORM CALCULATION
W = [0.2 0 0; 0 1.2 0; 0 0 0.2];
b = [0.9; 0; -0.9];
a = p;
% SHOW FIRST CALCULATION
axes(fig_axis);
nntxtchk;
for i=1:3
if i == 1
str = ['p = [',num2str(p1),';',num2str(p2),';',num2str(p3),']'];
elseif i == 2
str = 'a(0) = p';
elseif i == 3
str = ['a(0) = [' num2str(a(1)) '; ' num2str(a(2)) '; ', ...
num2str(a(3)) ']'];
end
nnpause(1)
set(lines(i),...
'string',str,...
'color',nndkblue);
end
% REPEAT CALCULATION
i = 1;
path = [];
while any(a ~= [1;-1;-1]) & any(a ~= [1;1;-1])
nnpause(1)
set(lines(2),...
'color',nnltgray);
str = ['a(' num2str(i) ') = satlins(W*a(' num2str(i-1) ')+b)'];
set(lines(2),...
'string',str,...
'color',nndkblue);
nnpause(1)
old_a = a;
a = satlins(W*a+b);
a = round(a*100)*0.01;
set(lines(3),...
'color',nnltgray);
str = ['a(' num2str(i) ') = [' num2str(a(1)) '; ' num2str(a(2)) '; ', ...
num2str(a(3)) ']'];
set(lines(3),...
'string',str,...
'color',nndkblue);
new_path = plot3([a(1) old_a(1)],[a(2) old_a(2)],[a(3) old_a(3)],...
'color',nndkblue,...
'erasemode','none',...
'linewidth',2);
path = [path new_path];
i = i + 1;
end
p_marks = [p_marks path];
if (a(2) < 0)
fruit_str = 'Orange';
fruit_c = [1 0.5 0];
else
fruit_str = 'Apple';
fruit_c = [1 0 0];
end
% SHOW FRUIT
nnpause(1)
str = ['Fruit = ' fruit_str];
set(lines(4),...
'string',str,...
'color',nndkblue);
set(p_mark_ptr,'userdata',p_marks)
set(fig,'nextplot','new')
%==================================================================
% Clear fruit calculations.
%
% ME('clear')
%==================================================================
elseif strcmp(cmd,'clear') & (fig) & (nargin == 1)
% GET DATA
p = get(p_ptr,'userdata');
H = get(net_ptr,'userdata');
input_axis = H(1); % handle to input space axis
dots = H(2:3); % handles to orange & apple dots
frame = H(4:9); % frame & boundary
lines_ptr = H(10);
p_mark_ptr = H(11); % pointer to input marks
lines = get(lines_ptr,'userdata');
% HIDE INPUT LINES
p_marks = get(p_mark_ptr,'userdata');
set(p_marks,...
'color',nnltyell)
delete(p_marks)
set(dots(1),...
'color',[1 0.5 0])
set(dots(2),...
'color',[1 0 0])
set(frame,...
'color',nndkblue)
% HIDE CALCULATION
axes(fig_axis)
set(fig,'nextplot','add')
set(lines,'color',nnltgray);
nntxtchk;
set(fig,'nextplot','new')
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -