mne_rt.RTDecode#
- class mne_rt.RTDecode(info: Any | None = None, estimator: Any | None = None, spatial_filter: str = 'csp', n_components: int = 4, scalings: Any = 'mean')[source]#
Bases:
objectFit-offline / predict-online single-trial decoder for MNE-RT sessions.
Wraps a scikit-learn
sklearn.pipeline.Pipelinebuilt from MNE’s decoding primitives so that a classifier trained on labelled calibration epochs can be queried once per real-time acquisition window, wired intorecord_main()viaset_decoder()as the"decode"modality (seemne_rt.modalities).- Parameters:
- info
mne.Info Info describing the channels the decoder will be fit and queried on. Only used when
spatial_filter="scaler"(passed tomne.decoding.Scalerfor channel-type-aware standardisation).- estimatorsklearn-compatible
classifier, defaultNone Final pipeline step. Defaults to
sklearn.linear_model.LogisticRegression()whenNone. Must implementfit/predict;predict_probais additionally required forpredict_proba().- spatial_filter“csp” | “scaler”, default “csp”
Feature-extraction step applied before estimator:
"csp"—mne.decoding.CSP, log-variance of then_componentsmost discriminative spatial filters. Well suited to oscillatory/motor-imagery decoding; requires at least two classes."scaler"—mne.decoding.Scaler(channel-type-aware standardisation) followed bymne.decoding.Vectorizer(flattens to(n_epochs, n_channels * n_times)). A simpler, filter-agnostic alternative when CSP’s oscillatory-power assumption doesn’t fit the decoding target (e.g. ERP decoding).
- n_components
int, default 4 Number of CSP spatial filters. Only used when
spatial_filter="csp"; must not exceed the number of channels.- scalings“mean” | “median” |
dict, default “mean” Passed to
mne.decoding.Scaler. Only used whenspatial_filter="scaler".
- info
- Attributes:
Notes
As with
LearnedCombiner, fitting happens offline against a full calibration recording — there is no incremental/online update during a live session. Re-fit and swap in a newRTDecodeinstance between sessions instead.The fitted pipeline is sensitive to channel count and order: query windows must present the same channels, in the same order, as the
Xpassed tofit(). When used as the"decode"modality, this meansrecord_main()’spicksmust resolve to the same channel selection the decoder was fit on — a channel-count mismatch is caught atrecord_main()start, but a same-count reordering is not detected and will silently degrade predictions.The
"decode"modality always reportspredict_proba()(a continuous class probability), notpredict()(a discrete label) — unlike the other NF modalities’ outputs, a discrete label is not meaningful after the EMA smoothing / z-scoring every modality’s value passes through inrecord_main(). Usepredict()directly for offline/standalone decoding outside a live session.Examples
>>> import numpy as np >>> from mne import create_info >>> from mne_rt import RTDecode >>> info = create_info(["C3", "Cz", "C4"], sfreq=256.0, ch_types="eeg") >>> rng = np.random.default_rng(0) >>> X = rng.standard_normal((20, 3, 256)) >>> y = np.array([0, 1] * 10) >>> decoder = RTDecode(info=info, spatial_filter="csp", n_components=2) >>> _ = decoder.fit(X, y) >>> proba = decoder.predict_proba(rng.standard_normal((3, 256))) >>> proba.shape (2,)
- __init__(info: Any | None = None, estimator: Any | None = None, spatial_filter: str = 'csp', n_components: int = 4, scalings: Any = 'mean') None[source]#
Methods
__init__([info, estimator, spatial_filter, ...])fit(X, y[, verbose])Fit the pipeline on labelled calibration epochs.
predict(window)Predict the class label for a single window.
predict_proba(window)Predict per-class probabilities for a single window.
Attributes
- fit(X: ndarray, y: ndarray, verbose: Any | None = None) RTDecode[source]#
Fit the pipeline on labelled calibration epochs.
- Parameters:
- Returns:
- self
instanceofRTDecode The fitted decoder, for chaining.
- self