%
% A toy example of the  Lansner and Ekeberg work
%
%  construct the b vector and W matrix associated with a 4-pixel
%  screen
%     1  2   in which we train for pattern one  1 0  and two  1 1
%     3  4                                      1 0           0 1
%  with kappa=1 for each
%
% then solve    tau E' = b + W*pie(E) - E,  E(0) = E0  up to time T
%
%                   0  if E<b
% where   pie(E) =  exp(E) if b<=E<0
%                   1   if E>=0
%  

T = 4;
dt = .1;
tau = 1;

g = log(2);

b = -[0 g g g]';

W = [0  0  0  0
     0  g -g  g
     0 -g  g -g
     0  g -g  g];

E = [0.9 -2*g 0.8 -3*g]';   % initial data near pattern 1
%E = [0.9 0.7 -2*g 0.8]';   % initial data near pattern 2

t = 0;

plot(t,E,'o')
hold on

while t < T

      for j=1:4,
          if E(j) <= b(j)
             pie(j,1) = 0;
          elseif E(j) <= 0
             pie(j,1) = exp(E(j));
          else
             pie(j,1) = 1;
          end
      end

      t = t + dt;

      E = (E/dt + (b+W*pie)/tau) / (1/dt + 1/tau);  % hybrid euler

      plot(t,E,'o')

end

hold off

legend('E_1','E_2','E_3','E_4')
xlabel('t','fontsize',16)
