neuraltrain.models.preprocessor.OnTheFlyPreprocessor

class neuraltrain.models.preprocessor.OnTheFlyPreprocessor(*, ptp_threshold: float | None = None, scaler: float | Literal['RobustScaler', 'StandardScaler', 'QuantileAbsScaler', 'MinMaxScaler'] | None = None, scale_dim: int | list[int] | None = None, scaler_quantile: Annotated[float, Ge(ge=0.0), Le(le=1.0)] = 0.95, clamp: float | None = None, update_ch_pos: bool = True)[source][source]

Module to apply common preprocessing steps on-the-fly, inside an nn.Module.

Parameters:
  • ptp_threshold (float | None) – If provided, channels with a ptp higher are considered bad. If update_ch_pos is True, their positions will be set to common.INVALID_POS_VALUE, otherwise the amplitude of bad channels are replaced by 0.

  • scaler (float | Literal['RobustScaler', 'StandardScaler', 'QuantileAbsScaler', 'MinMaxScaler'] | None) – Scaling strategy to apply to the input. If provided as a float, the amplitude will be multiplied by this value. If “RobustScaler” or “StandardScaler”, the input data will be scaled along the dimensions specified by scale_dim. If “QuantileAbsScaler”, each channel is divided by the scaler_quantile-th percentile of its absolute value; this is the robust per-channel scaling used by the BIOT model (Yang et al., NeurIPS 2023). If “MinMaxScaler”, each channel is linearly rescaled to [-1, 1] across the time dimension (dim=-1); this is the per-window normalization used by BENDR (Kostas et al., Front. Hum. Neurosci. 2021).

  • scale_dim (int | list[int] | None) – Dimensions along which to apply scaling (see scaler). If None, scale along all dimensions.

  • scaler_quantile (float) – Quantile for "QuantileAbsScaler" mode (default 0.95, i.e. 95th percentile). Ignored when scaler is not "QuantileAbsScaler".

  • clamp (float | None) – If provided, clamp input to the range [-clamp, clamp].

  • update_ch_pos (bool) – If True, update channel positions of bad channels above ptp_threshold.