On the SAC-BL Algorithm for Anomaly Detection

Xinsong Ma, Jie Wu, Weiwei LiuNeurIPS 2025

TL;DR

Visual anomaly detection models excel at scoring how "weird" an image is, but often struggle with the final decision rule: where exactly do we draw the threshold? This paper addresses this gap by upgrading a recent statistical decision framework (SAC-BL) with a novel stochastic randomization strategy (SAC-SBL). This new approach mathematically guarantees a lower False Positive Rate (FPR) on finite datasets while strictly controlling the False Discovery Rate (FDR).

The Problem: Scoring vs. Deciding

In visual Anomaly Detection (AD)—used in applications ranging from manufacturing quality control to medical imaging—models are typically trained only on "normal" data. During inference, the model assigns an anomaly score to new images. Historically, the research community has heavily focused on building better scoring functions while largely ignoring the decision rules used to turn those scores into hard "normal" vs. "anomalous" classifications.

A recent method called SAC-BL framed this as a multiple hypothesis testing problem, using a Betting-Like (BL) algorithm to control the False Discovery Rate (FDR). While controlling FDR ensures high precision, the authors of this paper noticed a critical flaw: SAC-BL's performance on actual anomalous examples—measured by its False Positive Rate (FPR)—can be quite poor in practice. If a decision rule is too conservative to protect the FDR, it might misclassify too many true anomalies as normal. The authors set out to theoretically and practically reduce this FPR without losing the FDR guarantees.

The Solution: Stochastic Betting-Like (SBL) Algorithm

The authors first conduct an asymptotic analysis of the existing SAC-BL algorithm. They prove that if you have an infinite number of test samples and the anomaly scores follow a "generalized Gaussian-like" distribution, the FPR naturally converges to zero.

However, real-world AD tasks have finite, often small, test sets (e.g., only 167 test images for a specific class) and unknown distributions. To fix the FPR for practical scenarios, the authors propose the Stochastic BL (SBL) algorithm.

  • The Randomization Strategy: Instead of using a rigid, deterministic threshold for the p-values of the anomaly scores, SBL introduces a uniform random variable to perturb the decision boundary.
  • SAC-SBL: By combining the original SAC (Strong Anomaly Constraint) network's scoring with this new SBL decision rule, the algorithm can safely "push" the threshold to reject more null hypotheses (i.e., flag more true anomalies). Because the perturbation is mathematically bounded, it strictly reduces the FPR compared to the deterministic version while still guaranteeing that the FDR stays below a user-specified level (e.g., 5%).

Key Insights

  • FDR control isn't the whole story: In hypothesis testing for AD, solely controlling the False Discovery Rate can lead to a terrible False Positive Rate in worst-case scenarios. A practical algorithm must balance both to achieve a high F1-score.
  • Asymptotics vs. Reality: Theoretical guarantees that rely on infinite samples and perfect Gaussian distributions fall apart on small, real-world datasets. Decision rules must be designed to handle finite samples.
  • Stochasticity unlocks better thresholds: It seems counterintuitive to add randomness to a strict statistical threshold. However, by injecting a controlled uniform random variable into the p-value evaluation, the algorithm can smoothly relax overly conservative boundaries, allowing it to catch more anomalies that a rigid rule would miss.

Empirical Results

The authors evaluated their method on three standard visual anomaly detection benchmarks: MVTec AD, VisA, and BTAD. The theoretical proofs translate beautifully into empirical gains.

Performance comparison of SAC-BL and SAC-SBL on the MVTec AD dataset.
  • Theoretical Guarantee: The authors mathematically prove that the SAC-SBL algorithm will almost surely achieve an FPR less than or equal to the original SAC-BL algorithm, without violating the FDR limit.
  • MVTec Improvements: As detailed in the results table, SAC-SBL reduced the average image-level FPR from 17.45% to 11.79% and boosted the F1-score from 83.22% to 88.19%.
  • Massive Class-Specific Wins: In categories where the original algorithm struggled, the stochastic approach shined. For the "Pill" class in MVTec, FPR dropped from 43.26% to 29.08%. For "Carpet", it dropped from 15.73% to 4.49%.
  • VisA Improvements: Average image-level FPR was reduced from 57.42% to 51.92%, with F1-scores jumping from 71.95% to 74.95%.

Limitations and Future Work

While highly effective, the methodology has a few practical constraints. First, because the underlying distribution of normal data is unknown, the algorithm relies on a calibrated set of normal examples to compute empirical p-values. If this calibration set is poorly representative, the p-values will be inaccurate.

Second, the introduction of stochasticity means the algorithm's output has slight variance. To combat this in experiments, the authors had to repeat the stochastic perturbation 100 times and take the mean, which introduces additional computational overhead during inference compared to a purely deterministic rule. Future work could explore optimizing this sampling process or finding closed-form approximations for the stochastic boundary.

Summary updated

BibTeX
@inproceedings{ma2025sac,
  author = {Xinsong Ma and Jie Wu and Weiwei Liu},
  title = {{On the SAC-BL Algorithm for Anomaly Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=6NczjqEcO5},
}
Figure