Inferring how internal brain state shapes neural responses with state-dependent diffusion models

Kaiwen Sheng, Yiqi Jiang, Raina Song, Gaurav Tyagi, Haotian Ye, Fangzhao Zhang, Ruiming Du, Pengxiao Wang, Stefano Ermon, Karl Deisseroth, Anish MitraNeurIPS 2026

TL;DR

Show a brain the exact same picture twice, and it will fire differently depending on whether the organism is alert, zoned out, or moving. Because laboratory experiments are finite, neuroscientists can never record every possible combination of "external stimulus" and "internal brain state." BrainStateDiff solves this by using conditional diffusion models to turn sparse neural recordings into a controllable simulator—allowing researchers to ask counterfactual questions like, "How would this neuron have responded to that image if the animal had been in a different state?"

What Problem Does This Paper Address?

For a long time, trial-to-trial variability in brain recordings was treated like annoying static. Today, we know it isn't random noise: neural computation is fundamentally shaped by the brain’s moment-to-moment internal context (arousal, attention, movement). A brain's response isn't just a function of what it sees, but who it is at that exact millisecond.

This creates a massive data-collection headache, broken down into two gaps:

  1. The Combinatorial Coverage Gap: You have thousands of stimuli and a continuous spectrum of internal brain states. In a time-limited experiment, most valid state–stimulus combinations will simply never occur.
  2. The Local Variability Gap: Even when a specific state–stimulus pairing does occur, you might only catch it once or twice—nowhere near enough to map out the true probability distribution of the brain's inherently stochastic response.

Existing generative models in neuroscience either ignore internal brain states or infer them passively without giving you a "knob" to control them. We lacked a way to hold a brain state fixed and swap the stimulus, or vice versa.

Methods

Enter BrainStateDiff, a conditional diffusion framework designed to generate future neural activity (and behavior) conditioned on three things: recent brain state, external stimulus, and subject/session identity.

Figure 1: Overview of BrainStateDiff, a conditional diffusion framework for state-dependent neural response generation. A. The same external stimuli evoke different responses under different neural states. B. Real recordings cover the state–stimulus space sparsely, leaving many neural state– stimulus pairings unobserved. C. BrainStateDiff first stitches recordings from different sessions and subjects into a shared representation space, then trains a diffusion model conditioned on neural state, external stimuli, and recording identity. D. At inference, cross-state sampling recombines observed states and inputs to cover rare or absent pairings, while matched-state sampling reuses observed pairs to sample local variability. Synthetic and real data are combined for downstream analysis.

Here is what is standard versus what is new:

  • Standard: The core engine is a Denoising Diffusion Probabilistic Model (DDPM) using clean-sample ($x_0$) prediction, paired with session-specific "stitcher" encoders (like VAEs or linear projections) to align different animals/sessions into a shared latent space.
  • Novelty 1 — Explicit State Conditioning: Instead of drawing latent states from a black-box prior, the model defines "brain state" concretely as a rolling history window of recent pre-stimulus neural activity and behavior.
  • Novelty 2 — State-Aware Sampling: At inference time, the authors introduce two clever sampling strategies:
  • Matched-state sampling: Re-runs observed state–stimulus pairs to flesh out local trial-to-trial variability.
  • Cross-state sampling: Mixes and matches observed pre-stimulus brain states with different observed stimuli to synthesize responses for pairings that never happened in the lab.
  • Novelty 3 — Closed-Loop Rollouts: For interactive tasks, BrainStateDiff works autoregressively. It jointly generates neural activity and physical behavior (e.g., turning a wheel), uses known task rules to update the external stimulus (e.g., moving a cursor on a screen), and feeds that history right back into the next step.

Datasets

Beyond a synthetic ground-truth benchmark, the authors test across two species, three recording modalities, and both passive and active tasks:

  • Mouse V1 Wide-Field Calcium Imaging (Newly Introduced): Collected from 2 mice passively viewing 78 natural images from the THINGS database (repeated 80 times per mouse across 5 sessions). Preserves dense 2D spatial/retinotopic structure over time.
  • Monkey V4 Electrophysiology (TVSD): Multi-unit spiking activity from 2 macaques viewing natural images. Unlike the mouse dataset, each training image is shown only once, creating an extreme local-variability and combinatorial gap.
  • Mouse Striatum Two-Photon Calcium Imaging: Existing dataset of 13 sessions where head-fixed mice turn a wheel to guide a cursor to a target—a closed-loop, variable-length behavioral task.

Key Insights and Ideas

  • Compositional Generalization in the Brain: By cutting a diagonal "blind spot" out of a synthetic state–stimulus grid, the authors prove that diffusion models can smoothly interpolate both the mean response and the variance inside completely unobserved territory—where standard Generalized Linear Models (GLMs) fall apart.
