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

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

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

  slide(1).code={
   'slideData=nnslides(''start'',slideData,''Function Approximation with Radial Basis Networks'');' };
  slide(1).text={
   'NEWRB  - Creates a radial basis network.',
   'SIM  - Simulates a neural network.',
   'This demo uses the NEWRB function to create a radial basis network that approximates a function defined by a set of data points.'};

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

  slide(2).code={
   'slideData=nnslides(''axes'',slideData);',
   'P = -1:.1:1;',
   'T = [-.9602 -.5770 -.0729  .3771  .6405  .6600  .4609   .1336 -.2013 -.4344 -.5000 -.3930 -.1647  .0988  .3072  .3960  .3449  .1816 -.0312 -.2189 -.3201];',
   'plot(P,T,''+'');',
   'title(''Training Vectors'');',
   '  xlabel(''Input Vector P'');',
   '  ylabel(''Target Vector T'');' };
  slide(2).text={
   'Define 21 inputs P and associated targets T:',
   '>> P = -1:.1:1;',
   '>> T = [-.9602 -.5770 -.0729  .3771  .6405  .6600  .4609 ...',
   '          .1336 -.2013 -.4344 -.5000 -.3930 -.1647  .0988 ...',
   '          .3072  .3960  .3449  .1816 -.0312 -.2189 -.3201];',
   'Plot these 21 data points:',
   '>> plot(P,T,''+'');'};

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

  slide(3).code={
   'p = -3:.1:3;',
   'a = radbas(p);',
   'plot(p,a)',
   'title(''Radial Basis Transfer Function'');',
   'xlabel(''Input p'');',
   'ylabel(''Output a'');' };
  slide(3).text={
   'We would like to find a function which fits the 21 data points. One way to do this is with a radial basis network.  A radial basis network is a network with two layers.  A hidden layer of radial basis neurons and an output layer of linear neurons. Here is the radial basis transfer function used by the hidden layer:',
   '>> p = -3:.1:3;',
   '>> a = radbas(p);',
   '>> plot(p,a)'};

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

  slide(4).code={
   'slideData=nnslides(''axes'',slideData);',
   'a2 = radbas(p-1.5);',
   'a3 = radbas(p+2);',
   'a4 = a + a2*1 + a3*0.5;',
   'plot(p,a,''b--'',p,a2,''b--'',p,a3,''b--'',p,a4,''m-'')',
   'title(''Weighted Sum of Radial Basis Transfer Functions'');',
   'xlabel(''Input p'');',
   'ylabel(''Output a'');' };
  slide(4).text={
   'The weights and biases of each neuron in the hidden layer define the position and width of a radial basis function. Each linear output neuron forms a weighted sum of these radial basis functions. With the correct weight and bias values for each layer, and enough hidden neurons, a radial basis network can fit any function with any desired accuracy.',
   '>> plot(p,radbas(p)+radbas(p-1.5)+.05*radbas(p+2),''m-'');',
   'Above is an example of three radial basis functions (in blue) are scaled and summed to produce a function (in magenta).'};

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

  slide(5).code={
   'slideData=nnslides(''blank'',slideData);',
   'eg = 0.02; % sum-squared error goal.',
   'sc = 1;    % spread constant radial basis functions.',
   'net=newrb(P,T,eg,sc);',
   '' };
  slide(5).text={
   'Th function NEWRB quickly creates a radial basis network which approximates the function defined by P and T.',
   'In addition to the training set and targets, NEWRB takes two arguments:',
   '>> eg = 0.02;  % sum-squared error goal',
   '>> sc = 1;       % spread constant',
   '>> net=newrb(P,T,eg,sc);'};

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

  slide(6).code={
   'slideData=nnslides(''axes'',slideData);',
   'plot(P,T,''+'');',
   'title(''Training Vectors'');',
   '  xlabel(''Input Vector P'');',
   '  ylabel(''Target Vector T'');',
   'X=-1:.01:1;',
   'Y=sim(net,X);',
   'hold on;',
   'plot(X,Y);',
   'hold off;',
   '' };
  slide(6).text={
   'To see how the network performs, replot the training set:',
   '>> plot(P,T,''+'');',
   'Simulate the network response for inputs over the same range:',
   '>> X=-1:.1:1;',
   '>> Y=sim(net,X);',
   'And plot the results on the same graph:',
   '>> hold on;  plot(X,Y);  hold off;'};
end