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: object

Fit-offline / predict-online single-trial decoder for MNE-RT sessions.

Wraps a scikit-learn sklearn.pipeline.Pipeline built from MNE’s decoding primitives so that a classifier trained on labelled calibration epochs can be queried once per real-time acquisition window, wired into record_main() via set_decoder() as the "decode" modality (see mne_rt.modalities).

Parameters:
infomne.Info

Info describing the channels the decoder will be fit and queried on. Only used when spatial_filter="scaler" (passed to mne.decoding.Scaler for channel-type-aware standardisation).

estimatorsklearn-compatible classifier, default None

Final pipeline step. Defaults to sklearn.linear_model.LogisticRegression() when None. Must implement fit/predict; predict_proba is additionally required for predict_proba().

spatial_filter“csp” | “scaler”, default “csp”

Feature-extraction step applied before estimator:

  • "csp"mne.decoding.CSP, log-variance of the n_components most discriminative spatial filters. Well suited to oscillatory/motor-imagery decoding; requires at least two classes.

  • "scaler"mne.decoding.Scaler (channel-type-aware standardisation) followed by mne.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_componentsint, 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 when spatial_filter="scaler".

Attributes:
pipelinesklearn.pipeline.Pipeline

The assembled, not-yet-fit (until fit() is called) pipeline.

classes_ndarray | None

Class labels seen during fit(); None before fitting.

n_channels_int | None

Number of channels seen during fit(); None before fitting.

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 new RTDecode instance 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 X passed to fit(). When used as the "decode" modality, this means record_main()’s picks must resolve to the same channel selection the decoder was fit on — a channel-count mismatch is caught at record_main() start, but a same-count reordering is not detected and will silently degrade predictions.

The "decode" modality always reports predict_proba() (a continuous class probability), not predict() (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 in record_main(). Use predict() 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

fitted

Whether fit() has been called.

property fitted: bool#

Whether fit() has been called.

fit(X: ndarray, y: ndarray, verbose: Any | None = None) RTDecode[source]#

Fit the pipeline on labelled calibration epochs.

Parameters:
Xarray, shape (n_epochs, n_channels, n_times)

Calibration epochs.

yarray, shape (n_epochs,)

Class label per epoch.

verbosebool | str | None, default None

Control logging verbosity for this call, e.g. False to silence CSP’s per-class covariance-estimation messages. See mne_rt.set_log_level().

Returns:
selfinstance of RTDecode

The fitted decoder, for chaining.

predict(window: ndarray) Any[source]#

Predict the class label for a single window.

Parameters:
windowarray, shape (n_channels, n_times)

One acquisition window, e.g. from stream.get_data(winsize)[0].

Returns:
labelscalar

The predicted class label (same dtype as the y passed to fit()).

predict_proba(window: ndarray) ndarray[source]#

Predict per-class probabilities for a single window.

Parameters:
windowarray, shape (n_channels, n_times)

One acquisition window, e.g. from stream.get_data(winsize)[0].

Returns:
probaarray, shape (n_classes,)

Class probabilities in classes_ order.