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

% Copyright 1992-2000 The MathWorks, Inc.
% $Revision: 1.15 $  $Date: 2000/06/15 04:17:23 $

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

  slide(1).code={
   'slideData=nnslides(''start'',slideData,''Pattern Classification with a Competitive Layer'');' };
  slide(1).text={
   'NEWC  - Creates a competitive layer.',
   'TRAIN - Trains a neural network.',
   'SIM  - Simulates a neural network.',
   '',
   'Neurons in a competitive layer learn to represent different regions of the input space where input vectors occur.',
   ''};

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

  slide(2).code={
   'slideData=nnslides(''axes'',slideData);',
   'X = [0 1; 0 1];   % Cluster centers to be in these bounds',
   'clusters = 8;     % This many clusters',
   'points = 10;       % Number of points in each cluster.',
   'std_dev = 0.05;   % Standard deviation of each cluster.',
   'P = nngenc(X,clusters,points,std_dev);',
   '',
   'plot(P(1,:),P(2,:),''+r'');',
   'title(''Input Vectors'');',
   'xlabel(''p(1)'');',
   'ylabel(''p(2)'');' };
  slide(2).text={
   'P is a set of randomly generated but clustered test data points.  Here the data points are plotted.',
   '>> plot(P(1,:),P(2,:),''+r'');',
   'A competitive network will be used to classify these points into natural classes.',
   ''};

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

  slide(3).code={
   'net=newc([0 1;0 1],8,.1);',
   'net=init(net);',
   'w=net.IW{1};',
   'hold off;',
   'plot(P(1,:),P(2,:),''+r'');',
   'hold on;',
   'plot(w(:,1),w(:,2),''ob'');',
   'hold off;' };
  slide(3).text={
   'Here NEWC takes three input arguments, an Rx2 matrix of min and max values for R input elements, the number of neurons, and the learning rate:',
   '>> net=newc([0 1;0 1],8,.1);',
   'Plot the weight vectors to see their initial attempt at classification:',
   '>> w=net.IW{1};',
   '>> hold on;  h = plot(w(:,1),w(:,2),''ob'');',
   ''};

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

  slide(4).code={
   'net=newc([0 1;0 1],8,.1);',
   'net=init(net);',
   'w=net.IW{1};',
   'hold off;',
   'plot(P(1,:),P(2,:),''+r'');',
   'hold on;',
   'plot(w(:,1),w(:,2),''ob'');',
   'hold off;',
   'net.trainParam.epochs=7;' };
  slide(4).text={
   'The weight vectors (o''s) will be trained so that they occur centered in clusters of input vectors (+''s).',
   '',
   'Set the number of epochs to train before stopping:',
   '>> net.trainParam.epochs=7;',
   ''};

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

  slide(5).code={
   'slideData=nnslides(''axes'',slideData);',
   'slideData=nnslides(''lock'',slideData);',
   'more off;',
   'hold on;',
   'net=init(net);',
   'more off;',
   'net=train(net,P);',
   'w=net.IW{1};',
   'delete(findobj(gcf,''color'',[0 0 1]));',
   'plot(w(:,1),w(:,2),''ob'');',
   'hold off;',
   'slideData=nnslides(''unlock'',slideData);' };
  slide(5).text={
   'Train this competive layer (may take several seconds):',
   '>> net=train(net,P);',
   'Plot the updated layer weights on the same graph:',
   '>> w=net.IW{1};',
   '>> hold on;',
   '>> delete(h);',
   '>> h = plot(w(:,1),w(:,2),''ob'');'};

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

  slide(6).code={
   'a=0;',
   'p = [0; 0.2];',
   'a=sim(net,p);',
   'out=evalc(''a'');'
   'slideData=nnslides(''text'',slideData,out);' };
  slide(6).text={
   'Now we use the competitive layer as a classifier, where each neuron corresponds to a different category.  Here we present the input vector [0; 0.2].',
   '>> p = [0; 0.2];',
   '>> a = sim(net,p)',
   'The output, a, indicates which neuron is responding, and thereby which class the input belongs. Note that SIM returns outputs in sparse matrix form for competitive layers.',
   ''};
end
