medusa.local_activation package
Submodules
medusa.local_activation.nonlinear_parameters module
- medusa.local_activation.nonlinear_parameters.central_tendency_measure(signal, r)[source]
This method implements the central tendency measure (CTM). This parameter is useful to quantify the variability of a signal. It is based on calculating the second-order differences diagram of the time series and then counting the points within a radius “r”. CTM assigns higher values to less variable signals
References
Cohen, M. E., Hudson, D. L., & Deedwania, P. C. (1996). Applying continuous chaotic modeling to cardiac signal analysis. IEEE Engineering in Medicine and Biology Magazine, 15(5), 97-102.
- Parameters
signal (numpy.ndarray) – Signal with shape [n_epochs, n_samples, n_channels].
r (double) – Radius used to compute the CTM.
- Returns
ctm – CTM values for each channel in “signal”. [n_epochs, n_channels].
- Return type
numpy.ndarray
- medusa.local_activation.nonlinear_parameters.lempelziv_complexity(signal)[source]
- Calculate the signal binarisation and the Lempel-Ziv’s complexity.
This function takes advantage of its implementation in C to achieve a high performance.
- Parameters
signal (numpy.ndarray) – MEEG Signal [n_epochs, n_samples, n_channels]
- Returns
lz_result – Lempel-Ziv values for each epoch and each channel. [n_epochs, n_channels].
- Return type
numpy.ndarray
- medusa.local_activation.nonlinear_parameters.multiscale_entropy(signal, max_scale, m, r)[source]
This method implements the Multiscale Entropy (MSE). MSE is a measurement of complexity which measures the irregularity of a signal over multiple time-scales. This is accomplished through estimation of the Sample Entropy (SampEn) on coarse-grained versions of the original signal. As a result of the these calculations, MSE curves are obtained and can be used to compare the complexity of time-series. The MSE curve whose entropy values are higher for the most of time-scales is considered more complex.
References
Costa, M., Goldberger, A. L., & Peng, C. K. (2005). Multiscale entropy analysis of biological signals, Physical review E, 71(2), 021906.
- Parameters
signal (numpy.ndarray) – MEEG Signal. [n_epochs, n_samples, n_channels].
max_scale (int) – Maximum scale value
m (int) – Sequence length
r (float) – Tolerance
- Returns
mse_result – SampEn values for each scale for each channel in “signal” . [n_epochs, max_scale, n_channels].
- Return type
numpy.ndarray
- medusa.local_activation.nonlinear_parameters.multiscale_lempelziv_complexity(signal, W)[source]
Calculate the multiscale signal binarisation and the Multiscale Lempel-Ziv’s complexity.
References
Ibáñez-Molina, A. J., Iglesias-Parro, S., Soriano, M. F., & Aznarte, J. I, Multiscale Lempel-Ziv complexity for EEG measures. Clinical Neurophysiology, (2015), 126(3), 541–548.
- Parameters
signal (numpy.ndarray) – MEEG Signal [n_epochs, n_samples, n_channels]
W (list or numpy 1D array) – Set of window length to consider at multiscale binarisation stage. Values must be odd.
- Returns
result – Matrix of results with shape [n_epochs, n_window_length, n_channels]
- Return type
numpy.ndarray
- medusa.local_activation.nonlinear_parameters.sample_entropy(signal, m, r, dist_type='chebyshev')[source]
This method implements the sample entropy (SampEn). SampEn is an irregularity measure that assigns higher values to more irregular time sequences. It has two tuning parameters: the sequence length (m) and the tolerance (r)
Notes: IF A = 0 or B = 0, SamEn would return an infinite value. However, the lowest non-zero conditional probability that SampEn should report is A/B = 2/[(N-m-1)*(N-m)]. SampEn has the following limits:
Lower bound: 0
Upper bound : log(N-m) + log(N-m-1) - log(2)
References
Richman, J. S., & Moorman, J. R. (2000). Physiological time-series analysis using approximate entropy and sample entropy. American Journal of Physiology-Heart and Circulatory Physiology.
- Parameters
signal (numpy.ndarray) – Signal with shape [n_epochs, n_samples, n_channels].
m (int) – Sequence length
r (float) – Tolerance
dist_type (string) – Distance metric
- Returns
sampen – SampEn value. [n_epochs, n_channels]
- Return type
numpy.ndarray
medusa.local_activation.spectral_parameteres module
- medusa.local_activation.spectral_parameteres.absolute_band_power(psd, fs, target_band)[source]
This method computes the absolute band power of the signal in the given band using the power spectral density (PSD).
- Parameters
psd (numpy array) – PSD of the signal with shape [n_epochs, n_samples, n_channels]. Some of these dimensions may not exist in advance. In these case, create new axis using np.newaxis. E.g., non-epoched single-channel psd with shape [n_samples] can be passed to this function with psd[numpy.newaxis, …, numpy.newaxis]. Afterwards, you may use numpy.squeeze to eliminate those axes.
fs (int) – Sampling frequency of the signal
target_band (numpy 2D array) – Frequency band where to calculate the power in Hz. E.g., [8, 13]
- Returns
powers – RP value for each band, epoch and channel. [n_bands, n_epochs, n_channels]
- Return type
numpy 2D array
- medusa.local_activation.spectral_parameteres.median_frequency(psd, fs, target_band=(1, 70))[source]
This method computes the median frequency (MF) of the signal in the given band.
- Parameters
psd (numpy array) – PSD of the signal with shape [n_epochs, n_samples, n_channels]. Some of these dimensions may not exist in advance. In these case, create new axis using np.newaxis. E.g., non-epoched single-channel psd with shape [n_samples] can be passed to this function with psd[numpy.newaxis, …, numpy.newaxis]. Afterwards, you may use numpy.squeeze to eliminate those axes.
fs (int) – Sampling frequency of the signal
target_band (numpy array) – Frequency band where the MF will be computed. [b1_start, b1_end]. Default [1, 70].
- Returns
median_freqs – MF value for each epoch and channel with shape [n_epochs x n_channels].
- Return type
numpy 2D array
- medusa.local_activation.spectral_parameteres.relative_band_power(psd, fs, target_band, baseline_band=None)[source]
This method computes the relative band power of the signal in the given band using the power spectral density (PSD). Do not use this method on PSDs that are already normalized! In this case, use absolute_band_power function.
- Parameters
psd (numpy array) – PSD with shape [n_epochs, n_samples, n_channels]. Some of these dimensions may not exist in advance. In these case, create new axis using np.newaxis. E.g., non-epoched single-channel psd with shape [n_samples] can be passed to this function with psd[numpy.newaxis, …, numpy.newaxis]. Afterwards, you may use numpy.squeeze to eliminate those axes.
fs (int) – Sampling frequency of the signal
target_band (numpy nd array) – Frequency band where to calculate the power in Hz. E.g., [8, 13]
baseline_band (numpy nd array or None) – Frequency band where used as baseline in Hz. Leave to None to normalize by the whole spectrum, which is preferred in most cases
- Returns
powers – RP value for each band, epoch and channel. [n_bands, n_epochs, n_channels]
- Return type
numpy 2D array
- medusa.local_activation.spectral_parameteres.shannon_spectral_entropy(psd, fs, target_band=(1, 70))[source]
- Computes the Shannon spectral entropy of the power spectral density (PSD)
in the given band.
- Parameters
- psdnumpy array
PSD of the signal with shape [n_epochs, n_samples, n_channels]. Some of these dimensions may not exist in advance. In these case, create new axis using np.newaxis. E.g., non-epoched single-channel psd with shape [n_samples] can be passed to this function with psd[numpy.newaxis, …, numpy.newaxis]. Afterwards, you may use numpy.squeeze to eliminate those axes.
- fsint
Sampling frequency of the signal
- target_bandnumpy array
Frequency band where the SE will be computed. [b1_start, b1_end]. Default [1, 70]
- sample_entropynumpy 2D array
SE value for each epoch and channel with shape [n_epochs x n_channels].
medusa.local_activation.statistics module
- medusa.local_activation.statistics.signed_r2(class1, class2, signed=True, axis=0)[source]
This function computes the basic form of the squared point biserial correlation coefficient (r2-value).
- Parameters
class1 (list or numpy.ndarray) – Data that belongs to the first class
class1 – Data that belongs to the second class
signed (bool (Optional, default=True)) – Controls if the sign should be mantained.
axis (int (Optional, default=0)) – Dimension along which the r2-value is computed. Therefore, if class1 and class2 has dimensions of [observations x samples] and dim=0, the r2-value will have dimensions [1 x samples].
- Returns
r2 – (Signed) r2-value.
- Return type
numpy.ndarray