Abstract
In deep reinforcement learning (RL) systems, abnormal states pose significant risks by potentially triggering unpredictable behaviors and unsafe actions, thus impeding the deployment of RL systems in real-world scenarios. It is crucial for reliable decision-making systems to have the capability to cast an alert whenever they encounter unfamiliar observations that they are not equipped to handle. In this paper, we propose a novel Mahalanobis distance-based (MD) anomaly detection framework, called MDX, for deep RL algorithms. MDX simultaneously addresses random, adversarial, and out-of-distribution (OOD) state outliers in both offline and online settings. It utilizes Mahalanobis distance within class-conditional distributions for each action and operates within a statistical hypothesis testing framework under the Gaussian assumption. We further extend it to robust and distribution-free versions by incorporating Robust MD and conformal inference techniques. Through extensive experiments on classical control environments, Atari games and autonomous driving scenarios, we demonstrate the effectiveness of our MD-based detection framework. MDX offers a simple, unified, and practical tool for enhancing the safety and reliability of RL systems in real-world applications.
1. Introduction
Deep reinforcement learning (RL) agents are notoriously brittle when faced with noisy sensors, adversarial attacks, or unfamiliar environments. While these agents achieve superhuman performance in simulations, real-world deployment introduces significant risks. RL policies are often trained on "clean" data, but deployment involves random sensor noise (e.g., a jittery GPS), maliciously crafted adversarial inputs designed to trick the agent, and out-of-distribution (OOD) states, such as a car trained in sunshine encountering a heavy rainstorm.
Existing anomaly detection methods often struggle with the dynamic nature of RL, where the "normal" distribution of states changes as the agent learns. MDX aims to provide a unified, practical tool that allows an agent to "raise a red flag" when it encounters a state it isn't equipped to handle, thereby improving safety and reliability.
2. Methodology: The MDX Framework
The core of the MDX framework is the Mahalanobis Distance (MD). Unlike simple Euclidean distance, MD accounts for how different features correlate with each other, measuring distance in terms of standard deviations away from a data cluster.
MDX operates on Action-Conditional Manifolds. The authors observed that states leading to the same action share similar internal features. MDX extracts features from the penultimate layer of the policy network and estimates a separate mean ((\mu)) and covariance ((\Sigma)) for each possible action.
To handle real-world complexities, MDX includes several technical innovations:
- Robust MD (RMD): Uses the Minimum Covariance Determinant (MCD) estimator to prevent the detector from being "poisoned" by noisy training data.
- Conformal MD (MD+C): Incorporates conformal inference, a non-parametric technique that sets statistically rigorous detection thresholds without assuming a Gaussian data distribution. This variant proved to be the most robust across almost all testing scenarios.
- Online Adaptation: Implements a Moving Window Estimation to update the detector as the policy evolves and a Double Self-Supervised mechanism to cross-validate results.
3. Experimental Setup
The framework was evaluated across three distinct domains:
- Classical Control: Cartpole and MountainCar (feature-input tasks).
- Atari Games: Six games including Breakout and SpaceInvaders (image-input tasks).
- Autonomous Driving: The CARLA simulator, featuring realistic anomalies like sensor noise, adversarial traffic signs, and OOD weather conditions (rainy/nighttime).
The benchmark was created by injecting random Gaussian noise, FGSM-based adversarial perturbations, and cross-environment OOD states into these standard datasets.
4. Results and Discussion
MDX demonstrates superior performance across various metrics and scenarios:
- High Accuracy: In offline Atari experiments, MDX variants achieved average detection accuracy of 74-78%, significantly outperforming baselines like Policy Entropy (~50%) and Environment Models (~56%).
- Adversarial Defense: MDX effectively catches adversarial attacks that are often invisible to the naked eye but drastically alter internal feature representations.
- Real-world Viability: In CARLA autonomous driving tests, the Conformal MD variant achieved up to 97.5% accuracy in detecting critical OOD states.
- Efficiency: As a lightweight distance check, MDX can run in real-time, unlike computationally expensive environment models.
A key insight is that the agent's internal "brain" (high-level features) is the most effective place to detect anomalies. Furthermore, in online settings, MDX acts as a filter, removing noisy states during training to allow the agent to learn successful policies even in highly contaminated environments.
5. Conclusion
MDX provides a robust and efficient framework for anomaly detection in deep RL. While currently optimized for discrete action spaces, future work will address continuous action spaces and explore "correcting" anomalous states rather than simply discarding them. Distinguishing between harmful anomalies and beneficial novel states for exploration remains a fundamental challenge for future research.
Summary updated