clear all
close all
clc
%% System parameteres 
T = 300; %total time 
dt = 1e-3; %integration time step 
nt = round(T/dt); %number of steps 
gstar = 1.5; %initial coupling strength
N = 2000; %number of neurons 
omega = randn(N,N)/sqrt(N); %static weights.  
imin = round(10/dt); %start RLS 
imax = round(250/dt); %stop RLS
z0 = randn(N,1);  %initial condition for training 
time = (1:nt)*dt; %total time. 
sup = rossler_gen(time); %generate trace from supervisor (Rossler)
dim = size(sup,2); %dimension of supervisor 
eta = (2*rand(N,dim)-1); %encoder 
phi = zeros(N,dim); %decoder 
m = 1/2; %power for transfer function 
q = 1/(m-1); %rescaling constant. 
%% RLS parameters 
alpha = 1; 
P = (1/alpha) * eye(N);
train = 1;
%% Train with RLS
disp('Training Reservoir with g  = g_1')
[storexl,storerl,phi] = RLS_net1(N,z0,gstar,1,omega,phi,eta,nt,imax,imin,P,m,dt,sup,train);
disp('Training complete')
%% Test with a new initial condition. 
z0 = randn(N,1); 
train = 0;
disp('Testing the Reservoir with g  = g_1')
[storext,storet] =  RLS_net1(N,z0,gstar,1,omega,phi,eta,nt,imax,imin,P,m,dt,sup,train);
disp('Testing Complete (g = g_1)')
%% Change g/rescale the reservoir dynamics.  
g = 1.9;
z1 = ((gstar/g)^q)*z0;
phi_hat = phi*(g/gstar)^(q*m);
eta_hat = eta*(gstar/g)^(q);
%% Test with the rescaled reservoir and rescaled encoders/decoders 
train = 0;
disp('Testing the Reservoir with g  = g_2')
[storext2,store2] =  RLS_net1(N,z1,g,1,omega,phi_hat,eta_hat,nt,imax,imin,P,m,dt,sup,train);
disp('Testing Complete w/ Rescaled Reservoir, (g = g_2)')
%% 
save sim_1.mat -v7.3 
%% 
plotting_script