trftools.pipeline.FilePredictor
- class trftools.pipeline.FilePredictor(resample=None, columns=False, sampling=None)
Predictor stored in files corresponding to specific stimuli
There are two basic ways to represent predictors in files (see the Notes section below for details):
Uniform time series (UTS). A
NDVarwith time dimension matching the data.Non-uniform time series (NUTS). A
Datasetwith columns representing time stamps, event values and optionally event masks.
Warning
When changing a file in which a predictor is stored, cached results using that predictor will not automatically be deleted. Use
TRFExperiment.invalidate()whenever replacing a predictors.- Parameters:
resample (Literal['bin', 'resample']) –
How to resample predictor. When analyses are done at different sampling rates, it is often convenient to generate predictors at a high sampling rate and then downsample dynamically to match the data.
bin: averaging the values in time binsresample: use appropriate filter followed by decimation
For predictors with non-continuous information, such as impulses, binning is more appropriate. Alternatively, the predictor can be saved as a list of
NDVarwith all the needed sampling frequencies.columns (bool) – Only applies to NUTS (
Dataset) predictors. Use a single file with different columns. The code is interpreted as{name}-{value-column}-{mask-column}. The code{name}alone invokes an intercept, i.e. a value of 1 at each time point.sampling (Literal['continuous', 'discrete']) – Whether to expect a continuous or a discrete predictor (usually an
NDVaror aDataset, respectively). Used to decide whether to filter this predictor withfilter_x='continuous'. Note:'discrete'predictors with*-stepsuffix will always be trated as continuous.
Notes
The file-predictor expects to find a file for each stimulus containing the predictor at:
{root}/derivatives/predictors/{stimulus}~{key}[-{variant}].pickle
Where
stimulusrefers to the name provided bystim_var,keyrefers to the predictor’s name (key used inTRFExperiment.predictors), and the optionalvariantcan be used to distinguish different variants of the same predictor.UTS
UTS predictors are stored as
NDVarobjects with time dimension matching the data. The-{variant}part of the filename can be used freely to manage multiple predictors with the sameFilePredictorinstance. Use theresampleparameter to determine how the predictor is resampled to match the samplingrate of the data.NUTS
NUTS predictors are specified as
Datasetobjects. When loading a predictor,Datasetpredictors are converted to uniform time series by placing impulses at time-stamps specified in the datasets.Without the
columnsoption, the dataset is expected to contain the following columns:time: Time stamp of the event (impulse) in seconds.value: Value of the impulse (magnitude).mask(optional): If present, the (boolean) mask will be applied tovalue(i.e.,valuewill be set to zero wherevermaskisFalse).
With the
columns=Trueoption, the columns containing thevalueandmaskvalues can be specified dynamically in the variable name, as{key}-{value-column}or{key}-{value-column}-{mask-column}.Examples
Assume a
Datasetstored atpredictors/story~word.pickle, etc., with the following columns:time, indicating the word’s onset timefrequency, the word frequencysurprisal, how surprising the word is in its contextnoun,Trueif the word is a noun,Falseotherwise
This could be added to the experiment as follows:
- predictors = {
‘word’: FilePredictor(columns=True),
}
With this predictor, the following terms could be used for TRF models:
word: Unit size impulse at every word onsetword-frequency: An impulse at each word onset reflecting the word’s frequencyword-frequency-noun: An impulse at each noun’s onset reflecting the noun’s frequency
These terms in turn could be used to construct the following model:
experiment.load_trfs(x="word + word-frequency + word-surprisal")