outlier_detection.OutlierDetectionMixin#
- class autoclean.mixins.signal_processing.outlier_detection.OutlierDetectionMixin[source]#
Mixin class providing functionality for outlier detection in epochs.
This mixin provides methods for detecting and removing outlier epochs based on statistical measures. It implements statistical approaches based on the FASTER algorithm to detect outliers across multiple dimensions.
The detection process involves calculating various statistical measures for each epoch (amplitude range, variance, mean gradient) and identifying epochs that deviate significantly from the distribution of these measures across all epochs. Epochs identified as outliers are marked as bad and can be excluded from further processing.
The mixin respects configuration settings from the autoclean_config.yaml file, allowing users to customize the outlier detection threshold and other parameters.
- detect_outlier_epochs(epochs=None, threshold=3.0)[source]#
Detect and remove outlier epochs based on statistical measures.
This method identifies and marks epochs that are statistical outliers based on multiple measures, following the principles of the FASTER algorithm. It calculates z-scores for various epoch properties and marks epochs as bad if they exceed the specified threshold in any measure.
The statistical measures used for outlier detection include: * Mean amplitude across channels * Variance across channels * Maximum amplitude difference (range) * Mean gradient (rate of change)
This implementation is based on the Python implementation of the FASTER algorithm from Marijn van Vliet (https://gist.github.com/wmvanvliet/d883c3fe1402c7ced6fc).
- Parameters:
- epochs
mne.Epochs
,Optional
The epochs object to prepare for ICA. If None, uses self.epochs.
- threshold
float
,Optional
The z-score threshold for outlier detection (default: 3.0).
- epochs
- Returns:
- epochs_clean
instance
ofmne.Epochs
The epochs object with outlier epochs marked as bad
- epochs_clean
Examples
>>> # Detect outlier epochs with default parameters >>> self.detect_outlier_epochs() #Modifies self.epochs
>>> # Detect outlier epochs with a stricter threshold >>> self.detect_outlier_epochs(threshold=2.5) #Modifies self.epochs
>>> # Check how many epochs were marked as bad >>> n_good = len(self.epochs) >>> n_bad = len(self.epochs.drop_log) - n_good >>> print(f"Marked {n_bad} epochs as bad out of {n_good + n_bad} total")