<jupyter_start><jupyter_text>Homogeneous Poisson Process, Inhomogeneous Poisson Process and Absolute Refractoriness in a Homogeneous Poisson Process<jupyter_code>from __future__ import division, print_function
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>1. Spike-train statistics  1. a) Interspike interval<jupyter_code>spike_times = np.loadtxt('SpikeTimes.dat')  # in ms; dimensions: spike index, trial
spike_times.shape, spike_times[:, 0]  # this is the first trial
isi = np.diff(spike_times, axis=0)
isi.shape, isi[:, 0]
isi_flattened = isi[~np.isnan(isi)]  # omit nan values
plt.hist(isi_flattened, 70)
plt.xlabel('Interspike interval / ms')
plt.ylabel('Occurences')<jupyter_output><empty_output><jupyter_text>The ISI distribution is exponentially decaying, with another Gaussian-like distribution around 280 ms.  1. b) Coefficient of variation<jupyter_code>cv = np.std(isi_flattened) / np.mean(isi_flattened)
cv<jupyter_output><empty_output><jupyter_text>1. c) Fano factor<jupyter_code>spike_counts = []
for interval in range(4):
    start = interval * 1000
    end = (interval+1) * 1000 - 1
    spike_count = np.sum(np.logical_and(spike_times >= start, spike_times <= end)) / 100
    spike_counts.append(spike_count)
fano_factor = np.var(spike_counts) / np.mean(spike_counts)
fano_factor<jupyter_output>/Users/d068730/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:5: RuntimeWarning: invalid value encountered in greater_equal
/Users/d068730/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:5: RuntimeWarning: invalid value encountered in less_equal<jupyter_text>Calculating the Fano factor for smaller time windows (and not for the complete trial at once) yields a higher resolution.  2. Homogeneous and inhomogeneous Poisson process  2. a) ISI histograms<jupyter_code>from scipy.io import loadmat
variables = loadmat('PoissonSpikeTrains.mat')
spike_times = variables['SpikeTimes']
spike_times_inh = variables['SpikeTimes_inh']
spike_times_ref = variables['SpikeTimes_ref']
rates_ref = variables['rates_ref'][0]  # turn this into a vector
fig, axes = plt.subplots(1, 2, figsize=(15, 5))

for ax, times, title in zip(axes, [spike_times, spike_times_inh], ['Homogenous process', 'Inhomogenous process']):
    isi = np.diff(times, axis=0)
    isi_flattened = isi[~np.isnan(isi)]  # omit nan values
    plt.sca(ax)
    plt.hist(isi_flattened, range(0, 170, 3))
    plt.xlabel('Interspike interval / ms')
    plt.ylabel('Occurences')
    plt.title(title)
    plt.xlim(0, 160)<jupyter_output><empty_output><jupyter_text>For the homogenous process, we see only an exponential decay in the ISI histogram. For the inhomogenous process, we see an additional Gaussian-like distribution around 70 ms (like in exercise 1).  2. b) Coefficient of variation and Fano factor<jupyter_code>for times, title in zip([spike_times, spike_times_inh], ['Homogenous process', 'Inhomogenous process']):
    isi = np.diff(times, axis=0)
    isi_flattened = isi[~np.isnan(isi)]  # omit nan values
    
    cv = np.std(isi_flattened) / np.mean(isi_flattened)
    
    spike_counts = []
    for interval in range(4):
        start = interval * 1000
        end = (interval+1) * 1000 - 1
        spike_count = np.sum(np.logical_and(times >= start, times <= end))
        spike_counts.append(spike_count)
    fano_factor = np.var(spike_counts) / np.mean(spike_counts)
    
    print('{}: CV of {:.3}, Fano factor of {}'.format(title, cv, fano_factor))<jupyter_output>Homogenous process: CV of 0.965, Fano factor of 0.133333333333
Inhomogenous process: CV of 1.19, Fano factor of 0.690476190476<jupyter_text>2. c) Spike-train autocorrelation function<jupyter_code>def autocorr(x):
    return np.correlate(x, x, mode='full')
fig, axes = plt.subplots(1, 2, figsize=(15, 5))

for ax, times, title in zip(axes, [spike_times, spike_times_inh], ['Homogenous process', 'Inhomogenous process']):
    plt.sca(ax)
    isi_hist = np.histogram(times.flatten(), 100)[0]
    plt.plot(autocorr(isi_hist))
    plt.xlabel('t / ms')
    plt.ylabel('Autocorrelation')
    plt.title(title)<jupyter_output><empty_output><jupyter_text>2. d) Theoretical value The coefficient of variation and the Fano factor differ from the theoretical values of 1 because the neurons investigated here are not completely Poissonian. Especially the inhomogenous process is apparently not a Poisson process, as can be seen in the ISI histogram.  3. Poisson process with refractory period<jupyter_code>spike_times_ref.shape, spike_times_ref
spike_times_ref[:, 5]
rates_ref.shape, rates_ref<jupyter_output><empty_output><jupyter_text>3. a) Spike count rate<jupyter_code>spike_count_rates = len(spike_times_ref) / spike_times_ref[-1]
spike_count_rates
plt.plot(rates_ref, spike_count_rates, 'o')
plt.ylabel('$r_\mathrm{eff}  \ / \ \mathrm{ms}^{-1}$')
plt.xlabel('$r \ / \ \mathrm{s}^{-1}$')<jupyter_output><empty_output><jupyter_text>For large driving rates $r$, the effective spike rate $r_\mathrm{eff}$ saturates, because the neuron cannot fire quickly enough due to the refractory period. Its maximum spike rate is the inverse of duration of the refractory period.  3. b) ISI histograms<jupyter_code>fig, axes = plt.subplots(2, 3, figsize=(15, 8))
plt.subplots_adjust(hspace=0.4)

for ax, times, rate in zip(axes.flatten(), spike_times_ref.T, rates_ref):
    isi = np.diff(times, axis=0)
    plt.sca(ax)
    plt.hist(isi, range(0, 260, 10))
    plt.xlim(0, 250)
    plt.xlabel('Interspike interval / ms')
    plt.ylabel('Occurences')
    plt.title(r'$r = {} \ \mathrm{{Hz}}$'.format(rate))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11855396065922381, 'fraction_numerical': 0.026404394825447458, 'mean_word_length': 5.299107142857143, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '216163', 'license': 'MIT', 'n_tokens_mistral': 2139, 'n_tokens_neox': 1960, 'n_words': 491, 'path': '3/3.ipynb', 'repo_name': 'jrieke/aand', 'size': '5643'}