summaryrefslogtreecommitdiff
path: root/pyspike
diff options
context:
space:
mode:
authorMario Mulansky <mario.mulansky@gmx.net>2014-10-14 17:49:23 +0200
committerMario Mulansky <mario.mulansky@gmx.net>2014-10-14 17:49:23 +0200
commit65801901e6d3325c8d1c82ab92334ca19ebd92d7 (patch)
treecd15a17ef3da186e97b6aa222ad3ee3997f6ea23 /pyspike
parent1bd3fa7ef0bf395f44aea493858bbdd563fcb0c4 (diff)
changed isi distance profile to abs values
Diffstat (limited to 'pyspike')
-rw-r--r--pyspike/cython_distance.pyx4
-rw-r--r--pyspike/distances.py2
-rw-r--r--pyspike/function.py16
3 files changed, 6 insertions, 16 deletions
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: