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

Spike time tiling coefficient produces values larger than 1 #563

Closed
Celine-Serry opened this issue May 12, 2023 · 10 comments · Fixed by #564
Closed

Spike time tiling coefficient produces values larger than 1 #563

Celine-Serry opened this issue May 12, 2023 · 10 comments · Fixed by #564
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@Celine-Serry
Copy link

Hi,

Im working with the spike time tiling coefficient and have noticed that some values are larger than 1, while I thought the maximum value was 1. For example:
spiketrain E7:
array([ 1678. , 23786.3, 34641.8, 71520.7, 73606.9, 78383.3,
97387.9, 144313.4, 4607.6, 19275.1, 152894.2, 44240.1])

spiketrain E3:
array([ 1678. , 23786.3, 34641.8, 71520.7, 73606.9, 78383.3,
97387.9, 144313.4, 4607.6, 19275.1, 152894.2, 44240.1])

result in an STTC of 1.063003420467317

While spiketrain E8
array([ 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])

spiketrain B3
array([ 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])

Are less synchronous, but have an STTC of 2.2794178907759863, while I thought the maximum value would be 1, suggesting perfect synchronicity?

I calculated the STTC as: sttc = spike_time_tiling_coefficient(spiketrain1, spiketrain2, dt), with dt being 0.10 * pq.s. I also I made sure I used Neo in the right way to make the spike trains.

Is it possible that there is a bug in the code for calculating the spike time tiling coefficient?

@Moritz-Alexander-Kern
Copy link
Member

Hey @Celine-075 ,
thanks for reaching out to us.

I've created to the following minimal example to reproduce this, I get the results:

  • STTC for E7 and E3: 1.152482370309056
  • STTC for E8 and B3: 2.2166419047619055
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))
# result: 1.152482370309056


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))
# result: 2.2166419047619055

Which seems very close to what you get, did I reproduce this correctly?

@Celine-Serry
Copy link
Author

Celine-Serry commented May 12, 2023 via email

@Moritz-Alexander-Kern
Copy link
Member

Hey @Celine-075 ,

A reworked version of the code is proposed in PR #564 .

The results I get now are:

  • STTC for E7 and E3: 1.0
  • STTC for E8 and B3: -0.02

You can test this version of the code by installing:

pip install git+https://github.com/INM-6/elephant.git@fix/sttc

Then run your code and see if the results you obtain are within [-1 1].
I agree the values should be between -1 and 1.

@Moritz-Alexander-Kern Moritz-Alexander-Kern added the bug Indicates an unexpected problem or unintended behavior label May 12, 2023
@Celine-Serry
Copy link
Author

Celine-Serry commented May 12, 2023 via email

@Celine-Serry
Copy link
Author

Between E7 and E3 I also get 1.0 now, but for E8 and B3 I get 120.83066666666667

@Moritz-Alexander-Kern
Copy link
Member

Moritz-Alexander-Kern commented May 12, 2023

Hey @Celine-075 ,
I ran the example in the following environment using those versions of neo, numpy and quantities: (Python 3.10)

Package     Version  
--------------- -------- -----------------------------
elephant        0.13.0b1 @ branch fix/sttc
Jinja2          3.1.2
neo             0.12.0
numpy           1.24.3
quantities      0.14.1

This time I adjusted t_stop to 300 000 ms.
Now I get:

  • STTC for E7 and E3: 1.0
  • STTC for E8 and B3: -0.014

@Celine-Serry
Copy link
Author

Celine-Serry commented May 13, 2023 via email

@Celine-Serry
Copy link
Author

I've updated to the same versions as you showed, but unfortunately I still get a very large value (120.83066666666667). Ive noticed my spiketimes were not sorted so checked if that could be the problem, but that resulted in an even larger number: (645.9386666666666).

@Moritz-Alexander-Kern
Copy link
Member

Hey @Celine-075 ,

I used the following example to check the difference between using sorted and unsorted spiketimes:
Using the original implementation from elephant v0.12.0, not the fixed one I provided here

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("results obtained with unsorted spiketrains:")
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))

print("results obtained with sorted spiketrains:")
spiketrain_E7.sort()
spiketrain_E3.sort()
spiketrain_E8.sort()
spiketrain_B3.sort()
print(spike_time_tiling_coefficient(spiketrain_E7, spiketrain_E3, dt=0.10 * pq.s))
print(spike_time_tiling_coefficient(spiketrain_E8, spiketrain_B3, dt=0.10 * pq.s))

The results I obtain are:

results obtained with unsorted spiketrains:
1.152482370309056
2.2166419047619055
results obtained with sorted spiketrains:
1.0
-0.019828095238095245

Maybe you get correct results if you use sorted spiketimes with the original implementation?

@Celine-Serry
Copy link
Author

Yes I did sort the spiketrains, however, it produced even larger numbers after I did that. I'm also not sure why I dont obtain the same results while running the same versions of the packages ..

Moritz-Alexander-Kern pushed a commit to INM-6/elephant that referenced this issue May 23, 2023
Moritz-Alexander-Kern added a commit that referenced this issue Oct 31, 2023
…alidation test (#564)

* refactor run_P
* refactor run_T
* add checks for t_start and t_stop in run_t
* add input checks and unittests
* add regression test for Issue #563
* add validation tests
* add check if spike times are sorted, if not sort the spikes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants