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](https://private-user-images.githubusercontent.com/42555442/249113377-77fb8d43-cd6b-4e7e-bc97-46d5f86066b2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM0MjkwODQsIm5iZiI6MTcyMzQyODc4NCwicGF0aCI6Ii80MjU1NTQ0Mi8yNDkxMTMzNzctNzdmYjhkNDMtY2Q2Yi00ZTdlLWJjOTctNDZkNWY4NjA2NmIyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEyVDAyMTMwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc1NGViNWM1OWRkY2U1Yzc4YTdiOTQ1MDMwYWFhYjM2NWJkODUxNGEwNjYxNGI3YTQzY2U4MjE5NjE1YTU0MmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.V9nTfse3om3qGH00-RIwyqoiTJwzMR_nHukOyBHTw5A)
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](https://private-user-images.githubusercontent.com/42555442/249114354-2e254f18-bdb8-42c6-a783-9a998a41b227.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM0MjkwODQsIm5iZiI6MTcyMzQyODc4NCwicGF0aCI6Ii80MjU1NTQ0Mi8yNDkxMTQzNTQtMmUyNTRmMTgtYmRiOC00MmM2LWE3ODMtOWE5OThhNDFiMjI3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEyVDAyMTMwNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU3NzU3ZTMyYjQyOTUxNDRlNDlkMzM1YjA0OWRiOTJlYTYwMDk0Y2NjMWRmNGIyOTFmMzNhNDA4ZDhlOWE2ZWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Ny4uHHm8qQjRRZkwbKcnHOZbBycOIHRwUesZn97wphc)
Expected output
Spikes in the second plot would be shown with the lags, overlapping with the original spike trains in gray.