forked from bendalab/punitmodel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoisson_spike.py
42 lines (34 loc) · 1.26 KB
/
poisson_spike.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 15:17:06 2020
@author: Ibrahim Alperen Tunc
"""
#Poisson spike train
import numpy as np
import random
import matplotlib.pyplot as plt
import scipy.stats as st
random.seed(1000)
EODf = 800 #frequency of EOD in Hz
#Initialize parameters:
tEOD = np.arange(0,1000, 0.001) #time in EOD cycles, divide by EOD frequency to get the value in seconds
tms = tEOD*1000/EODf #time in ms
#Histogram kernel parameters
std_kernel = 0.005 #the kernel should be wider than temporal resolution -> std bigger tahn bins of tEOD
smooth_x = np.arange(0,10.0,0.01)
#Calculate the spikes
randomnums = np.random.rand(len(tEOD))
spikeidx = np.squeeze(np.where(randomnums<=0.2)) #indexes of the spikes aligned with t
spiketimes = tEOD[spikeidx] #in EOD cycles
ISIEOD = np.diff(spiketimes)
histkernel = st.gaussian_kde(ISIEOD, bw_method=std_kernel/np.var(ISIEOD))
smoothed_data = histkernel(smooth_x) #calculate the pdf for the given time window
fig, ax = plt.subplots(1,1)
ax.plot(smooth_x, smoothed_data)
ax.set_title('ISI histogram')
ax.set_xlabel('ISI [EOD period]')
ax.set_ylabel('Probability density')
"""
# scipy kde kernel density estimate
# bandwith = std_gaussian/np.var(ISIEOD) this is to pass the gaussian bandwidth you wanna pass
"""