added all my stuff
This commit is contained in:
10
pointprocesses/code/colorednoisepdf.m
Normal file
10
pointprocesses/code/colorednoisepdf.m
Normal file
@@ -0,0 +1,10 @@
|
||||
function pcn = colorednoisepdf( x, misi, epsilon, tau )
|
||||
% returns the ISI pdf for PIF with colored noise drive
|
||||
% x: the input ISI
|
||||
% misis: the mean isi
|
||||
% epsilon: a parameter
|
||||
% tau: the correlation time of the noise
|
||||
gamma1 = x/tau+exp(-x/tau)-1.0;
|
||||
gamma2 = 1.0-exp(-x/tau);
|
||||
pcn=exp(-(x-misi).^2./(4.0*epsilon*tau.^2.*gamma1)).*(((misi-x).*gamma2+2*gamma1*tau).^2./(2*gamma1*tau^2)-epsilon*(gamma2.^2-2*gamma1.*exp(-x/tau))) ./ (2*tau*sqrt(4*pi*epsilon*gamma1.^3));
|
||||
end
|
||||
24
pointprocesses/code/colorednoisepdfisifit.m
Normal file
24
pointprocesses/code/colorednoisepdfisifit.m
Normal file
@@ -0,0 +1,24 @@
|
||||
% misi = 0.02;
|
||||
% epsilon = 1.0;
|
||||
% tau = 0.1;
|
||||
x=0:0.002:0.1;
|
||||
% pcn = colorednoisepdf( x, misi, epsilon, tau )+10.0*randn( size( x ) );
|
||||
% plot( x, pcn );
|
||||
|
||||
spikes = lifouspikes( 10, 15, 50.0, 1.0, 1.0 );
|
||||
isivec = isis( spikes );
|
||||
misi = mean( isivec );
|
||||
1.0/misi
|
||||
isibins = 0:0.0005:0.1;
|
||||
[ n, c ] = hist( isivec, isibins );
|
||||
n = n / sum(n)/(isibins(2)-isibins(1));
|
||||
bar( c, n );
|
||||
|
||||
beta0 = [ 1.0, 0.01 ];
|
||||
b = nlinfit(c(1:end-2), n(1:end-2), @(b,x)(colorednoisepdf(x, misi, b(1), b(2))), beta0)
|
||||
|
||||
pcn = colorednoisepdf( x, misi, b(1), b(2) );
|
||||
hold on
|
||||
plot( x, pcn, 'r', 'LineWidth', 3 );
|
||||
hold off
|
||||
|
||||
38
pointprocesses/code/counthist.m
Normal file
38
pointprocesses/code/counthist.m
Normal file
@@ -0,0 +1,38 @@
|
||||
function [ counts, bins ] = counthist( spikes, w )
|
||||
% computes count histogram and compare them with Poisson distribution
|
||||
% spikes: a cell array of vectors of spike times
|
||||
% w: observation window duration for computing the counts
|
||||
|
||||
% collect spike counts:
|
||||
tmax = spikes{1}(end);
|
||||
n = [];
|
||||
r = [];
|
||||
for k = 1:length(spikes)
|
||||
for tk = 0:w:tmax-w
|
||||
nn = sum( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) );
|
||||
%nn = length( find( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) ) );
|
||||
n = [ n nn ];
|
||||
end
|
||||
rate = (length(spikes{k})-1)/(spikes{k}(end) - spikes{k}(1));
|
||||
r = [ r rate ];
|
||||
end
|
||||
% histogram of spike counts:
|
||||
maxn = max( n );
|
||||
[counts, bins ] = hist( n, 0:1:maxn+1 );
|
||||
counts = counts / sum( counts );
|
||||
if nargout == 0
|
||||
bar( bins, counts );
|
||||
hold on;
|
||||
% Poisson distribution:
|
||||
rate = mean( r );
|
||||
x = 0:1:20;
|
||||
l = rate*w;
|
||||
y = l.^x.*exp(-l)./factorial(x);
|
||||
plot( x, y, 'r', 'LineWidth', 3 );
|
||||
xlim( [ 0 20 ] );
|
||||
hold off;
|
||||
xlabel( 'counts k' );
|
||||
ylabel( 'P(k)' );
|
||||
end
|
||||
end
|
||||
|
||||
39
pointprocesses/code/fano.m
Normal file
39
pointprocesses/code/fano.m
Normal file
@@ -0,0 +1,39 @@
|
||||
function fano( spikes )
|
||||
% computes fano factor as a function of window size
|
||||
% spikes: a cell array of vectors of spike times
|
||||
|
||||
tmax = spikes{1}(end);
|
||||
windows = 0.01:0.05:0.01*tmax;
|
||||
mc = windows;
|
||||
vc = windows;
|
||||
ff = windows;
|
||||
fs = windows;
|
||||
for j = 1:length(windows)
|
||||
w = windows( j );
|
||||
% collect counts:
|
||||
n = [];
|
||||
for k = 1:length(spikes)
|
||||
for tk = 0:w:tmax-w
|
||||
nn = sum( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) );
|
||||
%nn = length( find( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) ) );
|
||||
n = [ n nn ];
|
||||
end
|
||||
end
|
||||
% statistics for current window:
|
||||
mc(j) = mean( n );
|
||||
vc(j) = var( n );
|
||||
ff(j) = vc( j )/mc( j );
|
||||
fs(j) = sqrt(vc( j )/mc( j ));
|
||||
end
|
||||
|
||||
subplot( 1, 2, 1 );
|
||||
scatter( mc, vc, 'filled' );
|
||||
xlabel( 'Mean count' );
|
||||
ylabel( 'Count variance' );
|
||||
|
||||
subplot( 1, 2, 2 );
|
||||
scatter( 1000.0*windows, fs, 'filled' );
|
||||
xlabel( 'Window W [ms]' );
|
||||
ylabel( 'Fano factor' );
|
||||
end
|
||||
|
||||
5
pointprocesses/code/inversegauss.m
Normal file
5
pointprocesses/code/inversegauss.m
Normal file
@@ -0,0 +1,5 @@
|
||||
function y = inversegauss( x, m, d )
|
||||
% returns the inverse Gauss density with mean isi m and diffusion
|
||||
% coefficent d
|
||||
y = exp(-(x-m).^2./(4.0*d.*x.*m.^2.0))./sqrt(4.0*pi*d.*x.^3.0);
|
||||
end
|
||||
28
pointprocesses/code/inversegaussplot.m
Normal file
28
pointprocesses/code/inversegaussplot.m
Normal file
@@ -0,0 +1,28 @@
|
||||
f = figure;
|
||||
subplot( 1, 2, 1 );
|
||||
dx=0.0001;
|
||||
x = dx:dx:0.5;
|
||||
hold all
|
||||
m = 0.02;
|
||||
for d = [ 0.1 1 10 50 200 ]
|
||||
plot( 1000.0*x, inversegauss( x, m, d ), 'LineWidth', 3, 'DisplayName', sprintf( 'D=%.1f', d ) );
|
||||
end
|
||||
title( sprintf( 'm=%g ms', 1000.0*m ) )
|
||||
xlim( [ 0 50 ] );
|
||||
xlabel( 'ISI [ms]' );
|
||||
ylabel( 'p(ISI)' );
|
||||
legend( '-DynamicLegend' );
|
||||
hold off;
|
||||
|
||||
subplot( 1, 2, 2 );
|
||||
hold all;
|
||||
d = 5.0;
|
||||
for m = [ 0.005 0.01 0.02 0.05 ]
|
||||
plot( 1000.0*x, inversegauss( x, m, d ), 'LineWidth', 3, 'DisplayName', sprintf( 'm=%g ms', 1000.0*m ) );
|
||||
end
|
||||
title( sprintf( 'D=%g Hz', d ) )
|
||||
xlim( [ 0 50 ] )
|
||||
xlabel( 'ISI [ms]' );
|
||||
ylabel( 'p(ISI)' );
|
||||
legend( '-DynamicLegend' )
|
||||
hold off
|
||||
32
pointprocesses/code/isihist.m
Normal file
32
pointprocesses/code/isihist.m
Normal file
@@ -0,0 +1,32 @@
|
||||
function isihist( isis, binwidth )
|
||||
% plot histogram of isis
|
||||
% isis: vector of interspike intervals
|
||||
% binwidth: optional width to be used for the isi bins
|
||||
|
||||
if nargin < 2
|
||||
nperbin = 200; % average number of data points per bin
|
||||
bins = length( isis )/nperbin; % number of bins
|
||||
binwidth = max( isis )/bins;
|
||||
if binwidth < 5e-4 % half a millisecond
|
||||
binwidth = 5e-4;
|
||||
end
|
||||
end
|
||||
bins = 0.5*binwidth:binwidth:max(isis);
|
||||
% histogram:
|
||||
[ nelements, centers ] = hist( isis, bins );
|
||||
% normalization (integral = 1):
|
||||
nelements = nelements / sum( nelements ) / binwidth;
|
||||
% plot:
|
||||
bar( 1000.0*centers, nelements );
|
||||
xlabel( 'ISI [ms]' )
|
||||
ylabel( 'p(ISI) [1/s]')
|
||||
% annotation:
|
||||
misi = mean( isis );
|
||||
sdisi = std( isis );
|
||||
disi = sdisi^2.0/2.0/misi^3;
|
||||
text( 0.5, 0.6, sprintf( 'mean=%.1f ms', 1000.0*misi ), 'Units', 'normalized' )
|
||||
text( 0.5, 0.5, sprintf( 'std=%.1f ms', 1000.0*sdisi ), 'Units', 'normalized' )
|
||||
text( 0.5, 0.4, sprintf( 'CV=%.2f', sdisi/misi ), 'Units', 'normalized' )
|
||||
%text( 0.5, 0.3, sprintf( 'D=%.1f Hz', disi ), 'Units', 'normalized' )
|
||||
end
|
||||
|
||||
24
pointprocesses/code/isireturnmap.m
Normal file
24
pointprocesses/code/isireturnmap.m
Normal file
@@ -0,0 +1,24 @@
|
||||
function isireturnmap( isis, lag2 )
|
||||
% plot return maps for lag 1 and lag lag2
|
||||
|
||||
clf;
|
||||
subplot( 1, 2, 1 );
|
||||
lag = 1;
|
||||
scatter( 1000.0*isis(1:end-lag)', 1000.0*isis(1+lag:end)', 'b', 'filled', 'MarkerEdgeColor', 'white' );
|
||||
xlabel( 'ISI T_i [ms]' );
|
||||
ylabel( 'ISI T_{i+1} [ms]' );
|
||||
maxisi = max( isis );
|
||||
maxy = ceil(maxisi/10)*10.0;
|
||||
xlim( [0 1.5*maxy ])
|
||||
ylim( [0 maxy ])
|
||||
|
||||
subplot( 1, 2, 2 );
|
||||
lag = lag2;
|
||||
scatter( 1000.0*isis(1:end-lag)', 1000.0*isis(1+lag:end)', 'b', 'filled', 'MarkerEdgeColor', 'white' );
|
||||
xlabel( 'ISI T_i [ms]' );
|
||||
ylabel( 'ISI T_{i+2} [ms]' );
|
||||
xlim( [0 1.5*maxy ])
|
||||
ylim( [0 maxy ])
|
||||
|
||||
end
|
||||
|
||||
15
pointprocesses/code/isis.m
Normal file
15
pointprocesses/code/isis.m
Normal file
@@ -0,0 +1,15 @@
|
||||
function isivec = isis( spikes )
|
||||
% returns a single list of isis computed from all trials in spikes
|
||||
% spikes: a cell array of vectors of spike times
|
||||
|
||||
isivec = [];
|
||||
for k = 1:length(spikes)
|
||||
difftimes = diff( spikes{k} );
|
||||
if ( size( difftimes, 1 ) == 1 )
|
||||
isivec = [ isivec difftimes ];
|
||||
elseif ( size( difftimes, 2 ) == 1 )
|
||||
isivec = [ isivec difftimes' ];
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
26
pointprocesses/code/isiserialcorr.m
Normal file
26
pointprocesses/code/isiserialcorr.m
Normal file
@@ -0,0 +1,26 @@
|
||||
function isicorr = isiserialcorr( isis, maxlag )
|
||||
% serial correlation of isis
|
||||
% isis: vector of interspike intervals
|
||||
% maxlag: the maximum lag
|
||||
|
||||
lags = 0:maxlag;
|
||||
isicorr = zeros( size( lags ) );
|
||||
for k = 1:length(lags)
|
||||
lag = lags(k);
|
||||
if length( isis ) > lag+10
|
||||
cc = corrcoef( [ isis(1:end-lag)', isis(1+lag:end)' ] );
|
||||
isicorr(k) = cc( 1, 2 );
|
||||
end
|
||||
end
|
||||
|
||||
if nargout == 0
|
||||
% plot:
|
||||
plot( lags, isicorr, '-b' );
|
||||
hold on;
|
||||
scatter( lags, isicorr, 100.0, 'b', 'filled' );
|
||||
hold off;
|
||||
xlabel( 'Lag k' )
|
||||
ylabel( '\rho_k')
|
||||
end
|
||||
end
|
||||
|
||||
53
pointprocesses/code/lifadaptspikes.m
Normal file
53
pointprocesses/code/lifadaptspikes.m
Normal file
@@ -0,0 +1,53 @@
|
||||
function spikes = lifadaptspikes( trials, input, tmaxdt, D, tauadapt, adaptincr )
|
||||
% Generate spike times of a leaky integrate-and-fire neuron
|
||||
% with an adaptation current
|
||||
% trials: the number of trials to be generated
|
||||
% input: the stimulus either as a single value or as a vector
|
||||
% tmaxdt: in case of a single value stimulus the duration of a trial
|
||||
% in case of a vector as a stimulus the time step
|
||||
% D: the strength of additive white noise
|
||||
% tauadapt: adaptation time constant
|
||||
% adaptincr: adaptation strength
|
||||
|
||||
tau = 0.01;
|
||||
if nargin < 4
|
||||
D = 1e0;
|
||||
end
|
||||
if nargin < 5
|
||||
tauadapt = 0.1;
|
||||
end
|
||||
if nargin < 6
|
||||
adaptincr = 1.0;
|
||||
end
|
||||
vreset = 0.0;
|
||||
vthresh = 10.0;
|
||||
dt = 1e-4;
|
||||
|
||||
if max( size( input ) ) == 1
|
||||
input = input * ones( ceil( tmaxdt/dt ), 1 );
|
||||
else
|
||||
dt = tmaxdt;
|
||||
end
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
times = [];
|
||||
j = 1;
|
||||
v = vreset;
|
||||
a = 0.0;
|
||||
noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
|
||||
for i=1:length( noise )
|
||||
v = v + ( - v - a + noise(i) + input(i))*dt/tau;
|
||||
a = a + ( - a )*dt/tauadapt;
|
||||
if v >= vthresh
|
||||
v = vreset;
|
||||
a = a + adaptincr/tauadapt;
|
||||
spiketime = i*dt;
|
||||
if spiketime > 4.0*tauadapt
|
||||
times(j) = spiketime - 4.0*tauadapt;
|
||||
j = j + 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
spikes{k} = times;
|
||||
end
|
||||
end
|
||||
51
pointprocesses/code/lifboltzmanspikes.m
Normal file
51
pointprocesses/code/lifboltzmanspikes.m
Normal file
@@ -0,0 +1,51 @@
|
||||
function spikes = lifboltzmanspikes( trials, input, tmaxdt, D, imax, ithresh, slope )
|
||||
% Generate spike times of a leaky integrate-and-fire neuron
|
||||
% trials: the number of trials to be generated
|
||||
% input: the stimulus either as a single value or as a vector
|
||||
% tmaxdt: in case of a single value stimulus the duration of a trial
|
||||
% in case of a vector as a stimulus the time step
|
||||
% D: the strength of additive white noise
|
||||
% imax: maximum output of boltzman
|
||||
% ithresh: threshold of boltzman input
|
||||
% slope: slope factor of boltzman input
|
||||
|
||||
tau = 0.01;
|
||||
if nargin < 4
|
||||
D = 1e0;
|
||||
end
|
||||
if nargin < 5
|
||||
imax = 20;
|
||||
end
|
||||
if nargin < 6
|
||||
ithresh = 10;
|
||||
end
|
||||
if nargin < 7
|
||||
slope = 1;
|
||||
end
|
||||
vreset = 0.0;
|
||||
vthresh = 10.0;
|
||||
dt = 1e-4;
|
||||
|
||||
if length( input ) == 1
|
||||
input = input * ones( ceil( tmaxdt/dt ), 1 );
|
||||
else
|
||||
dt = tmaxdt;
|
||||
end
|
||||
inb = imax./(1.0+exp(-slope.*(input - ithresh)));
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
times = [];
|
||||
j = 1;
|
||||
v = vreset;
|
||||
noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
|
||||
for i=1:length( noise )
|
||||
v = v + ( - v + noise(i) + inb(i))*dt/tau;
|
||||
if v >= vthresh
|
||||
v = vreset;
|
||||
times(j) = i*dt;
|
||||
j = j + 1;
|
||||
end
|
||||
end
|
||||
spikes{k} = times;
|
||||
end
|
||||
end
|
||||
23
pointprocesses/code/liffano.m
Normal file
23
pointprocesses/code/liffano.m
Normal file
@@ -0,0 +1,23 @@
|
||||
input = 65.0; % lifadapt 100Hz
|
||||
%input = 8.0; % lifadapt 10Hz
|
||||
%input = 15.7; % lif 100Hz
|
||||
%input = 8.3; % lif 10Hz
|
||||
trials = 10;
|
||||
tmax = 100.0;
|
||||
Dnoise = 0.1;
|
||||
Dounoise = 5e1;
|
||||
outau = 10.0;
|
||||
adapttau = 0.1;
|
||||
adaptincr = 5.0;
|
||||
|
||||
%spikes = lifouadaptspikes( trials, input, 1.0, Dnoise, Dounoise, outau, adapttau, adaptincr );
|
||||
%spikeraster( spikes );
|
||||
%return;
|
||||
|
||||
% generate spikes:
|
||||
%spikes = lifspikes( trials, input, tmax, noise );
|
||||
spikes = lifouspikes( trials, input, tmax, Dounoise, outau );
|
||||
%spikes = lifadaptspikes( trials, input, tmax, Dnoise, adapttau, adaptincr );
|
||||
%spikes = lifouadaptspikes( trials, input, tmax, Dnoise, Dounoise, outau, adapttau, adaptincr );
|
||||
|
||||
fano( spikes );
|
||||
36
pointprocesses/code/lifficurves.m
Normal file
36
pointprocesses/code/lifficurves.m
Normal file
@@ -0,0 +1,36 @@
|
||||
% lif:
|
||||
noises = [ 1e-5 1e-4 1e-3 1e-2 1e-1 ];
|
||||
inputs = 0:0.1:20;
|
||||
duration = 50.0;
|
||||
% pif:
|
||||
% noises = [ 1e-1 1 1e1 1e2 1e3 ];
|
||||
% inputs = -5:0.1:10;
|
||||
% duration = 100.0;
|
||||
|
||||
f = figure;
|
||||
hold all;
|
||||
for noise = noises
|
||||
fprintf( 'noise=%.0e\n', noise );
|
||||
rates = [];
|
||||
for input = inputs
|
||||
spikes = lifspikes( 10, input, duration, noise );
|
||||
% spikes = pifspikes( 50, input, duration, noise );
|
||||
nspikes = 0;
|
||||
for k = 1:length( spikes )
|
||||
nspikes = nspikes + length( spikes{k} );
|
||||
end
|
||||
rate = nspikes/duration/length( spikes );
|
||||
%fprintf( 'I=%g N=%d rate=%g\n', input, length( spikes ), rate )
|
||||
rates = [ rates rate ];
|
||||
end
|
||||
plot( inputs, rates, 'LineWidth', 2, 'DisplayName', sprintf( 'D=%.0e', noise ) );
|
||||
end
|
||||
xlabel( 'Input' );
|
||||
xlim( [ inputs(1) inputs(end) ] )
|
||||
ylabel( 'Firing rate [Hz]' );
|
||||
%title( 'Leaky integrate-and-fire' )
|
||||
title( 'Perfect integrate-and-fire' )
|
||||
legend( '-DynamicLegend', 'Location', 'NorthWest' )
|
||||
hold off
|
||||
|
||||
|
||||
65
pointprocesses/code/lifinputdiscriminationslope.m
Normal file
65
pointprocesses/code/lifinputdiscriminationslope.m
Normal file
@@ -0,0 +1,65 @@
|
||||
%input = 15.7; % lif 100Hz
|
||||
%input = 8.3; % lif 10Hz
|
||||
trials = 10;
|
||||
tmax = 50.0;
|
||||
Dnoise = 1.0;
|
||||
imax = 25.0;
|
||||
ithresh = 10.0;
|
||||
slope=0.2;
|
||||
|
||||
% inputs = 0:2:30;
|
||||
% rates = zeros( size( inputs ) );
|
||||
% for j = 1:length( inputs )
|
||||
% input = inputs(j);
|
||||
% spikes = lifboltzmanspikes( trials, input, tmax, Dnoise, imax, ithresh, slope );
|
||||
% nspikes = 0;
|
||||
% for k = 1:length( spikes )
|
||||
% nspikes = nspikes + length( spikes{k} );
|
||||
% end
|
||||
% rate = nspikes/tmax/length( spikes );
|
||||
% rates(j) = rate;
|
||||
% end
|
||||
% plot( inputs, rates );
|
||||
% grid on;
|
||||
% return
|
||||
|
||||
input = 10.0; % 80 Hz
|
||||
|
||||
window = 0.2;
|
||||
slopes = 0.1:0.1:2.0;
|
||||
pmax = zeros( size( slopes) );
|
||||
for j = 1:length( slopes )
|
||||
slope = slopes( j );
|
||||
spikes = lifboltzmanspikes( trials, input, tmax, Dnoise, imax, ithresh, slope );
|
||||
[ n1, bins1 ] = counthist( spikes, w );
|
||||
|
||||
spikes = lifboltzmanspikes( trials, input+1.0, tmax, Dnoise, imax, ithresh, slope );
|
||||
[ n2, bins2 ] = counthist( spikes, w );
|
||||
|
||||
subplot( 2, 1, 1 );
|
||||
bar( bins1, n1, 'b' );
|
||||
hold on;
|
||||
bar( bins2, n2, 'r' );
|
||||
hold off;
|
||||
|
||||
subplot( 2, 1, 2 );
|
||||
bmax = max( [ length( bins1 ), length( bins2 ) ] );
|
||||
decision1 = zeros( bmax, 1 );
|
||||
decision2 = zeros( bmax, 1 );
|
||||
cs1 = ones( bmax, 1 );
|
||||
cs1(1:length(n1)) = cumsum( n1 );
|
||||
cs2 = ones( bmax, 1 );
|
||||
cs2(1:length(n2)) = cumsum( n2 );
|
||||
cbins = 0:1:bmax-1;
|
||||
plot( cbins, cs1, 'b' );
|
||||
hold on;
|
||||
plot( cbins, cs2, 'r' );
|
||||
plot( cbins, cs1-cs2, 'g' );
|
||||
hold off;
|
||||
pause( 0.1 );
|
||||
pmax(j) = max( cs1-cs2 );
|
||||
end
|
||||
|
||||
clf;
|
||||
subplot( 1, 1, 1 );
|
||||
plot( slopes, pmax );
|
||||
51
pointprocesses/code/lifinputdiscriminationtime.m
Normal file
51
pointprocesses/code/lifinputdiscriminationtime.m
Normal file
@@ -0,0 +1,51 @@
|
||||
input = 65.0; % lifadapt 100Hz
|
||||
%input = 8.0; % lifadapt 10Hz
|
||||
%input = 15.7; % lif 100Hz
|
||||
%input = 8.3; % lif 10Hz
|
||||
trials = 10;
|
||||
tmax = 50.0;
|
||||
Dnoise = 0.1;
|
||||
Dounoise = 5e1;
|
||||
outau = 10.0;
|
||||
adapttau = 0.2;
|
||||
adaptincr = 0.5;
|
||||
|
||||
windows = 0.05:0.05:1.0;
|
||||
pmax = zeros( size( windows ) );
|
||||
for j = 1:length( windows )
|
||||
w = windows( j );
|
||||
spikes = lifadaptspikes( trials, input, tmax, Dnoise, adapttau, adaptincr );
|
||||
%spikes = lifouspikes( trials, input, tmax, Dounoise, outau);
|
||||
[ n1, bins1 ] = counthist( spikes, w );
|
||||
|
||||
spikes = lifadaptspikes( trials, input+10.0, tmax, Dnoise, adapttau, adaptincr );
|
||||
%spikes = lifouspikes( trials, input+10.0, tmax, Dounoise, outau );
|
||||
[ n2, bins2 ] = counthist( spikes, w );
|
||||
|
||||
subplot( 2, 1, 1 );
|
||||
bar( bins1, n1, 'b' );
|
||||
hold on;
|
||||
bar( bins2, n2, 'r' );
|
||||
hold off;
|
||||
|
||||
subplot( 2, 1, 2 );
|
||||
bmax = max( [ length( bins1 ), length( bins2 ) ] );
|
||||
decision1 = zeros( bmax, 1 );
|
||||
decision2 = zeros( bmax, 1 );
|
||||
cs1 = ones( bmax, 1 );
|
||||
cs1(1:length(n1)) = cumsum( n1 );
|
||||
cs2 = ones( bmax, 1 );
|
||||
cs2(1:length(n2)) = cumsum( n2 );
|
||||
cbins = 0:1:bmax-1;
|
||||
plot( cbins, cs1, 'b' );
|
||||
hold on;
|
||||
plot( cbins, cs2, 'r' );
|
||||
plot( cbins, cs1-cs2, 'g' );
|
||||
hold off;
|
||||
pause( 0.1 );
|
||||
pmax(j) = max( cs1-cs2 );
|
||||
end
|
||||
|
||||
clf;
|
||||
subplot( 1, 1, 1 );
|
||||
plot( windows, pmax );
|
||||
35
pointprocesses/code/lifisih.m
Normal file
35
pointprocesses/code/lifisih.m
Normal file
@@ -0,0 +1,35 @@
|
||||
%input = 65.0; % lifadapt 100Hz
|
||||
%input = 8.0; % lifadapt 10Hz
|
||||
input = 15.7; % lif 100Hz
|
||||
%input = 8.3; % lif 10Hz
|
||||
trials = 10;
|
||||
tmax = 100.0;
|
||||
noise = 1e-1;
|
||||
adapttau = 0.1;
|
||||
adaptincr = 5.0;
|
||||
|
||||
% generate spikes:
|
||||
spikes = lifspikes( trials, input, tmax, noise );
|
||||
%spikes = lifadaptspikes( trials, input, tmax, noise, adapttau, adaptincr );
|
||||
|
||||
% interspike intervals:
|
||||
isivec = isis( spikes );
|
||||
% histogram
|
||||
f = figure( 1 );
|
||||
isihist( isivec, 10e-4 );
|
||||
hold on
|
||||
% theoretical density:
|
||||
misi = mean( isivec );
|
||||
disi = var( isivec )/2.0/misi^3;
|
||||
xmax = 3.0*misi;
|
||||
x = 0:0.0001:xmax;
|
||||
plot( 1000.0*x, inversegauss( x, misi, disi ), 'r', 'LineWidth', 3 );
|
||||
% plot details:
|
||||
title( sprintf( 'LIF, input=%g, nisi=%d', input, length( isivec ) ) )
|
||||
xlim( [ 0.0 1000.0*xmax ] )
|
||||
legend( 'data', 'inverse Gaussian' )
|
||||
hold off
|
||||
|
||||
% serial correlations:
|
||||
f = figure( 2 );
|
||||
isiserialcorr( isivec, 10 );
|
||||
63
pointprocesses/code/lifisistats.m
Normal file
63
pointprocesses/code/lifisistats.m
Normal file
@@ -0,0 +1,63 @@
|
||||
inputs = 0:0.1:20; % lif
|
||||
inputs = 0:0.1:10; % pif
|
||||
avisi = [];
|
||||
sdisi = [];
|
||||
cvisi = [];
|
||||
dcisi = [];
|
||||
|
||||
for input = inputs
|
||||
input
|
||||
% spikes = lifspikes( 100, input, 100.0, 1e-2 );
|
||||
spikes = pifspikes( 100, input, 100.0, 1e-1 );
|
||||
isivec = isis( spikes );
|
||||
if length( isivec ) <= 1
|
||||
av = Inf;
|
||||
sd = NaN;
|
||||
cv = NaN;
|
||||
dc = NaN;
|
||||
else
|
||||
av = mean( isivec );
|
||||
sd = std( isivec );
|
||||
if av > 0.0
|
||||
cv = sd/av;
|
||||
dc = sd^2.0/2.0/av^3;
|
||||
else
|
||||
cv = NaN;
|
||||
dc = NaN;
|
||||
end
|
||||
end
|
||||
avisi = [ avisi av ];
|
||||
sdisi = [ sdisi sd ];
|
||||
cvisi = [ cvisi cv ];
|
||||
dcisi = [ dcisi dc ];
|
||||
end
|
||||
|
||||
f = figure;
|
||||
subplot( 2, 2, 1 );
|
||||
plot( inputs, 1.0./avisi, '-b', 'LineWidth', 3 );
|
||||
xlabel( 'Input' );
|
||||
xlim( [ inputs(1) inputs(end) ] )
|
||||
title( 'Mean rate [Hz]' );
|
||||
|
||||
subplot( 2, 2, 2 );
|
||||
plot( inputs, 1000.0*avisi, '-b', 'LineWidth', 3 );
|
||||
hold on;
|
||||
plot( inputs, 1000.0*sdisi, '-c', 'LineWidth', 3 );
|
||||
hold off;
|
||||
xlabel( 'Input' );
|
||||
xlim( [ inputs(1) inputs(end) ] )
|
||||
ylim( [ 0 1000 ] )
|
||||
title( 'ISI [ms]' );
|
||||
legend( 's.d. ISI', 'mean ISI' );
|
||||
|
||||
subplot( 2, 2, 3 );
|
||||
plot( inputs, cvisi, '-b', 'LineWidth', 3 );
|
||||
xlabel( 'Input' );
|
||||
xlim( [ inputs(1) inputs(end) ] )
|
||||
title( 'CV' );
|
||||
|
||||
subplot( 2, 2, 4 );
|
||||
plot( inputs, dcisi, '-b', 'LineWidth', 3 );
|
||||
xlabel( 'Input' );
|
||||
xlim( [ inputs(1) inputs(end) ] )
|
||||
title( 'D [Hz]' );
|
||||
64
pointprocesses/code/lifouadaptspikes.m
Normal file
64
pointprocesses/code/lifouadaptspikes.m
Normal file
@@ -0,0 +1,64 @@
|
||||
function spikes = lifouadaptspikes( trials, input, tmaxdt, D, Dou, outau, tauadapt, adaptincr )
|
||||
% Generate spike times of a leaky integrate-and-fire neuron
|
||||
% with colored noise and an adaptation current
|
||||
% trials: the number of trials to be generated
|
||||
% input: the stimulus either as a single value or as a vector
|
||||
% tmaxdt: in case of a single value stimulus the duration of a trial
|
||||
% in case of a vector as a stimulus the time step
|
||||
% D: the strength of additive noise
|
||||
% Dou: the strength of additive colored noise
|
||||
% outau: time constant of the colored noise
|
||||
% tauadapt: adaptation time constant
|
||||
% adaptincr: adaptation strength
|
||||
|
||||
tau = 0.01;
|
||||
if nargin < 4
|
||||
D = 1e0;
|
||||
end
|
||||
if nargin < 5
|
||||
Dou = 1e0;
|
||||
end
|
||||
if nargin < 6
|
||||
outau = 1.0;
|
||||
end
|
||||
if nargin < 7
|
||||
tauadapt = 0.1;
|
||||
end
|
||||
if nargin < 8
|
||||
adaptincr = 1.0;
|
||||
end
|
||||
vreset = 0.0;
|
||||
vthresh = 10.0;
|
||||
dt = 1e-4;
|
||||
|
||||
if max( size( input ) ) == 1
|
||||
input = input * ones( ceil( tmaxdt/dt ), 1 );
|
||||
else
|
||||
dt = tmaxdt;
|
||||
end
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
times = [];
|
||||
j = 1;
|
||||
v = vreset;
|
||||
n = 0.0;
|
||||
a = 0.0;
|
||||
noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
|
||||
noiseou = sqrt(2.0*Dou)*randn( length( input ), 1 )/sqrt(dt);
|
||||
for i=1:length( noise )
|
||||
n = n + ( - n + noiseou(i))*dt/outau;
|
||||
v = v + ( - v - a + noise(i) + n + input(i))*dt/tau;
|
||||
a = a + ( - a )*dt/tauadapt;
|
||||
if v >= vthresh
|
||||
v = vreset;
|
||||
a = a + adaptincr;
|
||||
spiketime = i*dt;
|
||||
if spiketime > 4.0*tauadapt
|
||||
times(j) = spiketime - 4.0*tauadapt;
|
||||
j = j + 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
spikes{k} = times;
|
||||
end
|
||||
end
|
||||
44
pointprocesses/code/lifouspikes.m
Normal file
44
pointprocesses/code/lifouspikes.m
Normal file
@@ -0,0 +1,44 @@
|
||||
function spikes = lifouspikes( trials, input, tmaxdt, D, outau )
|
||||
% Generate spike times of a leaky integrate-and-fire neuron
|
||||
% trials: the number of trials to be generated
|
||||
% input: the stimulus either as a single value or as a vector
|
||||
% tmaxdt: in case of a single value stimulus the duration of a trial
|
||||
% in case of a vector as a stimulus the time step
|
||||
% D: the strength of additive white noise
|
||||
% outau: time constant of the colored noise
|
||||
|
||||
tau = 0.01;
|
||||
if nargin < 4
|
||||
D = 1e0;
|
||||
end
|
||||
if nargin < 5
|
||||
outau = 1.0;
|
||||
end
|
||||
vreset = 0.0;
|
||||
vthresh = 10.0;
|
||||
dt = 1e-4;
|
||||
|
||||
if length( input ) == 1
|
||||
input = input * ones( ceil( tmaxdt/dt ), 1 );
|
||||
else
|
||||
dt = tmaxdt;
|
||||
end
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
times = [];
|
||||
j = 1;
|
||||
n = 0.0;
|
||||
v = vreset;
|
||||
noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
|
||||
for i=1:length( noise )
|
||||
n = n + ( - n + noise(i))*dt/outau;
|
||||
v = v + ( - v + n + input(i))*dt/tau;
|
||||
if v >= vthresh
|
||||
v = vreset;
|
||||
times(j) = i*dt;
|
||||
j = j + 1;
|
||||
end
|
||||
end
|
||||
spikes{k} = times;
|
||||
end
|
||||
end
|
||||
34
pointprocesses/code/lifrateisicorr.m
Normal file
34
pointprocesses/code/lifrateisicorr.m
Normal file
@@ -0,0 +1,34 @@
|
||||
% relation between firing rate and serieller correlation
|
||||
|
||||
input = 65.0; % lifadapt 100Hz
|
||||
%input = 8.0; % lifadapt 10Hz
|
||||
trials = 10;
|
||||
tmax = 50.0;
|
||||
noise = 1e-5;
|
||||
adapttau = 0.1;
|
||||
adaptincr = 0.5;
|
||||
|
||||
clf;
|
||||
for adapttau = 0.01:0.02:0.2
|
||||
inputs = 1:5:120;
|
||||
iscs = zeros( size( inputs ) );
|
||||
rates = zeros( size( inputs ) );
|
||||
for k = 1:length(inputs)
|
||||
input = inputs(k);
|
||||
% generate spikes:
|
||||
spikes = lifadaptspikes( trials, input, tmax, noise, adapttau, adaptincr );
|
||||
isivec = isis( spikes );
|
||||
isc = isiserialcorr( isivec, 10 );
|
||||
iscs(k) = isc(2);
|
||||
rates(k) = 1.0/mean( isivec );
|
||||
end
|
||||
|
||||
subplot( 2, 1, 1 );
|
||||
hold on;
|
||||
plot( inputs, rates );
|
||||
hold off;
|
||||
subplot( 2, 1, 2 );
|
||||
hold on;
|
||||
plot( rates, iscs );
|
||||
hold off;
|
||||
end
|
||||
38
pointprocesses/code/lifspikes.m
Normal file
38
pointprocesses/code/lifspikes.m
Normal file
@@ -0,0 +1,38 @@
|
||||
function spikes = lifspikes( trials, input, tmaxdt, D )
|
||||
% Generate spike times of a leaky integrate-and-fire neuron
|
||||
% trials: the number of trials to be generated
|
||||
% input: the stimulus either as a single value or as a vector
|
||||
% tmaxdt: in case of a single value stimulus the duration of a trial
|
||||
% in case of a vector as a stimulus the time step
|
||||
% D: the strength of additive white noise
|
||||
|
||||
tau = 0.01;
|
||||
if nargin < 4
|
||||
D = 1e0;
|
||||
end
|
||||
vreset = 0.0;
|
||||
vthresh = 10.0;
|
||||
dt = 1e-4;
|
||||
|
||||
if length( input ) == 1
|
||||
input = input * ones( ceil( tmaxdt/dt ), 1 );
|
||||
else
|
||||
dt = tmaxdt;
|
||||
end
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
times = [];
|
||||
j = 1;
|
||||
v = vreset;
|
||||
noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
|
||||
for i=1:length( noise )
|
||||
v = v + ( - v + noise(i) + input(i))*dt/tau;
|
||||
if v >= vthresh
|
||||
v = vreset;
|
||||
times(j) = i*dt;
|
||||
j = j + 1;
|
||||
end
|
||||
end
|
||||
spikes{k} = times;
|
||||
end
|
||||
end
|
||||
44
pointprocesses/code/pifouspikes.m
Normal file
44
pointprocesses/code/pifouspikes.m
Normal file
@@ -0,0 +1,44 @@
|
||||
function spikes = pifouspikes( trials, input, tmaxdt, D, outau )
|
||||
% Generate spike times of a perfect integrate-and-fire neuron
|
||||
% trials: the number of trials to be generated
|
||||
% input: the stimulus either as a single value or as a vector
|
||||
% tmaxdt: in case of a single value stimulus the duration of a trial
|
||||
% in case of a vector as a stimulus the time step
|
||||
% D: the strength of additive white noise
|
||||
% outau: time constant of the colored noise
|
||||
|
||||
tau = 0.01;
|
||||
if nargin < 4
|
||||
D = 1e0;
|
||||
end
|
||||
if nargin < 5
|
||||
outau = 1.0;
|
||||
end
|
||||
vreset = 0.0;
|
||||
vthresh = 10.0;
|
||||
dt = 1e-4;
|
||||
|
||||
if length( input ) == 1
|
||||
input = input * ones( ceil( tmaxdt/dt ), 1 );
|
||||
else
|
||||
dt = tmaxdt;
|
||||
end
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
times = [];
|
||||
j = 1;
|
||||
n = 0.0;
|
||||
v = vreset;
|
||||
noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
|
||||
for i=1:length( noise )
|
||||
n = n + ( - n + noise(i))*dt/outau;
|
||||
v = v + ( n + input(i))*dt/tau;
|
||||
if v >= vthresh
|
||||
v = vreset;
|
||||
times(j) = i*dt;
|
||||
j = j + 1;
|
||||
end
|
||||
end
|
||||
spikes{k} = times;
|
||||
end
|
||||
end
|
||||
38
pointprocesses/code/pifspikes.m
Normal file
38
pointprocesses/code/pifspikes.m
Normal file
@@ -0,0 +1,38 @@
|
||||
function spikes = pifspikes( trials, input, tmaxdt, D )
|
||||
% Generate spike times of a perfect integrate-and-fire neuron
|
||||
% trials: the number of trials to be generated
|
||||
% input: the stimulus either as a single value or as a vector
|
||||
% tmaxdt: in case of a single value stimulus the duration of a trial
|
||||
% in case of a vector as a stimulus the time step
|
||||
% D: the strength of additive white noise
|
||||
|
||||
tau = 0.01;
|
||||
if nargin < 4
|
||||
D = 1e-1;
|
||||
end
|
||||
vreset = 0.0;
|
||||
vthresh = 10.0;
|
||||
dt = 1e-4;
|
||||
|
||||
if length( input ) == 1
|
||||
input = input * ones( ceil( tmaxdt/dt ), 1 );
|
||||
else
|
||||
dt = tmaxdt;
|
||||
end
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
times = [];
|
||||
j = 1;
|
||||
v = vreset;
|
||||
noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
|
||||
for i=1:length( noise )
|
||||
v = v + ( noise(i) + input(i))*dt/tau;
|
||||
if v >= vthresh
|
||||
v = vreset;
|
||||
times(j) = i*dt;
|
||||
j = j + 1;
|
||||
end
|
||||
end
|
||||
spikes{k} = times;
|
||||
end
|
||||
end
|
||||
27
pointprocesses/code/poissonisih.m
Normal file
27
pointprocesses/code/poissonisih.m
Normal file
@@ -0,0 +1,27 @@
|
||||
rate = 100.0;
|
||||
trials = 50;
|
||||
tmax = 100.0;
|
||||
|
||||
% generate spikes:
|
||||
spikes = poissonspikes( trials, rate, tmax );
|
||||
% interspike intervals:
|
||||
isivec = isis( spikes );
|
||||
% histogram
|
||||
f = figure( 1 );
|
||||
isihist( isivec );
|
||||
hold on
|
||||
% theoretical density:
|
||||
xmax = 5.0/rate;
|
||||
x = 0:0.0001:xmax;
|
||||
y = rate*exp(-rate*x);
|
||||
plot( 1000.0*x, y, 'r', 'LineWidth', 3 );
|
||||
% plot details:
|
||||
title( sprintf( 'Poisson spike trains, rate=%g Hz, nisi=%d', rate, length( isivec ) ) )
|
||||
xlim( [ 0.0 1000.0*xmax ] )
|
||||
ylim( [ 0.0 1.1*rate ] )
|
||||
legend( 'data', 'poisson' )
|
||||
hold off
|
||||
|
||||
% serial correlations:
|
||||
f = figure( 2 );
|
||||
isiserialcorr( isivec, 10 );
|
||||
46
pointprocesses/code/poissonisistats.m
Normal file
46
pointprocesses/code/poissonisistats.m
Normal file
@@ -0,0 +1,46 @@
|
||||
rates = 1:1:100;
|
||||
avisi = [];
|
||||
sdisi = [];
|
||||
cvisi = [];
|
||||
|
||||
for rate = rates
|
||||
spikes = poissonspikes( 10, rate, 100.0 );
|
||||
isivec = isis( spikes );
|
||||
av = mean( isivec );
|
||||
sd = std( isivec );
|
||||
cv = sd/av;
|
||||
avisi = [ avisi av ];
|
||||
sdisi = [ sdisi sd ];
|
||||
cvisi = [ cvisi cv ];
|
||||
end
|
||||
|
||||
f = figure;
|
||||
subplot( 1, 3, 1 );
|
||||
scatter( rates, 1000.0*avisi, 'b', 'filled' );
|
||||
hold on;
|
||||
plot( rates, 1000.0./rates, 'r' );
|
||||
hold off;
|
||||
xlabel( 'Rate \lambda [Hz]' );
|
||||
ylim( [ 0 1000 ] );
|
||||
title( 'Mean ISI [ms]' );
|
||||
legend( 'simulation', 'theory 1/\lambda' );
|
||||
|
||||
subplot( 1, 3, 2 );
|
||||
scatter( rates, 1000.0*sdisi, 'b', 'filled' );
|
||||
hold on;
|
||||
plot( rates, 1000.0./rates, 'r' );
|
||||
hold off;
|
||||
xlabel( 'Rate \lambda [Hz]' );
|
||||
ylim( [ 0 1000 ] )
|
||||
title( 'Standard deviation ISI [ms]' );
|
||||
legend( 'simulation', 'theory 1/\lambda' );
|
||||
|
||||
subplot( 1, 3, 3 );
|
||||
scatter( rates, cvisi, 'b', 'filled' );
|
||||
hold on;
|
||||
plot( rates, ones( size( rates ) ), 'r' );
|
||||
hold off;
|
||||
xlabel( 'Rate \lambda [Hz]' );
|
||||
ylim( [ 0 2 ] )
|
||||
title( 'CV' );
|
||||
legend( 'simulation', 'theory' );
|
||||
20
pointprocesses/code/poissonspikes.m
Normal file
20
pointprocesses/code/poissonspikes.m
Normal file
@@ -0,0 +1,20 @@
|
||||
function spikes = poissonspikes( trials, rate, tmax )
|
||||
% Generate spike times of a homogeneous poisson process
|
||||
% trials: number of trials that should be generated
|
||||
% rate: the rate of the Poisson process in Hertz
|
||||
% tmax: the duration of each trial in seconds
|
||||
% returns a cell array of vectors of spike times
|
||||
|
||||
dt = 3.33e-5;
|
||||
p = rate*dt; % probability of event per bin of width dt
|
||||
% make sure p is small enough:
|
||||
if p > 0.1
|
||||
p = 0.1
|
||||
dt = p/rate;
|
||||
end
|
||||
spikes = cell( trials, 1 );
|
||||
for k=1:trials
|
||||
x = rand( 1, round(tmax/dt) ); % uniform random numbers for each bin
|
||||
spikes{k} = find( x < p ) * dt;
|
||||
end
|
||||
end
|
||||
BIN
pointprocesses/code/raster.pdf
Normal file
BIN
pointprocesses/code/raster.pdf
Normal file
Binary file not shown.
28
pointprocesses/code/savefigpdf.m
Normal file
28
pointprocesses/code/savefigpdf.m
Normal file
@@ -0,0 +1,28 @@
|
||||
function savefigpdf( fig, name, width, height )
|
||||
% Saves figure fig in pdf file name.pdf with appropriately set page size
|
||||
% and fonts
|
||||
|
||||
% default width:
|
||||
if nargin < 3
|
||||
width = 11.7;
|
||||
end
|
||||
% default height:
|
||||
if nargin < 4
|
||||
height = 9.0;
|
||||
end
|
||||
|
||||
% paper:
|
||||
set( fig, 'PaperUnits', 'centimeters' );
|
||||
set( fig, 'PaperSize', [width height] );
|
||||
set( fig, 'PaperPosition', [0.0 0.0 width height] );
|
||||
set( fig, 'Color', 'white')
|
||||
|
||||
% font:
|
||||
set( findall( fig, 'type', 'axes' ), 'FontSize', 12 )
|
||||
set( findall( fig, 'type', 'text' ), 'FontSize', 12 )
|
||||
|
||||
% save:
|
||||
saveas( fig, name, 'pdf' )
|
||||
|
||||
end
|
||||
|
||||
17
pointprocesses/code/spikeraster.m
Normal file
17
pointprocesses/code/spikeraster.m
Normal file
@@ -0,0 +1,17 @@
|
||||
function spikeraster( spikes )
|
||||
% Display a spike raster of the spike times given in spikes.
|
||||
% spikes: a cell array of vectors of spike times
|
||||
|
||||
ntrials = length(spikes);
|
||||
for k = 1:ntrials
|
||||
times = 1000.0*spikes{k}; % conversion to ms
|
||||
for i = 1:length( times )
|
||||
line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k' );
|
||||
end
|
||||
end
|
||||
xlabel( 'Time [ms]' );
|
||||
ylabel( 'Trials');
|
||||
ylim( [ 0.3 ntrials+0.7 ] )
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user