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

Function to plot patterns from SPADE does not consider lags #70

Open
kohlerca opened this issue Jun 27, 2023 · 0 comments
Open

Function to plot patterns from SPADE does not consider lags #70

kohlerca opened this issue Jun 27, 2023 · 0 comments

Comments

@kohlerca
Copy link
Contributor

The plot_patterns function apparently only works for synchronous patterns, but not when there is a lag between the spikes.

The code below illustrates that

import numpy as np
import quantities as pq
import neo
from elephant.spade import spade
from elephant.spike_train_generation import homogeneous_poisson_process
from copy import deepcopy
import viziphant

# Generate two types of pattern: one synchronous and other with lags

np.random.seed(123)
sync_spiketrains = [homogeneous_poisson_process(rate=3*pq.Hz, t_stop=1*pq.s) for _ in range(50)]
lag_spiketrains = deepcopy(sync_spiketrains)

pattern_times = pq.Quantity([212, 574, 876], units=pq.ms)

pattern_neurons = []
pattern = neo.SpikeTrain(pattern_times, t_stop=1*pq.s)
for st in sync_spiketrains[:4]:
    pattern_st = st.merge(pattern)
    pattern_neurons.append(pattern_st)
sync_spiketrains[:4] = pattern_neurons

pattern_neurons = []
for idx, st in enumerate(lag_spiketrains[:4]):
    pattern = neo.SpikeTrain(pattern_times + idx * (10 * pq.ms), t_stop=1*pq.s)
    pattern_st = st.merge(pattern)
    pattern_neurons.append(pattern_st)
lag_spiketrains[:4] = pattern_neurons

Run SPADE using the synchronous patterns and plot:

sync_patterns = spade(sync_spiketrains, bin_size=5*pq.ms, winlen=10, min_spikes=3,
    n_surr=100, dither=5*pq.ms, psr_param=[0,0,0], alpha=0.05)

print(sync_patterns['patterns'])
viziphant.patterns.plot_patterns(sync_spiketrains, sync_patterns['patterns'])

Output:

[{'itemset': (20, 0, 10, 30),
'windows_ids': (42, 114, 175),
'neurons': [2, 0, 1, 3],
'lags': array([0., 0., 0.]) * ms,
'times': array([210., 570., 875.]) * ms,
'signature': (4, 3),
'pvalue': 0.01}]

image

Run SPADE using the pattern with lags and plot:

lag_patterns = spade(lag_spiketrains, bin_size=5*pq.ms, winlen=10, min_spikes=3,
    n_surr=100, dither=5*pq.ms, psr_param=[0,0,0], alpha=0.05)
print(lag_patterns['patterns'])
viziphant.patterns.plot_patterns(lag_spiketrains, lag_patterns['patterns'])

Output:

[{'itemset': (24, 36, 12, 0),
'windows_ids': (42, 114, 175),
'neurons': [0, 1, 2, 3],
'lags': array([10., 20., 30.]) * ms,
'times': array([210., 570., 875.]) * ms,
'signature': (4, 3),
'pvalue': 0.0}]

image

Expected output

Spikes in the second plot would be shown with the lags, overlapping with the original spike trains in gray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant