% 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 Supplement Fig S13 (effects of
%%%%fluctuations for all 6 distributions). Please refer to 
%METHODS: Fluctuation Analysis in the paper for the implementation.
%
%NOTE: Each subplot generates two rows of Fig. S13 at a time. First 
%subplot for delta and gaussian, second for exponential and lognormal
%and third for power law and bimodal

clear variables;

fnt = 18;
fntlab = 10;

xtc = [0;50;100;150;200]*10^-3;  %x-axis ticks for time in (ms)
ytc = [0;5;10;15;20]*10^-3; %y-axis ticks for membrane potential in (mV)
xtl = [0;50;100;150;200]; %x-axis labels for time in (ms)
ytl = [0;5;10;15;20]; %y-axis labels for membrane potential in (mV)
xtcf = [1;50;100];  %x-axis ticks for time in (ms)
xtlf = [0;5;10]; %x-axis labels for time in (ms)

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

scale = 10^-3; %to convert prob densities to 1/mV

load 'excitabilities_1000.mat';

%%%ROW 1: Delta
load 'del_fluct_1000.mat';
figure;
s1 = subplot1(2,3,1);
hold all;
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(1,:)','b');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(end,:)','r');
hold off;
axis([0 0.02 0 0.1]);
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (a)');
axis square;box on;

s2 = subplot1(2,3,2);
hold all;
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(1,:)','b');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(end,:)','r');
hold off;
axis([0 0.02 0 0.1]);
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (b)');
axis square;box on;

s3 = subplot1(2,3,3);
hold all;
plot(1:length(excit_no_sd(:,5)),excit_no_sd(:,5),'linewidth',2);
plot(1:length(excit_sd(:,5)),excit_sd(:,5),'linewidth',2);
hold off;
axis([1 length(excit_no_sd(:,5)) 0 4]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtcf);
set(gca,'XTickLabel',xtlf);
set(gca,'FontSize',fnt);
ylabel('Relative excitability (\epsilon)');xlabel('Mean add. inputs per neuron (\lambda) \newline                       (c)');
axis square;box on;
leg1=legend('No depression','With depression','Location','Northeast');
set(leg1,'FontSize',fntlab,'Interpreter','tex','Location','NorthEast');

%%%ROW 2: Gaussian
load 'gauss_fluct_1000.mat';
s4 = subplot1(2,3,4);
hold all;
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(1,:)','b');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (a)');
axis square;box on;

s5 = subplot1(2,3,5);
hold all;
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(1,:)','b');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (b)');
axis square;box on;

s6 = subplot1(2,3,6);
hold all;
plot(1:length(excit_no_sd(:,1)),excit_no_sd(:,1),'linewidth',2);
plot(1:length(excit_sd(:,1)),excit_sd(:,1),'linewidth',2);
hold off;
axis([1 length(excit_no_sd(:,1)) 0 4]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtcf);
set(gca,'XTickLabel',xtlf);
set(gca,'FontSize',fnt);
ylabel('Relative excitability (\epsilon)');xlabel('Mean add. inputs per neuron (\lambda) \newline                       (c)');
axis square;box on;
leg2=legend('No depression','With depression','Location','Northeast');
set(leg2,'FontSize',fntlab,'Interpreter','tex','Location','NorthEast');

print2eps Fig_S13_DG.eps

%%%ROW 3: Exponential
load 'exp_fluct_1000.mat';
figure;
s7 = subplot1(2,3,1);
hold all;
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(1,:)','b');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (a)');
axis square;box on;

s8 = subplot1(2,3,2);
hold all;
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(1,:)','b');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (b)');
axis square;box on;

