WorksComputer Science
Flow-CAD: Flow Matching for Contextual Anomaly Detection and Explanation in Tabular Data
Abstract
Contextual anomaly detection in tabular data aims to identify objects whose behavior is unexpected under their contextual conditions. In data-engineering pipelines, this task screens table rows whose measurements violate context-dependent integrity relationships. Most existing approaches rely on either shallow conditional models with limited distributional expressiveness or localized estimators that require per-context modeling, making it difficult to capture complex conditional relationships and scale to high-dimensional settings. We propose Flow-CAD, a new framework for contextual anomaly detection based on Flow Matching. Flow-CAD learns a single global and amortized conditional generative model that flexibly represents behavioral distributions conditioned on context, without assuming simple parametric forms or retraining local models. To enable robust and interpretable anomaly scoring, we introduce a scale-normalized and truncated residual energy derived from the learned conditional flow, which stabilizes anomaly scores, mitigates domination by extreme deviations, and supports feature-wise attribution. We further provide theoretical insights showing that the proposed residual-based anomaly score is stable under velocity estimation error, and that its Monte Carlo estimator satisfies concentration bounds. Experiments on 20 benchmark datasets with 13 competitors demonstrate that Flow-CAD has the best average rank for PR AUC, ROC AUC, and P@n, highlighting its effectiveness and practicality for contextual anomaly detection in tabular data. We provide the source code at https://github.com/ZhongLIFR/FlowCAD.
Introduction
Contextual anomaly detection aims to identify data instances whose behavior is abnormal when interpreted relative to their contextual conditions [1, 2]. Under this setting, features are typically partitioned into contextual variables (e.g., operating conditions, demographic attributes, or environmental factors) and behavioral variables (e.g., measurements, responses, or outcomes). An instance is considered anomalous not because it is globally rare, but because its behavior is unlikely given its context. This setting arises naturally in a wide range of applications, including industrial monitoring [3], environmental analysis [4], and security in smart grids [5], where identical behaviors may be normal in one context but anomalous in another. For example, a plant may record its operating mode alongside pressure and temperature readings in each row. Each reading can be typical for that mode on its own, while the combination is unusual. In database-backed analytics, screening for such rows can precede aggregation, monitoring, and model training [6, 7]. For a flagged row, Flow-CAD reports how much each behavioral column contributes to the anomaly score, helping analysts decide which measurements to inspect [8].
Despite steady progress, existing contextual anomaly detection methods continue to face several fundamental limitations when applied to complex tabular data. Early generic frameworks such as CAD [1] rely on parametric assumptions and hand-crafted mapping functions to capture dependencies between contextual and behavioral variables, which restrict flexibility, scalability, and support for mixed feature types. A subsequent approach ROCOD [9] combines global regression models with local neighborhood statistics, but primarily characterizes conditional behavior through expectations, which can be inadequate when the conditional distribution is skewed, multimodal, or context-dependent. A recent method QCAD [2] improves robustness and interpretability by estimating conditional quantiles, yet remains fundamentally localized, relying on per-query neighborhood construction or local conditional estimation. This repeated local estimation adds scoring overhead (see Figure 8). Together, these limitations motivate a global and amortized approach that avoids repeated local modeling, captures complex context-dependent behavior, and supports efficient inference with interpretable anomaly scores.
Figure 8. Runtime comparison between Flow-CAD and QCAD on all 20 benchmark datasets (data seed 42, one Apple M4 CPU thread per run). Orange shows the time to compute row scores and feature contributions. Blue includes data loading and metric computation for both methods, plus the 1,000-epoch model fit for Flow-CAD and context encoding and Gower-neighborhood construction for QCAD. Flow-CAD is shown with solid bars and QCAD with striped bars. The vertical axis is logarithmic. Bar labels show total CPU time.
Recent advances in deep generative modeling [10, 11] provide an opportunity to revisit contextual anomaly detection from a global and amortized perspective. In principle, conditional generative models are well suited for representing complex conditional distributions without relying on restrictive parametric assumptions. For continuous flows, likelihood evaluation typically requires numerical integration of an ordinary differential equation (ODE) and estimation of the velocity field’s divergence. Likelihood values can also be unreliable as a direct anomaly signal in complex distributions [12, 13]. As a result, existing generative approaches do not naturally satisfy the combined requirements of efficient inference, robust anomaly scoring, and interpretability in contextual anomaly detection. Flow Matching [14, 15] offers an alternative training paradigm for continuous generative models that avoids explicit likelihood evaluation and ODE-based density computation during training. By learning a conditional velocity field that transports samples from a simple base distribution to the data, Flow Matching retains the expressive power of conditional generative models while enabling path-wise, residual-based assessments of how well observed behaviors are explained under a given context. Motivated by these properties, we propose Flow-CAD, a new framework for contextual anomaly detection based on Flow Matching.
Specifically, Flow-CAD learns a single global and amortized conditional generative model that captures the joint distribution of behavioral variables conditioned on context. Instead of relying on explicit likelihood evaluation, Flow-CAD derives anomaly scores from residuals of the learned conditional flow, measuring how well the model explains an observed behavior given its context. To obtain robust and interpretable anomaly scores, we further introduce a scale-normalized and truncated residual energy that aggregates deviations across behavioral dimensions while limiting the influence of extreme values. This construction yields native, decomposable feature-level attributions, which identify the behavioral columns contributing to a flagged row’s score. In addition, we relate the ideal-field residual to conditional denoising, establish the stability of the normalized and truncated score under velocity estimation error, and analyze the variance and concentration of its nested Monte Carlo estimator.
Contributions. The main contributions of this work are as follows. (1) We introduce Flow-CAD, a contextual anomaly detection framework based on Flow Matching for screening database tables. A single model learns how the behavioral columns vary together given the context columns. (2) We propose a residual-based anomaly energy for conditional flows that scores rows in batches without computing likelihoods or refitting for each query. A data engineering pipeline can use these scores to flag records before aggregation or model training. (3) We develop a normalized and truncated aggregation scheme that yields robust scores and additive column contributions. For a flagged row, these contributions show which columns account for most of its score, helping analysts decide which values to inspect first. (4) We provide theoretical analyses and compare Flow-CAD with 13 baselines on 20 benchmark tables, using a fixed training budget for our model. In a separate test on held-out synthetic rows, we ask whether the model can detect a context mismatch that only becomes visible when three behavioral columns are considered together. We also compare runtime with QCAD on full tables and report batch scoring time and peak memory on synthetic inputs of up to one million rows.
Related Work
Contextual Anomaly Detection. Anomaly detection in tabular data has been extensively studied, with prior work commonly distinguishing between point, contextual, and collective anomalies [16, 17]. This work focuses on contextual anomaly detection, where an instance is considered anomalous if its behavior is unlikely given its contextual attributes. Early methods such as CAD [1] use probabilistic mixtures, while subsequent approaches explore probabilistic and correlation-based formulations such as ROCOD [9] and LoPAD [18]. More recent methods emphasize interpretability, with QCAD [2] modeling conditional distributions via quantile regression forests and deriving feature-level explanations from conditional deviations. RFOD [19] predicts each feature from the remaining features, and Normalcy Score [20] quantifies uncertainty for a scalar behavioral target. Local models and per-context estimation can incur repeated computation at scoring time.
Generative Models for Anomaly Detection. Generative approaches to anomaly detection often use low likelihood as a signal of abnormality. Classical density models and, more recently, deep generative approaches have been explored for tabular anomaly detection [10, 11, 21]. Normalizing flows further enable exact likelihood evaluation through invertible transformations [22], but their practical application is often constrained by architectural design and the cost of likelihood computation in high-dimensional settings. Flow Matching [14, 15, 23, 24] has recently emerged as a scalable alternative for training continuous normalizing flows without explicit likelihood or ODE-based density evaluation. Building on this paradigm, TCCM [25] uses a single contraction residual toward the origin for point anomaly detection. Flow Mismatching [26] aggregates residuals over Gaussian-to-image paths for visual defects, fitting on normal images. On contaminated tables, Konz et al. [27] compare TCCM and Forest-Flow, whose Deviation score also pools velocity residuals over time and noise. Flow-CAD conditions the joint behavioral field on separate context columns and uses an additive score with median absolute deviation (MAD) scaling and clipping.
Explainability. Explainability is increasingly recognized as a critical requirement in anomaly detection, particularly for tabular data where decisions often have high practical impact. Recent surveys [28, 29] distinguish between post-hoc and intrinsic explanation methods, and highlight the importance of feature-level attribution in practical deployments. Flow-CAD contributes to this line of work by providing intrinsic and decomposable anomaly explanations derived directly from the coordinate terms of its residual score, without relying on post-hoc explanation models.
Flow-CAD: Conditional Flow-Based Contextual Anomaly Detection
Problem Setup and Method Overview
We study contextual anomaly detection in tabular data. Each instance is represented by a pair , where denotes the encoded context vector and denotes behavioral features. Given a table , our goal is to prioritize rows whose behavior conflicts with patterns expected under their context. We denote the corresponding conditional behavior distribution by .
Flow Matching as a modeling primitive. Flow Matching trains a continuous-time velocity field by regressing pathwise transport targets along prescribed interpolation paths [14, 24]. Its population optimum is the conditional mean target given the intermediate state, context, and time. The regression objective requires neither density evaluation nor ODE integration. Flow-CAD learns one conditional velocity field for the behavior distribution and reuses the field across contexts.
Method Overview. Figure 1 illustrates the overall pipeline of Flow-CAD, which consists of two phases: (1) Training Phase: Conditional Flow Matching (Section III-B), in which we train a context-conditioned neural velocity field via Flow Matching along a linear interpolation path between a Gaussian base sample and the observed behavioral vector. This yields a single global model that captures conditional behavior across all contexts; (2) Inference Phase: Residual-based contextual anomaly scoring (Section III-C), in which we quantify contextual abnormality by the discrepancy between the model-predicted velocity and the true velocity induced by an observed instance, aggregated over multiple noise and time samples. To ensure robustness and interpretability, residuals are normalized using the median absolute deviation (MAD) and truncated to mitigate the dictator effect where a single extreme deviation dominates the score. It also yields additive output-coordinate terms for inspecting flagged rows.
Figure 1. Illustration of the training (left) and inference (right) phases of Flow-CAD. The inference panel writes for within Gaussian block .
Phase 1: Training Detection Model using Flow Matching with Linear Interpolation
Let denote behavioral features and denote encoded contextual features. We introduce a conditional velocity field , , parameterized by a neural network with learnable parameters . This velocity field is trained via Flow Matching on a simple linear path [23] between a base distribution and the data in the behavioral space.
Linear path. Let be the density of , where is the -dimensional identity. For and , the path to is . For each sampled endpoint–noise pair, the pathwise target velocity is , which is independent of .
Flow Matching objective. We train so that it approximates this velocity along the path. We write the Flow Matching objective in squared-norm form as
We estimate this expectation over minibatches, drawing and independently for each row. The implementation averages over behavioral coordinates as well, multiplying this objective by without changing its minimizer.
Context encoder and architecture. In practice, is implemented as a context-conditional multi-layer perceptron (MLP): , and , where and are MLPs, and denotes concatenation. The embedding has width . Categorical contextual features are one-hot encoded and then fed into together with numerical contextual features, so that the model can handle mixed-type in a unified way. The parameters are optimized jointly via Eq. (1) using Adam [30].
Conditional likelihood. Under the usual regularity conditions for a conditional continuous normalizing flow [14], its log-density is evaluated along the model ODE trajectory:
Here is integrated backward from . This model ODE trajectory generally differs from the sampled straight interpolation paths. Evaluating (2) requires solving the ODE and integrating the divergence of along its trajectory. Flow-CAD scores rows through batched velocity-field evaluations without computing the density.
Phase 2: Residual-Based Anomaly Scoring with MAD Normalization and Truncation
Conditional denoising interpretation. Flow Matching regresses on state, context, and time. The induced reconstruction is . Along the sampled path , its error relative to is times the signed velocity residual. At the population optimum the reconstruction equals the posterior mean. The residual for an individual endpoint may remain nonzero. Proposition 1 relates field estimation error to our clipped conditional score.
Raw residuals. Given a fitted field and an observation , draw independent for . For each , draw fresh times , . All time draws are mutually independent and independent of the Gaussian draws; the same is reused only within its inner time loop. Set
Taking the absolute value coordinatewise gives
Robust per-dimension scaling via MAD. Behavioral dimensions can exhibit very different magnitudes and intrinsic variability. Directly aggregating raw residuals would therefore bias the anomaly score toward features with larger natural scales. To account for this, we normalize residuals using a robust, per-dimension scale estimate based on the median absolute deviation (MAD). For each behavioral dimension , we compute , and , where denotes the value of the -th behavioral feature of the -th training instance. We floor the scale at and write . The normalized residual magnitude is . Section IV-E ablates this scaling.
Truncation to avoid dictator effect. If we simply sum the normalized residuals across behavioral dimensions, a single extremely deviant dimension could dominate the anomaly score (namely the dictator effect, also observed in [2]). To mitigate this, we truncate each normalized residual at a fixed threshold : , with . In our experiments we use (see Section IV-E for a sensitivity analysis on setting of this value), which can be interpreted as an upper bound on the number of “typical MAD units” that a single dimension is allowed to contribute. We then aggregate across dimensions as follows:
Here is the truncated, normalized residual energy for a single pair .
Monte Carlo averaging. The truncated residual energy depends on both the sampled base noise and the interpolation time . A single realization may therefore be noisy and sensitive to stochastic variation along the transport path. To obtain a stable anomaly score that reflects the expected mismatch between the learned conditional flow and the observed behavior, we estimate the expectation over by Monte Carlo averaging:
We use , giving 256 field evaluations in 16 independent Gaussian-noise blocks. Proposition 2 establishes unbiasedness and quantifies the distinct effects of and on Monte Carlo variance. Section IV-E evaluates the sampling-budget trade-off empirically.
Ranking and column contributions. The raw anomaly scores do not have an intrinsic probabilistic scale and may vary across datasets and sampling configurations. We compute detection metrics from the raw scores. Percentile ranks preserve the within-table ordering. Because the anomaly energy in (4) is constructed from dimension-wise residuals, Flow-CAD naturally provides per-feature contributions: . The terms sum to the raw score in (4). Each output residual can depend on every behavioral input through the joint field. The score is decomposed by output coordinate.
Theoretical Insights
A row’s anomaly score depends on the velocity field and the random draws used to compute it. Proposition 1 compares the expected scores from the fitted and optimal fields using the same MAD scales and truncation threshold. It bounds the change for an individual row and relates the average absolute change at a fixed context to the excess Flow Matching loss. With the fitted field and scoring settings fixed, Proposition 2 bounds the error from estimating the expected score with a finite number of noise and time draws.
With from Section III-C and , define
For any field , its expected raw score at a fixed instance is
where and are independent. For , this is the expected raw score in (4).
Proposition 1 (Population optimality and stability of residual scoring). *Fix a context . Let , , and be independent, with . Here is the conditional law of the training endpoints, which can
include anomalies. Set and .
Define the population risk and its optimal regression field by
Let be measurable with .
(i) Population risk decomposition.
The expectations here include the random endpoint . The conditional covariance can vary with the intermediate state and time.
(ii) Conditional denoising interpretation. For , let . At a fixed test endpoint , with , the posterior version of satisfies
Thus is the expectation of the dimension-wise scaled and truncated denoising residual in (9).
(iii) Stability of the implemented robust score. Define the pointwise velocity estimation error
Whenever this quantity is finite,
In particular, averaging over gives
From training loss to row scores. Part (i) splits the average training loss into the loss of the optimal field and the error from estimating it. For a fixed row, the cross term can remain, so the decomposition does not determine the row’s rank. Part (ii) explains why the optimal field can still leave a residual: the posterior mean can differ from the observed behavior. Part (iii) bounds how much using the fitted field changes each row’s expected score. For rows and scored with the same MAD scales, let be the expected score of minus that of under the optimal field. The fitted field still gives a higher expected score if
The right-hand side adds the two bounds in (11), with velocity estimation errors and from (10). The average training loss does not determine this gap or how it changes with training duration or network size. In the one-dimensional Gaussian example in Section III-D1, even the optimal field gives higher expected scores to observations farther from the mean.
Proposition 2 (Nested Monte Carlo scoring). Fix , , the scales , and before drawing the scoring samples. Write , , and . For integers , draw independently from and draw all independently from , independently of the Gaussian draws. Define
For the same draws in (4), . Let
The estimator is unbiased and has exact variance
Since the block means are independent and lie in , for every ,
Equivalently, for , with probability at least ,
A variance-sensitive bound, with , is
When , the estimator equals almost surely.
Choosing the number of samples. For a fixed row, each Gaussian draw defines one path. Equation (15) separates variation across paths from variation across sampled times on the same path. Taking more time samples () gives a better average along each path, but leaves the variance term unchanged. Drawing more paths () reduces both terms, so the estimate converges to the expected score in mean square even with fixed.
The default uses 16 independent paths and evaluates the field at 16 sampled times on each, for 256 evaluations per row. Section IV-E examines how the sampling budgets affect detection and the stability of review lists. Two rows with close expected scores can still switch places when rescored. The argument following (20) gives a sufficient gap to preserve their order with high probability.
Proof of Proposition 1
Proof of Proposition 1: Step 1: Population orthogonality. Let at the fixed context. Conditional expectation gives . Writing , which is -measurable, yields
All terms are integrable by the second-moment assumptions and conditional Jensen’s inequality. Expanding the squared residual proves the first identity in (8). The remaining conditional squared norm has expectation
which proves the second identity and the optimality of [14, 31]. This orthogonality averages over the random endpoint ; conditioning additionally on a fixed test endpoint would change the regression problem and does not justify the same decomposition.
Step 2: Posterior denoising identity. For , the interpolation identity implies . Applying this identity at and conditioning on gives
For a fixed , one also has . Subtracting proves (9). The Gaussian corruption has a strictly positive density for , so posterior versions can be used along these fixed-endpoint paths almost surely. The singular endpoint has zero probability under the time-sampling law and is not needed for this identity.
Step 3: Stability of the robust energy. The absolute value and the clipping map are nonexpansive. Hence, for any ,
At a fixed endpoint , apply this inequality to the two fields’ residual vectors using the same . The target cancels. Taking expectations and applying Cauchy–Schwarz gives
Finally, average over and use Jensen’s inequality and Step 1:
This proves (12). The argument requires no differentiability or ODE assumptions, and applies to the ReLU field used in our implementation. □
A nonzero residual at the optimal field. For a one-dimensional reference distribution and independent , let . Suppressing the fixed context, and
Consequently, the unnormalized quadratic residual energy at a fixed is
For the implemented score, fix and write for the displayed residual evaluated at . The distribution of is that of for , where and . For its CDF is
Here is the standard normal CDF. The displayed CDF decreases strictly with , since the standard normal density at is smaller than at . Using and averaging over shows that the gap in the implemented score strictly increases with . It therefore orders Gaussian tail observations by increasing negative log-likelihood in this one-dimensional setting even at .
2) Proof of Proposition 2: Step 1: Unbiasedness under nested sampling. Each pair has the same marginal distribution as an independent . By linearity,
This step does not require independence of all residual terms.
Step 2: Exact variance. Conditional on , the terms within block are independent. Therefore,
The law of total variance gives . The complete random blocks are independent and identically distributed, so the are also independent and identically distributed. Dividing their variance by proves (15). In contrast, for within one block,
This covariance is generally nonzero.
Step 3: Finite-sample concentration. Since , every block average lies in . Applying Hoeffding’s inequality [32] to the independent block averages gives (16); solving its right-hand side for gives (17). For the variance-sensitive form, let . Then , , and . For , the exponential series and for yield
Here we used and . Independence and the exponential Markov inequality, with when , give
Apply the same argument to and add the two tails to obtain (18) [33]. If , each block average is constant almost surely, which gives the stated degenerate case. □
Consequence for score ordering. Let and be the expected and estimated raw scores for row . For fixed rows with common , , and , the union bound gives, with probability at least for ,
Thus a pair with retains its strict order on this event. At , , and , this bound’s sufficient gap is , exceeding the score range. We measure review-list stability under repeated scoring in § 4-E5.
Experiments
Our experiments are designed to answer the following research questions: RQ1. How well does Flow-CAD rank anomalous rows? RQ2. How does it compare with existing contextual and point detectors? RQ3. How do behavioral features contribute to individual anomaly scores? RQ4. How sensitive is it to scoring settings and context encoding?
Experimental Setup
This subsection describes the common experimental protocol. We introduce the datasets and their context–behavior partitions, describe how the benchmark tables and anomaly labels are constructed, explain how the baseline methods are configured, and then give the fixed Flow-CAD settings and evaluation metrics.
Datasets and feature partitions. We evaluate all methods on 20 real-world tabular datasets summarized in Table I. We use the source tables released with QCAD [2]. We assume the partitions of features are given beforehand. Behavior is numerical. Context may include categorical columns.
| Dataset | #Samples | #Anomalies (Rate) | #Contextual columns | #Behavioral columns |
| Abalone | 4177 | 100 (2.4%) | 4 | 5 |
| Airfoil | 1503 | 70 (4.7%) | 5 | 1 |
| BodyFat | 252 | 20 (7.9%) | 12 | 2 |
| Boston | 506 | 40 (7.9%) | 13 | 1 |
| Concrete | 1030 | 50 (4.9%) | 8 | 1 |
| ElNino | 20000 | 200 (1.0%) | 6 | 5 |
| Energy | 768 | 50 (6.5%) | 8 | 2 |
| FishWeight | 159 | 15 (9.4%) | 6 | 1 |
| ForestFires | 517 | 50 (9.7%) | 4 | 9 |
| GasEmission | 7384 | 100 (1.4%) | 8 | 3 |
| HeartFailure | 299 | 30 (10.0%) | 6 | 6 |
| Hepatitis | 589 | 30 (5.1%) | 3 | 10 |
| IndianLiver | 579 | 30 (5.2%) | 3 | 8 |
| Maintenance | 11934 | 100 (0.8%) | 15 | 3 |
| Parkinson | 5875 | 100 (1.7%) | 20 | 2 |
| PowerPlant | 9568 | 100 (1.0%) | 4 | 1 |
| QSRanking | 475 | 40 (8.4%) | 7 | 6 |
| SynMachine | 557 | 50 (9.0%) | 4 | 1 |
| Toxicity | 908 | 50 (5.5%) | 6 | 1 |
| Yacht | 308 | 30 (9.7%) | 6 | 1 |
Table I. Reconstructed benchmark tables used for full-table evaluation. Column counts are reported before encoding.
For example, in the Abalone dataset, Sex, Length, Diameter, Height are treated as contextual features and the remaining attributes as behavioral features. In ForestFires, spatial and temporal variables (, , month, day) define the context, and weather, fire-weather indices, and burned area form the behavior.
Benchmark construction. Following the QCAD benchmark [2], we remove incomplete rows, cap each input at 20,000 rows by seeded subsampling, and min–max scale the numerical columns designated by the benchmark. We sample the number of rows listed in Table I uniformly without replacement, excluding the first row as in the released generator. Each selected row receives an independent signed shift in every behavioral column, with magnitude drawn uniformly from and the sign chosen uniformly. The selected rows define the benchmark anomaly labels.
We use seven data seeds (43–49) for each dataset. All methods are evaluated on the same 140 benchmark tables, with runs paired by dataset and data seed.
Baselines. We compare Flow-CAD against 13 representative baselines, including four contextual anomaly detectors (QCAD [2], LoPAD [18], ROCOD [9], CAD [1]), and nine point anomaly detectors (Isolation Forest [34], LOF [35], -NN [36], SOD [37], HBOS [38], LUNAR [39], DTE-Categorical, DTE-NonParametric [40], and TCCM [25]).
We keep each baseline’s settings fixed across runs on a given dataset. We reimplemented QCAD using the neighborhood sizes specified in its benchmark. LoPAD uses the Markov blankets from the QCAD release and fits CART models on 20 subsamples. ROCOD uses the benchmark distance cutoff and relies on its global predictor for rows with no neighbors. CAD fits a joint Gaussian mixture with five components and scores rows by their conditional density. We use the authors’ released code for DTE and TCCM. For the remaining methods, we use the settings from PyOD 2.0.3 [41], including LUNAR’s built-in validation with synthetic negatives.
Flow-CAD configuration. Flow-CAD one-hot encodes the designated categorical context columns. The resulting context vector is held fixed along the interpolation path, while interpolation and feature attribution are defined only for the numerical behavioral features. We use the fixed settings in Table II for every run. Each model is trained on a complete benchmark table for 1,000 epochs, and its final checkpoint is used to score all rows in that table. The seven runs pair data seeds 43–49 with training seeds 202–208 in ascending order. Each run uses a single CPU thread.
| Component | Fixed value |
| Context encoder | 2 layers of width 32 |
| Velocity network | 3 hidden layers of width 64, ReLU |
| Optimizer | Adam, learning rate 0.001 |
| Batch size | 128 |
| Training epochs | 1,000 |
| Score aggregation | |
| Residual truncation | |
| Monte Carlo budget |
Table II. Flow-CAD configuration fixed across benchmark datasets and runs.
Evaluation metrics. Anomaly labels are reserved for evaluation. For the main same-table benchmark, we report the area under the receiver operating characteristic curve (ROC AUC), the trapezoidal area under the precision–recall curve (PR AUC), and precision at (P@), with equal to the number of labeled anomalies. We report mean and sample standard deviation across runs and average the per-dataset ranks over the 20 datasets.
Detection Quality Across Benchmark Tables (RQ1)
Tables III–V report results on 20 datasets. We analyze the overall ranks and detection when anomalies are rare, then leave out one dataset at a time to test rank stability.
1) Ranks across datasets. Among the 14 methods, Flow-CAD has the best average rank for PR AUC (1.900), ROC AUC (2.050), and P@ (1.825). These metrics examine different parts of detection: ROC AUC summarizes the full score ordering, PR AUC focuses on correctly retrieving anomalies, and P@ measures precision among the top rows. Thus, Flow-CAD performs well both across the full ranking and among the rows inspected first.
2) Detection with rare anomalies. Five datasets in Table I have anomaly rates below 2%. Across their 15 dataset–metric comparisons, Flow-CAD ranks among the top three methods in 13. It ranks first on all three metrics for Parkinson, and first for PR AUC and P@ on PowerPlant. These results show that its strong overall ranking is retained when only a small fraction of rows is anomalous.
3) Influence of individual datasets. Because an average rank can be driven by one especially favorable dataset, we recalculate it with one dataset left out at a time. Each calculation therefore averages the ranks over the other 19 datasets. Flow-CAD remains first for PR AUC and P@ in all 20 cases. For ROC AUC, it ranks first or ties for first in 16 cases and ranks second in the other four. Thus, the conclusions for PR AUC and P@ do not depend on any single table; the ROC AUC comparison is closer, but Flow-CAD never falls below second.
Comparison with Existing Detectors (RQ2)
We compare Flow-CAD with contextual and point anomaly detectors, first within each group and then against the strongest competitor for each dataset and metric.
1) Contextual anomaly detectors. Among QCAD, CAD, ROCOD, LoPAD, and Flow-CAD, Flow-CAD has the best average rank for all three metrics. Its average ranks are 1.900, 2.050, and 1.825, compared with 2.300, 2.100, and 2.350 for QCAD. Flow-CAD has higher PR AUC and P@ than QCAD on 13 of the 20 datasets, while the two methods each lead on ten datasets for ROC AUC. Flow-CAD also leads CAD on at least 15 datasets for every metric, and leads ROCOD and LoPAD on all 20.
2) Point anomaly detectors. The best average ranks among the nine point detectors are 6.350 for PR AUC (HBOS), 5.800 for ROC AUC (LUNAR), and 6.025 for P@ (HBOS). Flow-CAD’s corresponding ranks are 1.900, 2.050, and 1.825. Across datasets, it leads every point detector in 14 PR AUC cases, 14 ROC AUC cases, and 16 P@ cases.
3) Comparison with the strongest baseline on each table. The leading baseline changes with the dataset and metric. We therefore compare Flow-CAD with the best member of each group in every case. Across the 60 dataset–metric combinations, Flow-CAD exceeds the strongest contextual baseline in 34 cases and the strongest point detector in 44. Its average-rank advantage is thus supported by results across different datasets and metrics rather than by one favorable subset.
| Dataset | Flow-CAD (ours) | QCAD | LoPAD | ROCOD | CAD |
| Abalone | 1.00±0.00 (1) | 0.96±0.01 (3) | 0.01±0.00 (14) | 0.55±0.03 (10) | 0.98±0.01 (2) |
| Airfoil | 0.44±0.10 (4) | 0.68±0.05 (1) | 0.05±0.10 (14) | 0.42±0.04 (5) | 0.49±0.04 (2) |
| BodyFat | 0.84±0.08 (4) | 0.63±0.08 (4) | 0.07±0.02 (14) | 0.79±0.05 (3) | 0.81±0.12 (2) |
| Boston | 0.60±0.10 (2) | 0.63±0.10 (1) | 0.08±0.00 (13) | 0.30±0.06 (4) | 0.32±0.09 (3) |
| Concrete | 0.67±0.14 (1) | 0.60±0.09 (2) | 0.09±0.02 (9) | 0.31±0.06 (5) | 0.30±0.06 (6) |
| ElNino | 0.81±0.04 (3) | 0.99±0.00 (1) | 0.11±0.01 (8) | 0.39±0.05 (7) | 0.96±0.01 (2) |
| Energy | 0.94±0.03 (1) | 0.93±0.02 (2) | 0.05±0.00 (14) | 0.43±0.07 (7) | 0.91±0.03 (3) |
| FishWeight | 0.90±0.05 (1) | 0.85±0.10 (2) | 0.13±0.06 (8) | 0.44±0.10 (4) | 0.72±0.09 (3) |
| ForestFires | 0.97±0.02 (4) | 0.99±0.01 (2) | 0.10±0.01 (14) | 0.49±0.03 (10) | 0.88±0.03 (6) |
| GasEmission | 0.98±0.00 (2) | 0.98±0.00 (1) | 0.01±0.00 (14) | 0.87±0.02 (3) | 0.85±0.02 (4) |
| HeartFailure | 0.97±0.01 (2) | 0.91±0.03 (3) | 0.05±0.00 (14) | 0.54±0.03 (6) | 0.77±0.09 (5) |
| Hepatitis | 0.99±0.01 (2) | 0.98±0.01 (3) | 0.05±0.01 (14) | 0.55±0.03 (8) | 0.84±0.08 (5) |
| IndianLiver | 0.90±0.04 (4) | 0.90±0.04 (4) | 0.05±0.00 (8) | 0.50±0.06 (8) | 0.79±0.12 (6) |
| Maintenance | 0.76±0.08 (4) | 0.95±0.02 (1) | 0.01±0.00 (12) | 0.50±0.00 (5) | 0.87±0.04 (3) |
| Parkinson | 0.98±0.01 (1) | 0.92±0.02 (2) | 0.02±0.00 (14) | 0.66±0.05 (4) | 0.75±0.04 (3) |
| PowerPlant | 0.66±0.04 (1) | 0.46±0.04 (4) | 0.02±0.00 (10) | 0.66±0.05 (2) | 0.56±0.07 (3) |
| QSRanking | 0.74±0.08 (3) | 0.78±0.05 (1) | 0.06±0.00 (14) | 0.56±0.06 (4) | 0.77±0.07 (2) |
| SynMachine | 1.00±0.00 (1) | 0.97±0.02 (3) | 0.35±0.03 (13) | 0.80±0.07 (7) | 0.54±0.12 (11) |
| Toxicity | 0.61±0.06 (1) | 0.44±0.09 (4) | 0.11±0.01 (8) | 0.46±0.06 (3) | 0.46±0.06 (2) |
| Yacht | 0.92±0.03 (1) | 0.89±0.04 (2) | 0.53±0.02 (6) | 0.29±0.04 (6) | 0.25±0.07 (9) |
| Avg Rank | 1.900 | 2.300 | 11.900 | 5.550 | 4.100 |
| Dataset | iForest | LOF | -NN | SOD | HBOS |
| Abalone | 0.41±0.07 (11) | 0.92±0.01 (6) | 0.94±0.00 (5) | 0.75±0.01 (9) | 0.20±0.04 (13) |
| Airfoil | 0.10±0.02 (8) | 0.05±0.01 (11) | 0.05±0.01 (12) | 0.14±0.02 (7) | 0.09±0.02 (9) |
| BodyFat | 0.17±0.04 (7) | 0.09±0.02 (12) | 0.09±0.02 (13) | 0.10±0.04 (8) | 0.18±0.03 (6) |
| Boston | 0.11±0.02 (8) | 0.08±0.01 (11) | 0.08±0.01 (12) | 0.08±0.01 (9) | 0.13±0.02 (6) |
| Concrete | 0.08±0.02 (10) | 0.06±0.01 (12) | 0.06±0.02 (11) | 0.06±0.01 (13) | 0.26±0.06 (7) |
| ElNino | 0.55±0.10 (5) | 0.01±0.00 (14) | 0.01±0.00 (13) | 0.04±0.00 (9) | 0.77±0.03 (4) |
| Energy | 0.39±0.03 (8) | 0.11±0.02 (12) | 0.37±0.02 (9) | 0.89±0.05 (4) | 0.32±0.05 (11) |
| FishWeight | 0.22±0.05 (7) | 0.11±0.04 (14) | 0.11±0.04 (12) | 0.12±0.03 (11) | 0.20±0.07 (7) |
| ForestFires | 0.97±0.02 (3) | 0.17±0.02 (13) | 0.18±0.02 (12) | 0.57±0.04 (9) | 1.00±0.00 (1) |
| GasEmission | 0.10±0.02 (7) | 0.01±0.00 (13) | 0.01±0.00 (12) | 0.03±0.00 (8) | 0.25±0.05 (6) |
| HeartFailure | 0.86±0.02 (4) | 0.13±0.03 (12) | 0.17±0.05 (11) | 0.37±0.07 (9) | 0.98±0.01 (1) |
| Hepatitis | 0.93±0.04 (4) | 0.17±0.02 (12) | 0.15±0.02 (13) | 0.35±0.01 (10) | 0.99±0.01 (1) |
| IndianLiver | 0.94±0.02 (3) | 0.11±0.02 (12) | 0.17±0.04 (11) | 0.45±0.05 (9) | 0.99±0.01 (1) |
| Maintenance | 0.02±0.00 (10) | 0.01±0.00 (14) | 0.01±0.00 (13) | 0.02±0.00 (9) | 0.23±0.08 (6) |
| Parkinson | 0.00±0.00 (10) | 0.02±0.00 (13) | 0.02±0.00 (12) | 0.04±0.00 (8) | 0.02±0.00 (9) |
| PowerPlant | 0.05±0.01 (9) | 0.01±0.00 (14) | 0.01±0.00 (12) | 0.01±0.00 (11) | 0.23±0.03 (7) |
| QSRanking | 0.22±0.07 (7) | 0.10±0.02 (10) | 0.10±0.02 (12) | 0.09±0.01 (13) | 0.44±0.07 (5) |
| SynMachine | 0.36±0.06 (12) | 0.80±0.04 (8) | 0.91±0.02 (4) | 0.72±0.06 (9) | 0.26±0.04 (14) |
| Toxicity | 0.09±0.01 (10) | 0.08±0.02 (11) | 0.07±0.01 (14) | 0.12±0.02 (7) | 0.10±0.01 (9) |
| Yacht | 0.28±0.07 (7) | 0.19±0.04 (13) | 0.25±0.03 (10) | 0.25±0.05 (8) | 0.31±0.09 (4) |
| Avg Rank | 7.450 | 11.850 | 11.150 | 9.000 | 6.350 |
| Dataset | LUNAR | DTE-C | DTE-NP | TCCM | |
| Abalone | 0.92±0.03 (7) | 0.92±0.01 (8) | 0.94±0.00 (4) | 0.24±0.11 (12) | |
| Airfoil | 0.29±0.06 (6) | 0.46±0.18 (3) | 0.06±0.01 (10) | 0.05±0.01 (13) | |
| BodyFat | 0.31±0.08 (5) | 0.09±0.05 (11) | 0.10±0.03 (9) | 0.10±0.02 (10) | |
| Boston | 0.13±0.02 (7) | 0.07±0.01 (14) | 0.16±0.03 (5) | 0.08±0.02 (10) | |
| Concrete | 0.12±0.02 (8) | 0.52±0.00 (3) | 0.48±0.03 (4) | 0.05±0.01 (14) | |
| ElNino | 0.02±0.01 (10) | 0.51±0.00 (6) | 0.01±0.00 (11) | 0.01±0.00 (12) | |
| Energy | 0.44±0.08 (6) | 0.53±0.00 (5) | 0.34±0.02 (10) | 0.09±0.03 (13) | |
| FishWeight | 0.31±0.07 (5) | 0.11±0.04 (13) | 0.12±0.05 (10) | 0.13±0.05 (9) | |
| ForestFires | 0.78±0.16 (8) | 0.78±0.05 (7) | 0.21±0.02 (11) | 0.90±0.02 (5) | |
| GasEmission | 0.41±0.15 (5) | 0.01±0.00 (11) | 0.01±0.00 (10) | 0.03±0.00 (9) | |
| HeartFailure | 0.51±0.04 (9) | 0.12±0.02 (6) | 0.20±0.02 (11) | 0.40±0.11 (8) | |
| Hepatitis | 0.53±0.09 (9) | 0.84±0.04 (6) | 0.19±0.02 (11) | 0.73±0.20 (7) | |
| IndianLiver | 0.85±0.02 (5) | 0.08±0.03 (13) | 0.21±0.02 (10) | 0.59±0.13 (7) | |
| Maintenance | 0.94±0.08 (2) | 0.54±0.00 (5) | 0.07±0.01 (8) | 0.01±0.00 (11) | |
| Parkinson | 0.14±0.02 (6) | 0.51±0.00 (5) | 0.02±0.00 (11) | 0.12±0.07 (7) | |
| PowerPlant | 0.43±0.16 (6) | 0.43±0.19 (5) | 0.01±0.00 (13) | 0.15±0.11 (8) | |
| QSRanking | 0.17±0.03 (8) | 0.10±0.02 (11) | 0.43±0.03 (6) | 0.10±0.02 (9) | |
| SynMachine | 0.85±0.04 (6) | 0.62±0.04 (10) | 0.98±0.01 (2) | 0.90±0.02 (5) | |
| Toxicity | 0.15±0.04 (5) | 0.14±0.01 (6) | 0.07±0.01 (12) | 0.07±0.02 (13) | |
| Yacht | 0.23±0.06 (11) | 0.22±0.06 (12) | 0.30±0.05 (5) | 0.19±0.04 (14) | |
| Avg Rank | 6.600 | 8.450 | 8.600 | 9.800 |
Table III. TABLE III. PR AUC ON 20 DATASETS. ENTRIES GIVE MEAN ± STANDARD DEVIATION (RANK). RANKS USE UNROUNDED MEANS AND AVERAGE NUMERICAL TIES ( TOLERANCE). EQUAL DISPLAYED MEANS CAN HAVE DIFFERENT RANKS. BOLD AND UNDERLINING MARK THE TOP TWO DISTINCT RANKS. EACH METHOD HAS 140 PAIRED CASES, WITH SEVEN BENCHMARK RUNS PER DATASET.
| Dataset | Flow-CAD (ours) | QCAD | LoPAD | ROCOD | CAD |
| Abalone | (1) | (4) | (14) | (9) | (8) |
| Airfoil | (4) | (1) | (13) | (5) | (3) |
| BodyFat | (2) | (4) | (14) | (3) | (1) |
| Boston | (2) | (1) | (13) | (3) | (4) |
| Concrete | (2) | (1) | (7) | (3) | (4) |
| ElNino | (3) | (1) | (7) | (5) | (2) |
| Energy | (2) | (1) | (14) | (9) | (3) |
| FishWeight | (1) | (2) | (12) | (5) | (3) |
| ForestFires | (4) | (2) | (14) | (10) | (6) |
| GasEmission | (2) | (1) | (14) | (4) | (3) |
| HeartFailure | (2) | (3) | (14) | (13) | (5) |
| Hepatitis | (2) | (3) | (14) | (8) | (6) |
| IndianLiver | (2) | (4) | (14) | (7) | (6) |
| Maintenance | (3) | (2) | (11) | (13) | (4) |
| Parkinson | (1) | (2) | (14) | (3) | (5) |
| PowerPlant | (2) | (1) | (14) | (3) | (4) |
| QSRanking | (3) | (1) | (14) | (4) | (2) |
| SynMachine | (1) | (4) | (12) | (8) | (13) |
| Toxicity | (1) | (2) | (13) | (3) | (4) |
| Yacht | (1) | (2) | (3) | (7) | (10) |
| Avg Rank | 2.050 | 2.100 | 12.250 | 6.250 | 4.800 |
Table IV. ROC AUC on 20 datasets. Notation follows Table III.
| Dataset | Flow-CAD (ours) | QCAD | LoPAD | ROCOD | CAD |
| Abalone | (1) | (6) | (14) | (10) | (3) |
| Airfoil | (3) | (1) | (14) | (4) | (2) |
| BodyFat | (2) | (4) | (14) | (3) | (1) |
| Boston | (2) | (1) | (8.5) | (4) | (3) |
| Concrete | (1) | (2) | (7) | (3) | (4) |
| ElNino | (1) | (6) | (7) | (6) | (2) |
| Energy | (1) | (3) | (14) | (7) | (2) |
| FishWeight | (1) | (2) | (9) | (4) | (7) |
| ForestFires | (4) | (2) | (14) | (10) | (5) |
| GasEmission | (2) | (1) | (14) | (4) | (3) |
| HeartFailure | (1) | (3) | (14) | (11) | (5) |
| Hepatitis | (2) | (4) | (14) | (8) | (5) |
| IndianLiver | (2) | (3) | (14) | (8) | (5) |
| Maintenance | (1) | (2) | (8.5) | (12.5) | (3) |
| Parkinson | (1) | (2) | (7) | (4) | (3) |
| PowerPlant | (1) | (4) | (14) | (4) | (7) |
| QSRanking | (2.5) | (1) | (14) | (4) | (2.5) |
| SynMachine | (1) | (2) | (13) | (7) | (11) |
| Toxicity | (1) | (2) | (5) | (3) | (4) |
| Yacht | (1) | (2) | (3) | (5) | (9) |
| Avg Rank | 1.825 | 2.350 | 10.900 | 5.975 | 3.975 |
Table V. P@n on 20 datasets. Notation follows Table III.
Instance-Level Interpretability via Residual Decomposition (RQ3)
Flow-CAD assigns an anomaly score to each row and records how much each behavioral column contributes to that score. Figure 2 shows both quantities for one anomalous row from the Energy Efficiency dataset and a nearby normal row observed under a similar context. For this illustration, we train Flow-CAD on the QCAD benchmark table using the original Energy Efficiency configuration.
Figure 2. Illustrative raw-score decomposition for two Energy Efficiency instances with behavioral features (, ). (a) Sampled intermediate states and signed velocity differences ; the score uses their coordinate-wise magnitudes . (b) Feature contributions estimated with a separate set of Monte Carlo draws.
1) Why the anomalous row receives a high score. Figure 2(a) shows sampled points along the paths to the two observed rows. At each point, the arrow is the difference between the velocity predicted by Flow-CAD and the target velocity for that path. The anomalous row repeatedly produces longer and more dispersed arrows than the nearby normal row. Its high score therefore reflects large residuals across many Monte Carlo draws, rather than one unusual sample.
2) Which columns drive the score. Figure 2(b) reports the residual contribution of each behavioral column after MAD normalization and truncation. For the anomalous row, and contribute about 4.1 and 2.4, respectively, whereas both contributions are approximately 0.4 or less for the normal row. Because the contributions sum to the raw score in (4), their relative sizes indicate which column should be inspected first. In this example, the larger contribution of directs attention to that column when the row is compared with observations from similar contexts.
Ablation and Sensitivity Analysis (RQ4)
We conduct a series of ablation studies to assess the sensitivity of Flow-CAD to key design choices, including residual normalization, truncation, aggregation norms, and Monte Carlo sampling. Figures 3–7 vary one scoring choice at a time on the same tables and 1,000-epoch fits as the main benchmark. They report means and standard deviations across the seven benchmark runs, using MAD normalization, , aggregation, and as the defaults. We also test whether repeated scoring flags the same rows and how the encoding of categorical context affects detection.
Ablation studies on residual normalization and truncation
We compare the default configuration (MAD normalization with truncation) against variants that remove either component. Normalization puts residuals from different behavioral columns on a comparable scale, while truncation limits the influence of any single residual. Across the 20 datasets, the complete score has the highest mean on all three metrics. Truncation provides the larger average gain: removing it lowers mean PR AUC by 3.3 percentage points and mean P@n by 1.5 points. MAD normalization gives smaller gains on average, but is important when residual scales differ substantially across columns. On HeartFailure and GasEmission, the complete score gives PR AUCs of 0.974 and 0.976, versus 0.893 and 0.941 without normalization and 0.738 and 0.794 without truncation.
Sensitivity to truncation threshold tau
Sensitivity to truncation threshold : Figure 4 varies the positive truncation threshold from 2 to 100 while keeping MAD normalization enabled. Across , the median per-dataset PR AUC range is only 0.015. At the default , PR AUC is within one percentage point of the best of these three settings on 15 datasets and within two points on all 20. Thus, lies in a broad stable region rather than depending on a narrow optimum. The no-truncation case is reported separately in Figure 3.
Figure 3. Ablation on residual normalization and truncation across all datasets. Panels show PR AUC, ROC AUC, and P@n (top to bottom). We compare the default configuration (MAD normalization with truncation) against variants without normalization and without truncation.
Figure 4. Sensitivity to truncation with MAD normalization. The threshold varies from 2 to 100.
Sensitivity to residual aggregation norm
Sensitivity to residual aggregation norm: Figure 5 compares the default norm with the and norms. Across the 20 datasets, has the highest mean for all three metrics: 0.838 for PR AUC, 0.964 for ROC AUC, and 0.792 for P@n.
Figure 5. Residual aggregation with , , and norms. Panels show PR AUC, ROC AUC, and P@ (top to bottom).
The corresponding means are 0.829, 0.964, and 0.789 for , and 0.710, 0.927, and 0.636 for . Moreover, is best or tied on 13, 13, and 15 datasets, respectively, and is within one percentage point of the best norm in 52 of the 60 dataset–metric comparisons. We therefore retain as the most reliable overall choice; it also preserves the additive column-wise decomposition used in Section III-C.
Sensitivity to Monte Carlo sampling budgets
Sensitivity to Monte Carlo sampling budgets: Figures 6 and 7 show the effect of varying (time draws per Gaussian draw) and (Gaussian draws), respectively. We hold one budget at 16 while varying the other and reuse draws across settings. Residual normalization and truncation remain enabled.
Figure 6. Sensitivity to the number of time draws per Gaussian draw with MAD normalization and truncation.
Both budgets matter most when they are small. Increasing from 2 to 16 improves PR AUC on all 20 datasets, with a median gain of 5.3 percentage points. Increasing over the same range also improves all 20, with a median gain of 1.0 point. The gains then taper: moving from 16 to 128 adds median gains of 0.5 points for and 0.1 points for . The larger effect of agrees with Proposition 2: additional Gaussian draws reduce both variance components, whereas additional time draws reduce only the inner component.
Stability of rows selected for review
In practice, repeated runs should flag largely the same rows for inspection. We test this by scoring each table twice with independent Monte Carlo draws and comparing the two top-5% lists. The experiment covers six datasets, each with three single-column variants,
Figure 7. Sensitivity to the number of Gaussian draws with MAD normalization and truncation.
for a total of 18 fitted models. We fix and increase from 16 to 64. The median overlap rises from 80.4% to 91.2%, and 17 of the 18 models show higher overlap. More draws therefore make row selection more stable.
Representing categorical context
Categorical values such as countries have no natural numerical order, yet scalar codes in [?, 1] impose one. We compare scalar and one-hot encodings on FishWeight and QSRanking using the same seven benchmark runs (data seeds 43–49) and 1,000 training epochs. One-hot encoding performs better on all three metrics in both datasets. On FishWeight, PR AUC, ROC AUC, and P@ rise from 0.859, 0.955, and 0.781 to 0.904, 0.973, and 0.829. On QSRanking, they rise from 0.693, 0.911, and 0.646 to 0.745, 0.936, and 0.693. QSRanking has 57 country categories, so one-hot encoding is the more natural choice.
Controlled Sign-Parity Experiment
Results on real datasets do not show whether a detector has learned the joint relationship among behavioral columns or is relying on simpler one- or two-column patterns. We therefore construct a sign-parity task in which the context mismatch appears only in the joint pattern of three columns. Any one or two columns have the same distribution in both contexts, so success requires modeling all three together.
1) Test construction and evaluation. Each block contains all eight sign patterns for a fixed set of absolute values, and the parity of the negative signs determines the correct context. We train for 1,000 epochs on 800 rows, assigning the wrong context to 5% of them. The seven runs pair data seeds 43–49 with training seeds 202–208. We then score 800 new vectors under both the correct and wrong contexts. A pair earns one point when the wrong context receives a higher anomaly score and half a point for a tie. For each fitted flow, both contexts and all eight sign patterns in a test block share the same draws.
2) Comparison methods. The conditional-mean MLP tests whether mean prediction is sufficient; it uses the same encoder, hidden widths, initialization seed, and training MAD scales as Flow-CAD. Coordinatewise Flow fits one flow per column and adds their scores. Zero-context Flow keeps the joint model but removes context by setting its context inputs to zero.
Why separate column scores are insufficient. Fix one sign within a block. Across the four remaining patterns, each column takes the same values in both contexts. For any method that adds separate column scores, the four score gaps (wrong context minus correct context) must therefore sum to zero. If three gaps exceed the tie tolerance, the fourth must favor the correct context and count as a loss. Even with half credit for ties, paired accuracy cannot exceed 75%.
Results. Flow-CAD gives the wrong context a higher anomaly score for every test pair in all seven runs, achieving 100% paired accuracy (Table VI). The three alternatives remain near 50%. Flow-CAD gains 53.6 percentage points over the conditional-mean MLP (95% paired bootstrap interval across seeds: [50.0, 60.7]). The joint flow therefore detects a three-column mismatch that is not captured by mean prediction, separate column scores, or a joint model without context.
| Method | Paired accuracy |
| Flow-CAD | 100.00 |
| Conditional-mean MLP | 46.43 |
| Coordinatewise Flow | 49.98 |
| Zero-context Flow | 50.00 |
Table VI. Mean paired accuracy (%) over seven sign-parity runs.
Runtime Comparison
We compare Flow-CAD and QCAD on tables of different sizes, using one Apple M4 CPU thread per run. Scoring time covers row scores and column contributions. Total time also covers data loading, fitting or setup, and metric computation.
Effect of table size. To isolate the effect of row count on runtime, we test four nested PowerPlant subsets from 1,000 to 8,000 rows at three seeds (12 paired runs), keeping the columns fixed. QCAD uses 500 neighbors; Flow-CAD trains for 1,000 epochs. Flow-CAD is faster in every run. At 8,000 rows, its median scoring and total times are 2.57 and 38.33 CPU seconds; QCAD takes 54.88 and 55.99 seconds, respectively.
Timing on the full benchmark. To see if the PowerPlant result holds elsewhere, we compare all 20 benchmarks (159 to 20,000 rows). Flow-CAD scores each table 4.0× to 164.1× faster and has lower total time on 16 of them. On ElNino, total time falls from 595 CPU seconds with QCAD to 69 with Flow-CAD. Flow-CAD reuses one fitted model across rows; QCAD builds a local neighborhood and estimates conditional quantiles for each row.
For each row, Flow-CAD evaluates Gaussian draws at time points. With fixed network widths, scoring rows with encoded context columns and behavioral columns requires operations, while storing the draws requires memory.
Scaling to large tables. Since the benchmarks stop at 20,000 rows, we also test larger inputs by fitting Flow-CAD on 8,000 synthetic rows and scoring in 1,000-row batches with the training MAD scales. It scores one million rows with 64 encoded context and 10 behavioral columns in 564 CPU seconds. With 256 context and 128 behavioral columns, it scores 100,000 rows in 228 seconds. Peak memory is 322 and 364 MiB, respectively; batch scoring does not raise the peak reached during fitting.
Conclusion
We proposed Flow-CAD, a contextual anomaly detection framework for tabular data based on Flow Matching. Flow-CAD learns a single global and amortized model and employs a residual-based scoring mechanism that avoids explicit likelihood evaluation while providing native per-feature explanations. Experiments on 20 real-world datasets show that Flow-CAD has the best average rank for PR AUC, ROC AUC, and P@n. The ablations show stable performance around the default truncation and sampling settings, while the timing study shows faster scoring than QCAD on every benchmark table. These results demonstrate the effectiveness and practicality of Flow Matching for contextual anomaly detection. Future work will explore extensions to structured and temporal contexts.
Acknowledgment
This publication is part of the project Digital Twin with project number P18-03 of the research programme TTW Perspective, which is (partly) financed by the Dutch Research Council (NWO).
We used GPT for language editing and for programming assistance with running experiments.
References
- [1]X. Song, M. Wu, C. Jermaine, and S. Ranka, “Conditional anomaly detection,” IEEE Transactions on knowledge and Data Engineering, vol. 19, no. 5, pp. 631–645, 2007.DOI
- [2]Z. Li and M. Van Leeuwen, “Explainable contextual anomaly detection using quantile regression forests,” Data Mining and Knowledge Discovery, vol. 37, no. 6, pp. 2517–2563, 2023.DOI
- [3]H. Kayan, R. Heartfield, O. Rana, P. Burnap, and C. Perera, “Casper: Context-aware iot anomaly detection system for industrial robotic arms,” ACM Transactions on Internet of Things, vol. 5, no. 3, pp. 1–36, 2024.
- [4]M. A. Hayes and M. A. Capretz, “Contextual anomaly detection framework for big sensor data,” Journal of Big Data, vol. 2, no. 1, p. 2, 2015.
- [5]A. M. Kosek, “Contextual anomaly detection for cyber-physical security in smart grids based on an artificial neural network model,” in 2016 joint workshop on cyber-physical security and resilience in smart grids (CPSR-SG). IEEE, 2016, pp. 1–6.DOI
- [6]X. Ding, H. Su, Z. Qian, W. Cui, S. Chen, Z. Liang, C. Wang, and H. Wang, “Cbaclean: A comprehensive system for recommending data cleaning solutions through cost-benefit analysis in data quality management,” in 2025 IEEE 41st International Conference on Data Engineering (ICDE), 2025.DOI
- [7]S. Siddiqi, R. Kern, and M. Boehm, “Saga: A scalable framework for optimizing data cleaning pipelines for machine learning applications,” Proceedings of the ACM on Management of Data, vol. 1, no. 3, 2023.
- [8]S. Schelter, D. Lange, P. Schmidt, M. Celikel, F. Biessmann, and A. Grafberger, “Automating large-scale data quality verification,” Proceedings of the VLDB Endowment, vol. 11, no. 12, pp. 1781–1794, 2018.DOI
- [9]J. Liang and S. Parthasarathy, “Robust contextual outlier detection: Where context meets sparsity,” in Proceedings of the 25th ACM international on conference on information and knowledge management, 2016, pp. 2167–2172.arxiv.org/abs/1607.08329
- [10]A. X. Wang, S. S. Chukova, C. R. Simpson, and B. P. Nguyen, “Challenges and opportunities of generative models on tabular data,” Applied Soft Computing, vol. 166, p. 112223, 2024.DOI
- [11]J. Li, Q. Huang, L. Yang, J. Shi, Z. Yang, N. van Stein, T. Bäck, and M. van Leeuwen, “Diffusion and flow matching models for tabular data: A survey,” arXiv:2502.17119v2, May 2026. [Online]. Available: https://arxiv.org/abs/2502.17119v2
- [12]H. Kamkari, B. L. Ross, J. C. Cresswell, A. L. Caterini, R. Krishnan, and G. Loaiza-Ganem, “A geometric explanation of the likelihood odd detection paradox,” in International Conference on Machine Learning. PMLR, 2024, pp. 22 908–22 935.arxiv.org/abs/2403.18910
- [13]E. Nalisnick, A. Matsukawa, Y. W. Teh, D. Gorur, and B. Lakshminarayanan, “Do deep generative models know what they don’t know?” in International Conference on Learning Representations, 2019.
- [14]Y. Lipman, R. T. Chen, H. Ben-Hamu, M. Nickel, and M. Le, “Flow matching for generative modeling,” in 11th International Conference on Learning Representations, ICLR 2023, 2023.arxiv.org/abs/2210.02747
- [15]M. Albergo and E. Vanden-Eijnden, “Building normalizing flows with stochastic interpolants,” in ICLR 2023 Conference, 2023.arxiv.org/abs/2209.15571
- [16]V. Chandola, A. Banerjee, and V. Kumar, “Anomaly detection: A survey,” ACM computing surveys (CSUR), vol. 41, no. 3, pp. 1–58, 2009.
- [17]S. Han, X. Hu, H. Huang, M. Jiang, and Y. Zhao, “ADBench: Anomaly detection benchmark,” in Advances in Neural Information Processing Systems, vol. 35, 2022, pp. 32 142–32 159.
- [18]S. Lu, L. Liu, J. Li, T. D. Le, and J. Liu, “Lopad: A local prediction approach to anomaly detection,” in Pacific-Asia Conference on Knowledge Discovery and Data Mining. Springer, 2020, pp. 660–673.DOI
- [19]Y. Ang, P. Yao, Y. Bao, Y. Feng, Q. Huang, A. K. H. Tung, and Z. Huang, “RFOD: Random forest-based outlier detection for mixed-type tabular data,” in 2026 IEEE 42nd International Conference on Data Engineering (ICDE), 2026, pp. 2192–2205.
- [20]L. Bindini, L. Perini, S. Nistri, J. Davis, and P. Frasconi, “Dealing with uncertainty in contextual anomaly detection,” Transactions on Machine Learning Research, 2026. [Online]. Available: https://openreview.net/forum?id=yL oXQDNwwaarxiv.org/abs/2507.04490
- [21]G. Pang, C. Shen, L. Cao, and A. V. D. Hengel, “Deep learning for anomaly detection: A review,” ACM computing surveys (CSUR), vol. 54, no. 2, pp. 1–38, 2021.DOI
- [22]D. Rezende and S. Mohamed, “Variational inference with normalizing flows,” in International conference on machine learning. PMLR, 2015, pp. 1530–1538.arxiv.org/abs/1505.05770
- [23]X. Liu, C. Gong, and Q. Liu, “Flow straight and fast: Learning to generate and transfer data with rectified flow,” in The Eleventh International Conference on Learning Representations (ICLR), 2023.arxiv.org/abs/2209.03003
- [24]A. Tong, K. Fatras, N. Malkin, G. Huguet, Y. Zhang, J. Rector-Brooks, G. Wolf, and Y. Bengio, “Improving and generalizing flow-based generative models with minibatch optimal transport,” Transactions on Machine Learning Research, pp. 1–34, 2024.arxiv.org/abs/2302.00482
- [25]Z. Li, Q. Huang, Y. Zhu, L. Yang, M. M. Amiri, N. van Stein, and M. van Leeuwen, “Scalable, explainable and provably robust anomaly detection with one-step flow matching,” in The Thirty-ninth Annual Conference on Neural Information Processing Systems, 2025.arxiv.org/abs/2510.18328
- [26]S. Chen, M. Moradi, K. Paynabar, and H. Yan, “Flow mismatching: Unsupervised anomaly detection via velocity discrepancies in flow matching models,” arXiv preprint arXiv:2605.23070, 2026.arxiv.org/abs/2605.23070
- [27]P. Konz, T. Medi, and M. Keuper, “Unsupervised anomaly detection using flow matching on tabular data,” arXiv preprint arXiv:2608.19801, 2026.arxiv.org/abs/2608.19801
- [28]V. Yepmo, G. Smits, and O. Pivert, “Anomaly explanation: A review,” Data & Knowledge Engineering, vol. 137, p. 101946, 2022.
- [29]Z. Li, Y. Zhu, and M. Van Leeuwen, “A survey on explainable anomaly detection,” ACM Transactions on Knowledge Discovery from Data, vol. 18, no. 1, pp. 1–54, 2023.arxiv.org/abs/2210.06959
- [30]D. P. Kingma and J. Ba, “Adam: A method for stochastic optimization,” in International Conference on Learning Representations, 2015. [Online]. Available: https://arxiv.org/abs/1412.6980
- [31]Y. S. Abu-Mostafa, M. Magdon-Ismail, and H.-T. Lin, Learning from data. AMLBook New York, 2012, vol. 4.
- [32]W. Hoeffding, “Probability inequalities for sums of bounded random variables,” Journal of the American statistical association, vol. 58, no. 301, pp. 13–30, 1963.
- [33]S. Boucheron, G. Lugosi, and P. Massart, Concentration Inequalities: A Nonasymptotic Theory of Independence. Oxford University Press, 02 2013. [Online]. Available: https://doi.org/10.1093/acprof: oso/9780199535255.001.0001
- [34]F. T. Liu, K. M. Ting, and Z.-H. Zhou, “Isolation forest,” in 2008 eighth ieee international conference on data mining. IEEE, 2008, pp. 413–422.
- [35]M. M. Breunig, H.-P. Kriegel, R. T. Ng, and J. Sander, “Lof: Identifying density-based local outliers,” in Proceedings of the 2000 ACM SIGMOD international conference on Management of data, 2000, pp. 93–104.
- [36]F. Angiulli and C. Pizzuti, “Fast outlier detection in high dimensional spaces,” in European conference on principles of data mining and knowledge discovery. Springer, 2002, pp. 15–27.DOI
- [37]H.-P. Kriegel, P. Kröger, E. Schubert, and A. Zimek, “Outlier detection in axis-parallel subspaces of high dimensional data,” in Pacific-asia conference on knowledge discovery and data mining. Springer, 2009, pp. 831–838.DOI
- [38]M. Goldstein and A. Dengel, “Histogram-based outlier score (hbos): A fast unsupervised anomaly detection algorithm,” KI-2012: poster and demo track, vol. 1, pp. 59–63, 2012.
- [39]A. Goodge, B. Hooi, S.-K. Ng, and W. S. Ng, “Lunar: Unifying local outlier detection methods via graph neural networks,” in Proceedings of the AAAI Conference on Artificial Intelligence, vol. 36, 2022, pp. 6737–6745.
- [40]V. Livernoche, V. Jain, Y. Hezaweh, and S. Ravanbakhsh, “On diffusion modeling for anomaly detection,” in The Twelfth International Conference on Learning Representations, 2024.arxiv.org/abs/2305.18593
- [41]Y. Zhao, Z. Nasrullah, and Z. Li, “PyOD: A python toolbox for scalable outlier detection,” Journal of Machine Learning Research, vol. 20, no. 96, pp. 1–7, 2019.arxiv.org/abs/1901.01588







