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

📄 nnd2nm.m

📁 Martin T.Hagan等著,戴葵等译,神经网络设计,机械工业出版社,一书的所有例程
💻 M
字号:
function nnd2nm(cmd,arg1,arg2,arg3)
%NND2NM Neuron model demonstration.

% First Version, 8-31-95.

%==================================================================

% CONSTANTS
me = 'nnd2nm';
max_t = 0.5;

% DEFAULTS
if nargin == 0, cmd = ''; else cmd = lower(cmd); end

% FIND WINDOW IF IT EXISTS
fig = nnfgflag(me);
if length(get(fig,'children')) == 0, fig = 0; end
  
% GET WINDOW DATA IF IT EXISTS
if fig
  H = get(fig,'userdata');
  fig_axis = H(1);            % window axis
  desc_text = H(2);           % handle to first line of text sequence
end

%==================================================================
% Activate the window.
%
% ME() or ME('')
%==================================================================

if strcmp(cmd,'')
  if fig
    figure(fig)
    set(fig,'visible','on')
  else
    feval(me,'init')
  end

%==================================================================
% Close the window.
%
% ME() or ME('')
%==================================================================

elseif strcmp(cmd,'close') & (fig)
  delete(fig)

%==================================================================
% Initialize the window.
%
% ME('init')
%==================================================================

elseif strcmp(cmd,'init') & (~fig)

  % CONSTANTS
  w = [0.5 -0.5];
  b = [0.1];
  p = [0.2; -0.4];
  tf = 'hardlim';
  title_str = 'Neuron Model Demonstration';
  chapter_str = 'Chapter 2';

  % NEW DEMO FIGURE
  if strcmp(get(gcf,'nextplot'),'new')
    pos = get(0,'defaultfigureposition');
    figure('position',[pos(1:2) 500 400],'colormap',nncolor);
  else
    clf reset
  end
  fig = gcf;
  pos = get(fig,'position');
  set(fig,...
    'units','points',...
    'position',[pos(1:2) 500 400], ...
    'resize','off', ...
    'color',nnltgray, ...
    'inverthardcopy','off', ...
    'nextplot','add',...
    'visible','on',...
    'name',me,...
    'numbertitle','off',...
    'BackingStore','off',...
    'windowbuttondownfcn',[me '(''down'')']);

  % FIGURE AXIS
  figpos = get(gcf,'position');
  pos = [0 0 figpos(3:4)];
  fig_axis = axes(...
    'units','points', ...
    'position',pos,...
    'fontsize',10,...
    'nextplot','add',...
    'xlim',[0 pos(3)],...
    'ylim',[0 pos(4)]);
  axis('off')

  % OUTLINE AND BACKGROUND
  plot([0 0 500 500 0],[0 399 399 0 0],'color',nnblack)
  set(fig,'color',nndkgray,'color',nnltgray)

  % TITLES
  text(25,380,'Neural Network', ...
    'color',nnblack, ...
    'fontname','times', ...
    'fontsize',16, ...
    'fontangle','italic', ...
    'fontweight','bold');
  text(135,380,'Design', ...
    'color',nnblack, ...
    'fontname','times', ...
    'fontsize',16, ...
    'fontweight','bold');
  text(415,380,title_str,...
    'color',nnblack, ...
    'fontname','times', ...
    'fontsize',16, ...
    'fontweight','bold',...
    'HorizontalAlignment','right');
  nnline([0 415],[365 365],4,nndkblue);
  nnline([360 360],[340 22],4,nndkblue); % nndrwlin

  % DESCRIPTION TEXT
  desc_text = text(370,315,'',...
    'color',nnblack, ...
    'fontname','helvetica', ...
    'fontsize',10);
  text1 = desc_text;
  for i=1:24
    text2 = text(370,315-6*i,'',...
      'color',nnblack, ...
      'fontname','helvetica', ...
      'fontsize',10);
    set(text1,'userdata',text2);
    text1 = text2;
  end
  set(text1,'userdata','end');
  text(410,38,chapter_str, ...
    'color',nnblack, ...
    'fontname','times', ...
    'fontsize',12, ...
    'fontweight','bold');
  nnline([410 501],[24 24],4,nndkblue);

  % ICON
  nndicon(2,458,363,'shadow')

  % NEURON DIAGRAM
  x = 100; dx = 100;
  y = 330; dy = 50;
  nnline(x+[0 dx 0],y-[0 1 2]*dy,4,nnred)
  nnline(x+[dx dx],y-[1 2.5]*dy,4,nnred)
  nndrwcir(x,y,5,nnred)
  nndrwcir(x,y-2*dy,5,nnred)
  nndrwcir(x+dx,y-2.5*dy,5,nnred)
  nnarrow(x+[1 2]*dx,y-[dy dy],4,nnred);
  nndicon(2,x+dx,y-dy)

  % VALUES
  text(x-20,y,'p(1)',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right');
  if 0
  text(x-20,y-60,'p(2)',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right');
  text(x+50,y+10,'w(1,1)',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right');
  text(x+50,y-70,'w(1,2)',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right');
  text(x+80,y-95,'b',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','center');
  text(x+180,y-30,'a',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','left');
  end

  % SLIDE BARS
  drawnow % Let everything else appear before buttons 
  axes(fig_axis)

  % BUTTONS
  uicontrol(...
    'units','points',...
    'position',[400 145 60 20],...
    'string','Info',...
    'callback','nnd10nci')
  uicontrol(...
    'units','points',...
    'position',[400 110 60 20],...
    'string','Book',...
    'callback','nndbook')
  uicontrol(...
    'units','points',...
    'position',[400 75 60 20],...
    'string','Close',...
    'callback',[me '(''close'')'])

  % DATA POINTERS

  % SAVE WINDOW DATA AND LOCK
  H = [fig_axis desc_text];
  set(fig,'userdata',H,'nextplot','new')

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

  % UPDATE PLOTS
  cmd = 'update';

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

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

elseif strcmp(cmd,'instr') & (fig)
  nnsettxt(desc_text,...
    'Click on the bottom left axis',...
    'to change the initial weights.',...
    '',...
    'Use the sliders to alter the',...
    'learning rate & momentum.',...
    '',...
    'The radio buttons allow both',...
    'the actual noise free signal',...
    'and the network''s estimate',...
    'to be viewed, or just 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';
  
%==================================================================
end

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

if strcmp(cmd,'update') & (fig)
  
  % GET DATA

  % CALCULATE OUTPUT
   
  % SHOW OUTPUT

end

⌨️ 快捷键说明

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