Debian Codegraph @

pyspike/cython/cython_get_tau.pyx

raw
1 #cython language_level=3
2 from libc.math cimport fmin
3
4 cdef double Interpolate(a, b, t):
5 """ thresholded interpolation
6 If t small, return min(a,b)
7 if t big, return b
8 in between, return t
9 """
10 if t < a and a < b: return a
11 if t < b and b <= a: return b
12 if t > b: return b
13 return t # interpolation
14
15 cdef double get_tau(double[:] spikes1, double[:] spikes2,
16 int i, int j, double max_tau, double MRTS):
17 """ Compute coincidence window
18 In: spikes1, spikes2 - times of two spike trains
19 i, j - indices into spikes1, spikes2 to compare
20 max_tau - maximum size of threshold
21 MRTS - adaptation parameter
22 out: combined coincidence window (Eq 19 in reference)
23 """
24
25 ## "distances" to neighbor: F/P=future/past, 1/2=N in spikesN.
26 cdef double mF1 = max_tau
27 cdef double mP1 = max_tau
28 cdef double mF2 = max_tau
29 cdef double mP2 = max_tau
30
31 if i < len(spikes1)-1 and i > -1:
32 mF1 = (spikes1[i+1]-spikes1[i])
33 if j < len(spikes2)-1 and j > -1:
34 mF2 = (spikes2[j+1]-spikes2[j])
35 if i > 0:
36 mP1 = (spikes1[i]-spikes1[i-1])
37 if j > 0:
38 mP2 = (spikes2[j]-spikes2[j-1])
39
40 mF1, mF2, mP1, mP2 = mF1/2., mF2/2., mP1/2., mP2/2.
41 MRTS /= 4.
42
43 if i<0 or j<0 or spikes1[i] <= spikes2[j]:
44 s1F = Interpolate(mP1, mF1, MRTS)
45 s2P = Interpolate(mF2, mP2, MRTS)
46 return fmin(s1F, s2P)
47 else:
48 s1P = Interpolate(mF1, mP1, MRTS)
49 s2F = Interpolate(mP2, mF2, MRTS)
50 return fmin(s1P, s2F)