Fitting Reinforcement Learning Model to Behavioral Data under Bandits

Hao Zhu, Jasper Hoffmann, Baohe Zhang, Joschka BoedeckerarXiv 2025 · DOI

TL;DR

Fitting reinforcement learning (RL) models to animal or human behavioral data has traditionally been a slow, frustrating battle against non-convex optimization landscapes. This paper introduces a novel convex relaxation method that transforms this tricky problem into a mathematically tractable convex program. The result is a massive computational speedup—often turning seconds or minutes of processing time into milliseconds—with virtually no loss in accuracy, all packaged into an open-source Python library.

What Problem Does This Paper Address?

In behavioral neuroscience and psychology, researchers frequently use multi-armed bandit tasks to study decision-making. By observing the choices an animal or human makes and the rewards they receive, scientists fit RL models (like Q-learning) to estimate internal hidden states: specifically, the learning rate ($\alpha$) and reward sensitivity ($\beta$).

Mathematically, this is done by finding parameters that maximize the log-likelihood of the observed behavior. However, because RL models update value functions recursively over time, the relationship between the parameters and the choices is highly non-linear. This makes the optimization problem non-convex. Current standard approaches rely on direct local minimization (which easily gets stuck in local optima) or Bayesian Markov Chain Monte Carlo (MCMC) sampling (which is robust but computationally grueling and slow).

Methods

The authors bypass the non-convexity trap by introducing a convex surrogate problem.

  1. Convex Relaxation: The original RL formulation requires the influence of past rewards to decay geometrically over time based on the learning rate. The authors relax this strict constraint, requiring instead that the influence of past rewards simply decays monotonically (each step back in time matters less than or equal to the step after it). This relaxation turns the problem into a convex optimization problem that can be solved globally and efficiently using interior-point or first-order methods.
  2. Two-Step Parameter Recovery: If researchers only care about the latent value functions, they can stop after the convex step. If they need the exact $\alpha$ and $\beta$ parameters, the authors introduce a second step: a localized, non-convex optimization that maps the relaxed value functions back to the original RL parameters. Crucially, this step can be completely parallelized across CPU cores.
  3. Horizon Truncation: To prevent the problem size from exploding over long experiments, they introduce a hyperparameter ($p$) to truncate the history, considering only the last $p$ steps. This reduces the time complexity from $O(mn^2k)$ to a highly manageable $O(mp^2k)$.

Datasets

The authors evaluated their method using both synthetic and empirical datasets:

  • Simulated Bandits: They generated 1,000 episodes of a 2-armed bandit task (simulating rodent behavior with dynamic reward probability shuffling) and a 10-armed bandit task (simulating human laboratory paradigms).
  • Real-World Mouse Dataset: They utilized a real-world dataset from prior literature consisting of 9 mice performing a two-armed bandit reversal learning task across 64 experimental sessions.

Key Insights and Ideas

  • The GLM Connection: The authors reveal a deep theoretical link to generalized linear models (GLMs). While previous literature noted that logistic regression models behave similarly to RL models in bandit tasks, this paper proves mathematically that the logistic regression variant is actually a formal convex relaxation of the true RL model.
  • The Power of Truncation: One might worry that cutting off the history of rewards ($p=5$) would hurt accuracy. However, because true RL models discount the past exponentially, horizon truncation yields massive speedups with virtually zero impact on accuracy.
  • Decoupling Saves Time: By separating the estimation of value functions from the recovery of parameters, the non-convex part of the problem becomes completely decoupled across actions, allowing researchers to leverage modern multi-core processors effectively.

Key Results

The convex relaxation methods (CVX, CVX-T, CVX-LOC, CVX-LOC-T) were compared against Bayesian Monte Carlo (MC) sampling and direct local minimization (D-LOC).

  • Comparable Accuracy: Across both simulated and real mouse data, the convex relaxation methods achieved fitting accuracy (measured by KL-divergence to the ground truth action selection probabilities) that was neck-and-neck with the state-of-the-art Bayesian approach.
  • Dramatic Speedups: In the basic 2-armed bandit setup, the truncated convex method (CVX-T) found solutions in under 10 milliseconds, compared to ~400 milliseconds for direct local optimization and ~1.4 seconds for MCMC.
  • Scalability: As the RL models grew more complex (e.g., incorporating multiple learning rates and sub-reward functions), the direct local optimization method slowed down drastically, even taking longer than the Bayesian baseline. In contrast, the convex surrogate method remained highly stable and efficient.
Method Performance Comparison (2-Armed Bandit, Basic Setup)
┌───────────────┬─────────────────────────────┐
│ Method        │ Computation Time            │
├───────────────┼─────────────────────────────┤
│ MC (Bayesian) │ ~1400 ms                    │
│ D-LOC         │ ~400 ms                     │
│ CVX-T (Ours)  │ < 10 ms                     │
└───────────────┴─────────────────────────────┘

Limitations and Future Work

  • Step 2 is Still Non-Convex: While the first step of estimating value functions is fully convex, mapping those functions back to get the exact $\alpha$ and $\beta$ parameters still requires a non-convex local search (though it is fast and parallelized).
  • Alternative Convex Formulations Fail in Practice: The authors attempted to create a fully convex parameter recovery formulation in log-space (detailed in Appendix A). However, it suffered from severe numerical issues, such as over-penalizing the small "tails" of the reward history due to the nature of the $\log(x)$ function. Finding a perfectly stable, fully convex parameter recovery step remains an open challenge.

The authors have made their method fully accessible to the scientific community via an open-source Python package called rlfit, available on GitHub.

Summary updated

BibTeX
@misc{zhu2025fitting,
  author = {Hao Zhu and Jasper Hoffmann and Baohe Zhang and Joschka Boedecker},
  title = {{Fitting Reinforcement Learning Model to Behavioral Data under Bandits}},
  year = {2025},
  eprint = {2511.04454},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.04454},
}
Figure