Recursive Reward Aggregation

Yuting Tang, Yivan Zhang, Johannes Ackermann, Yu-Jie Zhang, Soichiro Nishimori, Masashi Sugiyama

TL;DR

Standard reinforcement learning assumes agents optimize the discounted sum of rewards, but many real-world tasks require optimizing alternative criteria like peak values, worst-case outcomes, or the Sharpe ratio. This paper introduces an algebraic framework that generalizes Bellman equations to any recursive reward aggregation function without altering the environment's state space or reward function. By plugging these generalized Bellman operators into standard algorithms like Q-learning, PPO, and TD3, agents directly learn behaviors aligned with non-sum objectives, including real-world portfolio optimization.

What Problem Does This Paper Address?

In reinforcement learning (RL), task goals are typically formalized by maximizing the discounted cumulative sum of scalar rewards. However, many practical objectives are non-cumulative:

  • Peak performance: Finding the most potent drug molecule (maximizing the maximum reward).
  • Risk aversion and safety: Avoiding worst-case or bottleneck failures in self-driving and network routing (maximizing the minimum reward).
  • Financial metrics: Balancing returns against volatility using the Sharpe ratio.

Traditionally, researchers force these non-cumulative objectives into standard RL by redesigning or "shaping" reward functions. Unfortunately, reward engineering is notoriously brittle: it can lead to reward hacking, goal misalignment, and the need to artificially expand the state space to track history. The authors ask: can we keep the reward function and state space fixed, and instead change how reward sequences are aggregated over time?

Methods

The paper relies on algebra fusion—a concept from functional programming and category theory where an "unfold" operation (a coalgebra that iteratively generates transitions and rewards) fuses directly with a "fold" operation (an algebra that recursively aggregates rewards):

  1. Recursive Statistic Aggregation: Rather than mapping directly from rewards to values, the agent updates an internal statistic $\tau \in T$ using an update rule $\triangleright: R \times T \to T$ and an initial value $\text{init} \in T$, then computes scalar values via a post-processing function $\text{post}: T \to R$.
  2. Discounted Sum: Updates $r + \gamma s$; $\text{post}(s) = s$.
  3. Discounted Max / Min: Updates $\max(r, \gamma m)$ or $\min(r, \gamma n)$.
  4. Mean & Variance: Tracks multi-dimensional accumulators (e.g., using Welford’s algorithm for incremental mean and variance).
  5. Sharpe Ratio: Tracks running mean and variance to evaluate $\frac{\text{mean}}{\text{std}}$.
  6. Generalized Bellman Operators: The authors define generalized Bellman evaluation and optimality operators. They prove that if the update operation is a contraction under a premetric on the statistic space $T$, the Bellman operators have unique fixed points.
  7. Algorithm Integration: The generalized Bellman operators seamlessly slot into standard RL algorithms—such as Q-learning (for discrete planning), PPO (for continuous policy optimization), and TD3 (for continuous control)—by replacing the Bellman backup targets with their recursive statistic counterparts.

Datasets

  • Grid-World & Continuous Wind-World: Synthetic navigation benchmarks evaluating discrete and continuous trajectory trade-offs.
  • Physics Control (Gym / MuJoCo):
  • Lunar Lander Continuous (Box2D)
  • Hopper and Ant (MuJoCo)
  • Financial Portfolio Benchmark: Historical daily market data across 11 S&P 500 sector indices from 2006 to 2021. The evaluation uses a 5-year rolling training window followed by a 1-year test period across 10 distinct out-of-sample backtesting periods (2012–2021).

Key Insights and Ideas

  • Bellman equations as algebraic fusion: The standard Bellman equation is not uniquely tied to summation; it is simply the composition of a sequential reward generator and an associative fold. Any aggregation that folds recursively yields a Bellman-style update.
  • Multi-dimensional accumulators: Aggregation need not operate on scalar returns directly. By maintaining low-dimensional statistical accumulators (such as count, running mean, and variance) within the critic, complex trajectory-level metrics become recursively computable online.
  • Expected aggregated rewards vs. aggregated expected rewards: In stochastic settings, $\mathbb{E}[\max(R)] \neq \max(\mathbb{E}[R])$. The authors clarify this distinction: standard value backups with expectations correspond to aggregated expected rewards, whereas true expected aggregated rewards require tracking full reward distributions (distributional RL).

Key Results

  • Predictable Behavior Shaping Without Reward Tuning:
  • In Grid-world and Wind-world, optimizing the max aggregation produces aggressive shortcuts indifferent to step penalties, while min aggregation forces risk-averse, conservative paths.
  • In Lunar Lander Continuous, sum lands efficiently in ~11s, sum + max achieves rapid touchdowns in ~7s, while sum − var leads to overly hesitant hover behavior (reaching the 33s timeout) to avoid high-magnitude landing rewards.
  • Real-World Portfolio Optimization (Sharpe Ratio):
  • When directly optimizing trajectory Sharpe ratios on S&P 500 sector allocations (2012–2021 backtest), the proposed method achieved a test Sharpe ratio of $1.12 \pm 0.92$, significantly outperforming baseline differential Sharpe optimization (DiffSharpe: $0.29 \pm 1.22$) and non-cumulative MDP reformulation (NCMDP: $0.48 \pm 0.79$).
  • The method achieved superior or competitive risk-adjusted returns in 8 out of 10 test years.

Limitations and Future Work

  • Strictly Recursive Objectives: The framework cannot directly represent non-recursive statistics that require unbounded history, such as the exact median or semivariance, without online sketching approximations.
  • Design Space Shift: While avoiding reward hacking, practitioners must still design or select the appropriate aggregation operator and premetric for their specific domain.
  • Stochastic Distributional Alignment: In stochastic environments with non-linear aggregations, expected statistics diverge from distributional aggregations. The authors suggest future work should formally integrate multivariate distributional RL to handle these discrepancies and quantile-based risk measures (e.g., VaR and CVaR).

Summary updated

BibTeX
@inproceedings{tang2025recursive,
  author = {Yuting Tang and Yivan Zhang and Johannes Ackermann and Yu-Jie Zhang and Soichiro Nishimori and Masashi Sugiyama},
  title = {{Recursive Reward Aggregation}},
  booktitle = {RLC},
  year = {2025},
  url = {https://openreview.net/forum?id=13lUcKpWy8},
}
Figure