% 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 Figure 2 (matched synaptic distributions)

clear variables;

match_drift_only=1;
match_4_distributions_1_var;
qdw_del=[0.001; 1; 1];
qdw_bidel=[0.0005 0.015;1 1;14/14.5 1-(14/14.5)];
qdw_hyp=[wts_hyp; ones(size(wts_hyp)); qwts_hyp]; 
qdw_gauss=[wts_gauss;ones(size(wts_gauss));qwts_gauss];
qdw_exp=[wts_exp; ones(size(wts_exp)); qwts_exp]; 
qdw_logn=[wts_logn; ones(size(wts_logn)); qwts_logn]; 

%plot settings
fnt = 18;
fntlab = 10;
xtc = [0;50;100]*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]; %x-axis labels for time in (ms)
ytl = [0;5;10;15;20]; %y-axis labels for membrane potential in (mV)

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

scale=10^3;   % to convert from V^-1 to mV^-1
scale1 = 10^0; 

load 'Fig2_gaussian_plots.mat';
load 'Fig2_matched_distributions.mat';
load 'Fig2_matched_frates.mat';

%%%%%SYNAPTIC DISTRIBUTION PLOTS
figure;
s1 = subplot1(2,3,1);
plot(wts_g,scale1*qdw_g(1,:),'.-',wts_g,scale1*qdw_g(2,:),'.-','MarkerSize',15,'linewidth',2);
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Probability');xlabel('synaptic wt (mV) \newline             (a)');
axis square;
legact1 = ['Mean=' num2str(scale*mean_std_matrix(1,1)) 'mV,\newline SD=' num2str(scale*mean_std_matrix(2,1)) 'mV'];
legact2 = ['Mean=' num2str(scale*mean_std_matrix(1,2)) 'mV,\newline SD=' num2str(scale*mean_std_matrix(2,2)) 'mV'];
legact=[legact1;legact2];
leg1 = legend(legact);
set(leg1,'FontSize',fntlab,'Interpreter','tex');

%%%%%EQUILIBRIUM DISTRIBUTION PLOTS
s2 = subplot1(2,3,2);
scale2 = 10^-3;
plot(v0,scale2*equil_g','--','linewidth',2);hold on;
plot(v0,scale2*equil_g2','.-','linewidth',2);
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;
leg2 = legend('f_{in} = 250 Hz','f_{in} = 500 Hz','f_{in} = 100 Hz','f_{in} = 200 Hz' );
set(leg2,'FontSize',8,'Interpreter','tex','Location','South');      %hard-coded fontsize for legends


%%%%%FIRING RATE PLOTS
s3=subplot1(2,3,3);
% dt2=t_vec(2)-t_vec(1);
% dt22=t_vec2(2)-t_vec2(1);
tvec=t_vec_del;
plot(tvec,fout_g','--','linewidth',2);hold on; %hard-coded time axis limits
plot(tvec,fout_g2','.-','linewidth',2);      %hard-coded time axis limits
axis([0 tvec(end) 0 60]);                                          %hard-coded time and FR axes limits
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'FontSize',fnt);
ylabel('Firing rate (Hz)');xlabel('time (ms) \newline       (c)');
axis square;
leg3 = legend('f_{in} = 250 Hz','f_{in} = 500 Hz','f_{in} = 100 Hz','f_{in} = 200 Hz' );
set(leg3,'FontSize',fntlab,'Interpreter','tex','Location','East');

%%%%%SYNAPTIC DISTRIBUTION PLOTS
s4=subplot1(2,3,4);
minyaxis=10^-5;
dplot=wts_hyp(1)/10;
wts_del=qdw_del(1,1)-dplot:dplot:qdw_del(1,1)+dplot;
qwts_del=0.1*minyaxis*ones(size(wts_del));
qwts_del(2)=1;
wts_bidel=[qdw_bidel(1,1)-dplot:dplot:qdw_bidel(1,1)+dplot qdw_bidel(1,2)-dplot:dplot:qdw_bidel(1,2)+dplot];
qwts_bidel=0.1*minyaxis*ones(size(wts_bidel));
qwts_bidel(2)=qdw_bidel(3,1);
qwts_bidel(5)=qdw_bidel(3,2);
semilogy(wts_del,qwts_del,'.-',wts_gauss,qwts_gauss,'.-',wts_exp,qwts_exp,'.-',wts_logn,qwts_logn,'.-','MarkerSize',15);
hold on;
semilogy(wts_bidel,qwts_bidel,'.-','Color',[0.2,0,0.5],'MarkerSize',15);
semilogy(wts_hyp,qwts_hyp,'.-','Color',[0.8,0.8,0],'MarkerSize',15);
axis([0 0.02 minyaxis 1.2]);            %hard-coded xy axes limits
set(gca,'FontSize',fnt);
set(gca,'XTick',ytc);
set(gca,'XTickLabel',ytl);
set(gca,'FontSize',fnt);
ylabel('Probability');xlabel('synaptic wt (mV) \newline             (d)');
axis square;
leg4 = legend('Delta','Gauss','Exp','LogN','Bimod','PL');
set(leg4,'FontSize',fntlab,'Location','North','Interpreter','tex');

%%%%%EQUILIBRIUM DISTRIBUTION PLOTS
s5=subplot1(2,3,5);
scale3 = 10^-3;
plot(v0,scale3*prob_del_unif(end,:),v0,scale3*prob_gauss_unif(end,:),v0,scale3*prob_exp_unif(end,:),v0,scale3*prob_logn_unif(end,:),'linewidth',2);
hold on;
plot(v0,scale3*prob_bidel_unif(end,:),'Color',[0.2,0,0.5],'linewidth',2);
plot(v0,scale3*prob_hyp_unif(end,:),'Color',[0.8,0.8,0],'linewidth',2);
axis([0 v0(end) 0 0.2]);         %hard-coded xy axes limits
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          (e)');
axis square;
leg5 = legend('Delta','Gauss','Exp','LogN','Bimod','PL');
set(leg5,'FontSize',fntlab,'Location','NorthEast','Interpreter','tex');

%%%%FIRING RATE PLOTS
s6=subplot1(2,3,6);
plot(t_vec_del,fout_del,t_vec_gauss,fout_gauss,t_vec_exp,fout_exp,t_vec_logn,fout_logn,'linewidth',2);
hold on;
plot(t_vec_bidel,fout_bidel,'Color',[0.2,0,0.5],'linewidth',2);
plot(t_vec_hyp,fout_hyp,'Color',[0.8,0.8,0],'linewidth',2);
axis([0 tvec(end) 0 30]);              %hard-coded xy axes limits
set(gca,'FontSize',fnt);
set(gca,'XTick',xtc);
set(gca,'XTickLabel',xtl);
set(gca,'FontSize',fnt);
ylabel('Firing rate (Hz)');xlabel('time (ms) \newline       (f)');
axis square; box on;
leg6 = legend('Delta','Gauss','Exp','LogN','Bimod','PL');
set(leg6,'FontSize',fntlab,'Location','SouthEast','Interpreter','tex');

print2eps Fig2.eps

