%% load data:
clear all
% alternative 1:
% pro: no structs. contra: global unknown variables
load poisson.mat
whos
poissonspikes = spikes;
load pifou.mat;
pifouspikes = spikes;
load lifadapt.mat;
lifadaptspikes = spikes;
clear spikes;
% alternative 2:
% pro: clean code. contra: structs that we do not really know yet
clear all
x = load( 'poisson.mat' );
poissonspikes = x.spikes;
x = load( 'pifou.mat' );
pifouspikes = x.spikes;
x = load( 'lifadapt.mat' );
lifadaptspikes = x.spikes;

%% spike raster plots:
tmax = 1.0;
subplot(1, 3, 1);
spikeraster(poissonspikes, tmax);
title('Poisson');

subplot(1, 3, 2);
spikeraster(pifouspikes, tmax);
title('PIF OU');

subplot(1, 3, 3);
spikeraster(lifadaptspikes, tmax);
title('LIF adapt');

%% isi histograms:
maxisi = 300.0;
binwidth = 0.002;
subplot(1, 3, 1);
poissonisis = isis(poissonspikes);
isihist(poissonisis, binwidth);
xlim([0, maxisi])
title('Poisson');

subplot(1, 3, 2);
pifouisis = isis(pifouspikes);
isihist(pifouisis, binwidth);
xlim([0, maxisi])
title('PIF OU');

subplot(1, 3, 3);
lifadaptisis = isis(lifadaptspikes);
isihist(lifadaptisis, binwidth);
xlim([0, maxisi])
title('LIF adapt');

%% serial correlations:
maxlag = 10;
rrange = [-0.5, 1.05];
subplot(1, 3, 1);
isiserialcorr(poissonisis, maxlag);
ylim(rrange)
title('Poisson');

subplot(1, 3, 2);
isiserialcorr(pifouisis, maxlag);
ylim(rrange)
title('PIF OU');

subplot(1, 3, 3);
isiserialcorr(lifadaptisis, maxlag);
ylim(rrange)
title('LIF adapt');

%% spike counts:
w = 0.1;
cmax = 8;
pmax = 0.5;
subplot(1, 3, 1);
counthist(poissonspikes, w);
xlim([0 cmax])
set(gca, 'XTick', 0:2:cmax)
ylim([0 pmax])
title('Poisson');

subplot(1, 3, 2);
counthist(pifouspikes, w);
xlim([0 cmax])
set(gca, 'XTick', 0:2:cmax)
ylim([0 pmax])
title('PIF OU');

subplot(1, 3, 3);
counthist(lifadaptspikes, w);
xlim([0 cmax])
set(gca, 'XTick', 0:2:cmax)
ylim([0 pmax])
title('LIF adapt');
savefigpdf(gcf, 'counthist.pdf', 20, 7);
