diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2014-10-14 17:49:23 +0200 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2014-10-14 17:49:23 +0200 |
commit | 65801901e6d3325c8d1c82ab92334ca19ebd92d7 (patch) | |
tree | cd15a17ef3da186e97b6aa222ad3ee3997f6ea23 | |
parent | 1bd3fa7ef0bf395f44aea493858bbdd563fcb0c4 (diff) |
changed isi distance profile to abs values
-rw-r--r-- | examples/plot.py | 2 | ||||
-rw-r--r-- | pyspike/cython_distance.pyx | 4 | ||||
-rw-r--r-- | pyspike/distances.py | 2 | ||||
-rw-r--r-- | pyspike/function.py | 16 | ||||
-rw-r--r-- | test/test_distance.py | 6 | ||||
-rw-r--r-- | test/test_function.py | 2 |
6 files changed, 9 insertions, 23 deletions
diff --git a/examples/plot.py b/examples/plot.py index da53670..4ac8f5d 100644 --- a/examples/plot.py +++ b/examples/plot.py @@ -29,8 +29,6 @@ plt.figure() plt.plot(x, np.abs(y), '--k') print("Average: %.8f" % f.avrg()) -print("Absolute average: %.8f" % f.abs_avrg()) - f = spk.spike_distance(spike_trains[0], spike_trains[1]) x, y = f.get_plottable_data() diff --git a/pyspike/cython_distance.pyx b/pyspike/cython_distance.pyx index ccf8060..178fcba 100644 --- a/pyspike/cython_distance.pyx +++ b/pyspike/cython_distance.pyx @@ -60,7 +60,7 @@ def isi_distance_cython(double[:] s1, isi_values = np.empty(N1+N2-1) with nogil: # release the interpreter to allow multithreading - isi_values[0] = (nu1-nu2)/fmax(nu1,nu2) + isi_values[0] = fabs(nu1-nu2)/fmax(nu1, nu2) index1 = 0 index2 = 0 index = 1 @@ -88,7 +88,7 @@ def isi_distance_cython(double[:] s1, nu1 = s1[index1+1]-s1[index1] nu2 = s2[index2+1]-s2[index2] # compute the corresponding isi-distance - isi_values[index] = (nu1 - nu2) / fmax(nu1, nu2) + isi_values[index] = fabs(nu1 - nu2) / fmax(nu1, nu2) index += 1 # the last event is the interval end spike_events[index] = s1[N1] diff --git a/pyspike/distances.py b/pyspike/distances.py index 3b9fe1f..08d0ed8 100644 --- a/pyspike/distances.py +++ b/pyspike/distances.py @@ -213,7 +213,7 @@ def isi_distance_matrix(spike_trains, indices=None): distance_matrix = np.zeros((len(indices), len(indices))) for i, j in pairs: - d = isi_distance(spike_trains[i], spike_trains[j]).abs_avrg() + d = isi_distance(spike_trains[i], spike_trains[j]).avrg() distance_matrix[i, j] = d distance_matrix[j, i] = d return distance_matrix diff --git a/pyspike/function.py b/pyspike/function.py index 7722cc3..bd3e2d5 100644 --- a/pyspike/function.py +++ b/pyspike/function.py @@ -18,7 +18,7 @@ import numpy as np ############################################################## class PieceWiseConstFunc: """ A class representing a piece-wise constant function. """ - + def __init__(self, x, y): """ Constructs the piece-wise const function. Args: @@ -66,16 +66,6 @@ class PieceWiseConstFunc: return np.sum((self.x[1:]-self.x[:-1]) * self.y) / \ (self.x[-1]-self.x[0]) - def abs_avrg(self): - """ Computes the average of the abs value of the piece-wise const - function: - a = 1/T int |f(x)| dx where T is the length of the interval. - Returns: - - the average a. - """ - return np.sum((self.x[1:]-self.x[:-1]) * np.abs(self.y)) / \ - (self.x[-1]-self.x[0]) - def add(self, f): """ Adds another PieceWiseConst function to this function. Note: only functions defined on the same interval can be summed. @@ -84,7 +74,7 @@ class PieceWiseConstFunc: """ assert self.x[0] == f.x[0], "The functions have different intervals" assert self.x[-1] == f.x[-1], "The functions have different intervals" - + # python implementation # from python_backend import add_piece_wise_const_python # self.x, self.y = add_piece_wise_const_python(self.x, self.y, @@ -107,7 +97,7 @@ class PieceWiseConstFunc: ############################################################## class PieceWiseLinFunc: """ A class representing a piece-wise linear function. """ - + def __init__(self, x, y1, y2): """ Constructs the piece-wise linear function. Args: diff --git a/test/test_distance.py b/test/test_distance.py index b500b2c..6e50467 100644 --- a/test/test_distance.py +++ b/test/test_distance.py @@ -23,8 +23,8 @@ def test_isi(): # pen&paper calculation of the isi distance expected_times = [0.0, 0.2, 0.3, 0.4, 0.45, 0.6, 0.7, 0.8, 0.9, 0.95, 1.0] - expected_isi = [-0.1/0.3, -0.1/0.3, 0.05/0.2, 0.05/0.2, -0.15/0.35, - -0.25/0.35, -0.05/0.35, 0.2/0.3, 0.25/0.3, 0.25/0.3] + expected_isi = [0.1/0.3, 0.1/0.3, 0.05/0.2, 0.05/0.2, 0.15/0.35, + 0.25/0.35, 0.05/0.35, 0.2/0.3, 0.25/0.3, 0.25/0.3] t1 = spk.add_auxiliary_spikes(t1, 1.0) t2 = spk.add_auxiliary_spikes(t2, 1.0) @@ -40,7 +40,7 @@ def test_isi(): t2 = np.array([0.1, 0.4, 0.5, 0.6]) expected_times = [0.0, 0.1, 0.2, 0.4, 0.5, 0.6, 1.0] - expected_isi = [0.1/0.2, -0.1/0.3, -0.1/0.3, 0.1/0.2, 0.1/0.2, -0.0/0.5] + expected_isi = [0.1/0.2, 0.1/0.3, 0.1/0.3, 0.1/0.2, 0.1/0.2, 0.0/0.5] t1 = spk.add_auxiliary_spikes(t1, 1.0) t2 = spk.add_auxiliary_spikes(t2, 1.0) diff --git a/test/test_function.py b/test/test_function.py index a579796..c5caa5a 100644 --- a/test/test_function.py +++ b/test/test_function.py @@ -28,8 +28,6 @@ def test_pwc(): assert_array_almost_equal(yp, yp_expected, decimal=16) assert_almost_equal(f.avrg(), (1.0-0.5+0.5*1.5+1.5*0.75)/4.0, decimal=16) - assert_almost_equal(f.abs_avrg(), (1.0+0.5+0.5*1.5+1.5*0.75)/4.0, - decimal=16) def test_pwc_add(): |