Wavelet Transform of CBGTC spike times

class analyseur.cbgtc.stats.wavelet.ContinuousWaveletTransform[source]

Bases: object

Continuous Wavelet Transform

Methods

Argument

smooth_signal()

scale_to_freq()

  • all_neurons_isi: Dictionary returned; see compute()

freq_window_to_scales()

  • all_inst_rates: Dictionary returned; see inst_rates()

  • all_times: 2nd tuple (Dictionary) returned; see compute()

  • binsz: [OPTIONAL] 0.01 (default)

compute_cwt_avg()

  • all_neurons_isi: Dictionary returned; see compute()

compute_cwt_sum()

  • all_neurons_isi: Dictionary returned; see compute()

Comments on Activity and Choices in Performing CWT

Activity

Description

Purpose

Signal Smoothing

converts binary spike trains to continuous signals

  • some smoothing can help visualize rhythmic spiking

  • over smoothing can obscure precise timing

scales

defines the frequencies analyzed

  • smaller scales for high frequencies and larger for lower frequencies

  • voices per ocatve ≜ number of scales between 2 frequencies (≜ octave)

  • higher voices per octave give smoother scalogram but increased computation

wavelet choice

determines trade-off between time and frequency resolution

  • Morlet (“cmorB-C”) for oscillation

  • Mexican hat (“mexh”) for transient spike detection


classmethod compute_cwt_avg(spiketimes_set, sampling_rate=None, window=None, sigma=None, scales=None, wavelet=None, neurons=None)[source]

Compute the Continuous Wavelet Transform as the average of the wavelet transform of the neurons in a population

Parameters:

spiketimes_set – Dictionary returned using get_spiketimes_superset()

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • sigma – standard deviation value, 2 [default]

  • wavelet“cmor1.5-1.0” [default], for possible options see pywt.cwt

  • scales – Tuple; (1, 128) [default]

Returns:

4-tuple

  • array of mean of coefficients of power spectral density

  • array of sample frequencies

  • list of neuron id’s

  • array of time


classmethod compute_cwt_sum(spiketimes_set, sampling_rate=None, window=None, sigma=None, scales=None, wavelet=None, neurons=None)[source]

Compute the Continuous Wavelet Transform on the sum of signals across neurons in a population.

Parameters:

spiketimes_set – Dictionary returned using get_spiketimes_superset()

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

  • sigma – standard deviation value, 2 [default]

  • wavelet

    ”cmor1.5-1.0” [default], for possible options see pywt.cwt

  • scales – Tuple; (1, 128) [default]

Returns:

4-tuple

  • array of mean of coefficients of power spectral density

  • array of sample frequencies

  • list of neuron id’s

  • array of time


static freq_window_to_scales(freq_window=None, voices_per_octave=None, wavelet=None, sampling_rate=None)[source]

Returns the array of scales between octaves given

Parameters:
  • freq_window – Tuple (min_freq, max_freq)

  • voices_per_octave – scalar

  • wavelet

    name of wavelet type available in pywt.cwt

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

Parameter

Description

Comment

frequency range

  • match signal’s expected content

  • 1-100 Hz (neuron spikes)

Voices Per Octave (VPO)

  • VPO ∝ frequency resolution

  • VPO ∝ 1/computational cost

  • 10-16 (general)

  • 32 (high precision analysis)

wavelet choice

  • time/frequency resolution trade-off

“cmorB-C” (good for neural data)

Scale is the dilation/compression factor applied to the wavelet.
  • Scale vs Frequency
    • Scales defines the frequencies in the wavelet transform analysis.

    • \(s_a < s_b \overset{\frown}{=} f_a > f_b\) where scale \(s_x\) corresponds to frequency \(f_x\)

  • Scale vs Voices/Octave
    • Voices per octave controls the number of scales between consecutive frequencies (≜ octave)

    • In other words, the number of scales between octaves is the voices per octave


static scale_to_freq(scale=None, wavelet=None, sampling_rate=None)[source]

Converts a scale value to its corresponding frequency value.

Parameters:
  • scale – a scalar

  • wavelet

    name of wavelet type available in pywt.cwt

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

Returns:

a frequency value

Scale is the dilation/compression factor applied to the wavelet.

Scale vs Frequency

Scale vs Voices/Octave

Scales defines the frequencies in the wavelet transform analysis.

Voices per octave controls the number of scales between consecutive frequencies (≜ octave)

\(s_a < s_b \overset{\frown}{=} f_a > f_b\) where scale \(s_x\) corresponds to frequency \(f_x\)

In other words, the number of scales between octaves is the voices per octave


static smooth_signal(spiketimes_set, sampling_rate=None, window=None, neurons=None, sigma=None)[source]

This method takes the spike times and converts it into respective binary spike trains which in turn is smoothened. The returned smoothened signal can be used to create a firing rate signal.

Parameters:

spiketimes_set – Dictionary returned using get_spiketimes_superset()

or using get_spiketimes_subset()

Parameters:
  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

  • sigma – standard deviation amount from a mean; 2 [default]

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

Returns:

4-tuple

  • smooth signal

  • list of neuron id’s

  • time axis

  • sampling period

Smoothening is done by Gaussian filtering

  • each binary spike (= 1) is placed into a Gaussian-shaped bump

  • the Gaussian filter replaces each point (spike = 1) with a Gaussian distribution centered at that position
    • the overall result is many Gaussian distributions (each per point when spike = 1)

    • where spikes are close the Gaussians overlap

  • sum together the overlaping Gaussians (i.e convolution)
    • this represents the “dense estimate” of the spikes, i.e, smoothened curve

Formula

Definitions

Interpretation

total neurons, \(n_{nuc}\)

total number of neurons in the Nucleus

neuron index, \(i\)

i-th neuron in the pool of \(n_{Nuc}\) neurons

total spikes, \(n_{spk}^{(i)}\)

total number of spikes (spike times) by i-th neuron

\(\vec{S}^{(i)}\)

array of spike times of i-th neuron

\(S = \left\{\vec{S}^{(i)} \mid \forall{i \in [1, n_{nuc}]} \right\}\)

set of spike times of all neurons

\(\vec{B}^{(i)} = \left[\sum_{k=1}^{n_{spk}^{(i)}} \delta[t - t_k]\right]_{\forall{t} \in [t_1, t_{n_{spk}^{(i)}}]}\)

binary spike train of i-th neuron for spike times \(\vec{S}^{(i)}\) at \(t_1, t_2, ..., t_{n_{spk}^{(i)}}\)

\(B = \left\{\vec{B}^{(i)} \mid \forall{i \in [1, n_{nuc}]} \right\}\)

set of spike trains of all neurons

\(\vec{G} = \left[\frac{1}{\sigma \sqrt{2\pi}}e^{-\frac{k^2}{2\sigma^2}}\right]_{\forall{k}}\)

Gaussian kernel

Then, the smoothened signal for i-th neuron is

\[ \begin{align}\begin{aligned}\vec{M}^{(i)} &= \vec{B}^{(i)} \ast \vec{G} \\ &\triangleq \left[ \sum_{k=1}^{n_{spk}^{(i)}} \left(B^{(i)}[t_k] \cdot G[t-t_k]\right) \right]_{\forall{t} \in [t_1, t_{n_{spk}^{(i)}}]} \\ &= \left[ \sum_{k=1}^{n_{spk}^{(i)}} G[t-t_k] \right]_{\forall{t} \in [t_1, t_{n_{spk}^{(i)}}]}\end{aligned}\end{align} \]

Note that the last line is due to the fact that only non-zero \(B^{(i)}[t_k]\) occurs at spike positions.