Recovering missing state-stimulus distributions
  • The Memorization Trap in Diffusion: When training a downstream classifier on synthetic Mouse V1 data across diffusion training epochs, matched-state accuracy climbed steadily, while cross-state accuracy peaked early and then dropped. Why? Over-trained diffusion models start memorizing training pairs! Memorization helps when replaying seen pairs, but actively hurts compositional generalization on recombined pairs. Early stopping is crucial here.
  • Spatial Inductive Biases Matter: BrainStateDiff crushed classic neuroscience baselines (like LFADS) on wide-field calcium movies partly because its architecture preserves 2D spatial neighborhoods, whereas traditional baselines flatten images into 1D vectors.

Key Results

Across every modality, pretraining or augmenting downstream models with BrainStateDiff synthetic data beat training on real data alone:

  • Mouse V1 (78-way image decoding): While training on synthetic data alone lagged slightly behind the real-data baseline (~0.80 accuracy), pretraining on synthetic data (up to $78\times$ scaling) and fine-tuning on real data pushed test accuracy comfortably past the real-only baseline (~0.83–0.85), with cross-state sampling yielding the biggest gains.
  • Monkey V4 (Natural Image Reconstruction): Training a latent-diffusion image reconstructor on synthetic + real V4 spikes beat the real-only benchmark (~10.35 PSNR / ~0.735 LPIPS), pushing PSNR above 11.1 (higher is better) and dropping LPIPS to ~0.725 (lower is better), yielding visibly sharper object edges and cleaner backgrounds.
  • Mouse Striatum (Behavioral Forecasting): Linear decoders predicting wheel velocity from neural activity saw $R^2$ jump significantly over the real-only baseline across instantaneous ($K=0$) and future ($K=3, 7$) horizons. Strikingly, gains grew at longer forecasting horizons (up to +0.08 $\Delta R^2$ at $K=7$), proving the model captured true multi-step dynamics rather than simple instantaneous correlations.

Limitations and Future Work

  • No Reckless Recombination: Cross-state sampling assumes the stimulus was chosen independently of the animal's brain state (standard in randomized passive viewing). If an experiment is adaptive or non-stationary, blindly swapping states and stimuli can fabricate biologically impossible scenarios unless constrained by explicit transition dynamics.
  • Proxy Brain States: Currently, "internal state" is approximated purely from recent neural and behavioral history. Future iterations could explicitly weave in richer physiological signals like pupil dilation, arousal metrics, heart rate, or task engagement.
  • Architecture vs. Diffusion: On 2D spatial calcium movies, baselines lacked spatial inductive biases; adapting non-diffusion baselines to handle 2D spatial structure remains an open engineering challenge for fairer head-to-head comparisons.

Summary updated

Abstract

Neural responses to the same stimulus can vary dramatically with fluctuations in the brain's internal state and the organism's behavioral state. Yet studying how brain state shapes neural responses is difficult: limited experimental recordings sparsely sample this joint space, leaving many biologically valid state-stimulus pairings unobserved. Existing methods either capture state-dependent modulation with restricted model assumptions or synthesize neural activity without explicitly controlling internal brain state. We introduce **BrainStateDiff**, a conditional diffusion framework that models the spatiotemporal distribution of future neural activity and behavior given external stimuli and recent brain states. Motivated by two gaps in finite recordings, missing state-stimulus combinations and limited repeats of observed conditions, BrainStateDiff introduces two state-aware sampling strategies: *cross-state sampling*, which recombines observed states and stimuli to synthesize plausible neural responses from unobserved pairings, and *matched-state sampling*, which resamples from observed pairings to capture local trial-to-trial variability. We evaluate BrainStateDiff on our newly collected wide-field calcium imaging data in mouse V1, electrophysiology data in monkey V4, and two-photon calcium imaging data in mouse striatum. Our results show that BrainStateDiff generates biologically meaningful samples that preserve the state-dependent structure of real recordings and expand neural response space coverage beyond the original recordings. BrainStateDiff supports both randomized passive designs, where cross-state sampling expands finite coverage over admissible state-stimulus pairs, and closed-loop designs, where neural state, behavior, and external conditions co-evolve through autoregressive generation and task design.
BibTeX
@inproceedings{sheng2026inferring,
  author = {Kaiwen Sheng and Yiqi Jiang and Raina Song and Gaurav Tyagi and Haotian Ye and Fangzhao Zhang and Ruiming Du and Pengxiao Wang and Stefano Ermon and Karl Deisseroth and Anish Mitra},
  title = {{Inferring how internal brain state shapes neural responses with state-dependent diffusion models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=oaGzFBAs66},
}
Figure