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

📄 nnd13breg.m

📁 《神经网络设计》英文版的配套源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
function nnd13breg(cmd,data)
%NND13BREG Steepest descent demonstration.

% $Revision: 1.6 $
% Copyright 1994-2002 PWS Publishing Company and The MathWorks, Inc.
% First Version, 8-31-95.

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

% BRING UP FIGURE IF IT EXISTS

me = 'nnd13breg';
fig = nndfgflg(me);
if length(get(fig,'children')) == 0, fig = 0; end
if nargin == 0, cmd = ''; end

% CONSTANTS
max_update = 20;
xlim = [-1 1]; 
ylim = [-1.5 1.5]; %dy = 0.2;
%zlim = [0 12];
%xpts = xlim(1):dx:xlim(2);
%ypts = ylim(1):dy:ylim(2);
%[X,Y] = meshgrid(xpts,ypts);
xtick = [-1 -0.5 0 0.5 1];
ytick = [-1.5 -1 -0.5 0 0.5 1 1.5];
%ztick = [0 6 12];
%circle_size = 8;

% CREATE FIGURE ========================================================

if fig == 0

  % CONSTANTS
  S1 = 20;
  S1_min = 2;
  S1_max = 40;
  % CONSTANTS
  di = 1;
  di_min = 0.1;
  di_max = 3;
  % CONSTANTS
  f = 1;
  f_min = 0.5;
  f_max = 4;
  % CONSTANTS
  dd = 21;
  dd_min = 10;
  dd_max = 40;
  
  dx = (xlim(2)-xlim(1))/(dd-1);
  dx2 = (xlim(2)-xlim(1))/round((dd/3)-1);
  
  % STANDARD DEMO FIGURE
  fig = nndemof(me,'DESIGN','Bayesian Regularization','','Chapter 13');
  %str = [me '(''down'',get(0,''pointerloc''))'];
  %set(fig,'windowbuttondownfcn',str);
  
  % UNLOCK AND GET HANDLES
  
  set(fig,'nextplot','add','pointer','watch')
  H = get(fig,'userdata');
  fig_axis = H(1);
  desc_text = H(2);
  
  % ICON
  nndicon(13,458,363,'shadow')
    
  % SLIDER NOISE STD INDEX
  x = 175;
  y = 25;
  text(x,y+20,'Noise STD:',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',10,...
    'horizontalalignment','left')
  di_slider = uicontrol(...
    'units','points',...
    'position',[x y-7 110 16],...
    'style','slider',...
    'min',di_min,...
    'max',di_max,...
    'callback',[me '(''di'')'],...
    'value',di);
  text(x-5,y-15,sprintf('%4.1f',di_min),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','left')
  text(x+110,y-15,sprintf('%4.0f',di_max),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right')
  di_text = text(x+100,y+20,['' num2str(di) ''],...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','center');

  % SLIDER NUMBER OF HIDDEN NEURONS
  y = 85;
  text(x,y+20,'# Hidden Neurons:',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',10,...
    'horizontalalignment','left')
  S1_slider = uicontrol(...
    'units','points',...
    'position',[x y-7 110 16],...
    'style','slider',...
    'min',S1_min,...
    'max',S1_max,...
    'callback',[me '(''S1'')'],...
    'value',S1);
  text(x-5,y-15,sprintf('%4.0f',S1_min),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','left')
  text(x+110,y-15,sprintf('%4.0f',S1_max),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right')
  S1_text = text(x+100,y+20,['' num2str(S1) ''],...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','center');

  % SLIDER FREQUENCY
  x = 300;
  y = 25;
  text(x,y+20,'frequency:',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',10,...
    'horizontalalignment','left')
  f_slider = uicontrol(...
    'units','points',...
    'position',[x y-7 110 16],...
    'style','slider',...
    'min',f_min,...
    'max',f_max,...
    'callback',[me '(''f'')'],...
    'value',f);
  text(x-5,y-15,sprintf('%4.1f',f_min),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','left')
  text(x+110,y-15,sprintf('%4.0f',f_max),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right')
  f_text = text(x+100,y+20,['' num2str(f) ''],...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','center');

  % SLIDER NUMBER OF HIDDEN NEURONS
  y = 85;
  text(x,y+20,'# Data Points:',...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',10,...
    'horizontalalignment','left')
  dd_slider = uicontrol(...
    'units','points',...
    'position',[x y-7 110 16],...
    'style','slider',...
    'min',dd_min,...
    'max',dd_max,...
    'callback',[me '(''dd'')'],...
    'value',dd);
  text(x-5,y-15,sprintf('%4.0f',dd_min),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','left')
  text(x+110,y-15,sprintf('%4.0f',dd_max),...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','right')
  dd_text = text(x+100,y+20,['' num2str(dd) ''],...
    'color',nndkblue,...
    'fontw','bold',...
    'fontsize',12,...
    'horizontalalignment','center');

  % LEFT AXES
  left = nnsfo('a2','Function','p','a^2');
  set(left, ...
    'xlim',xlim,'xtick',xtick, ...
    'ylim',ylim,'ytick',ytick);

  T = 2;
  seed = 4687;
  % Set random number seed, if needed
  temp = cputime;
  temp = temp-fix(temp);
  temp = temp*100000;
  randn('seed',temp);
  if(seed == 0)
     z=rand;
     nseed = randn('seed');
  else
     nseed = seed;
  end

  nseed = 4687;
  randn('seed',nseed)
  %nseed2 = rand('seed');
  rand('seed',nseed+13484)

  pp = [xlim(1):(dx/10):xlim(2)];
  tt = sin(2*pi*pp*f/T);
  p = [xlim(1):dx:xlim(2)];
  t = sin(2*pi*p*f/T) + randn(size(p))*0.2*di;
  % The UNION command is to secure last point
  pv = union([(xlim(1)+0.05):dx2:(xlim(2)-0.05)],(xlim(2)-0.05));
  %pv = [-.95 -.65 -.25 .25 .65 .95];
  tv = sin(2*pi*pv*f/T); % + randn(size(VV.P))*0.2;

  func_test = plot(pp,tt,'k');
  hold on
  func_plot = plot(pp,tt,'b');
  func_target = plot(p,t,'ok');
  b1_plot = plot(p,t,'ok');
  set(b1_plot,'visible','off');
  b2_plot = plot(p,t,'+k');
  set(b2_plot,'visible','off');
  hold off
  set(func_plot,'LineWidth',2);
  %F = (Y-X).^4 + 8*X.*Y - X + Y + 3;
  %F = min(max(F,zlim(1)),zlim(2));
  %[dummy,func_plot] = contour(xpts,ypts,F,[1.01 2 3 4 6 8 10]);
  
  %cont_color = [nnblack; nnred; nngreen];
  %for i=1:length(func_plot)
  %  set(func_plot(i),'edgecolor',cont_color(rem(i,3)+1,:),'linewidth',1);
  %end
  %text(0,1.3,'< CLICK ON ME >',...
  %  'horiz','center', ...
  %  'fontweight','bold',...
  %  'color',nndkblue);
  
  % RIGHT AXES
  right = nnsfo('a3','Performance Indexes','Iteration','F');
  axis([1 100 1e-1 1e3])
  mer_plot = plot([1 101],[1 1],'b');
  hold on
  gamk_plot = plot([1 101],[1 1],'r');
  perf_plot = plot([1 101],[1 1],'k');
  hold off
  set(right,'xscale','log','yscale','log')
  %set(right, ...
  %  'xlim',xlim,'xtick',xtick, ...
  %  'ylim',ylim,'ytick',ytick);

  % TEXT
  %nnsettxt(desc_text, ...
  %  'EARLY STOPPING',...
  %  'Select the Noise STD of the training points below. Then by selecting the',...
  %  'train button, the training over the training points will be executed. The training',...
  %  'and validation performance indexes will be presented at the right. You will notice',...
  %  'that without early stopping the validation error will increase.')
  nnsettxt(desc_text,...
    'Click the [Train] button to',...
    'train the network on the',...
    'noisy data points at left.',...
    '',...
    'Use the slide bars to choose',...
    'the Network Size, the Number',...
    'of Data Points, the Noise',...
    'Standard Deviation and the',...
    'frequency of the function.')
  text(150,250,'Training Error',...
    'color',get(mer_plot,'color'),...
    'fontw','bold',...
    'fontsize',10,...

⌨️ 快捷键说明

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