% Attractor bump model.  Follows the equations in: 
%   Redish, A.D.,  Elga, A.N., and Touretzky, D.S. (1996) A coupled
%   attractor model of the rodent head direction system.
%   NETWORK: Computation in Neural Systems, 7:671-685.
%
%  Mouse on one of the flanks of the bump to make the attractor move.


% David S. Touretzky, Carnegie Mellon University.
% April, 1998.

  NEUNITS = 101;  % should be an odd number for symmetry
  NEUNITS2 = floor(NEUNITS/2);
  W =  rot(exp(-((-NEUNITS2):NEUNITS2).^2/NEUNITS2)',NEUNITS2);
  wEE = 0.377 * allrot(W,-1);
  wEI = -8;
  wIE = 0.5;
  wII = -4;

  gammaE = -1.5;
  gammaI = -7.5;
  tauE = 0.001;
  tauI = 0.0002;
  deltaT = 0.0001;

  DecayRate = 0.9;
  Bias = 0;
  BiasInc = 0.1;

  SE = rand(NEUNITS,1)*0.1;
  SE = 3 * rot(wEE(:,1),NEUNITS2);
  SI = 0.2;

  clf reset, whitebg(gcf,[0 0 0])
  set(gcf,'Backingstore','off')
  set(gcf,'UserData',zeros(NEUNITS,1));
  hold on
  hbump = plot(SE,'EraseMode','background');
  hext = plot(SE*0,'r','EraseMode','background');
  axis([0 length(SE) 0 1])
  xlabel('Mouse on the bump to make it move.')
  set(gca,'ButtonDownFcn','clickhandler(W)')
  set(hbump,'ButtonDownFcn','clickhandler(W)')
  set(hext,'ButtonDownFcn','clickhandler(W)')
  set(gca,'Drawmode','fast')
  uicontrol('Style','PushButton','Position',[10 30 20 20],'String','+', ...
	'CallBack','Bias = Bias + BiasInc;')
  uicontrol('Style','PushButton','Position',[10 10 20 20],'String','-', ...
	'CallBack','Bias = Bias - BiasInc;')

    % for circular mean computation:
  coords = (0:(NEUNITS-1))' / NEUNITS * 2*pi - pi;
  sincoords = sin(coords);
  coscoords = cos(coords);

  t = 0;

  bump_mainloop

