ncrf.RegressionData

class ncrf.RegressionData(meg, stim, design, samples=None, forward=None)

Dataset for NCRF fitting: M/EEG segments, their predictors, and the design.

Use from_data() to derive the design, including its normalization, from the data itself.

Warning

The meg and stim NDVars are referenced rather than copied, and the arrays are built from them when first accessed. Do not modify the NDVars in place while the dataset, or one derived from it, is in use: arrays built afterwards would reflect the change, but the normalization recorded on the design would not.

Parameters:
  • meg (list[eelbrain._data_obj.NDVar]) – M/EEG segments, each an NDVar with sensor and time dimensions. All segments share the sensor dimension and the time axis length and step.

  • stim (list[collections.abc.Sequence[eelbrain._data_obj.NDVar]]) – Predictors, one list per segment with one NDVar per predictor variable. Each predictor may be 1-D over time or carry one feature dimension before time, and shares the time axis of its segment’s meg.

  • design (ncrf._trf_design.TRFDesign) – Design describing the predictors, the TRF lags and basis, and the normalization to apply to the covariates.

  • samples (numpy._typing._array_like.NDArray[numpy.int64] | None) – Indices of the time samples the dataset covers, into the time axis of meg; None for all samples. from_data() drops samples whose lag window extends beyond the stimulus, and timeslice() selects cross-validation folds.

  • forward (ncrf._forward.ForwardModel | None) – Forward model whose whitening filter is applied to the responses, or None for raw data. Set by whiten(); whitened data thus carries the forward model it is fit with, and recording it lets whiten() distinguish a no-op (same filter) from an error (different filter).

Notes

The stored fields are the raw inputs. The arrays the solver consumes, responses and covariates, are derived from them on demand according to design, which fixes the TRF lags, the Gaussian basis the predictors are projected onto, and the centering and scaling of the covariates.

Methods

from_data(meg, stim, tstart, tstop[, ...])

Construct a dataset from MEG and stimulus NDVars, deriving the design from them.

normalize(design)

Return a dataset whose covariates are centered and scaled.

timeslice(idx)

Return a new dataset restricted to a subset of this dataset's samples.

whiten(forward)

Return a dataset whose responses are whitened with forward.

Attributes

EtE

Per-segment E.T @ E covariate Gram matrices.

bE

Per-segment B @ E cross-product matrices.

bbt

Per-segment B @ B.T matrices of the responses.

covariates

Covariate matrices for the solver, one per segment, each shaped (n_samples, n_coefficients).

forward

is_whitened

Whether the responses are transformed by a whitening filter (see forward).

norm_factor

sqrt(n_samples) that responses and covariates are divided by.

responses

M/EEG arrays for the solver, one per segment, each shaped (n_sensors, n_samples).

samples

sensor_dim

Sensor dimension shared by all MEG segments.

meg

stim

design