SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2410.04383 · 2024

BrainCodec: Neural fMRI codec for the decoding of cognitive brain states

Masataka Sawayama, Hideki Nakayama, Ayumu Yamashita, Kaoru Amano, Yuto Nishimura

arXiv · PDF · Open in the Atlas

Code that ran

9 of 12 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 7 failures of our instrument; 3 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2410.04383.json · badge: /api/ran/2410.04383.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
amano-k-lab/BrainCodec canonical (classifier label)
classifier basis: census
7 ran · 2 no recorded run
athms/learning-from-brains community
Papers with Code archive
2 ran · 1 no recorded run
FunctionStatusWhere it lives
AutoEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
athms/learning-from-brains/src/decoder/autoencoder.py
pointer only (licence: NONE) · get_code("2774fa5e9b700603")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, athms/learning-from-brains when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

Decoder Ran
ran on a synthesized input · constructed an object; no result was computed
athms/learning-from-brains/src/decoder/autoencoder.py
pointer only (licence: NONE) · get_code("cfe872713d672311")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, athms/learning-from-brains when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

calculate_l1_dist Ran
ran; our contract draft was wrong, not the code
amano-k-lab/BrainCodec/braincodec/422_F3_create_mean_fMRI_data.py
code served (permissive licence) · get_code("d907b9008d2a240d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family float, shape (4,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Create two small BOLD signal tensors
# Shape: (batch_size=2, features=4)
bold1 = torch.randn(2, 4)
bold2 = torch.randn(2, 4)

ARGS = {
    "bold1": bold1,
    "bold2": bold2,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 1, dtype family float, shape (4,) — shape (4,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_adv_criterion Ran
ran; our contract draft was wrong, not the code
amano-k-lab/BrainCodec/audiocraft/adversarial/losses.py
code served (permissive licence) · get_code("b94d3dcb2a918be3")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import typing as tp

torch.manual_seed(0)

def mse_loss(x: torch.Tensor) -> torch.Tensor:
    if x.numel() == 0:
        return torch.tensor([0.0], device=x.device)
    return torch.nn.functional.mse_loss(x, torch.tensor(1.0, device=x.device).expand_as(x))

def hinge_loss(x: torch.Tensor) -> torch.Tensor:
    if x.numel() == 0:
        return torch.tensor([0.0], device=x.device)
    return -x.mean()

def hinge2_loss(x: torch.Tensor) -> torch.Tensor:
    if x.numel() == 0:
        return torch.tensor([0.0])
    return -torch.mean(torch.min(x - 1, torch.tensor(0.0, device=x.device).expand_as(x)))

ADVERSARIAL_LOSSES = ['mse', 'hinge', 'hinge2']

def get_adv_criterion(loss_type: str) -> tp.Callable:
    assert loss_type in ADVERSARIAL_LOSSES
    if loss_type == 'mse':
        return mse_loss
    elif loss_type == 'hinge':
        return hinge_loss
    elif loss_type == 'hinge2':
        return hinge2_loss
    raise ValueError('Unsupported loss')

ARGS = {
    'loss_type': 'mse'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_fake_criterion Ran
ran; our contract draft was wrong, not the code
amano-k-lab/BrainCodec/audiocraft/adversarial/losses.py
code served (permissive licence) · get_code("88b0022a7cb492a1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import typing as tp

torch.manual_seed(0)

def mse_fake_loss(x: torch.Tensor) -> torch.Tensor:
    return torch.nn.functional.mse_loss(x, torch.tensor(0.0, device=x.device).expand_as(x))

def hinge_fake_loss(x: torch.Tensor) -> torch.Tensor:
    return -torch.mean(torch.min(-x - 1, torch.tensor(0.0, device=x.device).expand_as(x)))

ADVERSARIAL_LOSSES = ['mse', 'hinge', 'hinge2']

def get_fake_criterion(loss_type: str) -> tp.Callable:
    assert loss_type in ADVERSARIAL_LOSSES
    if loss_type == 'mse':
        return mse_fake_loss
    elif loss_type in ['hinge', 'hinge2']:
        return hinge_fake_loss
    raise ValueError('Unsupported loss')

ARGS = {
    'loss_type': 'mse'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_real_criterion Ran
ran; our contract draft was wrong, not the code
amano-k-lab/BrainCodec/audiocraft/adversarial/losses.py
code served (permissive licence) · get_code("31e35a10d885d5a5")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn.functional as F
import typing as tp

torch.manual_seed(0)

ADVERSARIAL_LOSSES = ['mse', 'hinge', 'hinge2']

def mse_real_loss(x: torch.Tensor) -> torch.Tensor:
    return F.mse_loss(x, torch.tensor(1.0, device=x.device).expand_as(x))

def hinge_real_loss(x: torch.Tensor) -> torch.Tensor:
    return -torch.mean(torch.min(x - 1, torch.tensor(0.0, device=x.device).expand_as(x)))

def get_real_criterion(loss_type: str) -> tp.Callable:
    assert loss_type in ADVERSARIAL_LOSSES
    if loss_type == 'mse':
        return mse_real_loss
    elif loss_type in ['hinge', 'hinge2']:
        return hinge_real_loss
    raise ValueError('Unsupported loss')

ARGS = {
    'loss_type': 'mse'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_reconstructed_fMRI Ran
ran; our contract draft was wrong, not the code
amano-k-lab/BrainCodec/braincodec/422_calc_acc_for_each_layer_with_CSM.py
code served (permissive licence) · get_code("c7080127ea64de29")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal codec model that supports the expected interface
class MinimalCodecModel(nn.Module):
    def __init__(self, output_type='tensor'):
        super().__init__()
        self.output_type = output_type
        self.linear_encode = nn.Linear(4, 8)
        self.linear_decode = nn.Linear(8, 4)
    
    def encode(self, bold, tr):
        # bold: [batch, features], tr: [batch]
        encoded = self.linear_encode(bold)
        
        if self.output_type == 'tensor':
            return encoded
        elif self.output_type == 'tuple2':
            logvar = torch.randn(encoded.shape)
            return encoded, logvar
        elif self.output_type == 'tuple3':
            mu = torch.randn(encoded.shape)
            logvar = torch.randn(encoded.shape)
            return encoded, mu, logvar
    
    def decode(self, codes, tr, *args, noise_disable=False, use_layer=None):
        # Handle variable number of positional args (logvar, mu, or nothing)
        reconstructed = self.linear_decode(codes)
        return reconstructed

# Create a minimal config object
class MinimalConfig:
    def __init__(self):
        self.use_layer = None

# Construct the arguments
codec_model = MinimalCodecModel(output_type='tensor')
cfg = MinimalConfig()
bold = torch.randn(2, 4)  # batch_size=2, features=4
tr = torch.randn(2)  # batch_size=2

ARGS = {
    'codec_model': codec_model,
    'cfg': cfg,
    'bold': bold,
    'tr': tr
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sinkhorn Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
amano-k-lab/BrainCodec/braincodec/F2_sinkhorn_algorithm/compare_two_encodec.py
code served (permissive licence) · get_code("8fbfa70ae7d40c40")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# Construct a valid M tensor with shape (B, H, W) = (2, 3, 4)
# M represents a cost matrix or similarity matrix
M = torch.randn(2, 3, 4)

# r: row marginals, can be None or shape (B, H) or (1, H)
r = torch.ones(1, 3) / 3.0

# c: column marginals, can be None or shape (B, W) or (1, W)
c = torch.ones(1, 4) / 4.0

# gamma: temperature parameter for scaling
gamma = 1.0

# eps: convergence tolerance
eps = 8e-09

# maxiters: maximum number of iterations
maxiters = 100

# logspace: whether to use log-space computations
logspace = False

ARGS = {
    "M": M,
    "r": r,
    "c": c,
    "gamma": gamma,
    "eps": eps,
    "maxiters": maxiters,
    "logspace": logspace
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
tr_preprocess Ran
ran; our contract draft was wrong, not the code
amano-k-lab/BrainCodec/braincodec/422_F3_create_mean_fMRI_data.py
code served (permissive licence) · get_code("4b5d01111e61e37f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 2, dtype family int, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import typing as tp

torch.manual_seed(0)

# Analyze the function:
# - max_tr: float - maximum TR value
# - tr_precision: float - precision for TR quantization
# - raw_tr: tp.List[float] - list of TR values (one per sample)
# - max_durtion: int - maximum duration (typo in original, but we use it as-is)
# - bold_durations: tp.List[int] - list of BOLD durations, same length as raw_tr

# The function:
# 1. Asserts len(raw_tr) == len(bold_durations)
# 2. Creates a tensor of shape (len(raw_tr), max_durtion)
# 3. For each TR and duration, creates a sequence and pads/truncates to max_durtion

# Small example with 2 samples
max_tr = 2.0
tr_precision = 0.5
raw_tr = [0.5, 1.5]  # 2 TR values
max_durtion = 4  # max duration across all samples
bold_durations = [3, 2]  # 2 durations matching raw_tr length

ARGS = {
    "max_tr": max_tr,
    "tr_precision": tr_precision,
    "raw_tr": raw_tr,
    "max_durtion": max_durtion,
    "bold_durations": bold_durations,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family int, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Encoder Not yet run
unverified (harvested, no recorded run)
athms/learning-from-brains/src/decoder/autoencoder.py
pointer only (licence: NONE) · get_code("5daefb708a8f4720")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, athms/learning-from-brains when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

wasserstein_distance_numpy Not yet run
unverified (harvested, no recorded run)
amano-k-lab/BrainCodec/braincodec/F2_sinkhorn_algorithm/compare_two_encodec.py
code served (permissive licence) · get_code("a533f7d40bb7d99f")
How it ran

no invocation recorded.

wasserstein_distance_pytorch Not yet run
unverified (harvested, no recorded run)
amano-k-lab/BrainCodec/braincodec/F2_sinkhorn_algorithm/compare_two_encodec.py
code served (permissive licence) · get_code("d1bde2ba56eebe75")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 3 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 0 later) and 9 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_adv_criterion 2 other papers
2 dated earlier
2306.05284 (2023-06)
Simple and Controllable Music Generation
2401.17800 (2024-01)
Dance-to-Music Generation with Encoder-based Textual Inversion
get_fake_criterion 2 other papers
2 dated earlier
2306.05284 (2023-06)
Simple and Controllable Music Generation
2401.17800 (2024-01)
Dance-to-Music Generation with Encoder-based Textual Inversion
get_real_criterion 2 other papers
2 dated earlier
2306.05284 (2023-06)
Simple and Controllable Music Generation
2401.17800 (2024-01)
Dance-to-Music Generation with Encoder-based Textual Inversion

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Recently, leveraging big data in deep learning has led to significant performance improvements, as confirmed in applications like mental state decoding using fMRI data. However, fMRI datasets remain relatively small in scale, and the inherent issue of low signal-to-noise ratios (SNR) in fMRI data further exacerbates these challenges. To address this, we apply compression techniques as a preprocessing step for fMRI data. We propose BrainCodec, a novel fMRI codec inspired by the neural audio codec. We evaluated BrainCodec's compression capability in mental state decoding, demonstrating further improvements over previous methods. Furthermore, we analyzed the latent representations obtained through BrainCodec, elucidating the similarities and differences between task and resting state fMRI, highlighting the interpretability of BrainCodec. Additionally, we demonstrated that fMRI reconstructions using BrainCodec can enhance the visibility of brain activity by achieving higher SNR, suggesting its potential as a novel denoising method. Our study shows that BrainCodec not only enhances performance over previous methods but also offers new analytical possibilities for neuroscience. Our codes, dataset, and model weights are available at https://github.com/amano-k-lab/BrainCodec.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2410.04383")
get_code_for_paper("2410.04383")
have("2410.04383")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2410.04383.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2410.04383.svg)](https://syntology.ai/paper/2410.04383)

Connect an agent — have() is free.