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

% Copyright 1992-2000 The MathWorks, Inc.
% $Revision: 1.13 $  $Date: 2000/08/31 00:53:08 $

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

  slide(1).code={
   'slideData=nnslides(''start'',slideData,''Dealing with Outlier Input Vectors'');' };
  slide(1).text={
   'NEWP  - Creates a perceptron.',
   'SIM  - Simulates a neural network.',
   'ADAPT - Adapts a neural network.',
   '',
   'Using the above functions, a 2-input hard limit neuron is trained to classify 5 input vectors into two categories.  Despite the fact that one input vector is much bigger than the others, training with LEARNPN is quick.'};

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

  slide(2).code={
   'slideData=nnslides(''axes'',slideData);',
   'P = [-0.5 -0.5 +0.3 -0.1 -40; -0.5 +0.5 -0.5 +1.0 50];',
   'T = [1 1 0 0 1];',
   'plotpv(P,T);' };
  slide(2).text={
   'Each of the five column vectors  in P defines a 2-element input vectors:',
   '>> P = [ -0.5 -0.5 +0.3 -0.1 -40;',
   '             -0.5 +0.5 -0.5 +1.0 50];',
   'A row vector T defines the vector''s target categories.',
   '>> T = [1 1 0 0 1];',
   'The perceptron must properly classify the 5 input vectors in P into the two categories defined by T.  Now plot these vectors with PLOTPV:',
   '>> plotpv(P,T);'};

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

  slide(3).code={
   'net=newp([-40 1;-1 50],1,''hardlim'',''learnpn'');',
   '' };
  slide(3).text={
   'NEWP creates a perceptron.',
   '>> net=newp([-40 1; -1 50],1,''hardlim'',''learnpn'');',
   'The arguments of NEWP are: 1) Rx2 matrix of min and max values for R input elements, 2) Number of neurons, 3) Transfer function, 4) Learning Function.',
   'Note that 4 input vectors have much smaller magnitudes than the fifth vector in the upper left of the plot.  LEARNPN is less sensitive to large variations in input vector size than LEARNP (the default).'};

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

  slide(4).code={
   'plotpv(P,T);',
   'linehandle=plotpc(net.IW{1},net.b{1});' };
  slide(4).text={
   'The input vectors are replotted...',
   '>> plotpv(P,T)',
   '...with the neuron''s initial attempt at classification.',
   '>> linehandle=plotpc(net.IW{1},net.b{1})',
   'The classification line does not even appear on the plot, since with the initial weights set to zero, any input gives the same output, namely zero.  Fear not... we are going to train it.'};

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

  slide(5).code={
   'slideData=nnslides(''lock'',slideData);',
   'cla;',
   'plotpv(P,T);',
   'linehandle=plotpc(net.IW{1},net.b{1});',
   '',
   'E=1; net.adaptParam.passes=1;',
   'net=init(net);',
   'linehandle=plotpc(net.IW{1},net.b{1});',
   'while (sse(E))',
   '   [net,Y,E]=adapt(net,P,T);',
   '   linehandle=plotpc(net.IW{1},net.b{1},linehandle);',
   '   drawnow;',
   'end;',
   'slideData=nnslides(''unlock'',slideData);' };
  slide(5).text={
   'ADAPT returns a new network object that performs as a better classifier, the network output, and the error.  This loop allows the network to adapt for one pass, plots the classification line, and continues until the error is zero.',
   '>> net.adaptParam.passes=1; E=1;',
   '>> while (sse(E))',
   '>>    [net,Y,E]=adapt(net,P,T);',
   '>>    linehandle=plotpc(net.IW{1},net.b{1},linehandle); drawnow;',
   '>> end;'};

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

  slide(6).code={
   '' };
  slide(6).text={
   'Note that training with LEARNP took only 3 epochs, while solving the same problem with LEARNPN required 32 epochs.  Thus, LEARNPN does much better job than LEARNP when there are large variations in input vector size.',
   '',
   'With SIM, the perceptron can now be used to classify any other input vectors.'};

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

  slide(7).code={
   'p = [0.7; 1.2];',
   'a = sim(net,p);',
   'plotpv(p,a);',
   'ThePoint=findobj(gca,''type'',''line'');',
   'set(ThePoint,''Color'',''red'');' };
  slide(7).text={
   'For example, classify an input vector of [0.7; 1.2]:',
   '>> p = [0.7; 1.2]; a = sim(net,p);',
   ' A plot of this new point with the original training set shows how the network performs.  First, plot the new point:',
   '>> plotpv(p,a);',
   'To distinguish it from the training set, color it red:',
   '>> ThePoint=findobj(gca,''type'',''line'');',
   '>> set(ThePoint,''Color'',''red'');'};

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

  slide(8).code={
   'hold on;',
   'plotpv(P,T);',
   'plotpc(net.IW{1},net.b{1});',
   'hold off;' };
  slide(8).text={
   'Turn on "hold" so the previous plot is not erased.',
   '>> hold on;',
   'Now plot the training set:',
   '>> plotpv(P,T);',
   'And the classification line:',
   '>> plotpc(net.IW{1},net.b{1});',
   '>> hold off;',
   ''};

  %========== Slide 9 ==========

  slide(9).code={
   'axis([-2 2 -2 2]);' };
  slide(9).text={
   'Finally, zoom into the area of interest:',
   '>>axis([-2 2 -2 2]);',
   'The perceptron correctly classified our new point (in red) as category "zero" (represented by a circle) and not a "one" (represented by a plus).',
   'The perceptron learns properly in much shorter time in spite of the outlier (compare with DEMOP4).'};
end