[pointprocesses] python version of sketch

This commit is contained in:
Jan Benda 2021-01-10 20:37:40 +01:00
parent e5fd1ecb32
commit ea8add517c
7 changed files with 179 additions and 219 deletions

View File

@ -37,6 +37,7 @@ edgewidth = 0.0 if xkcd_style else 1.0
mainline = {'linestyle': '-', 'linewidth': lwthick} mainline = {'linestyle': '-', 'linewidth': lwthick}
minorline = {'linestyle': '-', 'linewidth': lwthin} minorline = {'linestyle': '-', 'linewidth': lwthin}
largemarker = {'marker': 'o', 'markersize': 9, 'markeredgecolor': colors['white'], 'markeredgewidth': edgewidth} largemarker = {'marker': 'o', 'markersize': 9, 'markeredgecolor': colors['white'], 'markeredgewidth': edgewidth}
largeopenmarker = {'marker': 'o', 'markersize': 7, 'markerfacecolor': colors['white'], 'markeredgewidth': 2}
smallmarker = {'marker': 'o', 'markersize': 6, 'markeredgecolor': colors['white'], 'markeredgewidth': edgewidth} smallmarker = {'marker': 'o', 'markersize': 6, 'markeredgecolor': colors['white'], 'markeredgewidth': edgewidth}
largelinepoints = {'linestyle': '-', 'linewidth': lwthick, 'marker': 'o', 'markersize': 10, 'markeredgecolor': colors['white'], 'markeredgewidth': 1} largelinepoints = {'linestyle': '-', 'linewidth': lwthick, 'marker': 'o', 'markersize': 10, 'markeredgecolor': colors['white'], 'markeredgewidth': 1}
smalllinepoints = {'linestyle': '-', 'linewidth': 1.4, 'marker': 'o', 'markersize': 7, 'markeredgecolor': colors['white'], 'markeredgewidth': 1} smalllinepoints = {'linestyle': '-', 'linewidth': 1.4, 'marker': 'o', 'markersize': 7, 'markeredgecolor': colors['white'], 'markeredgewidth': 1}
@ -88,6 +89,7 @@ fsAa = {'facecolor': colors['blue'], 'edgecolor': 'none', 'alpha': fillalpha}
lsB = dict({'color': colors['red']}, **mainline) lsB = dict({'color': colors['red']}, **mainline)
lsBm = dict({'color': colors['red']}, **minorline) lsBm = dict({'color': colors['red']}, **minorline)
psB = dict({'color': colors['red'], 'linestyle': 'none'}, **largemarker) psB = dict({'color': colors['red'], 'linestyle': 'none'}, **largemarker)
psBo = dict({'markeredgecolor': colors['red'], 'linestyle': 'none'}, **largeopenmarker)
psBm = dict({'color': colors['red'], 'linestyle': 'none'}, **smallmarker) psBm = dict({'color': colors['red'], 'linestyle': 'none'}, **smallmarker)
lpsB = dict({'color': colors['red']}, **largelinepoints) lpsB = dict({'color': colors['red']}, **largelinepoints)
lpsBm = dict({'color': colors['red']}, **smalllinepoints) lpsBm = dict({'color': colors['red']}, **smalllinepoints)

View File

