 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % 1-d Continuous Attractor Neural Network with Hebbian learning
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 clear; clf; hold on;

 nn = 100; dx=100/nn; % number of nodes and resolution in deg
 tau_inv = 1./1;      % inverse of membrane time constant
 beta =.07; alpha=.0; % transfer function is 1/(1+exp(-beta*(u-theta))

 %weight matrices
    sig = 5/dx;
    w_sym=hebb(nn,sig);
    w_inh=3*(sqrt(2*pi)*sig)^2/nn;
    w=w_sym-w_inh;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%   Experiment    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 %%%% external input to initiate bubble
    u0 = zeros(nn,1)-10;
    I_ext=zeros(nn,1); for i=-20:20; I_ext(nn/2+i)=50; end
    param=0;
    tspan=[0,10];
    [t,u]=ode45('rnn_ode',tspan,u0,[],nn,tau_inv,dx,beta,alpha,w,I_ext);
    r=1./(1+exp(-beta.*(u-alpha)));
    surf(t',1:nn,r','linestyle','none'); view(0,90);

 %%%% no external input to equilibrate
    u0 = u(size(t,1),:);
    I_ext=zeros(nn,1);
    param=0;
    tspan=[10,20];
    [t,u]=ode45('rnn_ode',tspan,u0,[],nn,tau_inv,dx,beta,alpha,w,I_ext);
    r=1./(1+exp(-beta.*(u-alpha)));
    surf(t',1:nn,r','linestyle','none');
    [max_val,max_ind1]=max(r(size(t,1),:))
