summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2015-05-11 17:54:02 +0200
committerMario Mulansky <mario.mulansky@gmx.net>2015-05-11 17:54:02 +0200
commita35402c208bd0ad31e5e60b6ddc55a3470e7bdde (patch)
tree1eca443c3b692c55438dd81b5f96cce51c8f4338
parentbec2529367f1bdd5dac6d6fbaec560a30feec3c7 (diff)
bugfix: spike_sync=1 for empty spike trains
-rw-r--r--pyspike/DiscreteFunc.py4
-rw-r--r--pyspike/cython/cython_distances.pyx3
-rw-r--r--pyspike/cython/cython_profiles.pyx12
-rw-r--r--pyspike/cython/python_backend.py12
-rw-r--r--test/test_empty.py4
5 files changed, 22 insertions, 13 deletions
diff --git a/pyspike/DiscreteFunc.py b/pyspike/DiscreteFunc.py
index 6ade87e..17153ee 100644
--- a/pyspike/DiscreteFunc.py
+++ b/pyspike/DiscreteFunc.py
@@ -137,8 +137,8 @@ class DiscreteFunc(object):
"""
if len(self.y) <= 2:
- # no actual values in the profile, return spike sync of 0
- return 0.0, 1.0
+ # no actual values in the profile, return spike sync of 1
+ return 1.0, 1.0
def get_indices(ival):
""" Retuns the indeces surrounding the given interval"""
diff --git a/pyspike/cython/cython_distances.pyx b/pyspike/cython/cython_distances.pyx
index 16780f2..c4f2349 100644
--- a/pyspike/cython/cython_distances.pyx
+++ b/pyspike/cython/cython_distances.pyx
@@ -391,7 +391,8 @@ def coincidence_value_cython(double[:] spikes1, double[:] spikes2,
coinc += 2
if coinc == 0 and mp == 0:
- # empty spike trains -> set mp to one to avoid 0/0
+ # empty spike trains -> spike sync = 1 by definition
+ coinc = 1
mp = 1
return coinc, mp
diff --git a/pyspike/cython/cython_profiles.pyx b/pyspike/cython/cython_profiles.pyx
index d937a02..f9893eb 100644
--- a/pyspike/cython/cython_profiles.pyx
+++ b/pyspike/cython/cython_profiles.pyx
@@ -416,9 +416,13 @@ def coincidence_profile_cython(double[:] spikes1, double[:] spikes2,
st[0] = t_start
st[len(st)-1] = t_end
- c[0] = c[1]
- c[len(c)-1] = c[len(c)-2]
- mp[0] = mp[1]
- mp[len(mp)-1] = mp[len(mp)-2]
+ if N1 + N2 > 0:
+ c[0] = c[1]
+ c[len(c)-1] = c[len(c)-2]
+ mp[0] = mp[1]
+ mp[len(mp)-1] = mp[len(mp)-2]
+ else:
+ c[0] = 1
+ c[1] = 1
return st, c, mp
diff --git a/pyspike/cython/python_backend.py b/pyspike/cython/python_backend.py
index 830dc69..69a420f 100644
--- a/pyspike/cython/python_backend.py
+++ b/pyspike/cython/python_backend.py
@@ -399,10 +399,14 @@ def coincidence_python(spikes1, spikes2, t_start, t_end, max_tau):
st[0] = t_start
st[len(st)-1] = t_end
- c[0] = c[1]
- c[len(c)-1] = c[len(c)-2]
- mp[0] = mp[1]
- mp[len(mp)-1] = mp[len(mp)-2]
+ if N1 + N2 > 0:
+ c[0] = c[1]
+ c[len(c)-1] = c[len(c)-2]
+ mp[0] = mp[1]
+ mp[len(mp)-1] = mp[len(mp)-2]
+ else:
+ c[0] = 1
+ c[1] = 1
return st, c, mp
diff --git a/test/test_empty.py b/test/test_empty.py
index b31d8a4..48be25d 100644
--- a/test/test_empty.py
+++ b/test/test_empty.py
@@ -106,11 +106,11 @@ def test_spike_sync_empty():
st1 = SpikeTrain([], edges=(0.0, 1.0))
st2 = SpikeTrain([], edges=(0.0, 1.0))
d = spk.spike_sync(st1, st2)
- assert_equal(d, 0.0)
+ assert_equal(d, 1.0)
prof = spk.spike_sync_profile(st1, st2)
assert_equal(d, prof.avrg())
assert_array_equal(prof.x, [0.0, 1.0])
- assert_array_equal(prof.y, [0.0, 0.0])
+ assert_array_equal(prof.y, [1.0, 1.0])
st1 = SpikeTrain([], edges=(0.0, 1.0))
st2 = SpikeTrain([0.4, ], edges=(0.0, 1.0))