% 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 plot Fig. S9 with tail weight numbers for matched distributions

clear variables;

load currmatched_resp_nos_poisson.mat;
load drdiffmatched_resp_nos_poisson.mat;

%plot settings
fnt = 20;
fntlab = 14;

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

x = 1:151; %vector containing index (\eta) for tail weight numbers

%Calculate (\eta x avg. syn weight for input rate and current matched distributions)
x_del = sum(qdw_del(3,:).*qdw_del(1,:))*x;
x_gauss = sum(qdw_gauss(3,:).*qdw_gauss(1,:))*x;
x_exp = sum(qdw_exp(3,:).*qdw_exp(1,:))*x;
x_logn = sum(qdw_logn(3,:).*qdw_logn(1,:))*x;
x_hyp = sum(qdw_hyp(3,:).*qdw_hyp(1,:))*x;
x_bidel = sum(qdw_bidel(3,:).*qdw_bidel(1,:))*x;

%Calculate (\eta x avg. syn weight for drift and diffusion matched distributions)
x_del_dd = sum(qdw_del_dd(3,:).*qdw_del_dd(1,:))*x;
x_gauss_dd = sum(qdw_gauss_dd(3,:).*qdw_gauss_dd(1,:))*x;
x_exp_dd = sum(qdw_exp_dd(3,:).*qdw_exp_dd(1,:))*x;
x_logn_dd = sum(qdw_logn_dd(3,:).*qdw_logn_dd(1,:))*x;
x_hyp_dd = sum(qdw_hyp_dd(3,:).*qdw_hyp_dd(1,:))*x;
x_bidel_dd = sum(qdw_bidel_dd(3,:).*qdw_bidel_dd(1,:))*x;

%Plot

figure;

%Plot panels S9 a) and b)
xtc = [0;0.025;0.05];
xtl = [0;25;50];
ytl = [0;0.2;0.4;0.6;0.8;1];

s1 = subplot(2,2,1);
plot(x_del,r_del,x_gauss,r_gauss,x_exp,r_exp,x_logn,r_logn,'linewidth',2);
hold on;
plot(x_bidel,r_bidel,'Color',[0.2,0,0.5],'linewidth',2);
plot(x_hyp,r_hyp,'Color',[0.8,0.8,0],'linewidth',2);
axis([0 0.05 0 1.1]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'YTick',ytl);
set(gca,'YTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Tail wt. no. (Q_{\eta})');xlabel('\eta \times avg. syn. wt (mV) \newline             (a)');
axis square; box on;
leg1 = legend('Delta','Gauss','Exp','LogN','Bimod','PL');
set(leg1,'FontSize',fntlab,'Location','SouthEast','Interpreter','tex');

s2 = subplot(2,2,2);
plot(x_del_dd,r_del_dd,x_gauss_dd,r_gauss_dd,x_exp_dd,r_exp_dd,x_logn_dd,r_logn_dd,'linewidth',2);
hold on;
plot(x_bidel_dd,r_bidel_dd,'Color',[0.2,0,0.5],'linewidth',2);
plot(x_hyp_dd,r_hyp_dd,'Color',[0.8,0.8,0],'linewidth',2);
axis([0 0.05 0 1.1]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'FontSize',fnt);
ylabel('Tail wt. no. (Q_{{\bf\eta}})');xlabel('\eta \times  avg. syn. wt (mV) \newline              (b)');
axis square; box on;
leg2 = legend('Delta','Gauss','Exp','LogN','Bimod','PL');
set(leg2,'FontSize',fntlab,'Location','SouthEast','Interpreter','tex');

%Align panels S9 a) and b)
s1Pos = get(s1,'Position');
s2Pos = get(s2,'Position');
s2Pos(1) = s1Pos(1)+0.35;
set(s2,'Position',s2Pos);

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

%Plot panels S9 c) and d)
xtc = [0;0.005;0.01];
xtl = [0;5;10];
ytl = [0;0.02;0.04;0.06];

s3 = subplot(2,2,3);
plot(x_del,r_del,x_gauss,r_gauss,x_exp,r_exp,x_logn,r_logn,'linewidth',2);
hold on;
plot(x_bidel,r_bidel,'Color',[0.2,0,0.5],'linewidth',2);
plot(x_hyp,r_hyp,'Color',[0.8,0.8,0],'linewidth',2);
axis([0 0.01 0 0.06]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'FontSize',fnt);
ylabel('Tail wt. no. (Q_{\eta})');xlabel('\eta \times avg. syn. wt (mV) \newline             (c)');
axis square; box on;
leg1 = legend('Delta','Gauss','Exp','LogN','Bimod','PL');
set(leg1,'FontSize',fntlab,'Location','NorthWest','Interpreter','tex');

s4 = subplot(2,2,4);
plot(x_del_dd,r_del_dd,x_gauss_dd,r_gauss_dd,x_exp_dd,r_exp_dd,x_logn_dd,r_logn_dd,'linewidth',2);
hold on;
plot(x_bidel_dd,r_bidel_dd,'Color',[0.2,0,0.5],'linewidth',2);
plot(x_hyp_dd,r_hyp_dd,'Color',[0.8,0.8,0],'linewidth',2);
axis([0 0.01 0 0.06]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'YTick',ytl);
set(gca,'YTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Tail wt. no. (Q_{\eta})');xlabel('\eta \times  avg. syn. wt (mV) \newline              (d)');
axis square; box on;
leg2 = legend('Delta','Gauss','Exp','LogN','Bimod','PL');
set(leg2,'FontSize',fntlab,'Location','NorthWest','Interpreter','tex');

%Plot panels S9 c) and d)
s3Pos = get(s3,'position');
s4Pos = get(s4,'position');
s4Pos(1) = s3Pos(1)+0.35;
s4Pos(2:4) = s3Pos(2:4);
set(s4,'position',s4Pos);

print2eps Fig_S9.eps


