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

% Copyright 1992-2000 The MathWorks, Inc.
% $Revision: 1.13 $  $Date: 2000/06/15 04:16:03 $

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

  slide(1).code={
   'slideData=nnslides(''start'',slideData,''A Hopfield Network with Unstable Equilibria'');' };
  slide(1).text={
   'NEWHOP  - Creates a Hopfield network.',
   'SIM   - Simulates a neural  network.',
   '',
   'A Hopfield network is designed with target stable points. However, while NEWHOP finds a solution with the minimum number of unspecified stable points, they do often occur. The Hopfield network designed here is shown to have an undesired equilibrium point.  However, these points are unstable in that any noise in the system will move the network out of them.',
   ''};

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

  slide(2).code={
   'slideData=nnslides(''blank'',slideData);',
   'T = [+1 -1; -1 +1];' };
  slide(2).text={
   'We would like to obtain a Hopfield network that has the two stable points define by the two target (column) vectors in T.',
   '',
   '>> T = [+1 -1;',
   '            -1 +1];',
   ''};

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

  slide(3).code={
   'slideData=nnslides(''axes'',slideData);',
   'cla;',
   'plot(T(1,:),T(2,:),''r*'')',
   'axis([-1.1 1.1 -1.1 1.1])',
   'title(''Hopfield Network State Space'')',
   'xlabel(''a(1)'');',
   'ylabel(''a(2)'');' };
  slide(3).text={
   'Here is a plot where the stable points are shown at the corners.  All possible states of the 2-neuron Hopfield network are contained within the plots boundaries.',
   '>> plot(T(1,:),T(2,:),''r*'')',
   '>> axis([-1.1 1.1 -1.1 1.1])',
   '>> title(''Hopfield Network State Space'')',
   '>> xlabel(''a(1)''); ylabel(''a(2)'');',
   '',
   ''};

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

  slide(4).code={
   ' net=newhop(T);' };
  slide(4).text={
   'The function NEWHOP creates Hopfield networks given the stable points T.',
   '>> net=newhop(T);',
   ''};

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

  slide(5).code={
   'cla;',
   'plot(T(1,:),T(2,:),''r*'')',
   'axis([-1.1 1.1 -1.1 1.1])',
   'a = {rands(2,1)};',
   '[y,Pf,Af] = sim(net,{1 50},{},a);' };
  slide(5).text={
   'Here we define a random starting point and simulate the Hopfield network for 50 steps. It should reach one of its stable points.',
   '',
   '>> a = {rands(2,1)};',
   '>> [y,Pf,Af] = sim(net,{1 50},{},a);'};

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

  slide(6).code={
   'cla;',
   'plot(T(1,:),T(2,:),''r*'')',
   'axis([-1.1 1.1 -1.1 1.1])',
   'record=[cell2mat(a) cell2mat(y)];',
   'start=cell2mat(a);',
   'hold on',
   'plot(start(1,1),start(2,1),''bx'',record(1,:),record(2,:))' };
  slide(6).text={
   'We can make a plot of the Hopfield networks activity.',
   '>> record=[cell2mat(a) cell2mat(y)];',
   '>> start=cell2mat(a);',
   '>> hold on',
   '>> plot(start(1,1),start(2,1),''bx'',record(1,:),record(2,:))',
   '',
   'Sure enough, the network ends up in either the upper-left or lower right corners of the plot.'};

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

  slide(7).code={
   'plot(0,0,''ko'');',
   'P = [-1.0 -0.5 0.0 +0.5 +1.0;  -1.0 -0.5 0.0 +0.5 +1.0];',
   'color = ''rgbmy'';',
   'for i=1:5',
   '   a = {P(:,i)};',
   '  [y,Pf,Af] = sim(net,{1 50},{},a);',
   '  record=[cell2mat(a) cell2mat(y)];  start=cell2mat(a);',
   '   plot(start(1,1),start(2,1),''kx'',record(1,:),record(2,:),color(rem(i,5)+1))',
   '  drawnow',
   'end' };
  slide(7).text={
   'Unfortunately, the network has undesired stable points at places other than the corners.  We can see this when we simulate the Hopfield for the following five initial weights:',
   '          [-1.0;        [-0.5;       [0.0;       [+0.5;       [+1.0;',
   '           -1.0]        -0.5]        0.0]        +0.5]        +1.0]',
   'These points are exactly between the two target stable points.  The result is that they all move into the center of the state space, where an undesired stable point exists.'};
end