@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
from plotstyle import * from plotstyle import *
def get_instantaneous_rate(times, max_t=30., dt=1e-4): def instantaneous_rate(times, max_t=30., dt=1e-4):
time = np.arange(0., max_t, dt) time = np.arange(0., max_t, dt)
indices = np.asarray(times / dt, dtype=int) indices = np.asarray(times / dt, dtype=int)
intervals = np.diff(np.hstack(([0], times))) intervals = np.diff(np.hstack(([0], times)))
@ -19,12 +19,12 @@ def get_instantaneous_rate(times, max_t=30., dt=1e-4):
def plot_isi_rate(spike_times, max_t=30, dt=1e-4): def plot_isi_rate(spike_times, max_t=30, dt=1e-4):
times = np.squeeze(spike_times[0][0])[:50000] times = np.squeeze(spike_times[0][0])[:50000]
time, rate = get_instantaneous_rate(times, max_t=50000*dt) time, rate = instantaneous_rate(times, max_t=50000*dt)
rates = np.zeros((len(rate), len(spike_times))) rates = np.zeros((len(rate), len(spike_times)))
for i in range(len(spike_times)): for i in range(len(spike_times)):
_, rates[:, i] = get_instantaneous_rate(np.squeeze(spike_times[i][0])[:50000], _, rates[:, i] = instantaneous_rate(np.squeeze(spike_times[i][0])[:50000],
max_t=50000*dt) max_t=50000*dt)
avg_rate = np.mean(rates, axis=1) avg_rate = np.mean(rates, axis=1)
rate_std = np.std(rates, axis=1) rate_std = np.std(rates, axis=1)
@ -48,7 +48,7 @@ def plot_isi_rate(spike_times, max_t=30, dt=1e-4):
plt.close() plt.close()
def get_binned_rate(times, bin_width=0.05, max_t=30., dt=1e-4): def binned_rate(times, bin_width=0.05, max_t=30., dt=1e-4):
time = np.arange(0., max_t, dt) time = np.arange(0., max_t, dt)
bins = np.arange(0., max_t, bin_width) bins = np.arange(0., max_t, bin_width)
bin_indices = np.asarray(bins / dt, np.int) bin_indices = np.asarray(bins / dt, np.int)
@ -62,10 +62,10 @@ def get_binned_rate(times, bin_width=0.05, max_t=30., dt=1e-4):
def plot_bin_rate(spike_times, bin_width, max_t=30, dt=1e-4): def plot_bin_rate(spike_times, bin_width, max_t=30, dt=1e-4):
times = np.squeeze(spike_times[0][0]) times = np.squeeze(spike_times[0][0])
time, rate = get_binned_rate(times) time, rate = binned_rate(times)
rates = np.zeros((len(rate), len(spike_times))) rates = np.zeros((len(rate), len(spike_times)))
for i in range(len(spike_times)): for i in range(len(spike_times)):
_, rates[:, i] = get_binned_rate(np.squeeze(spike_times[i][0])) _, rates[:, i] = binned_rate(np.squeeze(spike_times[i][0]))
avg_rate = np.mean(rates, axis=1) avg_rate = np.mean(rates, axis=1)
rate_std = np.std(rates, axis=1) rate_std = np.std(rates, axis=1)
@ -93,7 +93,7 @@ def plot_bin_rate(spike_times, bin_width, max_t=30, dt=1e-4):
plt.close() plt.close()
def get_convolved_rate(times, sigma, max_t=30., dt=1.e-4): def convolved_rate(times, sigma, max_t=30., dt=1.e-4):
time = np.arange(0., max_t, dt) time = np.arange(0., max_t, dt)
kernel = spst.norm.pdf(np.arange(-8*sigma, 8*sigma, dt),loc=0,scale=sigma) kernel = spst.norm.pdf(np.arange(-8*sigma, 8*sigma, dt),loc=0,scale=sigma)
indices = np.asarray(times/dt, dtype=int) indices = np.asarray(times/dt, dtype=int)
@ -105,11 +105,11 @@ def get_convolved_rate(times, sigma, max_t=30., dt=1.e-4):
def plot_conv_rate(spike_times, sigma=0.05, max_t=30, dt=1e-4): def plot_conv_rate(spike_times, sigma=0.05, max_t=30, dt=1e-4):
times = np.squeeze(spike_times[0][0]) times = np.squeeze(spike_times[0][0])
time, rate = get_convolved_rate(times, sigma) time, rate = convolved_rate(times, sigma)
rates = np.zeros((len(rate), len(spike_times))) rates = np.zeros((len(rate), len(spike_times)))
for i in range(len(spike_times)): for i in range(len(spike_times)):
_, rates[:, i] = get_convolved_rate(np.squeeze(spike_times[i][0]), sigma) _, rates[:, i] = convolved_rate(np.squeeze(spike_times[i][0]), sigma)
avg_rate = np.mean(rates, axis=1) avg_rate = np.mean(rates, axis=1)
rate_std = np.std(rates, axis=1) rate_std = np.std(rates, axis=1)
@ -139,9 +139,9 @@ def plot_conv_rate(spike_times, sigma=0.05, max_t=30, dt=1e-4):
def plot_comparison(spike_times, bin_width, sigma, max_t=30., dt=1e-4): def plot_comparison(spike_times, bin_width, sigma, max_t=30., dt=1e-4):
times = np.squeeze(spike_times[0][0]) times = np.squeeze(spike_times[0][0])
time, conv_rate = get_convolved_rate(times, bin_width/np.sqrt(12.)) time, conv_rate = convolved_rate(times, bin_width/np.sqrt(12.))
time, inst_rate = get_instantaneous_rate(times) time, inst_rate = instantaneous_rate(times)
time, binn_rate = get_binned_rate(times, bin_width) time, binn_rate = binned_rate(times, bin_width)
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, figsize=cm_size(figure_width, 1.8*figure_height)) fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, figsize=cm_size(figure_width, 1.8*figure_height))
fig.subplots_adjust(**adjust_fs(fig, left=6.0, right=1.5, bottom=3.0, top=1.0)) fig.subplots_adjust(**adjust_fs(fig, left=6.0, right=1.5, bottom=3.0, top=1.0))

