% 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 generate Supplement Figure S10 showing transient times taken to reach
%20% of steady state firing rate as a function of the first few moments and
%tail weight numbers for randomly generated synaptic weight distributions. 

%NOTE: The .mat file FigS10_randdist.mat consisting of the original
%distributions used for FigS10 has also been made available and can be 
%used to reproduce the figure exactly. 

clear variables;

load FigS10_randdist.mat;
load FigS10_transient_times.mat;
load FigS10_randdist_Poisson_conv.mat;
load FigS10_norm_moms1to10.mat; 
load beta.mat;
load betam.mat;
load res.mat;
load resm.mat;

norms = norms(1:1222,:);

%Plot settings
fnt = 36;
fntlab = 18;

set(0,'DefaultFigureWindowStyle','docked');
set(0,'defaultAxesFontName', 'Arial');

ytc = [0;2;4;6;8;10;12;14]*10^-3;
ytl = [0;2;4;6;8;10;12;14];

j=6;        %for transient time to 20% of steady state, T20 (change j for other times Tn) 

figure;

%Fig. S10 panels (a)-(d)
%-----------------------
nr_mom_t20=[];
lab = {char('mom2','(a)'),char('mom3','(b)'), char('mom4','(c)'), char('mom5','(d)')};
for m = 2:5
    s(m-1) = subplot1(2,4,m-1);
    plot(norms(:,m),outs(:,j+1),'o');hold on;
    x = sort(norms(:,m));
    nr_mom_t20 = [nr_mom_t20 sum(resm(m,j,:).*resm(m,j,:))];
    plot(x,expfunfit([betam(m,j,1),betam(m,j,2)],x),'r');
    set(gca,'FontSize',fnt);
    %axis([0 1 2*10^-3 12*10^-3]);
    set(gca,'YTick',ytc);
    set(gca,'YTickLabel',ytl);
    set(gca,'FontSize',fntlab);
    ylabel('T_{20}(ms)');xlabel(lab(m-1));
    axis square;box on;
end;

%Fig. S10 panels (e)-(h)
%--------------------------
ytc = [2;4;6;8;10;12]*10^-3;
ytl = [2;4;6;8;10;12];
nr_resp_t20=[];
lab2 =  {char('Q2','(e)'),char('Q3','(f)'), char('Q4','(g)'), char('Q5','(h)')};
for rp = 1:4
    s(rp) = subplot1(2,4,rp+4);
    plot(r_dist(:,rp+1),outs(:,j+1),'o');hold on;
    x = sort(r_dist(:,rp+1));
    nr_resp_t20 = [nr_resp_t20 sum(res(rp,j,:).*res(rp,j,:))];
    plot(x,expfunfit([beta(rp,j,1),beta(rp,j,2)],x),'r');
    set(gca,'FontSize',fnt);
    ylim([2*10^-3 12*10^-3]);
    set(gca,'YTick',ytc);
    set(gca,'YTickLabel',ytl);
    set(gca,'FontSize',fntlab);
    ylabel('T_{20}(ms)');xlabel(lab2(rp));
    axis square ;box on;
end;

print2eps Fig_S10.eps
