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

% Copyright 1992-2000 The MathWorks, Inc.
% $Revision: 1.2 $  $Date: 2000/06/15 04:15:53 $

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

  slideIndex = 1;
  slide(slideIndex).code={
   'slideData=nnslides(''start'',slideData,''Nonlinear Regression'');' };
  slide(slideIndex).text={
   'PRESTD  - Normalize data for zero mean and unity standard deviation.',
   'PREPCA  - Principal components analysis.',
   'NEWFF   - Inititializes feed-forward networks.',
   'TRAIN, SIM   - Train and simulate networks.',
   'POSTSTD - Inverts PRESTD to convert network outputs to original units.',
   'POSTREG - Linear regression between targets and trained network outputs.',
   '',
   ['Using the above functions a feed-forward network is trained to',...
   ' perform a nonlinear regression between spectral components',...
   ' and cholesterol levels.  The final network is analyzed to',...
   ' investigate overall performance.'],
    ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''blank'',slideData);',
   'load choles_all',
   '[pn,meanp,stdp,tn,meant,stdt] = prestd(p,t);',
   '[ptrans,transMat] = prepca(pn,0.001);',
   ''};
  slide(slideIndex).text={
   'Load in the data file',
   '>> load choles_all',
   '',
   'Normalize the inputs and targets so that they have zero mean and unity variance.',
   '>> [pn,meanp,stdp,tn,meant,stdt] = prestd(p,t);',
   '',
   'Perform a principal component analysis and remove those components which account for less than 0.1% of the variation.',
   '>> [ptrans,transMat] = prepca(pn,0.001);',
   ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''blank'',slideData);',
   '[R,Q] = size(ptrans); iitst = 2:4:Q;',
   'iival = 4:4:Q; iitr = [1:4:Q 3:4:Q];',
   'vv.P = ptrans(:,iival); vv.T = tn(:,iival);'
   'vt.P = ptrans(:,iitst); vt.T = tn(:,iitst);'
   'ptr = ptrans(:,iitr); ttr = tn(:,iitr);',
   ''};
  slide(slideIndex).text={
   ['Divide the data up into training, validation and test sets.',...
   ' The testing set will start with the second point and take',...
   ' every fourth point. The validation set will start with',...
   ' the fourth point and take every fourth point. The training set',...
   ' will take the remaining points.'],
   '>> [R,Q] = size(ptrans); iitst = 2:4:Q;',
   '>> iival = 4:4:Q; iitr = [1:4:Q 3:4:Q];',
   '>> vv.P = ptrans(:,iival); vv.T = tn(:,iival);',
   '>> vt.P = ptrans(:,iitst); vt.T = tn(:,iitst);',
   '>> ptr = ptrans(:,iitr); ttr = tn(:,iitr);',
   ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''blank'',slideData);',
   'net = newff(minmax(ptr),[5 3],{''tansig'' ''purelin''},''trainlm'');',
   ''};
  slide(slideIndex).text={
   ['Create a feedforward network with 5 hidden neurons, 3 output',...
   ' neurons, tansig hidden neurons and linear output neurons. Use', ...
   ' the Levenberg-Marquardt training function - trainlm.  The newff',...
   ' command will also initialize the weights in the network.'],
   '',
   '>> net = newff(minmax(ptr),[5 3],{''tansig'' ''purelin''},''trainlm'');',
   ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''axes'',slideData);',
   'net.trainParam.show = 5;',
   '[net,tr]=train(net,ptr,ttr,[],[],vv,vt);',
   ''};
  slide(slideIndex).text={
   'Show intermediate training results every five iterations.',
   '',
   '>> net.trainParam.show = 5;',
   '',
   'Train the network.  Use early stopping.',
   '',
   '>> [net,tr]=train(net,ptr,ttr,[],[],vv,vt);',
   ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''axes'',slideData);',
   'plot(tr.epoch,tr.perf,''r'',tr.epoch,tr.vperf,'':g'',tr.epoch,tr.tperf,''-.b'');',
   'legend(''Training'',''Validation'',''Test'',-1);',
   'ylabel(''Squared Error'')',
   ''};
  slide(slideIndex).text={
   'Plot the training, validation and test errors.',
   '',
   '>> plot(tr.epoch,tr.perf,''r'',tr.epoch,tr.vperf,'':g'',tr.epoch,tr.tperf,''-.b'')',
   '>> legend(''Training'',''Validation'',''Test'',-1);',
   '>> ylabel(''Squared Error'')',
   ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''blank'',slideData);',
   'an = sim(net,ptrans);',
   'a = poststd(an,meant,stdt);',
   ''};
  slide(slideIndex).text={
   'Simulate the trained network.',
   '>> an = sim(net,ptrans);',
   '',
   ['Convert the output of the network back into the original units', ...
   ' of the targets. Since the targets were transformed using prestd so', ...
   ' that the mean was 0 and the standard deviation was 1, we need to', ...
   ' use poststd (the inverse of prestd) and the original mean and standard', ...
   ' deviation to transform the network outputs back into the original units.'],
   '>> a = poststd(an,meant,stdt);',
   ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''axes'',slideData);',
   'i = 1;',
   '[m(i),b(i),r(i)] = postreg(a(i,:),t(i,:));',
   ''};
  slide(slideIndex).text={
   'Plot regression analysis for output element 1.',
   '',
   '>> i = 1;',
   '>> [m(i),b(i),r(i)] = postreg(a(i,:),t(i,:));',
   ''};

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

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''axes'',slideData);',
   'i = 2;',
   '[m(i),b(i),r(i)] = postreg(a(i,:),t(i,:));',
   ''};
  slide(slideIndex).text={
   'Plot regression analysis for output element 2.',
   '',
   '>> i = 2;',
   '>> [m(i),b(i),r(i)] = postreg(a(i,:),t(i,:));',
   ''};

  %========== Slide 10 ==========

  slideIndex = slideIndex + 1;
  slide(slideIndex).code={
   'slideData=nnslides(''axes'',slideData);',
   'i = 3;',
   '[m(i),b(i),r(i)] = postreg(a(i,:),t(i,:));',
   ''};
  slide(slideIndex).text={
   'Plot regression analysis for output element 3.',
   '',
   '>> i = 3;',
   '>> [m(i),b(i),r(i)] = postreg(a(i,:),t(i,:));',
   ''};
end
