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

📄 nnd14dynd.m

📁 《神经网络设计》英文版的配套源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
function [ret1,ret2,ret3,ret4,ret5]=nnd14dynd(cmd,arg1,arg2,arg3,arg4,arg5)
%NND14DYND Finite Impulse Response Network
%
%  This demonstration requires either the MININNET functions
%  on the NND disk or the Neural Network Toolbox.
%
%  NND14DYND
%  Opens demonstration with default values.
%
%  NND14DYND('random')
%  Sets network parameters to randomly chosen values.
%

% Copyright 1994-2002 PWS Publishing Company and The MathWorks, Inc.
% $Revision: 1.0 $

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

% CONSTANTS
me = 'nnd14dynd';

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

% FIND WINDOW IF IT EXISTS
fig = nndfgflg(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
  meters = H(3:4);            % parameter axes
  indicators = H(5:6);        % paramter indicators
  freq_menu = H(7);           % frequency of input function
  inp_menu = H(8);            % Type of input function
  func_axis = H(9);          % network function axis
  func_line = H(10);          % network function line
  a_line = H(11);             % horizontal output line
  values_ptr = H(12);         % Network parameter, input & output values
  inp_ptr = H(13);             % 2nd layer transfer functio name
  freq_ptr = H(14);             % 2nd layer transfer functio name
  func_axis2 = H(15);          % network function axis
  func_line2 = H(16);          % network function line
  a_line2 = H(17);             % horizontal output line
  func_axis3 = H(18);          % network function axis
  func_line3 = H(19);          % network function line
  a_line3 = H(20);             % horizontal output line
  func_axis4 = H(21);          % network function axis
  func_line4 = H(22);          % network function line
  a_line4 = H(23);             % horizontal output line
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)

  % CHECK FOR NNT
  % ODJ 12/23/07 Check for NN Toolbox removed
  %if ~nnfexist(me), return, end

  % CONSTANTS
  W1 = [1/2; -1/2];
  inp = 'square';
  freq=1/12;
  p = 0;
  values = [W1(1) W1(2)];

  % NEW DEMO FIGURE
  fig = nndemof2(me,'DESIGN','Dynamic Derivatives','','Chapter 14');
  set(fig, ...
    'windowbuttondownfcn',nncallbk(me,'down'), ...
    'BackingStore','off',...
    'nextplot','add');
  H = get(fig,'userdata');
  fig_axis = H(1);
  desc_text = H(2);

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

  % NETWORK POSITIONS
  x1 = 40;     % input
  x2 = x1+90;  % 1st layer sum
  x3 = x2+40;  % 1st layer transfer function
  x4 = x3+100; % 2nd layer sum
  x5 = x4+40;  % 2nd layer transfer function
  x6 = x5+50;  % output
  y1 = 265;    % top neuron
  y2 = y1-20;  % input & output neuron
  y3 = y1-40;  % bottom neuron
  sz = 15;     % size of icons
  wx = 50;     % weight vertical offset (from 1st layer)
  wy = 55;     % weight horizontal offset (from middle)

  % NETWORK INPUT
  nndtext(x1-10,y2+110,'p');
  plot([x1 x2+60 x4-14],[y2+110 y2+110 y2+87],'linewidth',2,'color',nnred);
  plot([x3-80 x3-80 x5+sz+15 x5+sz+15],[y2+65 y1 y1 y2+87],'linewidth',2,'color',nnred);

  % TOP NEURON
  %nndsicon('delay',x3-80,y1+70,sz)

  % BOTTOM NEURON
  nndsicon('delay',x3-80,y1+25,sz)

  % OUTPUT NEURON
  plot([x3-80 x2+60 x4-14],[y2+65 y2+65 y2+87],'linewidth',2,'color',nnred);
  plot([x4 x6],[y2+87 y2+87],'linewidth',2,'color',nnred);
  plot([x6-10 x6 x6-10],[y2+80 y2+87 y2+94],'linewidth',2,'color',nnred);
  nndsicon('sum',x4,y2+87,sz)
  nndsicon('purelin',x5,y2+87,sz);
  nndtext(x3+wx,y2+wy+36,'iW(0)');
  nndtext(x3+wx,y2+52,'lW(1)');
  %nndtext(x3+wx,y2-wy+73,'iW(2)');
  nndtext(x5+sz+5,y2+95,'a(t)','left');

  % PARAMETER POSITIONS
  xx = 120; %20 + [0:3]*90;
  yy = [330 285 240];

  % PARAMETER METERS & INDICATORS
  meters = [];
  indicators = [];
  for i=1:2
      pn = i;
      val = values(pn);
      maxval = 2;
      maxstr = num2str(maxval);
      ax = nnsfo('a2','','','');
      set(ax,...
          'units','points',...
          'position',[xx yy(i) 70 20],...
          'color',nnmdgray,...
          'ylim',[-0.3 1.3],...
          'ytick',[],...
          'xlim',[-1.3 1.3]*maxval,...
          'xtick',[-1 -0.5 0 0.5 1]*maxval,...
          'xticklabel',str2mat(['-' maxstr],'','0','',maxstr));
      ind = fill([0 0.2 -0.2]*maxval+val,[0 1 1],nnred,...
          'edgecolor',nndkblue,...
          'erasemode','none');
      meters = [meters ax];
      indicators = [indicators ind];
  end

  % TRANSFER FUNCTION POPUP MENU
  inp_menu = uicontrol(...
    'units','points',...
    'position',[10 yy(1)-10 50 20],...
    'style','popupmenu',...
    'string','square|sine',...
    'callback',[me '(''inp'')']);
  set(inp_menu,'value',1);

  freq_menu = uicontrol(...
    'units','points',...
    'position',[10 yy(1)-40 50 20],...
    'style','popupmenu',...
    'string','1/16|1/14|1/12|1/10|1/8',...
    'callback',[me '(''freq'')']);
  set(freq_menu,'value',3);

  % PARAMETER LINES
  xx = xx + 0.5;
  y = yy(1)+10;
  x = xx(1)+70;
  plot([0 5 5]+x,[0 0 35]+y,'color',nndkgray);
  y = yy(2)+10;
  plot([0 5 5]+x,[0 0 35]+y,'color',nndkgray);
  y = yy(3)+10;
  plot([0 5 5]+x,[0 0 35]+y,'color',nndkgray);

  % NETWORK FUNCTION
  a0 = 0;
  a_1 = 0;
  p = [1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1];
  w110 = 1/2;
  w111 = -1/2;

  t = 1:length(p);
  t1 = 0:length(p);
  %num = [w110 w111];
  %den = [1];
  num = [w110];
  den = [1 w111];
  zi = [a0];
  A = filter(num,den,p,zi);

  % FUNCTION AXIS
  y = 20;
  x = 40;
  func_axis = nnsfo('a2','','','');
  set(func_axis, ...
    'units','points',...
    'position',[x-15 y+130 160 90],...
    'color',nnltyell);
  p_line = plot([0 25],[0 0],'--',...
    'color',nnred,...
    'erasemode','none');
  func_line = plot(t1,[a0 A],...
    '.k','color',nndkblue,...
    'erasemode','none',...
    'linewidth',2);
  lw111 = w111;
  iw11 = w110+.1;
  num = [iw11];
  den = [1 lw111];
  a1 = filter(num,den,p,zi);
  a_line = plot(t1,[a0 a1],'xb',...
    'erasemode','none');

  a_max = max([A a1]);
  a_min = min([A a1]);
  a_edge = (a_max-a_min)*0.1;

  set(func_axis, ...
    'xlim',[0 25],...
    'ylim',[a_min a_max]+[-a_edge a_edge])

  title('Incremental Response iw+0.1')

  func_legend = nnsfo('a2','','','');
  set(func_legend, ...
    'units','points',...
    'position',[x+360 y+150 80 25],...
    'color',nnltyell)
  plot(1,1,'.k',1,1,'xb',1,1,'db',1,1,'sk')
  lege=legend('Original Response','Incremental Response',...
      'Total Derivative','Static Derivative','location','best');
  set(lege,'fontsize',7);

  da_diw_0 = 0;
  da_diw = filter(1,den,p,da_diw_0);
  func_axis2 = nnsfo('a2','','','');
  set(func_axis2, ...
    'units','points',...
    'position',[x-15 y 160 90],...
    'color',nnltyell)
  p_line2 = plot([0 25],[0 0],'--',...
    'color',nnred,...
    'erasemode','none');
  a_line2 = plot(t1,[da_diw_0 da_diw],'db','markersize',5,...
    'erasemode','none');
  func_line2 = plot(t,p,...
    'sk','markersize',4,...
    'erasemode','none');

  a_max = max([p da_diw]);
  a_min = min([p da_diw]);
  a_edge = (a_max-a_min)*0.1;

  set(func_axis2, ...
    'xlim',[0 25],...
    'ylim',[a_min a_max]+[-a_edge a_edge])

  title('derivative with respect iw')

  da_dlw_0 = 0;
  ad = [a0 A(1:end-1)];
  da_dlw = filter(1,den,ad,da_dlw_0);

  func_axis3 = nnsfo('a2','','','');
  set(func_axis3, ...
    'units','points',...
    'position',[x+170 y 160 90],...
    'color',nnltyell,...
    'xlim',[0 25],...
    'ylim',[a_min a_max]+[-a_edge a_edge])
  p_line3 = plot([0 25],[0 0],'--',...
    'color',nnred,...
    'erasemode','none');
  a_line3 = plot(t1,[da_dlw_0 da_dlw],'db','markersize',5,...
    'erasemode','none');
  func_line3 = plot(t,ad,...
    'sk','markersize',4,...
    'erasemode','none');

  a_max = max([p da_dlw]);
  a_min = min([p da_dlw]);
  a_edge = (a_max-a_min)*0.1;

  set(func_axis3, ...
    'xlim',[0 25],...
    'ylim',[a_min a_max]+[-a_edge a_edge])

  title('derivative with respect lw')

  func_axis4 = nnsfo('a2','','','');
  set(func_axis4, ...
    'units','points',...
    'position',[x+170 y+130 160 90],...
    'color',nnltyell,...
    'xlim',[0 25],...
    'ylim',[a_min a_max]+[-a_edge a_edge])
  p_line4 = plot([0 25],[0 0],'--',...
    'color',nnred,...
    'erasemode','none');
  func_line4 = plot(t1,[a0 A],...
    '.k','color',nndkblue,...
    'erasemode','none',...
    'linewidth',2);

  lw111 = w111+.1;
  iw11 = w110;
  num = [iw11];
  den = [1 lw111];
  a1 = filter(num,den,p,zi);

  a_line4 = plot(t1,[a0 a1],'xb',...
    'erasemode','none');

  a_max = max([A a1]);
  a_min = min([A a1]);
  a_edge = (a_max-a_min)*0.1;

  set(func_axis4, ...
    'xlim',[0 25],...
    'ylim',[a_min a_max]+[-a_edge a_edge])

  title('Incremental Response lw+0.1')

  % BUTTONS
  drawnow % Let everything else appear before buttons 
  uicontrol(...
    'units','points',...
    'position',[400 130 60 20],...
    'string','Random',...
    'callback',[me '(''random'')'])
  uicontrol(...
    'units','points',...
    'position',[400 105 60 20],...
    'string','Reset',...
    'callback',[me '(''reset'')'])
  uicontrol(...
    'units','points',...
    'position',[400 80 60 20],...
    'string','Contents',...
    'callback','nndtoc')
  uicontrol(...
    'units','points',...
    'position',[400 55 60 20],...
    'string','Close',...
    'callback',[me '(''close'')'])

  % DATA POINTERS
  value_ptr = uicontrol('visible','off','userdata',values);
  inp_ptr = uicontrol('visible','off','userdata',inp);
  freq_ptr = uicontrol('visible','off','userdata',freq);

  % SAVE WINDOW DATA AND LOCK
  H = [fig_axis desc_text meters indicators  freq_menu inp_menu ...
    func_axis func_line a_line value_ptr inp_ptr freq_ptr ...
    func_axis2 func_line2 a_line2 ...
    func_axis3 func_line3 a_line3 ...
    func_axis4 func_line4 a_line4];

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

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

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

  nnchkfs;

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

elseif strcmp(cmd,'instr') & (fig)
  nnsettxt(desc_text,...
    'Show the meaning of',...
    'dynamics derivatives',....

⌨️ 快捷键说明

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