summaryrefslogtreecommitdiff
path: root/pyspike/cython_distance.pyx
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2014-10-01 17:01:07 +0200
committerMario Mulansky <mario.mulansky@gmx.net>2014-10-01 17:01:07 +0200
commit47c9bfc45db078d9a134a7b2b10dcf0cc6556641 (patch)
tree1ed0cda446cc6e842bb449ee32efde9c09201827 /pyspike/cython_distance.pyx
parent9335f9a4f78b561b8c875704a2e52ba27a45ad9b (diff)
switched from pyximport to distutils
Diffstat (limited to 'pyspike/cython_distance.pyx')
-rw-r--r--pyspike/cython_distance.pyx18
1 files changed, 10 insertions, 8 deletions
diff --git a/pyspike/cython_distance.pyx b/pyspike/cython_distance.pyx
index 1a6d24a..6edcc01 100644
--- a/pyspike/cython_distance.pyx
+++ b/pyspike/cython_distance.pyx
@@ -3,7 +3,7 @@
#cython: cdivision=True
"""
-cython_distances.py
+cython_distances.pyx
cython implementation of the isi- and spike-distance
@@ -159,13 +159,14 @@ def spike_distance_cython(double[:] t1,
# first calculate the previous interval end value
dt_p1 = dt_f1 # the previous time now was the following time before
s1 = dt_p1
- s2 = (dt_p2*(t2[index2+1]-t1[index1]) + dt_f2*(t1[index1]-t2[index2])) / isi2
- y_ends[index-1] = (s1*isi2 + s2*isi1) / ((isi1+isi2)**2/2)
+ s2 = (dt_p2*(t2[index2+1]-t1[index1]) +
+ dt_f2*(t1[index1]-t2[index2])) / isi2
+ y_ends[index-1] = (s1*isi2 + s2*isi1)/(0.5*(isi1+isi2)*(isi1+isi2))
# now the next interval start value
dt_f1 = get_min_dist_cython(t1[index1+1], t2, N2, index2)
isi1 = t1[index1+1]-t1[index1]
# s2 is the same as above, thus we can compute y2 immediately
- y_starts[index] = (s1*isi2 + s2*isi1) / ((isi1+isi2)**2/2)
+ y_starts[index] = (s1*isi2 + s2*isi1)/(0.5*(isi1+isi2)*(isi1+isi2))
elif t1[index1+1] > t2[index2+1]:
index2 += 1
if index2+1 >= N2:
@@ -173,15 +174,16 @@ def spike_distance_cython(double[:] t1,
spike_events[index] = t2[index2]
# first calculate the previous interval end value
dt_p2 = dt_f2 # the previous time now was the following time before
- s1 = (dt_p1*(t1[index1+1]-t2[index2]) + dt_f1*(t2[index2]-t1[index1])) / isi1
+ s1 = (dt_p1*(t1[index1+1]-t2[index2]) +
+ dt_f1*(t2[index2]-t1[index1])) / isi1
s2 = dt_p2
- y_ends[index-1] = (s1*isi2 + s2*isi1) / ((isi1+isi2)**2/2)
+ y_ends[index-1] = (s1*isi2 + s2*isi1) / (0.5*(isi1+isi2)*(isi1+isi2))
# now the next interval start value
dt_f2 = get_min_dist_cython(t2[index2+1], t1, N1, index1)
#s2 = dt_f2
isi2 = t2[index2+1]-t2[index2]
# s2 is the same as above, thus we can compute y2 immediately
- y_starts[index] = (s1*isi2 + s2*isi1) / ((isi1+isi2)**2/2)
+ y_starts[index] = (s1*isi2 + s2*isi1)/(0.5*(isi1+isi2)*(isi1+isi2))
else: # t1[index1+1] == t2[index2+1] - generate only one event
index1 += 1
index2 += 1
@@ -204,7 +206,7 @@ def spike_distance_cython(double[:] t1,
isi2 = max(t2[N2-1]-t2[N2-2], t2[N2-2]-t2[N2-3])
s1 = dt_p1*(t1[N1-1]-t1[N1-2])/isi1
s2 = dt_p2*(t2[N2-1]-t2[N2-2])/isi2
- y_ends[index-1] = (s1*isi2 + s2*isi1) / ((isi1+isi2)**2/2)
+ y_ends[index-1] = (s1*isi2 + s2*isi1) / (0.5*(isi1+isi2)*(isi1+isi2))
# use only the data added above
# could be less than original length due to equal spike times