View File

@ -2,6 +2,15 @@ import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from plotstyle import * from plotstyle import *
rate = 20.0
trials = 10
duration = 100.0
dt = 0.001
drate = 50.0
tau = 0.1;
def hompoisson(rate, trials, duration) : def hompoisson(rate, trials, duration) :
spikes = [] spikes = []
for k in range(trials) : for k in range(trials) :
@ -13,6 +22,7 @@ def hompoisson(rate, trials, duration) :
spikes.append( times ) spikes.append( times )
return spikes return spikes
def inhompoisson(rate, trials, dt) : def inhompoisson(rate, trials, dt) :
spikes = [] spikes = []
p = rate*dt p = rate*dt
@ -40,12 +50,27 @@ def pifspikes(input, trials, dt, D=0.1) :
spikes.append( times ) spikes.append( times )
return spikes return spikes
def oupifspikes(rate, trials, duration, dt, D, drate, tau):
# OU noise:
rng = np.random.RandomState(54637281)
time = np.arange(0.0, duration, dt)
x = np.zeros(time.shape)+rate
n = rng.randn(len(time))*drate*tau/np.sqrt(dt) + rate
for k in range(1,len(x)) :
x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau
x[x<0.0] = 0.0
spikes = pifspikes(x, trials, dt, D)
return spikes
def isis( spikes ) : def isis( spikes ) :
isi = [] isi = []
for k in range(len(spikes)) : for k in range(len(spikes)) :
isi.extend(np.diff(spikes[k])) isi.extend(np.diff(spikes[k]))
return isi return isi
def plotisih( ax, isis, binwidth=None ) : def plotisih( ax, isis, binwidth=None ) :
if binwidth == None : if binwidth == None :
nperbin = 200.0 # average number of isis per bin nperbin = 200.0 # average number of isis per bin
@ -61,42 +86,29 @@ def plotisih( ax, isis, binwidth=None ) :
ax.set_ylabel('p(ISI)', '1/s') ax.set_ylabel('p(ISI)', '1/s')
ax.bar( 1000.0*b[:-1], h, bar_fac*1000.0*np.diff(b), **fsA) ax.bar( 1000.0*b[:-1], h, bar_fac*1000.0*np.diff(b), **fsA)
# parameter:
rate = 20.0 def plot_hom_isih(ax):
drate = 50.0 homspikes = hompoisson(rate, trials, duration)
trials = 10 ax.set_xlim(0.0, 150.0)
duration = 100.0 ax.set_ylim(0.0, 31.0)
dt = 0.001 ax.set_xticks(np.arange(0.0, 151.0, 50.0))
tau = 0.1; ax.set_yticks(np.arange(0.0, 31.0, 10.0))
plotisih(ax, isis(homspikes), 0.005)
def plot_inhom_isih(ax):
inhspikes = oupifspikes(rate, trials, duration, dt, 0.3, drate, tau)
ax.set_xlim(0.0, 150.0)
ax.set_ylim(0.0, 31.0)
ax.set_xticks(np.arange(0.0, 151.0, 50.0))
ax.set_yticks(np.arange(0.0, 31.0, 10.0))
plotisih(ax, isis(inhspikes), 0.005)
# homogeneous spike trains:
homspikes = hompoisson(rate, trials, duration) if __name__ == "__main__":
fig, (ax1, ax2) = plt.subplots(1, 2)
# OU noise: fig.subplots_adjust(**adjust_fs(fig, top=0.5, right=1.5))
rng = np.random.RandomState(54637281) plot_hom_isih(ax1)
time = np.arange(0.0, duration, dt) plot_inhom_isih(ax2)
x = np.zeros(time.shape)+rate plt.savefig('isihexamples.pdf')
n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate plt.close()
for k in range(1,len(x)) :
x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau
x[x<0.0] = 0.0
# pif spike trains:
inhspikes = pifspikes(x, trials, dt, D=0.3)
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.subplots_adjust(**adjust_fs(fig, top=0.5, right=1.5))
ax1.set_xlim(0.0, 150.0)
ax1.set_ylim(0.0, 31.0)
ax1.set_xticks(np.arange(0.0, 151.0, 50.0))
ax1.set_yticks(np.arange(0.0, 31.0, 10.0))
plotisih(ax1, isis(homspikes), 0.005)
ax2.set_xlim(0.0, 150.0)
ax2.set_ylim(0.0, 31.0)
ax2.set_xticks(np.arange(0.0, 151.0, 50.0))
ax2.set_yticks(np.arange(0.0, 31.0, 10.0))
plotisih(ax2, isis(inhspikes), 0.005)
plt.savefig('isihexamples.pdf')
plt.close()

