diff options
author | Mario Mulansky <mario.mulansky@gmx.net> | 2015-10-10 20:45:09 +0200 |
---|---|---|
committer | Mario Mulansky <mario.mulansky@gmx.net> | 2018-06-02 12:59:43 -0700 |
commit | 18ea80e2d01e9eb4ceee17219f91098efbcdf67c (patch) | |
tree | d7819736b059e9885d53c14e28160d6487d93e6c /test | |
parent | a5e6a12a619cb9528a4cf7f3ef8f082e5eb877c2 (diff) |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_sync_filter.py | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/test/test_sync_filter.py b/test/test_sync_filter.py index ce03b23..66ffcb6 100644 --- a/test/test_sync_filter.py +++ b/test/test_sync_filter.py @@ -17,17 +17,18 @@ import pyspike as spk from pyspike import SpikeTrain -def test_cython(): +def test_single_prof(): st1 = np.array([1.0, 2.0, 3.0, 4.0]) st2 = np.array([1.1, 2.1, 3.8]) + st3 = np.array([0.9, 3.1, 4.1]) # cython implementation try: - from pyspike.cython.cython_profiles import coincidence_single_profile_cython \ - as coincidence_impl + from pyspike.cython.cython_profiles import \ + coincidence_single_profile_cython as coincidence_impl except ImportError: - from pyspike.cython.python_backend import coincidence_single_profile_python \ - as coincidence_impl + from pyspike.cython.python_backend import \ + coincidence_single_profile_python as coincidence_impl sync_prof = spk.spike_sync_profile(SpikeTrain(st1, 5.0), SpikeTrain(st2, 5.0)) @@ -41,3 +42,53 @@ def test_cython(): for i, t in enumerate(st2): assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], "At index %d" % i) + + sync_prof = spk.spike_sync_profile(SpikeTrain(st1, 5.0), + SpikeTrain(st3, 5.0)) + + coincidences = np.array(coincidence_impl(st1, st3, 0, 5.0, 0.0)) + for i, t in enumerate(st1): + assert_equal(coincidences[i], sync_prof.y[sync_prof.x == t], + "At index %d" % i) + + st1 = np.array([1.0, 2.0, 3.0, 4.0]) + st2 = np.array([1.0, 2.0, 4.0]) + + sync_prof = spk.spike_sync_profile(SpikeTrain(st1, 5.0), + SpikeTrain(st2, 5.0)) + + coincidences = np.array(coincidence_impl(st1, st2, 0, 5.0, 0.0)) + for i, t in enumerate(st1): + expected = sync_prof.y[sync_prof.x == t]/sync_prof.mp[sync_prof.x == t] + assert_equal(coincidences[i], expected, + "At index %d" % i) + + +def test_filter(): + st1 = SpikeTrain(np.array([1.0, 2.0, 3.0, 4.0]), 5.0) + st2 = SpikeTrain(np.array([1.1, 2.1, 3.8]), 5.0) + st3 = SpikeTrain(np.array([0.9, 3.1, 4.1]), 5.0) + + # filtered_spike_trains = spk.filter_by_spike_sync([st1, st2], 0.5) + + # assert_equal(filtered_spike_trains[0].spikes, [1.0, 2.0, 4.0]) + # assert_equal(filtered_spike_trains[1].spikes, [1.1, 2.1, 3.8]) + + # filtered_spike_trains = spk.filter_by_spike_sync([st2, st1], 0.5) + + # assert_equal(filtered_spike_trains[0].spikes, [1.1, 2.1, 3.8]) + # assert_equal(filtered_spike_trains[1].spikes, [1.0, 2.0, 4.0]) + + filtered_spike_trains = spk.filter_by_spike_sync([st1, st2, st3], 0.75) + + for st in filtered_spike_trains: + print(st.spikes) + + assert_equal(filtered_spike_trains[0].spikes, [1.0, 4.0]) + assert_equal(filtered_spike_trains[1].spikes, [1.1, 3.8]) + assert_equal(filtered_spike_trains[2].spikes, [0.9, 4.1]) + + +if __name__ == "main": + test_single_prof() + test_filter() |