function slide=demolin7
% This is a slideshow file for use with playshow.m and makeshow.m
% To see it run, type 'playshow demolin7', 

% Copyright (c) 1992-1998 by The MathWorks, Inc.
% $Revision: 1.9 $  $Date: 1998/06/11 16:23:42 $

if nargout<1,
  playshow demolin7
else
  %========== Slide 1 ==========

  slide(1).code={
   'slideData=nnslides(''start'',slideData,''Too Large a Learning Rate'');' };
  slide(1).text={
   'NEWLIN - Creates a linear layer.',
   'TRAIN  - Trains a neural network.',
   'SIM  - Simulates a neural network.',
   '',
   'Using the above functions a linear neuron is trained to find the minimum error solution for a simple problem.  The neuron is trained with the learning rate larger than the one suggested by MAXLINLR.'};

  %========== Slide 2 ==========

  slide(2).code={
   'slideData=nnslides(''blank'',slideData);',
   'P = [+1.0 -1.2];',
   'T = [+0.5 +1.0];' };
  slide(2).text={
   'P defines two 1-element input patterns (column vectors):',
   '>> P = [+1.0 -1.2];',
   'T defines associated 1-element targets (column vectors):',
   '>> T = [+0.5 +1.0];',
   '',
   '',
   ''};

  %========== Slide 3 ==========

  slide(3).code={
   'slideData=nnslides(''axes'',slideData);',
   'slideData=nnslides(''wipeaxes'',slideData'');',
   'w_range =-2:0.4:2;  b_range = -2:0.4:2;',
   'ES = errsurf(P,T,w_range,b_range,''purelin'');',
   'plotes(w_range,b_range,ES);' };
  slide(3).text={
   'ERRSURF calculates errors for a neuron with a range of possible weight and bias values.  PLOTES plots this error surface with a contour plot underneath.',
   '>> w_range =-2:0.4:2;  b_range = -2:0.4:2;',
   '>> ES = errsurf(P,T,w_range,b_range,''purelin'');',
   '>> plotes(w_range,b_range,ES);',
   'The best weight and bias values are those that result in the lowest point on the error surface.',
   '',
   '',
   ''};

  %========== Slide 4 ==========

  slide(4).code={
   'slideData=nnslides(''blank'',slideData);',
   'maxlr=maxlinlr(P,''bias'');',
   'net=newlin([-2 2],1,[0],maxlr*2.25);' };
  slide(4).text={
   'MAXLINLR finds the fastest stable learning rate for training a linear network.',
   '>> maxlr=maxlinlr(P,''bias'');',
   'NEWLIN creates a linear neuron. To see what happens when the learning rate is too large, increase the learning rate to 225% of the recommended value.',
   '>> net=newlin([-2 2],1,[0],maxlr*1.5);',
   'NEWLIN takes these arguments: 1) Rx2 matrix of min and max values for R input elements, 2) Number of elements in the output vector, 3) Input delay vector, and 4) Learning rate.'};

  %========== Slide 5 ==========

  slide(5).code={
   'slideData=nnslides(''wipeaxes'',slideData);',
   'slideData=nnslides(''axes'',slideData);',
   'net.trainParam.epochs=20;',
   'plotes(w_range,b_range,ES);' };
  slide(5).text={
   'Override the default training parameters by setting the maximum number of epochs.  This ensures that training will stop:',
   '>> net.trainParam.epochs=20;',
   'Use PLOTES to replot the error surface:',
   '>> plotes(w_range,b_range,ES);'};

  %========== Slide 6 ==========

  slide(6).code={
   'slideData=nnslides(''lock'',slideData);',
   'slideData=nnslides(''axes'',slideData);',
   'slideData=nnslides(''wipeaxes'',slideData);',
   'ES = errsurf(P,T,w_range,b_range,''purelin'');',
   'plotes(w_range,b_range,ES);',
   'subplot(1,2,2);',
   'h = text(sum(get(gca,''xlim''))*0.5,sum(get(gca,''ylim''))*0.5,''* Click On Me *'');',
   'set(h,''horizontal'',''center'', ''fontweight'',''bold'');',
   '[net.IW{1,1} net.b{1}]=ginput(1);',
   'delete(h);',
   '[slideData,net,tr]=nnslides(''trainlin'',slideData,net,P,T);',
   'slideData=nnslides(''unlock'',slideData);' };
  slide(6).text={
   'Override the randomly generated weight and bias by getting a mouse click on the Error Contour Plot with GINPUT:',
   '>> subplot(1,2,2);  [net.IW{1,1} net.b{1}] = ginput(1);',
   'To show the path of the training we will train only one epoch at a time and call PLOTEP every epoch (code not shown here).',
   '>> net = train(net,P,T);',
   'The plot shows a history of the training.  Each dot represents an epoch and the blue lines show each change made by the learning rule (Widrow-Hoff by default).',
   ''};

  %========== Slide 7 ==========

  slide(7).code={
   'lideData=nnslides(''axes'',slideData);',
   'plotperf(tr,net.trainParam.goal);' };
  slide(7).text={
   'The train function outputs the trained network and a history of the training performance (tr).  Here the errors are plotted with respect to training epochs:',
   '>> plotperf(tr,net.trainParam.goal);'};

  %========== Slide 8 ==========

  slide(8).code={
   'p = -1.2;',
   'a = sim(net, p);',
   'slideData=nnslides(''text'',slideData,[''a = '' num2str(a)]);' };
  slide(8).text={
   'We can now use SIM to test the associator with one of the original inputs, -1.2, and see if it returns the target, 1.0.',
   '>> p = -1.2;',
   '>> a = sim(net, p)',
   '(see above window for result)',
   'The result is not very close to 0.5!  This is because the network was trained with too large a learning rate.'};
end