View File

@ -60,8 +60,8 @@ process]{Punktprozess}{point processes}.
\texpicture{pointprocessscetch} \texpicture{pointprocessscetch}
\titlecaption{\label{pointprocessscetchfig} Statistics of point \titlecaption{\label{pointprocessscetchfig} Statistics of point
processes.}{A point process is a sequence of instances in time processes.}{A point process is a sequence of instances in time
$t_i$ that can be characterized through the inter-event-intervals $t_i$ that can be also characterized by inter-event intervals
$T_i=t_{i+1}-t_i$ and the number of events $n_i$. } $T_i=t_{i+1}-t_i$ and event counts $n_i$.}
\end{figure} \end{figure}
\noindent \noindent
@ -150,9 +150,8 @@ the interval $T_i$. The parameter $k$ is called the \enterm{lag}
maps are distinctly different \figref{returnmapfig}. maps are distinctly different \figref{returnmapfig}.
\begin{figure}[tp] \begin{figure}[tp]
\includegraphics[width=1\textwidth]{returnmapexamples}
\includegraphics[width=1\textwidth]{serialcorrexamples} \includegraphics[width=1\textwidth]{serialcorrexamples}
\titlecaption{\label{returnmapfig}Interspike interval \titlecaption{\label{returnmapfig}Interspike-interval
correlations}{of the spike trains shown in correlations}{of the spike trains shown in
\figref{rasterexamplesfig}. Upper panels show the return maps and \figref{rasterexamplesfig}. Upper panels show the return maps and
lower panels the serial correlations of successive intervals lower panels the serial correlations of successive intervals
@ -191,7 +190,7 @@ with itself and is always 1.
% \begin{figure}[t] % \begin{figure}[t]
% \includegraphics[width=0.48\textwidth]{poissoncounthist100hz10ms}\hfill % \includegraphics[width=0.48\textwidth]{poissoncounthist100hz10ms}\hfill
% \includegraphics[width=0.48\textwidth]{poissoncounthist100hz100ms} % \includegraphics[width=0.48\textwidth]{poissoncounthist100hz100ms}
% \titlecaption{\label{countstatsfig}Count Statistik.}{} % \titlecaption{\label{countstatsfig}Count statistic.}{}
% \end{figure} % \end{figure}
Counting the number of events $n_i$ (counts) in time windows $i$ of duration $W$ Counting the number of events $n_i$ (counts) in time windows $i$ of duration $W$
yields positive integer random numbers that are commonly quantified yields positive integer random numbers that are commonly quantified

View File

@ -2,6 +2,15 @@ import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from plotstyle import * from plotstyle import *
rate = 20.0
trials = 10
duration = 2.0
dt = 0.001
drate = 50.0
tau = 0.1;
def hompoisson(rate, trials, duration) : def hompoisson(rate, trials, duration) :
spikes = [] spikes = []
for k in range(trials) : for k in range(trials) :
@ -13,6 +22,7 @@ def hompoisson(rate, trials, duration) :
spikes.append(times) spikes.append(times)
return spikes return spikes
def inhompoisson(rate, trials, dt) : def inhompoisson(rate, trials, dt) :
spikes = [] spikes = []
p = rate*dt p = rate*dt
@ -40,47 +50,44 @@ def pifspikes(input, trials, dt, D=0.1) :
spikes.append(times) spikes.append(times)
return spikes return spikes
# parameter:
rate = 20.0
drate = 50.0
trials = 10
duration = 2.0
dt = 0.001
tau = 0.1;
# homogeneous spike trains:
homspikes = hompoisson(rate, trials, duration)
# OU noise: def oupifspikes(rate, trials, duration, dt, D, drate, tau):
rng = np.random.RandomState(54637281) # OU noise:
time = np.arange(0.0, duration, dt) rng = np.random.RandomState(54637281)
x = np.zeros(time.shape)+rate time = np.arange(0.0, duration, dt)
n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate x = np.zeros(time.shape)+rate
for k in range(1,len(x)) : n = rng.randn(len(time))*drate*tau/np.sqrt(dt) + rate
x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau for k in range(1,len(x)) :
x[x<0.0] = 0.0 x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau
x[x<0.0] = 0.0
# inhomogeneous spike trains: spikes = pifspikes(x, trials, dt, D)
#inhspikes = inhompoisson(x, trials, dt) return spikes
# pif spike trains:
inhspikes = pifspikes(x, trials, dt, D=0.3)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 0.5*figure_width))
fig.subplots_adjust(**adjust_fs(fig, left=4.0, right=1.0, top=1.2)) def plot_homogeneous_spikes(ax):
homspikes = hompoisson(rate, trials, duration)
ax.set_title('stationary')
ax.set_xlim(0.0, duration)
ax.set_ylim(-0.5, trials-0.5)
ax.set_xlabel('Time [s]')
ax.set_ylabel('Trial')
ax.eventplot(homspikes, colors=[lsA['color']], linelength=0.8, lw=1)
ax1.set_title('stationary')
ax1.set_xlim(0.0, duration) def plot_inhomogeneous_spikes(ax):
ax1.set_ylim(-0.5, trials-0.5) inhspikes = oupifspikes(rate, trials, duration, dt, 0.3, drate, tau)
ax1.set_xlabel('Time [s]') ax.set_title('non-stationary')
ax1.set_ylabel('Trial') ax.set_xlim(0.0, duration)
ax1.eventplot(homspikes, colors=[lsA['color']], linelength=0.8, lw=1) ax.set_ylim(-0.5, trials-0.5)
ax.set_xlabel('Time [s]')
ax.set_ylabel('Trial')
ax.eventplot(inhspikes, colors=[lsA['color']], linelength=0.8, lw=1)
ax2.set_title('non-stationary')
ax2.set_xlim(0.0, duration)
ax2.set_ylim(-0.5, trials-0.5)
ax2.set_xlabel('Time [s]')
ax2.set_ylabel('Trial')
ax2.eventplot(inhspikes, colors=[lsA['color']], linelength=0.8, lw=1)
plt.savefig('rasterexamples.pdf') if __name__ == "__main__":
plt.close() fig, (ax1, ax2) = plt.subplots(1, 2, figsize=cm_size(figure_width, 0.5*figure_width))
fig.subplots_adjust(**adjust_fs(fig, left=4.0, right=1.0, top=1.2))
plot_homogeneous_spikes(ax1)
plot_inhomogeneous_spikes(ax2)
plt.savefig('rasterexamples.pdf')
plt.close()

