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

📄 nnd10nc.m

📁 《神经网络设计》(neural networks design)的源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
    'style','radiobutton',...
    'string','Difference',...
    'callback',[me '(''show_e'')'],...
    'background',nnltgray,...
    'value',0);

  % 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',...
    'userdata',w);
  w_cont_ptr = uicontrol(...
    'visible','off',...
    'userdata',w_cont);
  P_ptr = uicontrol(...
    'visible','off',...
    'userdata',P);
  T_ptr = uicontrol(...
    'visible','off',...
    'userdata',T);
  s_line_ptr = uicontrol(...
    'visible','off',...
    'userdata',[]);
  w_path_ptr = uicontrol(...
    'visible','off',...
    'userdata',[]);
  S_ptr = uicontrol(...
    'visible','off',...
    'userdata',signal);

  % SAVE WINDOW DATA AND LOCK
  H = [fig_axis desc_text signal_axis weight_axis ...
       lr_text lr_bar mc_bar mc_text dc_line w_ptr w_cont_ptr w_pt ...
       P_ptr T_ptr show_s show_e w_line e_line t_line d_line S_ptr];
  set(fig,'userdata',H,'nextplot','new')

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

  % UPDATE PLOTS
  cmd = 'update';

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

  nnchkfs;

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

elseif strcmp(cmd,'instr') & (fig)
  nnsettxt(desc_text,...
    'Click on the bottom',...
    'contour plot to change.',...
    'initial weights.',...
    '',...
    'Use the sliders to',...
    'alter the learning rate',...
    'and momentum.',...
    '',...
    'The radio buttons',...
    'allow the display of',...
    'the original and',...
    'estimated signals',...
    'or their difference')

%==================================================================
% Respond to new learning rate.
%
% ME('lr')
%==================================================================

elseif strcmp(cmd,'lr') & (fig)
  
  % CHANGE LR TEXT
  lr = get(lr_bar,'value');
  lr = round(lr*100)/100;
  set(lr_text,'string',num2str(lr))
  cmd = 'update';
  
%==================================================================
% Respond to new momentum constant.
%
% ME('mc')
%==================================================================

elseif strcmp(cmd,'mc') & (fig)
  
  % CHANGE MC TEXT
  mc = get(mc_bar,'value');
  mc = round(mc*100)/100;
  set(mc_text,'string',num2str(mc))

  % UPDATE PLOTS
  cmd = 'update';
  
%==================================================================
% Respond to mouse down.
%
% ME('down')
%==================================================================

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

  % SEE IF POINT IS IN WEIGHT AXIS
  pt = get(weight_axis,'currentpoint');
  x = pt(1);
  y = pt(3);
  xlim = get(weight_axis,'xlim');
  ylim = get(weight_axis,'ylim');
  if (x >= -2) & (x <= 2) & (y >= -2) & (y <= 2)

    % HIDE INITIAL WEIGHTS
    set(w_pt,'color',nnltyell);
    
    % CREATE NEW INITIAL WEIGHTS
    set(w_pt,...
      'xdata',x,...
      'ydata',y,...
      'color',nnred)

    % STORE DATA
    set(w_ptr,'userdata',[x y])

    % UPDATE PLOTS
    cmd = 'update';
  end

%==================================================================
% Respond to request to show signals.
%
% ME('show_s')
%==================================================================

elseif strcmp(cmd,'show_s') & (fig)
  
  % TURN OFF OTHER RADIO BUTTON
  set(show_e,'value',0); set(show_s,'value',1)
  
  % HIDE DIFFERENCE PLOT
  set(d_line,'color',nnltyell);
  set(d_line,'visible','off')
  set(dc_line,'color',nndkblue);

  % SHOW SIGNAL PLOTS
  set(t_line,...
    'color',nndkblue,...
    'visible','on')
  set(e_line,...
    'color',nnred,...
    'visible','on')

  % SHOW SIGNAL TITLE
  set(get(signal_axis,'title'),...
    'string','Original (blue) and Estimated (red) Signals')

%==================================================================
% Respond to request to show errors.
%
% ME('show_e')
%==================================================================

elseif strcmp(cmd,'show_e') & (fig)
  
  % TURN OFF OTHER RADIO BUTTON
  set(show_s,'value',0); set(show_e,'value',1)

  % HIDE SIGNAL PLOTS
  set(t_line,'color',nnltyell);
  set(t_line,'visible','off')
  set(e_line,'color',nnltyell);
  set(e_line,'visible','off')
  set(dc_line,'color',nndkblue);

  % SHOW SIGNAL PLOTS
  set(d_line,...
    'color',nnred,...
    'visible','on')

  % SHOW DIFFERENCE TITLE
  set(get(signal_axis,'title'),...
    'string','Difference between Original and Estimated Signals')

%==================================================================
end

%==================================================================
% Respond to request to update displays.
%
% ME('update')
%==================================================================

if strcmp(cmd,'update') & (fig)
  
  % GET DATA
  P = get(P_ptr,'userdata');
  T = get(T_ptr,'userdata');
  S = get(S_ptr,'userdata');
  w = get(w_ptr,'userdata');
  lr = get(lr_bar,'value');
  mc = get(mc_bar,'value');
  w_cont = get(w_cont_ptr,'userdata');
  lr = round(lr*100)/100;
  mc = round(mc*100)/100;


  % GET READY TO ADAPT
  w0 = w;               % Initial weights
  q = size(P,2);        % Number of timesteps
  a = zeros(1,q);       % Network output over time
  e = zeros(1,q);       % Network error over time
  W = zeros(2,q);       % Network weights over time
  time = [1:q]/q*max_t; % Simulation time points
   
  % ADAPTING
  old_dw = [0 0];
  for i=1:q
    a(i) = w*P(:,i);
    e(i) = T(i) - a(i);
    dw = mc*old_dw + (1-mc)*lr*e(i)*P(:,i)';
    w = w + dw;
    W(:,i) = w';
    old_dw = dw;
  end
  
  % CLEAR SIGNAL AXIS
  axes(signal_axis)
  set(e_line,'color',nnltyell);
  set(t_line,'color',nnltyell);
  set(d_line,'color',nnltyell);
  set(dc_line,'color',nndkblue);
  drawnow

  % CLEAR WEIGHT AXIS
  axes(weight_axis)
  set(w_line,'color',nnltyell);
  for i=(w_cont')
    set(i,'edgecolor',get(i,'edgecolor'))
  end
  set(w_pt,'color',nnred)

  % NEW WEIGHTS
  axes(weight_axis)
  index = find((W(1,:) < -2) | (W(1,:) > 2) | (W(2,:) < -2) | (W(2,:) > 2));
  if (length(index))
    mode = 'normal';
  else
    mode = 'none';
  end
  set(w_line,...
    'erasemode',mode);
  set(w_line,...
    'xdata',[w0(1) W(1,:)],...
    'ydata',[w0(2) W(2,:)],...
    'color',nnred);

  % NEW SIGNALS
  axes(signal_axis)
  ylim = [-2 2];
  ymin = ylim(1);
  ymax = ylim(2);

  set(d_line,...
    'ydata',max(ymin,min(ymax,S-e)),...
    'color',nnred);
  set(t_line,...
    'color',nndkblue);
  set(e_line,...
    'ydata',max(ymin,min(ymax,e)),...
    'color',nnred);
end

⌨️ 快捷键说明

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