s9 = subplot1(2,3,3);
hold all;
plot(1:length(excit_no_sd(:,3)),excit_no_sd(:,3),'linewidth',2);
plot(1:length(excit_sd(:,3)),excit_sd(:,3),'linewidth',2);
hold off;
axis([1 length(excit_no_sd(:,3)) 0 4]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtcf);
set(gca,'XTickLabel',xtlf);
set(gca,'FontSize',fnt);
ylabel('Relative excitability (\epsilon)');xlabel('Mean add. inputs per neuron (\lambda) \newline                       (c)');
axis square;box on;
leg3=legend('No depression','With depression','Location','Northeast');
set(leg3,'FontSize',fntlab,'Interpreter','tex','Location','NorthEast');

%%%ROW 4: Lognormal
load 'logn_fluct_1000.mat';
s10 = subplot1(2,3,4);
hold all;
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(1,:)','b');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (a)');
axis square;box on;

s11 = subplot1(2,3,5);
hold all;
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(1,:)','b');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (b)');
axis square;box on;

s12 = subplot1(2,3,6);
hold all;
plot(1:length(excit_no_sd(:,4)),excit_no_sd(:,4),'linewidth',2);
plot(1:length(excit_sd(:,4)),excit_sd(:,4),'linewidth',2);
hold off;
axis([1 length(excit_no_sd(:,4)) 0 4]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtcf);
set(gca,'XTickLabel',xtlf);
set(gca,'FontSize',fnt);
ylabel('Relative excitability (\epsilon)');xlabel('Mean add. inputs per neuron (\lambda) \newline                       (c)');
axis square;box on;
leg4=legend('No depression','With depression','Location','Northeast');
set(leg4,'FontSize',fntlab,'Interpreter','tex','Location','NorthEast');

print2eps Fig_S13_EL.eps

%%%ROW 5: Hyperbolic
load 'hyper_fluct_1000.mat';
figure;
s13 = subplot1(2,3,1);
hold all;
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(1,:)','b');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (a)');
axis square;box on;

s14 = subplot1(2,3,2);
hold all;
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(1,:)','b');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (b)');
axis square;box on;

s15 = subplot1(2,3,3);
hold all;
plot(1:length(excit_no_sd(:,2)),excit_no_sd(:,2),'linewidth',2);
plot(1:length(excit_sd(:,2)),excit_sd(:,2),'linewidth',2);
hold off;
axis([1 length(excit_no_sd(:,2)) 0 4]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtcf);
set(gca,'XTickLabel',xtlf);
set(gca,'FontSize',fnt);
ylabel('Relative excitability (\epsilon)');xlabel('Mean add. inputs per neuron (\lambda) \newline                       (c)');
axis square;box on;
leg5=legend('No depression','With depression','Location','Northeast');
set(leg5,'FontSize',fntlab,'Interpreter','tex','Location','NorthEast');


%%%ROW 6: Bimodal
load 'bidel_fluct_1000.mat';
s16 = subplot1(2,3,4);
hold all;
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(1,:)','b');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop(2).v0,scale*newcellpop(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (a)');
axis square;box on;

s17 = subplot1(2,3,5);
hold all;
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(1,:)','b');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(2:10:end-1,:)','g');
plot(newcellpop_sd(2).v0,scale*newcellpop_sd(2).prob_unif(end,:)','r');
hold off;
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Prob density (mV^{-1})');xlabel('voltage (mV) \newline        (b)');
axis square;box on;

s18 = subplot1(2,3,6);
hold all;
plot(1:length(excit_no_sd(:,6)),excit_no_sd(:,6),'linewidth',2);
plot(1:length(excit_sd(:,6)),excit_sd(:,6),'linewidth',2);
hold off;
axis([1 length(excit_no_sd(:,2)) 0 4]);
set(gca,'FontSize',fnt);
set(gca,'XTick',xtcf);
set(gca,'XTickLabel',xtlf);
set(gca,'FontSize',fnt);
ylabel('Relative excitability (\epsilon)');xlabel('Mean add. inputs per neuron (\lambda) \newline                       (c)');
axis square;box on;
leg6=legend('No depression','With depression','Location','Northeast');
set(leg6,'FontSize',fntlab,'Interpreter','tex','Location','NorthEast');

print2eps Fig_S13_HB.eps
