% 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 plots for Supp Figure S12 (input-output curves for a given
%%%%set of distributions.

clear variables;

baserates=0.5:0.25:2;    %Set of input rates to plot (will be multiplied by firing rate)
fractions=0.5:0.1:1;    %Set of fractions of firing rates at which to take equilibrium distributions to identify peak transients
baserate=1000;

%Plot settings
fnt = 18;
fntlab = 10;

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


%%%%%PANEL A: Input-output curves for delta synaptic distribution
load('delta_transient_frates.mat');

figure;
s1 = subplot1(2,3,1);
hold all;
legendstring=cell(length(fractions),1);
for ii=1:length(fractions)-2
    indices=find(transient_frates(:,1)==fractions(ii));
    plot(transient_frates(indices,2),transient_frates(indices,3),'-o','linewidth',2);
    legendstring{ii}=['Frac = ' num2str(fractions(ii))];
end;
indices=find(transient_frates(:,1)==fractions(5));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.2,0,0.5],'linewidth',2);
legendstring{5}=['Frac = ' num2str(fractions(5))];
indices=find(transient_frates(:,1)==fractions(6));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.8,0.8,0],'linewidth',2);
legendstring{6}=['Frac = ' num2str(fractions(6))];
hold off;
legend(legendstring,'Location','Northwest');
set(gca,'FontSize',fnt);
set(gca,'FontSize',fnt);
xlim([500 2000]);
ylabel('Peak output FR (Hz)');xlabel('Syn input events per sec \newline                (a)');
axis square;  box on;
leg1 = legend(legendstring,'Location','Northwest');
set(leg1,'FontSize',fntlab,'Interpreter','tex');


%%%%%PANEL B: Input-output curves for Gaussian synaptic distribution
load('gauss_transient_frates.mat');
s2 = subplot1(2,3,2);
hold all;
legendstring=cell(length(fractions),1);
for ii=1:length(fractions)-2
    indices=find(transient_frates(:,1)==fractions(ii));
    plot(transient_frates(indices,2),transient_frates(indices,3),'-o','linewidth',2);
    legendstring{ii}=['Frac = ' num2str(fractions(ii))];
end;
indices=find(transient_frates(:,1)==fractions(5));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.2,0,0.5],'linewidth',2);
legendstring{5}=['Frac = ' num2str(fractions(5))];
indices=find(transient_frates(:,1)==fractions(6));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.8,0.8,0],'linewidth',2);
legendstring{6}=['Frac = ' num2str(fractions(6))];
hold off;
set(gca,'FontSize',fnt);
set(gca,'FontSize',fnt);
xlim([500 2000]);
ylabel('Peak output FR (Hz)');xlabel('Syn input events per sec \newline                (b)');
axis square; box on;
leg4 = legend(legendstring,'Location','Northwest');
set(leg4,'FontSize',fntlab,'Interpreter','tex');


%%%%%PANEL C: Input-output curves for exponential synaptic distribution
load('exp_transient_frates.mat');
s3 = subplot1(2,3,3);
hold all;
legendstring=cell(length(fractions),1);
for ii=1:length(fractions)-2
    indices=find(transient_frates(:,1)==fractions(ii));
    plot(transient_frates(indices,2),transient_frates(indices,3),'-o','linewidth',2);
    legendstring{ii}=['Frac = ' num2str(fractions(ii))];
end;
indices=find(transient_frates(:,1)==fractions(5));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.2,0,0.5],'linewidth',2);
legendstring{5}=['Frac = ' num2str(fractions(5))];
indices=find(transient_frates(:,1)==fractions(6));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.8,0.8,0],'linewidth',2);
legendstring{6}=['Frac = ' num2str(fractions(6))];
hold off;
set(gca,'FontSize',fnt);
set(gca,'FontSize',fnt);
xlim([500 2000]);
ylabel('Peak output FR (Hz)');xlabel('Syn input events per sec \newline                (c)');
axis square;  box on;
leg2 = legend(legendstring,'Location','Northwest');
set(leg2,'FontSize',fntlab,'Interpreter','tex');

