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.9.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.9.0
File Size Uploaded Provenance Actions
braincoder-0.9.0.tar.gz 2.5 MB With provenance Details for braincoder-0.9.0.tar.gz

Built distribution (wheel)

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

Total release size: 4.4 MB

Release files / braincoder-0.9.0.tar.gz

Download URL braincoder-0.9.0.tar.gz
Size 2.5 MB
Tags Source
SHA-256 checksum
How to use checksums
9ae947d24a436acd525617d5f1b9518ea012196b7ef02bbf4a89dd7cccac18f1
BLAKE2b-256 checksum
How to use checksums
f6915cf070e0908a146617bc0e871f63510847430aaa92734ae9f140642de3a6
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.9.0-py3-none-any.whl

Download URL braincoder-0.9.0-py3-none-any.whl
Size 1.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
80fe1822071de87f034737af51c4e6a10ac9c4648fad2ab5c0f16e21c1d4b0c7
BLAKE2b-256 checksum
How to use checksums
e225359876d83a503b1a6c7dc53f37aa706a7e8cbad0d8b3ec6874c6663bda29
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.9.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.9.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