Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] spike time tiling coefficient for unsorted spiketrains, added validation test #564

Merged
merged 22 commits into from
Oct 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add validation tests
  • Loading branch information
Moritz-Alexander-Kern committed May 24, 2023
commit 7d69e01aa5b423aacad811c4aba52bc77123fbc6
38 changes: 34 additions & 4 deletions elephant/test/test_spike_train_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
:license: Modified BSD, see LICENSE.txt for details.
"""

import math
import unittest

import neo
from neo.io import NixIO
import numpy as np
import quantities as pq
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
from numpy.testing import assert_array_equal, assert_array_almost_equal

import elephant.conversion as conv
import elephant.spike_train_correlation as sc
from elephant.datasets import download_datasets, ELEPHANT_TMP_DIR
from elephant.spike_train_generation import homogeneous_poisson_process, \
homogeneous_gamma_process
import math


class CovarianceTestCase(unittest.TestCase):
Expand Down Expand Up @@ -831,11 +833,39 @@ def test_sttc_unsorted_spiketimes(self):
spiketrain_B3, dt=0.10 * pq.s)
self.assertAlmostEqual(sttc_unsorted_E8_B3, sttc_sorted_E8_B3)

def test_exist_alias(self):
def test_sttc_validation_test(self):
"""This test checks the results of elephants implementation of
the spike time tiling coefficient against the results of the
original c-implementation.
The c-code and the test data is located at
NeuralEnsemble/elephant-data/unittest/spike_train_correlation/
spike_time_tiling_coefficient"""

repo_path = r"unittest/spike_train_correlation/spike_time_tiling_coefficient/data" # noqa

files_to_download = [("spike_time_tiling_coefficient_results.nix ",
"db4e81febc0ca48f1c125891a85c9a7a")]

for filename, checksum in files_to_download:
download_datasets(repo_path=f"{repo_path}/{filename}",
checksum=checksum)

reader = NixIO(
ELEPHANT_TMP_DIR / 'spike_time_tiling_coefficient_results.nix',
mode='ro')
test_data_block = reader.read()

for segment in test_data_block[0].segments:
spiketrain_i = segment.spiketrains[0]
spiketrain_j = segment.spiketrains[1]
dt = segment.annotations['dt']
sttc_result = segment.annotations['sttc_result']
self.assertAlmostEqual(sc.sttc(spiketrain_i, spiketrain_j, dt),
sttc_result)
def test_sttc_exist_alias(self):
# Test if alias cch still exists.
self.assertEqual(sc.spike_time_tiling_coefficient, sc.sttc)


class SpikeTrainTimescaleTestCase(unittest.TestCase):

def test_timescale_calculation(self):
Expand Down