pyeeg.models.TRFEstimator.fit

TRFEstimator.fit(X, y, lagged=False, drop=True, feat_names=(), rotations=(), weights=None, cache_lagged=None)

Fit the TRF model.

Parameters:
  • X (ndarray (nsamples x nfeats)) – Array of features (time-lagged or not, if it is, then second dim’s shape should be nfeats*nlags)

  • y (ndarray (nsamples x nchans)) – EEG data

  • lagged (bool) – Default: False. Whether the X matrix has been previously ‘lagged’ (intercept still to be added).

  • drop (bool) – Default: True. Whether to drop non valid samples (if False, non valid sample are filled with 0.)

  • feat_names (list) – Names of features being fitted. Must be of length nfeats.

  • rotations (list of ndarrays (shape (nlag x nlags))) – List of rotation matrices (if V is one such rotation, V @ V.T is a projection). Can use empty item in place of identity matrix.

  • weights (ndarray (nsamples,), optional) – Sample weights for weighted least squares. If provided, each sample is scaled by sqrt(weights) (after dropping invalid samples and lagging, before the intercept is added). Must be non-negative and of length n_samples (the full length, before dropping). Sample weights are not currently combined with robust fitting.

  • cache_lagged (bool, optional) – Override the instance-level cache_lagged for this call. When True (and X is not already lagged), the lagged design matrix is cached and reused on subsequent calls whose X has the same buffer, shape, dtype, and for which lags, drop, and block_order are identical. When None (default), the instance-level setting is used. The cache sits before intercept/weight application, so it is never mutated by downstream operations; in-place changes to X are not detected — call clear_cache() or pass cache_lagged=False when X changes. Only the single-array fit path is cached (not _fitlists).

Notes

Set loss='cauchy' in the constructor to fit the Cauchy loss log(1 + (residual / robust_sigma)**2). The default loss='linear' preserves the ordinary least-squares and ridge paths. Robust fitting uses IRLS by default; robust_solver='least_squares' selects SciPy’s nonlinear Cauchy solver for small, unregularized dense problems. Classical t- and p-values are not computed for robust fits.

Returns:

  • coef_ (ndarray (nlags x nfeats x nchans))

  • intercept_ (ndarray (nchans x 1))