-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalized interface to isi profile and distance
isi profile and distance functionc an now compute bi-variate and multi-variate results. Therefore, it can be called with different "overloads".
- Loading branch information
1 parent
2f48f27
commit 5a556a1
Showing
2 changed files
with
148 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" test_isi_interface.py | ||
Tests the generic interfaces of the profile and distance functions | ||
Copyright 2016, Mario Mulansky <mario.mulansky@gmx.net> | ||
Distributed under the BSD License | ||
""" | ||
|
||
from __future__ import print_function | ||
from numpy.testing import assert_equal | ||
|
||
import pyspike as spk | ||
from pyspike import SpikeTrain | ||
|
||
|
||
class dist_from_prof: | ||
""" Simple functor that turns profile function into distance function by | ||
calling profile.avrg(). | ||
""" | ||
def __init__(self, prof_func): | ||
self.prof_func = prof_func | ||
|
||
def __call__(self, *args, **kwargs): | ||
return self.prof_func(*args, **kwargs).avrg() | ||
|
||
|
||
def check_func(dist_func): | ||
""" generic checker that tests the given distance function. | ||
""" | ||
# generate spike trains: | ||
t1 = SpikeTrain([0.2, 0.4, 0.6, 0.7], 1.0) | ||
t2 = SpikeTrain([0.3, 0.45, 0.8, 0.9, 0.95], 1.0) | ||
t3 = SpikeTrain([0.2, 0.4, 0.6], 1.0) | ||
t4 = SpikeTrain([0.1, 0.4, 0.5, 0.6], 1.0) | ||
spike_trains = [t1, t2, t3, t4] | ||
|
||
isi12 = dist_func(t1, t2) | ||
isi12_ = dist_func([t1, t2]) | ||
assert_equal(isi12, isi12_) | ||
|
||
isi12_ = dist_func(spike_trains, indices=[0, 1]) | ||
assert_equal(isi12, isi12_) | ||
|
||
isi123 = dist_func(t1, t2, t3) | ||
isi123_ = dist_func([t1, t2, t3]) | ||
assert_equal(isi123, isi123_) | ||
|
||
isi123_ = dist_func(spike_trains, indices=[0, 1, 2]) | ||
assert_equal(isi123, isi123_) | ||
|
||
|
||
def test_isi_profile(): | ||
check_func(dist_from_prof(spk.isi_profile)) | ||
|
||
|
||
def test_isi_distance(): | ||
check_func(spk.isi_distance) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_isi_profile() | ||
test_isi_distance() |