%%%%%PANEL D: Input-output curves for lognormal synaptic distribution
load('logn_transient_frates.mat');
s4 = subplot1(2,3,4);
hold all;
legendstring=cell(length(fractions),1);
for ii=1:length(fractions)-2
    indices=find(transient_frates(:,1)==fractions(ii));
    plot(transient_frates(indices,2),transient_frates(indices,3),'-o','linewidth',2);
    legendstring{ii}=['Frac = ' num2str(fractions(ii))];
end;
indices=find(transient_frates(:,1)==fractions(5));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.2,0,0.5],'linewidth',2);
legendstring{5}=['Frac = ' num2str(fractions(5))];
indices=find(transient_frates(:,1)==fractions(6));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.8,0.8,0],'linewidth',2);
legendstring{6}=['Frac = ' num2str(fractions(6))];
hold off;
axis([500 2000 0 100]);
set(gca,'FontSize',fnt);
set(gca,'FontSize',fnt);
ylabel('Peak output FR (Hz)');xlabel('Syn input events per sec \newline                (d)');
axis square;  box on;
leg5 = legend(legendstring,'Location','Northwest');
set(leg5,'FontSize',fntlab,'Interpreter','tex');


%%%%%PANEL E: Input-output curves for bimodal synaptic distribution
load('bidel_transient_frates.mat');
s5 = subplot1(2,3,5);
hold all;
legendstring=cell(length(fractions),1);
for ii=1:length(fractions)-2
    indices=find(transient_frates(:,1)==fractions(ii));
    plot(transient_frates(indices,2),transient_frates(indices,3),'-o','linewidth',2);
    legendstring{ii}=['Frac = ' num2str(fractions(ii))];
end;
indices=find(transient_frates(:,1)==fractions(5));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.2,0,0.5],'linewidth',2);
legendstring{5}=['Frac = ' num2str(fractions(5))];
indices=find(transient_frates(:,1)==fractions(6));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.8,0.8,0],'linewidth',2);
legendstring{6}=['Frac = ' num2str(fractions(6))];
hold off;
axis([500 2000 0 100]);
set(gca,'FontSize',fnt);
set(gca,'FontSize',fnt);
ylabel('Peak output FR (Hz)');xlabel('Syn input events per sec \newline                (e)');
axis square;  box on;
leg6 = legend(legendstring,'Location','Northwest');
set(leg6,'FontSize',fntlab,'Interpreter','tex');

%%%%%PANEL F: Input-output curves for hyperbolic synaptic distribution
load('hyp_transient_frates.mat');
s6 = subplot1(2,3,6);
hold all;
legendstring=cell(length(fractions),1);
for ii=1:length(fractions)-2
    indices=find(transient_frates(:,1)==fractions(ii));
    plot(transient_frates(indices,2),transient_frates(indices,3),'-o','linewidth',2);
    legendstring{ii}=['Frac = ' num2str(fractions(ii))];
end;
indices=find(transient_frates(:,1)==fractions(5));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.2,0,0.5],'linewidth',2);
legendstring{5}=['Frac = ' num2str(fractions(5))];
indices=find(transient_frates(:,1)==fractions(6));
plot(transient_frates(indices,2),transient_frates(indices,3),'-o','Color',[0.8,0.8,0],'linewidth',2);
legendstring{6}=['Frac = ' num2str(fractions(6))];
hold off;
axis([500 2000 0 100]);
set(gca,'FontSize',fnt);
set(gca,'FontSize',fnt);
ylabel('Peak output FR (Hz)');xlabel('Syn input events per sec \newline                (f)');
axis square;  box on;
leg3 = legend(legendstring,'Location','Northwest');
set(leg3,'FontSize',fntlab,'Interpreter','tex');

print2eps Fig_S12.eps
