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
Vis one such rotation,V @ V.Tis 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 lengthn_samples(the full length, before dropping). Sample weights are not currently combined with robust fitting.cache_lagged (bool, optional) – Override the instance-level
cache_laggedfor this call. WhenTrue(andXis not already lagged), the lagged design matrix is cached and reused on subsequent calls whoseXhas the same buffer, shape, dtype, and for whichlags,drop, andblock_orderare identical. WhenNone(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 toXare not detected — callclear_cache()or passcache_lagged=FalsewhenXchanges. Only the single-arrayfitpath is cached (not_fitlists).
Notes
Set
loss='cauchy'in the constructor to fit the Cauchy losslog(1 + (residual / robust_sigma)**2). The defaultloss='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))