⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nnd11bc.m

📁 Martin T.Hagan等著,戴葵等译,神经网络设计,机械工业出版社,一书的所有例程
💻 M
📖 第 1 页 / 共 3 页
字号:
    'color',nnltgray,...
    'linewidth',wdth,...
    'erasemode','none');
  bp2_marker = plot([x5-sz-5 (x3-sz+[0 10 0 10])],y+[0 0 5 0 -5],...
    'color',nnltgray,...
    'linewidth',wdth,...
    'erasemode','none');
  W1_marker = plot(x1+20+[0 0 box_len box_len],y+[5 -5 -5 5],...
    'color',nnltgray,...
    'linewidth',wdth,...
    'erasemode','none');
  b1_marker = plot(x2-box_len/2+[0 0 box_len box_len],y+[5 -5 -5 5],...
    'color',nnltgray,...
    'linewidth',wdth,...
    'erasemode','none');
  W2_marker = plot(x3+sz+40+[0 0 box_len box_len],y+[5 -5 -5 5],...
    'color',nnltgray,...
    'linewidth',wdth,...
    'erasemode','none');
  b2_marker = plot(x4-box_len/2+[0 0 box_len box_len],y+[5 -5 -5 5],...
    'color',nnltgray,...
    'linewidth',wdth,...
    'erasemode','none');

  % LAST ERROR
  temp = nndtext(430,220,'Last Error:','right');
  set(temp,'fontsize',10);
  last_text = nndtext(440,220,'?.??','left');
  set(last_text,'fontsize',10);

  % BUTTONS
  go_box = plot(409+[0 1 1 0 0]*64,157+[0 0 1 1 0]*24,...
    'color',nnred,...
    'linewidth',4,...
    'erasemode','none');
  go_button = uicontrol(...
    'units','points',...
    'position',[410 160 60 20],...
    'string','Target',...
    'callback',[me '(''go'')']);
  uicontrol(...
    'units','points',...
    'position',[410 130 60 20],...
    'string','Reset',...
    'callback',[me '(''reset'')']);
  uicontrol(...
    'units','points',...
    'position',[410 105 60 20],...
    'string','Random',...
    'callback',[me '(''random'')'])
  uicontrol(...
    'units','points',...
    'position',[410 80 60 20],...
    'string','Contents',...
    'callback','nndtoc')
  uicontrol(...
    'units','points',...
    'position',[410 55 60 20],...
    'string','Close',...
    'callback',[me '(''close'')'])

  % DATA POINTERS
  W1_ptr = uicontrol('visible','off','userdata',W1);
  b1_ptr = uicontrol('visible','off','userdata',b1);
  W2_ptr = uicontrol('visible','off','userdata',W2);
  b2_ptr = uicontrol('visible','off','userdata',b2);
  state_ptr = uicontrol('visible','off','userdata',1);
  p_ptr = uicontrol('visible','off','userdata',1);
  a1_ptr = uicontrol('visible','off','userdata',[]);
  a2_ptr = uicontrol('visible','off','userdata',[]);
  e_ptr = uicontrol('visible','off','userdata',[]);
  s1_ptr = uicontrol('visible','off','userdata',[]);
  s2_ptr = uicontrol('visible','off','userdata',[]);
  t_ptr = uicontrol('visible','off','userdata',[]);
  blip_ptr = uicontrol('visible','off','userdata',nndsnd(6));
  bloop_ptr = uicontrol('visible','off','userdata',nndsnd(7));
  blp_ptr = uicontrol('visible','off','userdata',nndsnd(9));

  % SAVE WINDOW DATA AND LOCK
  H = [fig_axis desc_text,...
       W1_ptr b1_ptr W2_ptr b2_ptr,...
       p_name W11_box W11_text W11_name W12_box W12_text W12_name,...
       b11_box b11_text b11_name b12_box b12_text b12_name,...
       a11_name a12_name W21_box W21_text W21_name,...
       W22_box W22_text W22_name b2_box b2_text b2_name,...
       a2_name t_name e_name,...
       vars vals,...
       fp1_marker fp2_marker fp3_marker bp1_marker bp2_marker,...
       W1_marker b1_marker W2_marker b2_marker p_marker t_marker,...
       state_ptr, ...
       p_ptr a1_ptr a2_ptr e_ptr s1_ptr s2_ptr t_ptr,...
       go_button,...
       s11_name s12_name s2_name,...
       blip_ptr bloop_ptr blp_ptr,...
       state1 state2 state3 state4,...
       go_box last_text,...
       p_edit];

  set(fig,'userdata',H,'nextplot','new')

  % INSTRUCTION TEXT
  % eval(me,'instr');

  % LOCK WINDOW
  set(fig,'nextplot','new','color',nnltgray);

  nnchkfs;

