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.

Installation

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

Pin the version in your project's environment, e.g. braincoder[tensorflow]==0.7.1, so that its results stay reproducible.

For development, use conda/mamba. Clone the repo, then create the environment:

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 .) along with a TensorFlow backend and dev tools. See the installation docs for other backends (JAX, PyTorch) and pip-only setups.

Quick start

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.

Using an AI coding assistant

The braincoder skill for Claude Code gives an assistant a step-by-step manual for new projects, the common silent errors, and measured runtimes. It is also readable on its own. Install it with:

git clone https://github.com/Gilles86/gilles-claude-skills.git
ln -s "$PWD/gilles-claude-skills/skills/braincoder" ~/.claude/skills/braincoder

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.7.1

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

Built distribution (wheel)

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

Total release size: 4.4 MB

Release files / braincoder-0.7.1.tar.gz

Download URL braincoder-0.7.1.tar.gz
Size 2.5 MB
Tags Source
SHA-256 checksum
How to use checksums
ddc52e1fff34ed0ac339f4d3e170ac9cee0163010686e33e798178c93dbdc4bb
BLAKE2b-256 checksum
How to use checksums
d2922e2d9b1682d09811886f29c78412b4377ee49853a33db1509959e5469a7b
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 16, 2026.

Transparency log

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

Download URL braincoder-0.7.1-py3-none-any.whl
Size 1.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f94e1b839ba091d34f998d0cf6839a0dbec3439413aa398238e7920223a11646
BLAKE2b-256 checksum
How to use checksums
be0426244f8cea9c8996fd0807e6a22222f9720b8a7ee87d4ee9e03e4ff44571
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 16, 2026.

Transparency log

Security for braincoder 0.7.1

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.7.1.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 16, 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