timeflux_rasr.estimators.rasr


rasr

timeflux_rasr.estimators.rasr.logger
class timeflux_rasr.estimators.rasr.RASR(estimator='scm', rejection_cutoff=3.0, max_dimension=0.66, **kwargs)[source]

Bases: sklearn.base.BaseEstimator, sklearn.base.TransformerMixin

RASR Implements this (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6499032/) paper. Matlab code from the author here: https://github.com/s4rify/rASRMatlab

Parameters
  • estimator (string (default: 'scm')) – covariance matrix estimator. For regularization consider ‘lwf’ or ‘oas’ For a complete list of estimator, see pyriemann.utils.covariance

  • rejection_cutoff (float (default: 3.0)) – Standard deviation cutoff for rejection. Data portions whose variance is larger than this threshold relative to the calibration data are considered missing data and will be removed. The most aggressive value that can be used without losing too much EEG is 2.5. A quite conservative value would be 5.

  • max_dimension (float (default: 0.66)) – Maximum dimensionality of artifacts to remove. Up to this many dimensions (or up to this fraction of dimensions) can be removed for a given data segment. If the algorithm needs to tolerate extreme artifacts a higher value than the default may be used (the maximum fraction is 1.0).

  • max_dropout_fraction (float (default: 0.1)) – Maximum fraction of windows that can be subject to signal dropouts (e.g., sensor unplugged), used for threshold estimation in _fit_eeg_distribution.

  • min_clean_fraction (float (default: 0.25)) – Minimum fraction of windows that need to be clean, used for threshold estimation in _fit_eeg_distribution.

  • quantile_range – additional parameters passed to _fit_eeg_distribution (should be kept as default in general).

  • step_sizes – additional parameters passed to _fit_eeg_distribution (should be kept as default in general).

  • beta_range – additional parameters passed to _fit_eeg_distribution (should be kept as default in general).

Variables
  • Ne (int) – The dimension managed by the fitted RASR, e.g. number of electrodes.

  • mixing (ndarray, shape(n_chan, n_chan)) – Mixing matrix computed from geometric median covariance matrix U such as: \(mixing = M: M*M = U\)

  • threshold (ndarray, shape(n_chan,)) – Threshold operator used to find the subspace dimension such as: \(threshold = T: X_{clean} = m ( V^T_{clean} M )^+ V^T X\)

Init.

fit(self, X, y=None)[source]
Parameters
  • X (ndarray, shape (n_trials, n_samples, n_channels)) – Training data, already filtered.

  • y (ndarray, shape (n_trials,) | None, optional) – labels corresponding to each trial, not used (mentioned for sklearn comp)

Returns

self – the fitted RASR estimator.

Return type

RASR instance.

transform(self, X)[source]

Clean signal :param X: Data to clean, already filtered :type X: ndarray, shape (n_trials, n_samples, n_channels)

Returns

Xclean – Cleaned data

Return type

ndarray, shape (n_trials, n_samples, n_channels)

fit_transform(self, X, y=None)[source]
Parameters
  • X (ndarray, shape (n_trials, n_samples, n_channels)) – Training data.

  • y (ndarray, shape (n_trials,) | None, optional) – labels corresponding to each trial, not used (mentioned for sklearn comp)

Returns

X – Cleaned data

Return type

ndarray, shape (n_trials, n_samples, n_channels)