📄 nnd11nf.m
字号:
for i=1:7
if any([3 6 7] == i)
maxval = 2;
else
maxval = 10;
end
pt = get(meters(i),'currentpoint');
x = pt(1);
y = pt(3);
if (abs(x) <= maxval*1.3) & (y >= -0.3 & y <= 1.3)
handled = 1;
% SET UP MOTION TRACKING IN METER
set(fig,'WindowButtonMotionFcn',[me '(''m_motion'',' num2str(i) ')']);
set(fig,'WindowButtonUpFcn',[me '(''m_up'',' num2str(i) ')']);
feval(me,'m_motion',i);
end
end
if (~handled)
pt = get(func_axis,'currentpoint');
x = pt(1);
y = pt(3);
ylim = get(func_axis,'ylim');
if (abs(x) <= p_max) & (y >= ylim(1) & y <= ylim(2))
% SET UP MOTION TRACKING FOR FUNCTION
set(fig,'WindowButtonMotionFcn',[me '(''f_motion'')']);
set(fig,'WindowButtonUpFcn',[me '(''f_up'')']);
feval(me,'f_motion',i);
end
end
%==================================================================
% Respond to motion in meter.
%
% ME('m_motion',meter_index)
%==================================================================
elseif strcmp(cmd,'m_motion') & (fig)
if any([3 6 7] == arg1)
maxval = 2;
else
maxval = 10;
end
% GET CURRENT POINT
pt = get(meters(arg1),'currentpoint');
x = pt(1);
x = round(x*10/maxval)*maxval/10;
x = max(-maxval,min(maxval,x));
% GET DATA
mdgray = nnmdgray;
values = get(values_ptr,'userdata');
% MOVE INDICATOR
xdata = [0 0.2 -0.2]*maxval+x;
set(indicators(arg1),'facecolor',mdgray,'edgecolor',mdgray);
set(indicators(arg1),'facecolor',nnwhite,'edgecolor',nndkblue,'xdata',xdata);
% STORE DATA
values(arg1) = x;
set(values_ptr,'userdata',values);
%==================================================================
% Respond to mouse up in meter.
%
% ME('m_up',meter_index)
%==================================================================
elseif strcmp(cmd,'m_up') & (fig)
% DISABLE TRACKING
set(fig,'WindowButtonMotionFcn','');
set(fig,'WindowButtonMotionFcn','');
% RESET INDICATOR COLORS
set(indicators(arg1),'facecolor',nnred,'edgecolor',nndkblue);
% UPDATE FUNCTION
cmd = 'update';
%==================================================================
% Respond to motion in function.
%
% ME('f_motion')
%==================================================================
elseif strcmp(cmd,'f_motion') & (fig)
% GET CURRENT POINT
pt = get(func_axis,'currentpoint');
x = pt(1);
x = max(-p_max,min(p_max,x));
% GET DATA
mdgray = nnmdgray;
tf = get(tf_ptr,'userdata');
values = get(values_ptr,'userdata');
W1 = values([1 4])';
b1 = values([2 5])';
W2 = values([3 6]);
b2 = values(7);
ltyell = nnltyell;
% NEW INPUT & OUTPUT
p = x;
a = feval(tf,W2*logsig(W1*p+b1)+b2);
% MOVE LINES
set(a_line,'color',ltyell);
set(p_line,'color',ltyell);
set(p_line,'color',nngreen,'xdata',[p p])
set(a_line,'color',nnred,'ydata',[a a],'xdata',[-p_max p])
set(func_line,'color',nndkblue)
% STORE DATA
values(8) = p;
values(9) = a;
set(values_ptr,'userdata',values);
%==================================================================
% Respond to mouse up in function.
%
% ME('f_up')
%==================================================================
elseif strcmp(cmd,'f_up') & (fig)
% DISABLE TRACKING
set(fig,'WindowButtonMotionFcn','');
set(fig,'WindowButtonMotionFcn','');
% RESET P-LINE COLOR
red = nnred;
set(p_line,'color',red)
set(a_line,'color',red)
set(func_line,'color',nndkblue)
%==================================================================
% Set parameters.
%
% ME('set',W1,b1,W2,b2,f2)
%==================================================================
elseif strcmp(cmd,'set') & (fig) & (nargin == 6)
% CHECK SIZES
if all(size(arg1) == [2 1]) & ...
all(size(arg2) == [2 1]) & ...
all(size(arg3) == [1 2]) & ...
all(size(arg4) == [1 1])
% GET VALUES
values = get(values_ptr,'userdata');
tf = get(tf_ptr,'userdata');
p = values(8);
% ALTER VALUES
W1 = min(w_max,max(-w_max,arg1));
b1 = min(w_max,max(-w_max,arg2));
W2 = min(w_max,max(-w_max,arg3));
b2 = min(w_max,max(-w_max,arg4));
if strcmp(arg5,'linear')
tf = 'purelin';
set(tf_menu,'value',2)
elseif strcmp(arg5,'logsig')
tf = 'logsig';
set(tf_menu,'value',1)
elseif strcmp(arg5,'purelin')
tf = 'purelin';
set(tf_menu,'value',2)
elseif strcmp(arg5,'tansig')
tf = 'tansig';
set(tf_menu,'value',3)
end
[R,Q] = size(p);
a = feval(tf,W2*logsig(W1*p+b1*ones(1,Q))+b2*ones(1,Q));
values = [W1(1) b1(1) W2(1) W1(2) b1(2) W2(2) b2 p a];
% SAVE VALUES
set(values_ptr,'userdata',values);
% MOVE METERS
cmd = 'move';
end
%==================================================================
% Randomize parameters.
%
% ME('random')
%==================================================================
elseif strcmp(cmd,'random') & (fig)
% GET VALUES
values = get(values_ptr,'userdata');
p = values(8);
% ALTER VALUES
W1 = (rand(2,1)*2-1)*10;
b1 = (rand(2,1)*2-1)*01;
W2 = (rand(1,2)*2-1)*2;
b2 = (rand(1,1)*2-1)*2;
tf_ind = fix(rand*3)+1;
set(tf_menu,'value',tf_ind)
if tf_ind == 1
tf = 'logsig';
elseif tf_ind == 2
tf = 'purelin';
elseif tf_ind == 3
tf = 'tansig';
end
set(tf_ptr,'userdata',tf)
[R,Q] = size(p);
a = feval(tf,W2*logsig(W1*p+b1*ones(1,Q))+b2*ones(1,Q));
values = [W1(1) b1(1) W2(1) W1(2) b1(2) W2(2) b2 p a];
% SAVE VALUES
set(values_ptr,'userdata',values);
% MOVE METERS
cmd = 'move';
%==================================================================
% Get parameters.
%
% [W1,b1,W2,b2,f2] = ME('get')
%==================================================================
elseif strcmp(cmd,'get') & (fig)
% GET DATA
values = get(values_ptr,'userdata');
ret1 = values([1 4])';
ret2 = values([2 5])';
ret3 = values([3 6]);
ret4 = values(7);
ret5 = get(tf_ptr,'userdata');
end
%==================================================================
% Move meters.
%
% ME('move')
%==================================================================
if strcmp(cmd,'move') & (fig)
% GET DATA
values = get(values_ptr,'userdata');
% PICK PROPER ICON
axes(fig_axis);
tf_icon = get(tf_icon_ptr,'userdata');
delete(tf_icon);
tf_icon = nndsicon(tf,310,245,15);
set(tf_icon_ptr,'userdata',tf_icon);
% HILIGHT METERS
mdgray = nnmdgray;
red = nnred;
white = nnwhite;
dkblue = nndkblue;
for i=1:7
set(indicators(i),'facecolor',white);
end
nnpause(0.25)
% MOVE METERS
for i=1:7
if any([3 6 7] == i)
maxval = 2;
else
maxval = 10;
end
xx = [0 0.2 -0.2]*maxval+values(i);
set(indicators(i),'facecolor',mdgray,'edgecolor',mdgray);
set(indicators(i),'facecolor',white,'edgecolor',dkblue,'xdata',xx);
end
nnpause(0.25)
% UNHILIGHT METERS
for i=1:7
set(indicators(i),'facecolor',red);
end
% ALWAYS DO AN UPDATE AFTERWARDS
cmd = 'update';
end
%==================================================================
% Update function.
%
% ME('update')
%==================================================================
if strcmp(cmd,'update') & (fig)
% GET DATA
tf = get(tf_ptr,'userdata');
values = get(values_ptr,'userdata');
W1 = values([1 4])';
b1 = values([2 5])';
W2 = values([3 6]);
b2 = values(7);
p = values(8);
ltyell = nnltyell;
red = nnred;
% NEW FUNCTION
[R,Q] = size(p);
a = feval(tf,W2*logsig(W1*p+b1*ones(1,Q))+b2*ones(1,Q));
P = -p_max:0.05:p_max;
[R,Q] = size(P);
A = feval(tf,W2*logsig(W1*P+b1*ones(1,Q))+b2*ones(1,Q));
% CALCULATE AXIS AND LINE LIMITS
a_max = max(A);
a_min = min(A);
a_mid = (a_max+a_min)/2;
a_dif = a_max-a_min;
a_dif = a_dif + max(a_dif*0.1,0.1);
a_max = a_mid+0.45*a_dif;
a_min = a_mid-0.45*a_dif;
a_edge = 0.05*a_dif;
% HIDE LINES
set(func_line,'color',ltyell);
set(p_line,'color',ltyell);
set(a_line,'color',ltyell);
% RESIZE AXIS
set(func_axis,'ylim',[a_min-a_edge a_max+a_edge]);
hold on
% REDRAW LINES
set(p_line,'color',red,'xdata',[p p],'ydata',[a_min a_max])
set(a_line,'color',red,'ydata',[a a],'xdata',[-p_max p])
set(func_line,'color',nndkblue,'xdata',P,'ydata',A)
% STORE DATA
set(values_ptr,'userdata',values);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -