TL;DR
When a black-box time-series classifier flags a heartbeat or a power grid reading as anomalous, how do you minimally tweak the signal to make it "normal" again? This paper introduces CTCF, a framework that guides an unconditional generative Flow Matching model at inference time to create clean, localized counterfactual explanations. Crucially, it works even when the classifier offers no gradients, no class probabilities, and has only ever been trained on a single class.
What Problem Does This Paper Address?
Imagine asking an opaque, industrial-grade diagnostic tool why it flagged an ECG signal. A great way to get an answer is through a counterfactual (CF) explanation: a synthetic version of the original signal with small, realistic edits that flip the model’s verdict to the desired class. For time series, these edits shouldn't look like scattered static across the whole timeline; they need to be concentrated in a few contiguous intervals—a property called segment-wise locality.
Existing time-series CF methods hit three major roadblocks in the real world:
- Gradient dependency: Many assume you can differentiate through the classifier. Yet some of the strongest, fastest time-series classifiers (like interval- or kernel-based models) aren't end-to-end differentiable neural networks.
- Data privacy: Several methods require keeping training data around at deployment time to search for nearest neighbors, violating strict data-governance rules.
- One-class settings: In anomaly detection, you often only have "normal" data during training, leaving CF generators starved of supervised signals from the "abnormal" side.
The authors tackle how to generate plausible, localized counterfactuals when your classifier is a strict black box that only outputs hard yes/no labels—in both standard supervised and one-class setups.
Methods
CTCF (Counterfactual explanations for Time-series Classification via Constrained Flow Matching) cleverly decouples learning how time series look from satisfying a specific classifier.
First, the authors train a standard, unconditional Flow Matching (FM) model (specifically, Rectified Flow). If you haven't crossed paths with FM lately, think of it as diffusion’s cleaner cousin: it learns a continuous velocity field that transports random Gaussian noise (at flow time $t=0$) along straight-line paths into realistic data ($t=1$) via an ordinary differential equation (ODE). Because it is unconditional, this generator can be reused across any classifier.
What’s new is how CTCF learns where the desired class lives along that flow-time journey, and how it steers the trajectory at inference time:
- Flow-Time Desired-Class Region: Extending DeepSVDD-style one-class learning, CTCF maps intermediate states along the straight-line interpolation path into a feature space and encloses states belonging to the desired class within a time-varying hypersphere. Since intermediate noisy states don't have labels, they inherit the hard-decision label of their clean $t=1$ endpoint. Desired states are pulled toward the sphere's center; non-desired states are pushed away (after an activation time $\tau$, since early $t \approx 0$ states are pure noise).
- Dual-Control Inference: At deployment, CTCF guides the ODE generation step-by-step using two mechanisms:
- Fused-lasso steering: Borrowing from FlowChef, it peeks at the predicted $t=1$ endpoint and takes a subgradient step on a fused-lasso objective ($\ell_1$ penalty on both change magnitude and adjacent timestamp differences). This keeps the counterfactual close to the original series and forces edits into smooth, contiguous segments.
- Linearized projection correction: Inspired by PCFM, if the steered step wanders outside the learned desired-class hypersphere, a fast linearized projection nudges it right back inside.
Datasets
The authors evaluate CTCF on 26 datasets from the UCR Time Series Archive (including classic benchmarks like GunPoint, ECGFiveDays, ItalyPowerDemand, and PowerCons), plus an additional evaluation on the 12 native multiclass datasets (spanning 3 to 50 classes). No new datasets are introduced, though the authors slightly adjust the standard UCR train/test splits—reserving the last 30 instances per class for testing—to ensure enough training samples exist for stable one-class classifier training.
Key Insights and Ideas
- Simulation-free region training is theoretically sound: During training, the desired-class region is learned on cheap straight-line interpolations between noise and data, not by running expensive ODE simulations. The authors prove (Theorem 1) that under ideal marginal matching, the surrogate risk on these straight-line interpolations exactly equals the risk along true ODE trajectories.
- Constrain the journey, not just the destination: What if you only check whether the predicted $t=1$ endpoint looks good at each step? Replacing CTCF's intermediate-state region with an autoencoder constraint evaluated on predicted endpoints degraded mean validity and lost on every CF-quality metric. Keeping intermediate flow states on-manifold matters.
- Fused lasso is a natural fit for time-series edits: Penalizing first-differences alongside overall perturbation size neatly prevents jittery, high-frequency noise, concentrating modifications into human-readable intervals without sacrificing validity.
Key Results
Tested on non-differentiable classifiers—QUANT (and LOF on QUANT features for one-class), as well as MultiROCKET-HYDRA—CTCF delivers strong performance across the board:
- Validity: CTCF achieves the best mean rank (2.73) across 26 datasets in the supervised setting, and ties statistically with the top baseline in the one-class setting (2.96 vs. CELT's 2.88). Removing projection ("w/o proj") causes supervised validity rank to plummet to 6.48, proving how vital projection is when the base generator knows multiple classes.
- Proximity, Sparsity, and Locality: Evaluated on commonly valid counterfactuals, CTCF significantly outperforms all existing baselines (CELT, CVAE, LASTS, MCCE) on proximity, sparsity, and number of changed segments (NumSeg) in two-sided Wilcoxon signed-rank tests ($p < 0.05$).
- Speed & Qualitative Sense: Inference takes at most 0.41 minutes (mean per dataset) on a single L40S GPU. Qualitatively, even in one-class settings where the generator never sees abnormal training data, CTCF discovers domain-accurate fixes—like adding the characteristic holster-draw "bump" in GunPoint or isolating edits strictly to the discriminative T-wave in ECGFiveDays.
Limitations and Future Work
While the paper does not feature a standalone "Limitations and Future Work" section, two clear constraints emerge from the analysis and experiments:
- Implausibility trade-off: On the nearest-neighbor implausibility metric, CTCF shows mixed results—performing significantly worse than MCCE ($p = 3.40 \times 10^{-3}$) in the supervised setting (though MCCE lags far behind on validity, proximity, and sparsity).
- Theoretical idealizations: The exact equivalence between interpolation risk and ODE-trajectory risk relies on ideal marginal matching, which ignores finite-data, model-approximation, and numerical ODE integration errors (though the authors note an approximation-error bound relaxation in the appendix).
Summary updated