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.
Figures & tables
Fig. 1: Illustration of the training (left) and inference (right) phases of Flow-CAD. The inference panel writes t(ℓ) for t(k,ℓ) within Gaussian block k .
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
TABLE I: Reconstructed benchmark tables used for full-table evaluation. Column counts are reported before encoding.
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
L1
TABLE II: Flow-CAD configuration fixed across benchmark datasets and runs.
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.00 (14)
0.42 ± 0.04 (5)
0.49 ± 0.04 (2)
BodyFat
0.84 ± 0.08 (1)
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)
TABLE III: PR AUC on 20 datasets. Entries give mean ± standard deviation (rank). Ranks use unrounded means and average numerical ties ( 10−12 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.00 ± 0.00 (1)
1.00 ± 0.00 (4)
0.29 ± 0.03 (14)
0.98 ± 0.00 (9)
0.99 ± 0.01 (8)
Airfoil
0.81 ± 0.05 (4)
0.92 ± 0.02 (1)
0.50 ± 0.03 (13)
0.79 ± 0.02 (5)
0.82 ± 0.02 (3)
BodyFat
0.96 ± 0.03 (2)
0.93 ± 0.04 (4)
0.49 ± 0.03 (14)
0.94 ± 0.03 (3)
0.98 ± 0.01 (1)
Boston
0.89 ± 0.04 (2)
0.93 ± 0.02 (1)
0.47 ± 0.02 (13)
0.82 ± 0.04 (3)
0.78 ± 0.05 (4)
Concrete
0.91 ± 0.06 (2)
0.93 ± 0.03 (1)
0.63 ± 0.03 (7)
0.77 ± 0.03 (3)
0.74 ± 0.04 (4)
ElNino
0.99 ± 0.00 (3)
1.00 ± 0.00 (1)
0.91 ± 0.01 (7)
0.98 ± 0.00 (5)
1.00 ± 0.00 (2)
TABLE IV: ROC AUC on 20 datasets. Notation follows Table III .
Dataset
Flow-CAD (ours)
QCAD
LoPAD
ROCOD
CAD
Abalone
0.97 ± 0.02 (1)
0.91 ± 0.01 (6)
0.00 ± 0.00 (14)
0.57 ± 0.01 (10)
0.94 ± 0.01 (3)
Airfoil
0.43 ± 0.07 (3)
0.67 ± 0.03 (1)
0.03 ± 0.02 (14)
0.41 ± 0.04 (4)
0.45 ± 0.04 (2)
BodyFat
0.74 ± 0.11 (2)
0.61 ± 0.06 (4)
0.06 ± 0.06 (14)
0.70 ± 0.06 (3)
0.77 ± 0.08 (1)
Boston
0.60 ± 0.09 (2)
0.64 ± 0.07 (1)
0.08 ± 0.01 (8.5)
0.36 ± 0.04 (4)
0.39 ± 0.08 (3)
Concrete
0.61 ± 0.11 (1)
0.61 ± 0.08 (2)
0.11 ± 0.04 (7)
0.33 ± 0.05 (3)
0.31 ± 0.06 (4)
ElNino
0.73 ± 0.04 (3)
0.94 ± 0.01 (1)
0.12 ± 0.03 (7)
0.40 ± 0.05 (6)
0.91 ± 0.02 (2)
TABLE V: P@ n on 20 datasets. Notation follows Table III .
Fig. 2: Illustrative raw-score decomposition for two Energy Efficiency instances with behavioral features (Y1,Y2) . (a) Sampled intermediate states and signed velocity differences Δv ; the score uses their coordinate-wise magnitudes r=∣Δv∣ . (b) Feature contributions estimated with a separate set of Monte Carlo draws.
Fig. 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.
Fig. 4: Sensitivity to truncation with MAD normalization. The threshold τ varies from 2 to 100 .
Fig. 5: Residual aggregation with L1 , L2 , and L∞ norms. Panels show PR AUC, ROC AUC, and P@ n (top to bottom).
Fig. 6: Sensitivity to the number of time draws Kt per Gaussian draw with MAD normalization and truncation.
Fig. 7: Sensitivity to the number of Gaussian draws Kz with MAD normalization and truncation.
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.
Fig. 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.
Faculty of Mathematics and Computer Science, Jagiellonian University, Kraków, Poland · Doctoral School of Exact and Natural Sciences, Jagiellonian University, Kraków, Poland