diff options
Diffstat (limited to 'pyspike/distances.py')
-rw-r--r-- | pyspike/distances.py | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/pyspike/distances.py b/pyspike/distances.py index 38c5cc2..5ee8261 100644 --- a/pyspike/distances.py +++ b/pyspike/distances.py @@ -11,7 +11,7 @@ import numpy as np import threading from functools import partial -from pyspike import PieceWiseConstFunc, PieceWiseLinFunc, IntervalSequence +from pyspike import PieceWiseConstFunc, PieceWiseLinFunc, MultipleValueSequence ############################################################ @@ -132,9 +132,7 @@ def spike_distance(spikes1, spikes2, interval=None): ############################################################ # spike_sync_profile ############################################################ -def spike_sync_profile(spikes1, spikes2, k=3): - - assert k > 0 +def spike_sync_profile(spikes1, spikes2): # cython implementation try: @@ -148,34 +146,16 @@ def spike_sync_profile(spikes1, spikes2, k=3): from python_backend import coincidence_python \ as coincidence_impl - st, J = coincidence_impl(spikes1, spikes2) - - N = len(J) - - # compute the cumulative sum, include some extra values for boundary - # conditions - c = np.zeros(N + 2*k) - c[k:-k] = np.cumsum(J) - # set the boundary values - # on the left: c_0 = -c_1, c_{-1} = -c_2, ..., c{-k+1} = c_k - # on the right: c_{N+1} = c_N, c_{N+2} = 2*c_N - c_{N-1}, - # c_{N+2} = 2*c_N - c_{N-2}, ..., c_{N+k} = 2*c_N - c_{N-k+1} - for n in xrange(k): - c[k-n-1] = -c[k+n] - c[-k+n] = 2*c[-k-1] - c[-k-1-n] - # with the right boundary values, the differences become trivial - J_w = c[2*k:] - c[:-2*k] - # normalize to half the interval width - J_w *= 1.0/k + times, coincidences, multiplicity = coincidence_impl(spikes1, spikes2) - return IntervalSequence(st, J_w) + return MultipleValueSequence(times, coincidences, multiplicity) ############################################################ # spike_sync_distance ############################################################ -def spike_sync_distance(spikes1, spikes2, k=3): - return spike_sync_profile(spikes1, spikes2, k).avrg() +def spike_sync_distance(spikes1, spikes2): + return spike_sync_profile(spikes1, spikes2).avrg() ############################################################ @@ -336,7 +316,7 @@ def spike_profile_multi(spike_trains, indices=None): ############################################################ # spike_profile_multi ############################################################ -def spike_sync_profile_multi(spike_trains, indices=None, k=3): +def spike_sync_profile_multi(spike_trains, indices=None): """ Computes the multi-variate spike synchronization profile for a set of spike trains. That is the average spike-distance of all pairs of spike trains: @@ -351,7 +331,7 @@ def spike_sync_profile_multi(spike_trains, indices=None, k=3): :rtype: :class:`pyspike.function.PieceWiseConstFunc` """ - prof_func = partial(spike_sync_profile, k=k) + prof_func = partial(spike_sync_profile) average_dist, M = _generic_profile_multi(spike_trains, prof_func, indices) # average_dist.mul_scalar(1.0/M) # no normalization here! |