Explaining Reinforcement Learning Policies through Counterfactual Trajectories

Julius Frost, Olivia Watkins, Eric Weiner, Pieter Abbeel, Trevor Darrell, Bryan A. Plummer, Kate SaenkoarXiv 2022

Abstract

In order for humans to confidently decide where to employ RL agents for real-world tasks, a human developer must validate that the agent will perform well at test-time. Some policy interpretability methods facilitate this by capturing the policy's decision making in a set of agent rollouts. However, even the most informative trajectories of training time behavior may give little insight into the agent's behavior out of distribution. In contrast, our method conveys how the agent performs under distribution shifts by showing the agent's behavior across a wider trajectory distribution. We generate these trajectories by guiding the agent to more diverse unseen states and showing the agent's behavior there. In a user study, we demonstrate that our method enables users to score better than baseline methods on one of two agent validation tasks.

Introduction: The Challenge of Distribution Shifts

Reinforcement learning (RL) agents often excel in training environments but fail when deployed in real-world scenarios due to distribution shifts. Traditional explainability methods typically present "highlights" of an agent's training performance, such as successful runs or states with high confidence. While these trajectories demonstrate competence within the training distribution, they offer little information about how the agent will react to novel, out-of-distribution (OOD) states. This can lead to a false sense of security for human developers who may overestimate an agent's generalization capabilities.

Conceptual comparison between low-diversity training trajectories (prior work) and high-diversity counterfactual trajectories (ours).

Proposed Method: Counterfactual Trajectories

To address this gap, the authors propose generating counterfactual trajectories—videos demonstrating agent behavior in diverse, previously unseen states. The core innovation is the use of an exploration policy to "nudge" the agent into novel situations before handing back control to the original behavioral policy. This ensures that the counterfactual states are physically reachable within the environment's constraints, unlike purely random state sampling.

The pipeline consists of four primary steps:

  1. Agent Training: The behavioral policy ($\pi_\theta$) is trained using standard RL techniques in a specific environment.
  2. Exploration: An exploration policy ($\pi_\phi$) navigates the agent away from its typical training paths into a diverse set of reachable states that match a prior over test-time visitation.
  3. Trajectory Collection: Once the agent reaches a counterfactual state, the behavioral policy ($\pi_\theta$) takes over. The resulting rollout is recorded to show how the agent handles the unfamiliar starting point.
  4. User Evaluation: These videos are presented to users to assess their ability to predict the agent's performance in a new test environment.
The four-step pipeline for generating counterfactual trajectories compared to a standard baseline.

Experimental Evaluation

The method was evaluated using the MiniGrid environment, a 2D grid-world. The agent was trained to reach a goal starting from the top-left room of a four-room layout. At test time, the agent was initialized in the top-right room—a significant distribution shift where the agent typically fails.

A user study compared counterfactual trajectories against two baselines: Random States (random training clips) and Critical States (clips where the agent exhibited high certainty). Participants performed two tasks: predicting the agent's next moves and predicting overall success/failure.

Key Results

  • Behavior Understanding: Users shown counterfactual trajectories were significantly more accurate at predicting the agent's next moves in a new environment, achieving 36.38% accuracy compared to 4% for Random and 14.58% for Critical states.
  • Performance Evaluation: Predicting global success or failure remained challenging across all methods. This suggests a persistent "pro-agent bias" where users assume training success generalizes universally, even when shown evidence of confusion in new areas.

Discussion and Future Work

While counterfactual trajectories significantly improve a user's ability to predict local behavior under distribution shifts, judging global performance remains difficult for non-experts. Future work will focus on scaling this method to high-dimensional environments, such as 3D robotics, where training effective exploration policies is more complex. Additionally, the study highlights the importance of accounting for human cognitive biases when designing interpretability tools for RL.

Summary updated

BibTeX
@misc{frost2022explaining,
  author = {Julius Frost and Olivia Watkins and Eric Weiner and Pieter Abbeel and Trevor Darrell and Bryan A. Plummer and Kate Saenko},
  title = {{Explaining Reinforcement Learning Policies through Counterfactual Trajectories}},
  year = {2022},
  eprint = {2201.12462},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2201.12462},
}
Figure