SPADE Tutorial¶
[1]:
import numpy as np
import quantities as pq
import neo
import elephant
import viziphant
np.random.seed(4542)
Mining patterns with SPADE¶
In the next step, we run the spade()
method to extract the synchronous patterns. We choose 1 ms as the time scale for discretization of the patterns, and specify a window length of 1 bin (meaning, we search for synchronous patterns only). Also, we concentrate on patterns that involve at least 3 spikes, therefore significantly accelerating the search by ignoring frequent events of order 2. To test for the significance of patterns, we set to repeat the pattern detection on 100 spike dither
surrogates of the original data, creating by dithing spike up to 5 ms in time. For the final step of pattern set reduction (psr), we use the standard parameter set [0, 0, 0]
.
[4]:
patterns = elephant.spade.spade(
spiketrains=spiketrains, binsize=1*pq.ms, winlen=1, min_spikes=3,
n_surr=100,dither=5*pq.ms,
psr_param=[0,0,0],
output_format='patterns')['patterns']
Time for data mining: 0.10827088356018066
Time for pvalue spectrum computation: 16.29210901260376
The output patterns
of the method contains information on the found patterns. In this case, we retrieve the pattern we put into the data: a pattern involving the first 10 neurons (IDs 0 to 9), occuring 5 times.
[5]:
patterns
[5]:
[{'itemset': (3, 4, 7, 9, 0, 2, 5, 6, 8, 1),
'windows_ids': (369, 1223, 4178, 8498, 9038),
'neurons': [3, 4, 7, 9, 0, 2, 5, 6, 8, 1],
'lags': array([0., 0., 0., 0., 0., 0., 0., 0., 0.]) * ms,
'times': array([ 369., 1223., 4178., 8498., 9038.]) * ms,
'signature': (10, 5),
'pvalue': 0.0}]
Lastly, we visualize the found patterns using the function plot_patterns()
of the viziphant library. Marked in red are the patterns of order ten injected into the data.
[6]:
viziphant.patterns.plot_patterns(spiketrains, patterns)
[6]:
<Axes: xlabel='Time (s)', ylabel='Neuron'>