Learning to Shape Rewards using a Game of Two Partners

David Mguni, Taher Jafferjee, Jianhong Wang, Nicolas Perez-Nieves, Tianpei Yang, Matthew Taylor, Wenbin Song, Feifei Tong, Hui Chen, Jiangcheng Zhu, Jun Wang, Yaodong Yang

TL;DR

ROSA (Reinforcement Learning Optimising Shaping Algorithm) automates reward shaping by framing it as a cooperative game between two agents: a "Controller" that performs the task and a "Shaper" that learns where to add auxiliary rewards. By utilizing a novel "switching control" mechanism, ROSA efficiently guides agents through sparse-reward environments while theoretically guaranteeing that the original optimal policy is preserved.

What Problem Does This Paper Address?

Reinforcement Learning (RL) is notoriously difficult in environments with sparse rewards, where an agent might perform hundreds of actions before receiving any feedback (e.g., a robot navigating a complex building or Mario running through a level).

To solve this, researchers use Reward Shaping (RS)—adding auxiliary rewards to "nudge" the agent toward the goal. Traditionally, these shaping functions are hand-crafted by experts, which is time-consuming and error-prone. Automated methods exist, but they often face three major hurdles:

  1. Policy Invariance: Poorly designed rewards can change the optimal solution, leading the agent to "cheat" (e.g., spinning in circles to collect auxiliary points instead of finishing the task).
  2. Convergence Issues: Learning the shaping function and the task policy simultaneously can be unstable.
  3. Computational Complexity: Learning what reward to add at every possible state is a massive search problem.

Methods

The authors introduce ROSA, which models reward shaping as a two-player, non-zero-sum Markov Game.

  • The Controller: This is the primary RL agent trying to solve the environment's task.
  • The Shaper: A secondary agent that observes the Controller and decides how to augment its rewards.
  • Switching Controls: This is the paper's "secret sauce." Instead of the Shaper acting at every time step, it uses a switching policy ($g_2$) to make a binary decision: Should I intervene at this state? This drastically reduces the Shaper's decision space, allowing it to learn much faster than the Controller and provide guidance when it matters most.
  • Potential-Based RS: To ensure the optimal policy doesn't change, the Shaper's rewards are structured as a difference in "potentials" between states. This mathematical framework guarantees that the agent's long-term goals remain aligned with the original environment.

The framework is "plug-and-play," meaning you can use standard algorithms like PPO or TRPO for both the Controller and the Shaper.

Datasets

The authors evaluated ROSA across a variety of environments designed to test specific failure modes:

  • Didactic Mazes: A maze with a "trap" (an easy-to-reach but low-value goal) and a "Subgoal Maze" requiring the discovery of a specific gateway.
  • Red-Herring Maze: A custom environment with a large, novel, but ultimately useless area to test if the agent gets distracted by "novelty for novelty's sake."
  • Standard Benchmarks: Sparse-reward versions of Cartpole, Atari (Gravitar, Solaris), and Super Mario Brothers.

Key Insights and Ideas

  • Selective Intervention: By penalizing the Shaper for every intervention (a "switching cost"), ROSA forces the Shaper to identify only the most critical states for guidance. This leads to a heatmap of rewards that clearly identifies subgoals, as seen in the Subgoal Maze (Figure 2).
  • Ignoring "Red Herrings": Unlike curiosity-based methods (like RND or ICM) that reward an agent for visiting any new state, ROSA's Shaper only rewards exploration that eventually leads to actual environment rewards. In the Red-Herring Maze, ROSA learns to ignore the useless novel area, while RND gets stuck exploring it.
  • Theoretical Soundness: The paper provides proofs that ROSA converges to a stable equilibrium and that the Shaper’s optimal policy is guaranteed to maximize the Controller’s original objective.
Figure 2: Discovering subgoals on Subgoal Maze. Left. Learn- ing curves. Right. Heatmap of shaping rewards.

Key Results

ROSA demonstrated significant performance gains over state-of-the-art baselines:

  • Goal Alignment: In mazes with suboptimal "safe" goals, ROSA successfully guided the agent to the optimal goal, whereas other methods often settled for the lesser reward (Figure 1).
  • Benchmark Performance: In Gravitar, ROSA achieved nearly double the score of the next best baseline. In Sparse Cartpole, it reached maximum performance significantly faster than RND or PPO.
  • Robustness: In Solaris, where other curiosity-based methods showed "catastrophic forgetting" (performance dropping after an initial peak), ROSA remained stable and continued to improve.
Figure 4: Benchmark performance.

Limitations and Future Work

  • Switching Cost Sensitivity: The effectiveness of ROSA depends on the "switching cost" hyperparameter. If the cost is too high, the Shaper never helps; if it's too low, it helps too much and loses efficiency. Currently, this requires some environment-specific tuning.
  • Computational Overhead: While the Shaper's decision space is small, you are still training two agents instead of one, which increases the initial memory and compute requirements.
  • Future Directions: The authors suggest investigating automated ways to schedule or learn the switching cost dynamically during training.

Summary updated

Abstract

Reward shaping (RS) is a powerful method in reinforcement learning (RL) for overcoming the problem of sparse or uninformative rewards. However, RS typically relies on manually engineered shaping-reward functions whose construction is time-consuming and error-prone. It also requires domain knowledge which runs contrary to the goal of autonomous learning. We introduce Reinforcement Learning Optimising Shaping Algorithm (ROSA), an automated reward shaping framework in which the shaping-reward function is constructed in a Markov game between two agents. A reward-shaping agent (Shaper) uses switching controls to determine which states to add shaping rewards for more efficient learning while the other agent (Controller) learns the optimal policy for the task using these shaped rewards. We prove that ROSA, which adopts existing RL algorithms, learns to construct a shaping-reward function that is beneficial to the task thus ensuring efficient convergence to high performance policies. We demonstrate ROSA's properties in three didactic experiments and show its superior performance against state-of-the-art RS algorithms in challenging sparse reward environments.
BibTeX
@inproceedings{mguni2023learning,
  author = {David Mguni and Taher Jafferjee and Jianhong Wang and Nicolas Perez-Nieves and Tianpei Yang and Matthew Taylor and Wenbin Song and Feifei Tong and Hui Chen and Jiangcheng Zhu and Jun Wang and Yaodong Yang},
  title = {{Learning to Shape Rewards using a Game of Two Partners}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i10.26371},
}
Figure