% This file is licensed under the Allen Institute Terms of Use, which can be found at:
%http://www.alleninstitute.org/Media/policies/terms_of_use_content.html

%------------------------------------------------------------------------------------

%Script to calculate the various transient times (Tn) taken to reach n% of the 
%steady state output firing rate for the first 1222 of the randomly
%generated synaptic weight distributions. Transient times calculated for 
%n = 1,2,3,5,10,20,30 and 50 respectively.

clear variables;

load FigS10_randdist_DiPDEoutput.mat;

numdist = 1222;
t=t_vec;

%Calculate steady state firing rates and various transient times
for ii=1:length(output_fr(:,1))
    equil_fr(ii)=output_fr(ii,end);
    [trans_1 transind_1]=min(abs(output_fr(ii,:)-(0.01*output_fr(ii,end))));
    trans_time_1(ii)=t(transind_1);
    [trans_2 transind_2]=min(abs(output_fr(ii,:)-(0.02*output_fr(ii,end))));
    trans_time_2(ii)=t(transind_2);
    [trans_3 transind_3]=min(abs(output_fr(ii,:)-(0.03*output_fr(ii,end))));
    trans_time_3(ii)=t(transind_3);
    [trans_5 transind_5]=min(abs(output_fr(ii,:)-(0.05*output_fr(ii,end))));
    trans_time_5(ii)=t(transind_5);
    [trans_10 transind_10]=min(abs(output_fr(ii,:)-(0.1*output_fr(ii,end))));
    trans_time_10(ii)=t(transind_10);
    [trans_20 transind_20]=min(abs(output_fr(ii,:)-(0.2*output_fr(ii,end))));
    trans_time_20(ii)=t(transind_20);
    [trans_30 transind_30]=min(abs(output_fr(ii,:)-(0.3*output_fr(ii,end))));
    trans_time_30(ii)=t(transind_30);
    [trans_50 transind_50]=min(abs(output_fr(ii,:)-(0.5*output_fr(ii,end))));
    trans_time_50(ii)=t(transind_50);
end

equil_fir_rates = equil_fr';
transient_times_1 = trans_time_1';
transient_times_2 = trans_time_2';
transient_times_3 = trans_time_3';
transient_times_5 = trans_time_5';
transient_times_10 = trans_time_10';
transient_times_20 = trans_time_20';
transient_times_30 = trans_time_30';
transient_times_50 = trans_time_50';

outs=[equil_fir_rates transient_times_1 transient_times_2 transient_times_3 transient_times_5 transient_times_10 transient_times_20 transient_times_30 transient_times_50];

save('FigS10_transient_times.mat','outs');