View File

@ -1,94 +0,0 @@
import numpy as np
import matplotlib.pyplot as plt
from plotstyle import *
def hompoisson(rate, trials, duration) :
spikes = []
for k in range(trials) :
times = []
t = 0.0
while t < duration :
t += np.random.exponential(1/rate)
times.append( t )
spikes.append( times )
return spikes
def inhompoisson(rate, trials, dt) :
spikes = []
p = rate*dt
for k in range(trials) :
x = np.random.rand(len(rate))
times = dt*np.nonzero(x<p)[0]
spikes.append( times )
return spikes
def pifspikes(input, trials, dt, D=0.1) :
vreset = 0.0
vthresh = 1.0
tau = 1.0
spikes = []
for k in range(trials) :
times = []
v = vreset
noise = np.sqrt(2.0*D)*np.random.randn(len(input))/np.sqrt(dt)
for k in range(len(noise)) :
v += (input[k]+noise[k])*dt/tau
if v >= vthresh :
v = vreset
times.append(k*dt)
spikes.append( times )
return spikes
def isis( spikes ) :
isi = []
for k in range(len(spikes)) :
isi.extend(np.diff(spikes[k]))
return np.array( isi )
def plotreturnmap(ax, isis, lag=1, max=1.0) :
ax.set_xlabel(r'ISI$_i$', 'ms')
ax.set_ylabel(r'ISI$_{i+1}$', 'ms')
ax.set_xlim(0.0, 1000.0*max)
ax.set_ylim(0.0, 1000.0*max)
isiss = isis[isis<max]
ax.plot(1000.0*isiss[:-lag], 1000.0*isiss[lag:], clip_on=False, **psAm)
# parameter:
rate = 20.0
drate = 50.0
trials = 10
duration = 10.0
dt = 0.001
tau = 0.1;
# homogeneous spike trains:
homspikes = hompoisson(rate, trials, duration)
# OU noise:
rng = np.random.RandomState(54637281)
time = np.arange(0.0, duration, dt)
x = np.zeros(time.shape)+rate
n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate
for k in range(1,len(x)) :
x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau
x[x<0.0] = 0.0
# pif spike trains:
inhspikes = pifspikes(x, trials, dt, D=0.3)
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.subplots_adjust(**adjust_fs(fig, left=6.5, top=1.5))
plotreturnmap(ax1, isis(homspikes), 1, 0.3)
ax1.set_xticks(np.arange(0.0, 301.0, 100.0))
ax1.set_yticks(np.arange(0.0, 301.0, 100.0))
plotreturnmap(ax2, isis(inhspikes), 1, 0.3)
ax2.set_ylabel('')
ax2.set_xticks(np.arange(0.0, 301.0, 100.0))
ax2.set_yticks(np.arange(0.0, 301.0, 100.0))
plt.savefig('returnmapexamples.pdf')
plt.close()

