Skip to main content

BrainCoder: neural encoding/decoding models

Braincoder

DOI

Braincoder is a package to fit encoding models to neural data (for now fMRI) and to then invert those models to decode stimulus information from neural data. It wraps stimulus handling, model definition, HRF convolution, and optimization into a single Keras 3-based toolkit that runs on TensorFlow, JAX, or PyTorch.

Highlights

  • Composable models. Pick from ready-made encoding models (Gaussian PRF, HRF-aware, linear) or subclass EncodingModel to implement your own.
  • End-to-end workflow. Utilities for simulation, fitting, and decoding stay in pandas/tensor-friendly formats.
  • Backend-agnostic. Runs on TensorFlow, JAX, or PyTorch via Keras 3.

Quick start

Install braincoder with one of the three backends:

pip install "braincoder[tensorflow]"   # or [jax], or [torch]

Then predict the responses of two voxels to a stimulus:

import numpy as np
import pandas as pd
from braincoder.models import GaussianPRF

paradigm = pd.DataFrame({"x": np.linspace(-5, 5, 100)},
                        index=pd.Index(np.arange(100), name="time"))
parameters = pd.DataFrame({"mu": [0.0, 1.0], "sd": [1.0, 2.0], "amplitude": [1.0, 1.0], "baseline": [0.0, 0.0]},
                          index=pd.Index(["v1", "v2"], name="voxel"))

model = GaussianPRF()
predicted = model.predict(paradigm=paradigm, parameters=parameters)

See the tutorials for full fitting and decoding pipelines. Pin the version in your project's environment, e.g. braincoder[tensorflow]==0.7.1, so that its results stay reproducible.

Development install

git clone https://github.com/Gilles86/braincoder.git
cd braincoder
conda env create -f environment.yml
conda activate braincoder

This installs braincoder in editable mode (pip install -e .) with a TensorFlow backend and dev tools. See the installation docs for the other backends.

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.

prfmodel is a Python package for population receptive field modelling, also built on Keras 3. It covers further pRF models, such as CSS, delayed normalization and connective fields.

How to cite

de Hollander, G., Renkert, M., Ruff, C. C., & Knapen, T. H. (2024). Braincoder: A package for fitting encoding models to neural data and decoding stimulus features. Zenodo. DOI: 10.5281/zenodo.10778413.

@software{deHollander2024braincoder,
  author    = {Gilles de Hollander and Maike Renkert and Christian C. Ruff and Tomas H. Knapen},
  title     = {braincoder: A package for fitting encoding models to neural data and decoding stimulus features},
  year      = {2024},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.10778413},
  url       = {https://github.com/Gilles86/braincoder}
}

Metadata

Release files for braincoder 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for braincoder 0.8.0
File Size Uploaded Provenance Actions
braincoder-0.8.0.tar.gz 2.5 MB With provenance Details for braincoder-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for braincoder 0.8.0
File Interpreter ABI Platform Actions
braincoder-0.8.0-py3-none-any.whl Python 3 none any Details for braincoder-0.8.0-py3-none-any.whl

Total release size: 4.4 MB

Release files / braincoder-0.8.0.tar.gz

Download URL braincoder-0.8.0.tar.gz
Size 2.5 MB
Tags Source
SHA-256 checksum
How to use checksums
6bea036c9e4f34ab6878eb763b20b85230b730f847f0e4c1e7611482fa9b5027
BLAKE2b-256 checksum
How to use checksums
59a967f6643addd76042c1a6c12a6a1ab63ff5bcfb735ef005f772dc86d48cd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / braincoder-0.8.0-py3-none-any.whl

Download URL braincoder-0.8.0-py3-none-any.whl
Size 1.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
91dbd238e964cea701ff7677918bc339ce736b951d43e21ae252ab7bc223e139
BLAKE2b-256 checksum
How to use checksums
26c3a7ce4fd6e6acda9a03a9616c9b9b371285060cfc1302e7d22c3730d47d8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for braincoder 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for braincoder-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page