pyeeg.models
.TRFEstimator
- class pyeeg.models.TRFEstimator(times=(0.0,), tmin=None, tmax=None, srate=1.0, alpha=0.0, fit_intercept=True, verbose=True)
Temporal Response Function (TRF) Estimator Class.
This class allows to estimate TRF from a set of feature signals and an EEG dataset in the same fashion than
mne.decoding.ReceptiveFieldEstimator
does in MNE. However, an arbitrary set of lags can be given. Namely, it can be used in two wayscalling with
tmin
andtmax
arguments will compute lags spanning fromtmin
totmax
.with the
times
argument, one can request an arbitrary set of time lags at which to compute the coefficients of the TRF.
- lags
Array of
int
, corresponding to lag in samples at which the TRF coefficients are computed- Type:
1d-array
- times
Array of
float
, corresponding to lag in seconds at which the TRF coefficients are computed- Type:
1d-array
- srate
Sampling rate
- Type:
float
- use_regularisation
Whether ot not the Ridge regularisation is used to compute the TRF
- Type:
bool
- fit_intercept
Whether a column of ones should be added to the design matrix to fit an intercept
- Type:
bool
- fitted
True once the TRF has been fitted on EEG data
- Type:
bool
- intercept_
Intercepts
- Type:
1d array (nchans, )
- coef_
Actual TRF coefficients
- Type:
ndarray (nlags, nfeats, nchans)
- n_feats_
Number of word level features in TRF
- Type:
int
- n_chans_
Number of EEG channels in TRF
- Type:
int
- feat_names_
Names of each word level features
- Type:
list
Notes
Attributes with a
_
suffix are only set once the TRF has been fitted on EEG data (i.e. after the methodTRFEstimator.fit()
has been called).Can fit on a list of multiple dataset, where we have a list of target
Y
and a single stimulus matrix of featuresX
, then the computation is made such that the coefficients computed are similar to those obtained by concatenating all matrices
Examples
>>> trf = TRFEstimator(tmin=-0.5, tmax-1.2, srate=125) >>> x = np.random.randn(1000, 3) >>> y = np.random.randn(1000, 2) >>> trf.fit(x, y, lagged=False)
See also
Methods
TRFEstimator.apply_func
(func)Apply a function over all values in coef_ and intercept_.
Fill the lags attributes.
TRFEstimator.fit
(X, y[, lagged, drop, ...])Fit the TRF model.
TRFEstimator.fromArray
(tmin, tmax, fs)Creates a TRF instance from a 3D array.
Get metadata routing of this object.
TRFEstimator.get_params
([deep])Get parameters for this estimator.
Load and return a TRF instance from numpy archive file (created with trf.save)
TRFEstimator.plot
([feat_id, ax, ...])Plot the TRF of the feature requested as a butterfly plot.
Plot the score against different alphas to visualise effect of regularisation.
TRFEstimator.plot_topomap
(time_lag, feat_id, ...)Plot the topomap of the TRF at a given time-lag.
Compute output based on fitted coefficients and feature matrix X.
TRFEstimator.save
(filename)Save the current trf object to file.
TRFEstimator.score
(Xtest, ytrue[, scoring, ...])Compute a score of the model given true target and estimated target from
Xtest
.
TRFEstimator.select_best_coefs
(best_index[, ...])This method can be used to select the best set of coefficients when the TRF model has been trained with several regularisation parmaters.
TRFEstimator.set_fit_request
(*[, drop, ...])Request metadata passed to the
fit
method.
TRFEstimator.set_params
(**params)Set the parameters of this estimator.
TRFEstimator.set_score_request
(*[, Xtest, ...])Request metadata passed to the
score
method.
TRFEstimator.xfit
(X, y[, n_splits, lagged, ...])Apply a cross-validation procedure to find the best regularisation parameters among the list of alphas given (ndim alpha must be == 1, and len(alphas)>1).