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 ways

  • calling with tmin and tmax arguments will compute lags spanning from tmin to tmax.

  • 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 method TRFEstimator.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 features X, 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

_svd_regress()

Methods

TRFEstimator.apply_func(func)

Apply a function over all values in coef_ and intercept_.

TRFEstimator.copy()

TRFEstimator.fill_lags()

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.

TRFEstimator.get_metadata_routing()

Get metadata routing of this object.

TRFEstimator.get_params([deep])

Get parameters for this estimator.

TRFEstimator.load()

Load and return a TRF instance from numpy archive file (created with trf.save)

TRFEstimator.multialpha_score(X, y)

TRFEstimator.plot([feat_id, ax, ...])

Plot the TRF of the feature requested as a butterfly plot.

TRFEstimator.plot_multialpha_scores(X, y)

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.

TRFEstimator.predict(X)

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).