Inverse Constrained Reinforcement Learning

Shehryar Malik, Usman Anwar, Alireza Aghasi, Ali Ahmed

In the world of Reinforcement Learning (RL), we typically instruct agents on what to do by providing them with a reward function. However, in real-world deployments, "what to do" is often secondary to "what not to do." For instance, we want a self-driving car to reach its destination quickly (the reward), but it is absolutely critical that it avoids hitting pedestrians or breaking traffic laws (the constraints).

Manually coding every single safety constraint for complex environments is practically impossible. The paper "Inverse Constrained Reinforcement Learning" proposes a novel framework allowing agents to "read between the lines" and learn these hidden safety rules simply by observing an expert.

The Agent Alignment Problem

Standard RL agents are notoriously "reward-hungry." They will readily find the shortest path to a goal, even if it involves dangerous behavior or "cheating," simply because they were never explicitly told not to. This is a classic example of the agent alignment problem.

While Constrained RL exists to address this, it requires human engineers to mathematically define every constraint (e.g., "stay exactly 2 meters away from all walls"). In high-dimensional environments, this is unscalable. Alternatively, Inverse RL attempts to learn the reward function itself from expert behavior, but it often struggles to distinguish between an expert's preference ("the expert likes this path") and a hard rule ("the expert is forced to take this path to avoid a hazard").

This paper bridges the gap by focusing on Inverse Constrained RL (ICRL): given a known reward function (e.g., "reach the goal") and a set of expert trajectories, can the agent deduce the specific constraints the expert was following?

Methodology

The authors build upon the Maximum Entropy (MaxEnt) framework, introducing several key innovations to make constraint learning viable in complex, real-world scenarios:

  1. Neural Constraint Representation: Instead of relying on unscalable lookup tables, the framework uses a neural network binary classifier to predict whether a specific state-action pair is "allowed" or "forbidden."
  2. Model-Free Learning: Unlike previous approaches that required perfect knowledge of the environment's transition dynamics, this method is sample-based. It updates the constraint model by comparing the expert's actions to trajectories generated by the agent's current policy.
  3. Lagrangian Optimization: The agent is trained by solving a min-max problem. It attempts to maximize its reward while a dynamic penalty (a Lagrange multiplier) grows heavier if the agent violates the newly learned constraints.
  4. Importance Sampling: Because training a new policy from scratch after every constraint update is computationally expensive, the authors utilize importance sampling to reuse old data, drastically accelerating the algorithm's forward step.

Environments and Datasets

The authors evaluated their ICRL framework across several environments designed to test different facets of constraint learning:

  • TwoBridges & ThreeBridges: Navigation tasks where the shortest path to a goal is blocked by a hazard (like a lion). The expert takes a longer, safer route, and the agent must learn why.
  • LapGridWorld: A safety gridworld where a standard agent would "cheat" by stepping back and forth on a single reward tile. The ICRL agent must learn the constraint to follow the full track.
  • MuJoCo Continuous Control: High-dimensional tasks from OpenAI Gym, such as HalfCheetah and Walker2d, testing the algorithm's ability to scale to complex robotics simulations.
The TwoBridges environment comparing expert, standard, and ICRL agents.
The HalfCheetah environment used to test continuous control.

Key Insights and Results

By focusing strictly on learning constraints rather than complex reward functions, the problem becomes significantly more tractable.

  • The "Minimalist" Constraint: The framework employs a regularizer to ensure the agent learns the smallest set of constraints necessary to explain the expert's behavior. This prevents the agent from becoming overly cautious and refusing to move.
  • Transferability: A major finding is that constraints are often properties of the environment, not the specific agent. The authors successfully learned constraints using a HalfCheetah agent and transferred them directly to a Walker2d agent, demonstrating that safety rules can be recycled across different robot morphologies.
  • Efficiency and Scalability: The model achieved expert-level performance with as few as a single expert demonstration in certain environments. Furthermore, while previous state-of-the-art methods were limited to small discrete grids, ICRL successfully navigated the 18-dimensional continuous state space of the HalfCheetah.
  • Safety: In tasks like TwoBridges, the ICRL agent's constraint violations dropped to near zero during training, while its true reward reached expert levels.

Limitations and Future Work

While a significant step forward, the current formulation relies on a MaxEnt model that technically assumes deterministic environments; extending this to highly stochastic worlds remains a future challenge. Additionally, the paper focuses on "hard" binary constraints (allowed vs. forbidden), whereas "soft" constraints (e.g., "minimize battery usage") might be more appropriate in some contexts. Finally, achieving a fully offline version that learns constraints purely from log data—without needing simulator interaction—would be a massive breakthrough for industrial applications.

Summary updated

BibTeX
@inproceedings{malik2021inverse,
  author = {Shehryar Malik and Usman Anwar and Alireza Aghasi and Ali Ahmed},
  title = {{Inverse Constrained Reinforcement Learning}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
  url = {https://openreview.net/forum?id=4GgrEGCDBog},
}
Figure