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

Conversation

Moritz-Alexander-Kern
Copy link
Member

@Moritz-Alexander-Kern Moritz-Alexander-Kern commented May 12, 2023

This is related to Issue #563 .

The example from the Issue now returns:

  • STTC for E7 and E3: 1.0 (Spiketrains identical)
  • STTC for E8 and B3: -0.02 (Spiketrains different)

Previously, this function encountered a bug when using unsorted spiketrains as input, leading to the generation of values exceeding the desired range of -1 to 1.

This fix involves several improvements:

  • the spiketrains used as input are now sorted
  • additional input checks were added
  • added a regression test, verifying that the sttc function returns values within the desired range of -1 to 1, with the example given in the Issue

Example Code:

import neo

import quantities as pq

from elephant.spike_train_correlation import spike_time_tiling_coefficient

spiketrain_E7 = neo.SpikeTrain([ 1678. , 23786.3, 34641.8, 71520.7, 73606.9, 78383.3,
97387.9, 144313.4, 4607.6, 19275.1, 152894.2, 44240.1], units='ms', t_stop=160000*pq.ms)

spiketrain_E3 = neo.SpikeTrain([ 1678. , 23786.3, 34641.8, 71520.7, 73606.9, 78383.3,
97387.9, 144313.4, 4607.6, 19275.1, 152894.2, 44240.1], units='ms', t_stop=160000*pq.ms)

print(spike_time_tiling_coefficient(spiketrain_E7, spiketrain_E3, dt=0.10 * pq.s))

spiketrain_E8 = neo.SpikeTrain([ 20646.8, 25875.1, 26154.4, 35121. , 55909.7, 79164.8,
110849.8, 117484.1, 3731.5, 4213.9, 119995.1, 123748.1,
171016.8, 172989. , 185145.2, 12043.5, 185995.9, 186740.1,
12629.8, 23394.3, 34993.2], units='ms', t_stop=210000*pq.ms)

spiketrain_B3 = neo.SpikeTrain([ 10600.7, 19699.6, 22803. , 40769.3, 121385.7, 127402.9,
130829.2, 134363.8, 1193.5, 8012.7, 142037.3, 146628.2,
165925.3, 168489.3, 175194.3, 10339.8, 178676.4, 180807.2,
201431.3, 22231.1, 38113.4], units='ms', t_stop=210000*pq.ms)

print(spike_time_tiling_coefficient(spiketrain_E8, spiketrain_B3, dt=0.10 * pq.s))

todo:

A description of the sttc algorithm can be found here: https://doi.org/10.1523/jneurosci.2767-14.2014 .

@coveralls
Copy link
Collaborator

coveralls commented May 12, 2023

Coverage Status

Coverage: 86.768% (+0.4%) from 86.418% when pulling 64c8ad9 on INM-6:fix/sttc into 471bf0f on NeuralEnsemble:master.

@Moritz-Alexander-Kern Moritz-Alexander-Kern added the bugfix Fix for an indentified bug. label May 12, 2023
@Moritz-Alexander-Kern Moritz-Alexander-Kern added this to the v0.14.0 milestone Sep 18, 2023
@Moritz-Alexander-Kern Moritz-Alexander-Kern changed the title fix spike_time_tiling_coefficient [Fix] spike time tiling coefficient for unsorted spiketrains and validate results Sep 20, 2023
@Moritz-Alexander-Kern Moritz-Alexander-Kern changed the title [Fix] spike time tiling coefficient for unsorted spiketrains and validate results [Fix] spike time tiling coefficient for unsorted spiketrains, added validation test Sep 20, 2023
@pep8speaks
Copy link

pep8speaks commented Oct 27, 2023

Hello @Moritz-Alexander-Kern! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2023-10-30 17:08:20 UTC

Copy link
Member

@mdenker mdenker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After pair programming review, the following was identified:

  • new implementation was checked against pen and paper solution, based on the spike trains generated in the test setup. The validation test against the c implementation should check against this example as well.
  • Adding a third spike train to the validation unit test would be good. For the existing validation unit test based on the regression test, it should be noted that this test has no overlaps between spikes -- therefore it tests for PA=PB=0.
  • Additional comments for the new improved implementation and for the validation code calling the original c code would be nice.

@Moritz-Alexander-Kern
Copy link
Member Author

* new implementation was checked against pen and paper solution, based on the spike trains generated in the test setup. The validation test against the c implementation should check against this example as well.

Added this example to generate_results.py , see PR on GIN: https://gin.g-node.org/NeuralEnsemble/elephant-data/pulls/4

* Adding a third spike train to the validation unit test would be good. For the existing validation unit test based on the regression test, it should be noted that this test has no overlaps between spikes -- therefore it tests for PA=PB=0.

Generated two spiketrains with:

# Generate two spiketrains with different firing rates
np.random.seed(0)
spiketrain_5_hz = StationaryPoissonProcess(rate=5*pq.Hz, t_start=0*pq.ms, t_stop=5000*pq.ms, refractory_period=3*pq.ms).generate_spiketrain()
spiketrain_30_hz = StationaryPoissonProcess(rate=30*pq.Hz, t_start=0*pq.ms, t_stop=5000*pq.ms, refractory_period=3*pq.ms).generate_spiketrain()

The STTC for this example using dt=100ms is: 0.5445476264987906

* Additional comments for the new improved implementation and for the validation code calling the original c code would be nice.

Added comments for run_t and run_p functions, added comments to the Cython code in wrapper_spike_time_tiling_coefficient.pyx, see PR on GIN.

Copy link
Member Author

@Moritz-Alexander-Kern Moritz-Alexander-Kern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build wheels

@Moritz-Alexander-Kern Moritz-Alexander-Kern merged commit 8bac14c into NeuralEnsemble:master Oct 31, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fix for an indentified bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spike time tiling coefficient produces values larger than 1
4 participants