This directory contains optional demo and comparison code that is not part of
the core ffTRF library API.
The main installable toolbox lives in:
src/fftrf/
The files here are intended for:
- runnable usage examples for the main
TRFAPI patterns - sanity checks against time-domain references
- side-by-side comparisons with
mTRF - exploratory plotting for development and validation
The example scripts are organized around the main modeling combinations that are
practical with TRF:
example_single_trial_single_channel.pySingle trial, single stimulus feature, single response channel, forward model.example_multi_trial_single_channel.pyMultiple trials, single feature, single channel, cross-validated regularization.example_multifeature_multichannel.pyMultiple stimulus features, multiple response channels, forward model.example_banded_regularization.pyOptional banded ridge search over grouped multifeature predictors.example_multitaper_estimator.pyOptional multi-taper estimation withR^2, transfer-function plots, cross spectra, and coherence.example_frequency_resolved_weights.pySpectrogram-like frequency-resolved view of one recovered kernel, shown as both signed weights and Hilbert-envelope power.example_mtrf_sample_eeg.pyOptional real-data comparison against the public mTRF speech EEG sample, withneg_mse-based lambda selection and held-out Pearson reporting for both a forward benchmark and a backward compressed-envelope benchmark on the same split; the backward target uses ap=0.4broadband compression, and optional segmented Hann settings are available for practical forward and backward ffTRF runs.benchmark_real_eeg.pyReproduce the practical 2 s Hann ffTRF and finite-lag mTRF benchmark in isolated processes and write runtime, peak RSS, and held-out accuracy to a Markdown table.generate_documentation_figures.pyRegenerate the real EEG documentation figures used in the README and documentation site.example_backward_decoding.pyBackward model: multichannel responses used to reconstruct a single stimulus.example_bootstrap_confidence_interval.pyForward model with a stored bootstrap confidence interval.example_trial_weighting.pyCompare an unweighted fit to a fit that uses inverse-variance trial weights.example_save_and_load.pySave a fitted model, load it again, and export a different lag window.
Each example is intentionally a plain Python script showing the API calls,
learned attributes, and one corresponding figure. Running a script prints the
relevant TRF attributes and saves a figure under artifacts/examples/.
They are meant to be read alongside the main README: each script follows the
same pattern of train(...), attribute inspection, predict(...), and
plotting, but focuses on one concrete use case. The optional features are
covered with dedicated examples rather than changing the baseline examples into
advanced-only workflows. The examples now also demonstrate friendlier options
such as segment_duration=... in seconds and k="loo" for leave-one-out
cross-validation.
Example commands:
python examples/example_single_trial_single_channel.py
python examples/example_multi_trial_single_channel.py
python examples/example_multifeature_multichannel.py
python examples/example_banded_regularization.py
python examples/example_multitaper_estimator.py
python examples/example_frequency_resolved_weights.py
python examples/example_backward_decoding.py
python examples/example_bootstrap_confidence_interval.py
python examples/example_trial_weighting.py
python examples/example_save_and_load.pyOptional compare-environment example:
pixi run -e compare python examples/example_mtrf_sample_eeg.py
pixi run -e compare python examples/benchmark_real_eeg.py
pixi run -e compare python examples/generate_documentation_figures.pyDevelopment-only synthetic checks:
pixi run -e compare compare-demoOr with pip:
pip install -e ".[compare]" mtrf
python examples/compare_with_mtrf.py --output artifacts/kernel_comparison.png --no-show