%==================================================================
% Display the instructions.
%
% ME('instr')
%==================================================================

elseif strcmp(cmd,'instr') & (fig)
  nnsettxt(desc_text,...
    'Alter network weights',...
    'and biases by dragging',...
    'the triangular shaped',...
    'indicators.',...
    '',...
    'Drag the vertical line',...
    'in the graph below to',...
    'find the output for a',...
    'particular input.',...
    '',...
    'Click on [Random] to',...
    'set each parameter',...
    'to a random value.')
    
%==================================================================
% Change input.
%
% ME('p')
%==================================================================

elseif strcmp(cmd,'p') & (fig)

  p = str2num(get(p_edit,'string'));
  set(p_ptr,'userdata',p);
  set(p_edit,'string',num2str(p));

%==================================================================
% Reset parameters.
%
% ME('reset')
%==================================================================

elseif strcmp(cmd,'reset') & (fig)

  W1 = [-0.27; -0.41];
  b1 = [-0.48; -0.13];
  W2 = [0.09 -0.17];
  b2 = [0.48];

  set(W1_ptr,'userdata',W1);
  set(b1_ptr,'userdata',b1);
  set(W2_ptr,'userdata',W2);
  set(b2_ptr,'userdata',b2);

  set(W11_name,'color',nnwhite);
  set(W12_name,'color',nnwhite);
  set(b11_name,'color',nnwhite);
  set(b12_name,'color',nnwhite);
  set(W21_name,'color',nnwhite);
  set(W22_name,'color',nnwhite);
  set(b2_name,'color',nnwhite);
  nnsound(blip);
  nnpause(pause_time);

  set(W11_box,'facecolor',nnwhite);
  set(W12_box,'facecolor',nnwhite);
  set(b11_box,'facecolor',nnwhite);
  set(b12_box,'facecolor',nnwhite);
  set(W21_box,'facecolor',nnwhite);
  set(W22_box,'facecolor',nnwhite);
  set(b2_box,'facecolor',nnwhite);
  set(W11_text,'color',nndkblue);
  set(W12_text,'color',nndkblue);
  set(b11_text,'color',nndkblue);
  set(b12_text,'color',nndkblue);
  set(W21_text,'color',nndkblue);
  set(W22_text,'color',nndkblue);
  set(b2_text,'color',nndkblue);
  nnsound(blp);
  nnpause(pause_time);

  set(W11_box,'facecolor',nnltgray);
  set(W12_box,'facecolor',nnltgray);
  set(b11_box,'facecolor',nnltgray);
  set(b12_box,'facecolor',nnltgray);
  set(W21_box,'facecolor',nnltgray);
  set(W22_box,'facecolor',nnltgray);
  set(b2_box,'facecolor',nnltgray);
  set(W11_text,'string',sprintf('%5.3f',W1(1)));
  set(W12_text,'string',sprintf('%5.3f',W1(2)));
  set(b11_text,'string',sprintf('%5.3f',b1(1)));
  set(b12_text,'string',sprintf('%5.3f',b1(2)));
  set(W21_text,'string',sprintf('%5.3f',W2(1)));
  set(W22_text,'string',sprintf('%5.3f',W2(2)));
  set(b2_text,'string',sprintf('%5.3f',b2));
  set(W11_name,'color',nndkblue);
  set(W12_name,'color',nndkblue);
  set(b11_name,'color',nndkblue);
  set(b12_name,'color',nndkblue);
  set(W21_name,'color',nndkblue);
  set(W22_name,'color',nndkblue);
  set(b2_name,'color',nndkblue);
  nnsound(blp);
  nnpause(pause_time);

  set(state_ptr,'userdata',1);
  set(go_button,'string','Target');
  for i=1:11
    set(vals(i),'color',nnltgray);
    set(vals(i),'string','?');
    set(vals(i),'color',nndkblue);
  end
  nnsound(bloop);

  set(last_text,'color',nnltgray);
  set(last_text,'string','?.??');
  set(last_text,'color',nndkblue);