View File

@ -2,6 +2,16 @@ import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from plotstyle import * from plotstyle import *
# parameter:
rate = 20.0
trials = 10
duration = 500.0
dt = 0.001
drate = 50.0
tau = 0.1;
def hompoisson(rate, trials, duration) : def hompoisson(rate, trials, duration) :
spikes = [] spikes = []
for k in range(trials) : for k in range(trials) :
@ -41,11 +51,35 @@ def pifspikes(input, trials, dt, D=0.1) :
spikes.append( times ) spikes.append( times )
return spikes return spikes
def oupifspikes(rate, trials, duration, dt, D, drate, tau):
# OU noise:
rng = np.random.RandomState(54637281)
time = np.arange(0.0, duration, dt)
x = np.zeros(time.shape)+rate
n = rng.randn(len(time))*drate*tau/np.sqrt(dt) + rate
for k in range(1,len(x)) :
x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau
x[x<0.0] = 0.0
spikes = pifspikes(x, trials, dt, D)
return spikes
def isis( spikes ) : def isis( spikes ) :
isi = [] isi = []
for k in range(len(spikes)) : for k in range(len(spikes)) :
isi.extend(np.diff(spikes[k])) isi.extend(np.diff(spikes[k]))
return np.array( isi ) return np.array(isi)
def plotreturnmap(ax, isis, lag=1, max=1.0) :
ax.set_xlabel(r'ISI$_i$', 'ms')
ax.set_ylabel(r'ISI$_{i+1}$', 'ms')
ax.set_xlim(0.0, 1000.0*max)
ax.set_ylim(0.0, 1000.0*max)
isiss = isis[isis<max]
ax.plot(1000.0*isiss[:-lag], 1000.0*isiss[lag:], clip_on=False, **psAm)
def plotserialcorr(ax, isis, maxlag=10) : def plotserialcorr(ax, isis, maxlag=10) :
lags = np.arange(maxlag+1) lags = np.arange(maxlag+1)
@ -59,39 +93,39 @@ def plotserialcorr(ax, isis, maxlag=10) :
ax.plot([0, 10], [0.0, 0.0], **lsGrid) ax.plot([0, 10], [0.0, 0.0], **lsGrid)
ax.plot(lags, corr, clip_on=False, zorder=100, **lpsAm) ax.plot(lags, corr, clip_on=False, zorder=100, **lpsAm)
# parameter:
rate = 20.0
drate = 50.0
trials = 10
duration = 500.0
dt = 0.001
tau = 0.1;
# homogeneous spike trains: def plot_hom_returnmap(ax, spikes):
homspikes = hompoisson(rate, trials, duration) plotreturnmap(ax, isis(spikes)[:200], 1, 0.3)
ax.set_xticks(np.arange(0.0, 301.0, 100.0))
ax.set_yticks(np.arange(0.0, 301.0, 100.0))
def plot_inhom_returnmap(ax, spikes):
plotreturnmap(ax, isis(spikes)[:200], 1, 0.3)
ax.set_ylabel('')
ax.set_xticks(np.arange(0.0, 301.0, 100.0))
ax.set_yticks(np.arange(0.0, 301.0, 100.0))
# OU noise:
rng = np.random.RandomState(54637281)
time = np.arange(0.0, duration, dt)
x = np.zeros(time.shape)+rate
n = rng.randn(len(time))*drate*tau/np.sqrt(dt)+rate
for k in range(1,len(x)) :
x[k] = x[k-1] + (n[k]-x[k-1])*dt/tau
x[x<0.0] = 0.0
# pif spike trains: def plot_hom_serialcorr(ax, spikes):
inhspikes = pifspikes(x, trials, dt, D=0.3) plotserialcorr(ax, isis(spikes))
ax.set_ylim(-0.2, 1.0)
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.subplots_adjust(**adjust_fs(fig, left=7.0, right=1.0))
plotserialcorr(ax1, isis(homspikes)) def plot_inhom_serialcorr(ax, spikes):
ax1.set_ylim(-0.2, 1.0) plotserialcorr(ax, isis(spikes))
ax.set_ylabel('')
ax.set_ylim(-0.2, 1.0)
plotserialcorr(ax2, isis(inhspikes))
ax2.set_ylabel('')
ax2.set_ylim(-0.2, 1.0)
plt.savefig('serialcorrexamples.pdf') if __name__ == "__main__":
plt.close() homspikes = hompoisson(rate, trials, duration)
inhomspikes = oupifspikes(rate, trials, duration, dt, 0.3, drate, tau)
fig, axs = plt.subplots(2, 2, figsize=cm_size(figure_width, 1.8*figure_height))
fig.subplots_adjust(**adjust_fs(fig, left=6.5, right=1.5))
plot_hom_returnmap(axs[0,0], homspikes)
plot_inhom_returnmap(axs[0,1], inhomspikes)
plot_hom_serialcorr(axs[1,0], homspikes)
plot_inhom_serialcorr(axs[1,1], inhomspikes)
plt.savefig('serialcorrexamples.pdf')
plt.close()