Braincoder documentation¶
braincoder provides tools to build encoding models, convolve them with
hemodynamic response functions, and decode stimuli from neural data.
Quick start¶
Install braincoder with one of the three backends:
pip install "braincoder[tensorflow]" # or [jax], or [torch]
See Installation for choosing a backend, GPUs and a development install.
The example below mirrors the steps you will take in most analyses: prepare a paradigm, instantiate a model, simulate data, and fit parameters.
import numpy as np
import pandas as pd
from braincoder.models import GaussianPRF
from braincoder.optimize import ParameterFitter
n_tp = 200
paradigm = pd.DataFrame(
{"x": np.linspace(-5, 5, n_tp)},
index=pd.Index(np.arange(n_tp), name="time"),
)
true_params = pd.DataFrame(
{"mu": [-1.0, 2.0], "sd": [1.0, 2.0], "amplitude": [1.0, 2.0], "baseline": [0.0, 0.5]},
index=pd.Index(["voxel_1", "voxel_2"], name="voxel"),
)
model = GaussianPRF()
simulated = model.simulate(paradigm, true_params, noise=0.1)
fitter = ParameterFitter(model=model, data=simulated, paradigm=paradigm)
grid = fitter.fit_grid(mu=np.linspace(-4, 4, 17), sd=np.linspace(0.5, 3, 6),
amplitude=[1.0], baseline=[0.0], use_correlation_cost=True)
init = fitter.refine_baseline_and_amplitude(grid)
estimates = fitter.fit(init_pars=init, max_n_iterations=500, progressbar=False)
print(estimates)
Models hold only their configuration. The paradigm, parameters, weights and noise model are passed to each method.
More resources¶
What’s new — release notes (latest: 0.7.1).
Concepts & Architecture — architectural overview and workflow tips.
Noise models for decoding: low-rank Ω and temperature — calibrated decoding: low-rank Ω with cross-validated rank and temperature.
API Reference — autodoc for the most used modules.
Tutorial — hands-on lessons that walk through realistic encoding/decode pipelines.
Examples — gallery of runnable scripts.
Using an AI coding assistant?¶
The braincoder skill gives an AI coding assistant a step-by-step manual for new projects, the common silent errors, and measured runtimes. It is also readable on its own. In Claude Code, install it with:
/plugin install braincoder --marketplace Gilles86/braincoder
Other assistants (Codex, Cursor, Gemini CLI, …) can read
skills/braincoder/SKILL.md
directly, e.g. by pointing to it from your project’s AGENTS.md.
Citing braincoder¶
Please cite the Zenodo record: de Hollander, G., Renkert, M., Ruff, C. C., & Knapen, T. H. braincoder: A package for fitting encoding models to neural data and decoding stimulus features. Zenodo. doi:10.5281/zenodo.10778413. braincoder is released under the MIT license, and the code is at https://github.com/Gilles86/braincoder.