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

% Copyright (c) 1992-1998 by The MathWorks, Inc.
% $Revision: 1.11 $  $Date: 1998/06/25 12:12:12 $

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

  slide(1).code={
   'slideData=nnslides(''start'',slideData,''Two-Dimensional Grid of Neurons'');',
   '' };
  slide(1).text={
   'NEWSOM   - Creates a self-organizing map.',
   'TRAIN  - Trains a neural network.',
   'SIM   - Simulates a neural network.',
   '',
   'As in DEMOSM1, this self-organizing map will learn to represent different regions of the input space where input vectors occur.  In this demo, however, the neurons will arrange themselves in a two-dimensional grid, rather than a line.'};

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

  slide(2).code={
   'slideData=nnslides(''axes'',slideData);',
   'P = rands(2,1000);',
   'plot(P(1,:),P(2,:),''+r'')' };
  slide(2).text={
   'We would like to classify 1000 two-element vectors occuring in a rectangular shaped vector space.',
   '>> P = rands(2,1000);',
   'Plot these vectors:',
   '>> plot(P(1,:),P(2,:),''+r'')'};

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

  slide(3).code={
   'net=newsom([0 1; 0 1],[5 6]);',
   '' };
  slide(3).text={
   ' We will use a 5 by 6 layer of neurons to classify the vectors above. We would like each neuron to respond to a different region of the rectangle, and neighboring neurons to respond to adjacent regions.  We create a layer of 30 neurons spread out in a 5 by 6 grid:',
   ' >> net=newsom([0 1; 0 1],[5 6]);',
   ''};

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

  slide(4).code={
   'plotsom(net.iw{1,1},net.layers{1}.distances)' };
  slide(4).text={
   'We can visualize the network we have just created with PLOTSOM.',
   ' >> plotsom(net.iw{1,1},net.layers{1}.distances)',
   'Each neuron is represented by a red dot at the location of its two weights.  Initially all the neurons have the same weights in the middle of the vectors, so only one dot appears.'};

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

  slide(5).code={
   'slideData=nnslides(''lock'',slideData);',
   'slideData=nnslides(''axes'',slideData);',
   'more off;',
   'net.trainParam.epochs=1000;',
   'net=train(net,P);',
   'plotsom(net.iw{1,1},net.layers{1}.distances)',
   'slideData=nnslides(''unlock'',slideData);' };
  slide(5).text={
   'Now we train the map on the vectors for 1000 epochs and replot the network weights.  Please wait for it to finish before moving to the next slide:',
   '>> net.trainParam.epochs=1000;',
   '>> net=train(net,P);',
   '>> plotsom(net.iw{1,1},net.layers{1}.distances)',
   'Note that the layer of neurons has begun to self-organize so that each neuron now classifies a different region of the input space, and adjacent (connected) neurons respond to adjacent regions.'};

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

  slide(6).code={
   'more off;',
   'p=[0.5;0.3];',
   'a=0;',
   'a = sim(net,p);',
   'out=evalc(''a'');',
   'slideData=nnslides(''text'',slideData,out);' };
  slide(6).text={
   ' We can now use SIMUSM to classify vectors by giving them to the',
   ' network and seeing which neuron responds.',
   ' >> p = [0.5; 0.3];',
   ' >> a = simusm(p,W,M,0)',
   'The neuron in parenthesis above responded with a "1", so p belongs to that class.'};
end