TL;DR
This paper introduces a scalable framework for generating counterfactual explanations for time series by replacing slow, per-instance optimization with a learned policy. By training an actor-critic agent in the latent space of an autoencoder, the authors enable the generation of valid and realistic "what-if" scenarios through a single forward pass, achieving massive speedups for large-scale datasets.
What Problem Does This Paper Address?
Counterfactual Explanations (CFEs) are a cornerstone of Explainable AI (XAI). They answer the question: "What is the smallest change I could make to this input to change the model's prediction?" For example, in healthcare, a CFE might show how a patient's heart rate trajectory would need to change to move from a "high risk" to a "low risk" classification.
However, generating CFEs for time series is notoriously difficult for two reasons:
- Temporal Complexity: Time series data has dependencies. If you change just one data point, you might create an unrealistic "spike" that breaks the natural flow of the data (low plausibility).
- Computational Cost: Most existing methods are "instance-based." They run a fresh iterative optimization loop for every single sample they explain. This doesn't scale; if you have 10,000 test samples, you have to run 10,000 separate optimizations.
Methods
The authors propose a framework that treats counterfactual generation as a one-step reinforcement learning (RL) problem, specifically a contextual bandit.
- Latent Space Operation: Instead of perturbing raw time steps, they use a pre-trained autoencoder. The RL agent works in the compressed latent space ($z$), which naturally captures global structural regularities and ensures that decoded changes look like real time series.
- Actor-Critic Architecture:
- The Actor learns a policy: given an input's latent state and a target class, it outputs a perturbed latent vector ($z_{CF}$).
- The Critic acts as a differentiable surrogate for the black-box classifier. It learns to predict the reward (whether the change successfully flipped the label).
- Reward & Loss: The agent is rewarded for Validity (flipping the label) while being penalized by a Proximity Loss ($L_1 + L_2$) to ensure the counterfactual stays close to the original input.
- Training vs. Inference: Unlike traditional methods, this model learns a transferable policy during a training phase. At inference time, generating a counterfactual requires only a single forward pass through the actor and the decoder.
Datasets
The framework was evaluated on 13 univariate time series datasets from the UCR Time Series Classification Archive. These cover diverse domains including:
- Medical: ECG200, TwoLeadECG.
- Human Activity: GunPoint (and its variants).
- Sensors/Industry: FordA, FordB, Wafer, FreezerRegularTrain.
- Traffic: Chinatown.
Key Insights and Ideas
- Knowledge Transfer: The core "aha" moment is that counterfactual generation shouldn't start from scratch every time. By training on a whole dataset, the actor learns the "global rules" of what makes a sequence belong to a certain class.
- The Plausibility Trade-off: The authors found that while their method might have slightly higher $L_1$ or $L_2$ distances (changing more points slightly) compared to sparse input-space methods, it scores much better on plausibility. Because changes are distributed through the autoencoder, they avoid the "extreme spikes" that often plague optimization-based methods.
- Efficiency at Scale: The "break-even" point for the training cost is reached quickly. For small datasets, iterative methods might seem faster, but as the number of test instances grows, the learned policy's millisecond-level inference time becomes a massive advantage.
Key Results
- High Validity: The method achieved a mean flip rate of ~0.95 across all datasets, showing it is highly reliable at actually changing the model's prediction.
- Superior Plausibility: Using anomaly detection metrics (Isolation Forest, LOF, One-Class SVM), the proposed method consistently produced counterfactuals that looked more like "real" data compared to baselines like Wachter or TimeX.
- Scalability: On large datasets like FreezerRegularTrain, the total runtime (including training) was significantly lower than instance-based baselines, which can take hours to process a full test set.
Limitations and Future Work
- Autoencoder Dependency: The quality of the counterfactual is capped by the autoencoder's ability to reconstruct the data. Minor distortions can occur if the AE isn't perfectly tuned.
- Reward Sparsity: The current reward is a simple binary (flip or no flip). The authors suggest that more expressive, continuous reward functions could further improve training stability.
- Univariate Focus: The current study focuses on univariate time series. Extending this to multivariate data (where multiple sensors interact) is a logical next step.
- Temporal Constraints: While the AE helps, future work could integrate explicit temporal constraints (like trend or seasonality preservation) directly into the RL reward.
Summary updated