diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2018-09-20 10:49:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-20 10:49:42 -0700 |
commit | 34bd30415dd93a2425ce566627e24ee9483ada3e (patch) | |
tree | dcfa9164d46e3cf501a1e8dcf4970f350063561a /pyspike/PieceWiseConstFunc.py | |
parent | 44d23620d2faa78ca74437fbd3f1b95da722a853 (diff) |
Spike Order support (#39)0.6.0
* reorganized directionality module
* further refactoring of directionality
* completed python directionality backend
* added SPIKE-Sync based filtering
new function filter_by_spike_sync removes spikes that have a multi-variate
Spike Sync value below some threshold
not yet fully tested, python backend missing.
* spike sync filtering, cython sim ann
Added function for filtering out events based on a threshold for the spike
sync values. Usefull for focusing on synchronous events during directionality
analysis.
Also added cython version of simulated annealing for performance.
* added coincidence single profile to python backend
missing function in python backend added, identified and fixed a bug in the
implementation as well
* updated test case to new spike sync behavior
* python3 fixes
* another python3 fix
* reorganized directionality module
* further refactoring of directionality
* completed python directionality backend
* added SPIKE-Sync based filtering
new function filter_by_spike_sync removes spikes that have a multi-variate
Spike Sync value below some threshold
not yet fully tested, python backend missing.
* spike sync filtering, cython sim ann
Added function for filtering out events based on a threshold for the spike
sync values. Usefull for focusing on synchronous events during directionality
analysis.
Also added cython version of simulated annealing for performance.
* added coincidence single profile to python backend
missing function in python backend added, identified and fixed a bug in the
implementation as well
* updated test case to new spike sync behavior
* python3 fixes
* another python3 fix
* Fix absolute imports in directionality measures
* remove commented code
* Add directionality to docs, bump version
* Clean up directionality module, add doxy.
* Remove debug print from tests
* Fix bug in calling Python backend
* Fix incorrect integrals in PieceWiseConstFunc (#36)
* Add (some currently failing) tests for PieceWiseConstFunc.integral
* Fix implementation of PieceWiseConstFunc.integral
Just by adding a special condition for when we are only taking an
integral "between" two edges of a PieceWiseConstFunc
All tests now pass.
Fixes #33.
* Add PieceWiseConstFunc.integral tests for ValueError
* Add testing bounds of integral
* Raise ValueError in function implementation
* Fix incorrect integrals in PieceWiseLinFunc (#38)
Integrals of piece-wise linear functions were incorrect if the
requested interval lies completely between two support points.
This has been fixed, and a unit test exercising this behavior
was added.
Fixes #38
* Add Spike Order example and Tutorial section
Adds an example computing spike order profile and the optimal
spike train order. Also adds a section on spike train order to the
tutorial.
Diffstat (limited to 'pyspike/PieceWiseConstFunc.py')
-rw-r--r-- | pyspike/PieceWiseConstFunc.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/pyspike/PieceWiseConstFunc.py b/pyspike/PieceWiseConstFunc.py index 5ce5f27..17fdd3f 100644 --- a/pyspike/PieceWiseConstFunc.py +++ b/pyspike/PieceWiseConstFunc.py @@ -129,19 +129,31 @@ class PieceWiseConstFunc(object): # no interval given, integrate over the whole spike train a = np.sum((self.x[1:]-self.x[:-1]) * self.y) else: + if interval[0]>interval[1]: + raise ValueError("Invalid averaging interval: interval[0]>=interval[1]") + if interval[0]<self.x[0]: + raise ValueError("Invalid averaging interval: interval[0]<self.x[0]") + if interval[1]>self.x[-1]: + raise ValueError("Invalid averaging interval: interval[0]<self.x[-1]") # find the indices corresponding to the interval start_ind = np.searchsorted(self.x, interval[0], side='right') end_ind = np.searchsorted(self.x, interval[1], side='left')-1 - assert start_ind > 0 and end_ind < len(self.x), \ - "Invalid averaging interval" - # first the contribution from between the indices - a = np.sum((self.x[start_ind+1:end_ind+1] - - self.x[start_ind:end_ind]) * - self.y[start_ind:end_ind]) - # correction from start to first index - a += (self.x[start_ind]-interval[0]) * self.y[start_ind-1] - # correction from last index to end - a += (interval[1]-self.x[end_ind]) * self.y[end_ind] + if start_ind > end_ind: + # contribution from between two closest edges + a = (self.x[start_ind]-self.x[end_ind]) * self.y[end_ind] + # minus the part that is not within the interval + a -= ((interval[0]-self.x[end_ind])+(self.x[start_ind]-interval[1])) * self.y[end_ind] + else: + assert start_ind > 0 and end_ind < len(self.x), \ + "Invalid averaging interval" + # first the contribution from between the indices + a = np.sum((self.x[start_ind+1:end_ind+1] - + self.x[start_ind:end_ind]) * + self.y[start_ind:end_ind]) + # correction from start to first index + a += (self.x[start_ind]-interval[0]) * self.y[start_ind-1] + # correction from last index to end + a += (interval[1]-self.x[end_ind]) * self.y[end_ind] return a def avrg(self, interval=None): |