%==================================================================
% Randomize parameters.
%
% ME('random')
%==================================================================

elseif strcmp(cmd,'random') & (fig)

  W1 = rands(2,1);
  b1 = rands(2,1);
  W2 = rands(1,2);
  b2 = rands(1,1);

  set(W1_ptr,'userdata',W1);
  set(b1_ptr,'userdata',b1);
  set(W2_ptr,'userdata',W2);
  set(b2_ptr,'userdata',b2);

  set(W11_name,'color',nnwhite);
  set(W12_name,'color',nnwhite);
  set(b11_name,'color',nnwhite);
  set(b12_name,'color',nnwhite);
  set(W21_name,'color',nnwhite);
  set(W22_name,'color',nnwhite);
  set(b2_name,'color',nnwhite);
  nnsound(blip);
  nnpause(pause_time);

  set(W11_box,'facecolor',nnwhite);
  set(W12_box,'facecolor',nnwhite);
  set(b11_box,'facecolor',nnwhite);
  set(b12_box,'facecolor',nnwhite);
  set(W21_box,'facecolor',nnwhite);
  set(W22_box,'facecolor',nnwhite);
  set(b2_box,'facecolor',nnwhite);
  set(W11_text,'color',nndkblue);
  set(W12_text,'color',nndkblue);
  set(b11_text,'color',nndkblue);
  set(b12_text,'color',nndkblue);
  set(W21_text,'color',nndkblue);
  set(W22_text,'color',nndkblue);
  set(b2_text,'color',nndkblue);
  nnsound(blp);
  nnpause(pause_time);

  set(W11_box,'facecolor',nnltgray);
  set(W12_box,'facecolor',nnltgray);
  set(b11_box,'facecolor',nnltgray);
  set(b12_box,'facecolor',nnltgray);
  set(W21_box,'facecolor',nnltgray);
  set(W22_box,'facecolor',nnltgray);
  set(b2_box,'facecolor',nnltgray);
  set(W11_text,'string',sprintf('%5.3f',W1(1)));
  set(W12_text,'string',sprintf('%5.3f',W1(2)));
  set(b11_text,'string',sprintf('%5.3f',b1(1)));
  set(b12_text,'string',sprintf('%5.3f',b1(2)));
  set(W21_text,'string',sprintf('%5.3f',W2(1)));
  set(W22_text,'string',sprintf('%5.3f',W2(2)));
  set(b2_text,'string',sprintf('%5.3f',b2));
  set(W11_name,'color',nndkblue);
  set(W12_name,'color',nndkblue);
  set(b11_name,'color',nndkblue);
  set(b12_name,'color',nndkblue);
  set(W21_name,'color',nndkblue);
  set(W22_name,'color',nndkblue);
  set(b2_name,'color',nndkblue);
  nnsound(blp);
  nnpause(pause_time);

  set(state_ptr,'userdata',1);
  set(go_button,'string','Target');
  for i=1:11
    set(vals(i),'color',nnltgray);
    set(vals(i),'string','?');
    set(vals(i),'color',nndkblue);
  end
  nnsound(bloop);

  set(last_text,'color',nnltgray);
  set(last_text,'string','?.??');
  set(last_text,'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])

    W1 = arg1;
    b1 = arg2;
    W2 = arg3;
    b2 = arg4;

    set(W1_ptr,'userdata',W1);
    set(b1_ptr,'userdata',b1);
    set(W2_ptr,'userdata',W2);
    set(b2_ptr,'userdata',b2);

  set(W11_name,'color',nnwhite);
  set(W12_name,'color',nnwhite);
  set(b11_name,'color',nnwhite);
  set(b12_name,'color',nnwhite);
  set(W21_name,'color',nnwhite);
  set(W22_name,'color',nnwhite);
  set(b2_name,'color',nnwhite);
  nnsound(blip);
  nnpause(pause_time);

  set(W11_box,'facecolor',nnwhite);
  set(W12_box,'facecolor',nnwhite);
  set(b11_box,'facecolor',nnwhite);
  set(b12_box,'facecolor',nnwhite);
  set(W21_box,'facecolor',nnwhite);
  set(W22_box,'facecolor',nnwhite);
  set(b2_box,'facecolor',nnwhite);
  set(W11_text,'color',nndkblue);
  set(W12_text,'color',nndkblue);
  set(b11_text,'color',nndkblue);
  set(b12_text,'color',nndkblue);
  set(W21_text,'color',nndkblue);
  set(W22_text,'color',nndkblue);
  set(b2_text,'color',nndkblue);
  nnsound(blp);
  nnpause(pause_time);

  set(W11_box,'facecolor',nnltgray);
  set(W12_box,'facecolor',nnltgray);
  set(b11_box,'facecolor',nnltgray);
  set(b12_box,'facecolor',nnltgray);
  set(W21_box,'facecolor',nnltgray);
  set(W22_box,'facecolor',nnltgray);
  set(b2_box,'facecolor',nnltgray);
  set(W11_text,'string',sprintf('%5.3f',W1(1)));
  set(W12_text,'string',sprintf('%5.3f',W1(2)));
  set(b11_text,'string',sprintf('%5.3f',b1(1)));
  set(b12_text,'string',sprintf('%5.3f',b1(2)));
  set(W21_text,'string',sprintf('%5.3f',W2(1)));
  set(W22_text,'string',sprintf('%5.3f',W2(2)));
  set(b2_text,'string',sprintf('%5.3f',b2));
  set(W11_name,'color',nndkblue);
  set(W12_name,'color',nndkblue);
  set(b11_name,'color',nndkblue);
  set(b12_name,'color',nndkblue);
  set(W21_name,'color',nndkblue);
  set(W22_name,'color',nndkblue);
  set(b2_name,'color',nndkblue);
  nnsound(blp);
  nnpause(pause_time);

  set(state_ptr,'userdata',1);
  set(go_button,'string','Target');
  for i=1:11
    set(vals(i),'color',nnltgray);
    set(vals(i),'string','?');
    set(vals(i),'color',nndkblue);
  end
  nnsound(bloop);

  set(last_text,'color',nnltgray);
  set(last_text,'string','?.??');
  set(last_text,'color',nndkblue);

  end

%==================================================================
% Get parameters.
%
% [W1,b1,W2,b2,f2] = ME('get')
%==================================================================

elseif strcmp(cmd,'get') & (fig)

  % GET DATA
  ret1 = get(W1_ptr,'userdata');
  ret2 = get(b1_ptr,'userdata');
  ret3 = get(W2_ptr,'userdata');
  ret4 = get(b2_ptr,'userdata');

%==================================================================
% Simulate network.
%
% [W1,b1,W2,b2,f2] = ME('go')
%==================================================================

elseif strcmp(cmd,'go') & (fig)

  % TARGET
  % ======

  set(go_box,'color',nnltgray);

  if (state == 1)

  % P
  p = get(p_ptr,'userdata');

  set(state1,'color',nngreen);
  set(vars(2),'color',nnwhite);
  nnsound(blip);
  nnpause(pause_time)

  % T
  t = 1+sin(pi/4*p);
  set(t_name,'color',nnwhite);
  set(t_marker,'color',nngreen);
  nnsound(blip);
  nnpause(pause_time)

  str = '1+sin(p*pi/4)';
  set(vals(2),'color',nnltgray);
  set(vals(2),'string',str);
  set(vals(2),'color',nndkblue);
  nnsound(blp);
  nnpause(pause_time);

  str = sprintf('1+sin(p*pi/4) = %5.3f',t);
  set(vals(2),'color',nnltgray);
  set(vals(2),'string',str);
  set(vals(2),'color',nndkblue);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -