Anomaly scores for generative models

Václav Smídl, Jan Bím, Tomás PevnýarXiv 2019

Abstract

Traditional anomaly detection using generative models often relies on reconstruction error, a metric that lacks a rigorous theoretical foundation. This paper introduces a novel anomaly score that combines reconstruction error with latent space probability, adjusted by the Jacobian determinant of the generator. This approach accounts for the geometric "stretch" of the data manifold, providing a mathematically sound likelihood estimate. Evaluation across ten benchmark datasets shows that the proposed score consistently outperforms standard reconstruction-based methods, particularly in realistic unsupervised model selection scenarios.

Introduction

In unsupervised learning, identifying samples that deviate from the majority distribution—anomalies—is a critical task. Deep generative models, such as Variational Autoencoders (VAEs) and Generative Adversarial Networks (GANs), are frequently employed for this purpose. The prevailing heuristic uses reconstruction error: if a model cannot accurately reconstruct an input, it is flagged as an anomaly. However, this method assumes that normal data lies on a low-dimensional manifold and that the model behaves predictably off-manifold, which is often not the case. Alternatively, latent space likelihoods can be over-optimistic for off-manifold regions. This work proposes a hybrid score that bridges these gaps.

Methodology

The proposed score treats the generative model as a transformation of variables from a low-dimensional latent space to a high-dimensional input space.

The Hybrid Score

The core idea is to factor the probability of a sample $x$ into two components: the probability of its projection onto the learned manifold and the probability of the "residue" (the distance from the manifold). This ensures that both the position within the manifold and the deviation from it are accounted for.

Geometric Correction via Jacobian Determinants

To compute a valid likelihood on a manifold, one must account for how the decoder function $G(z)$ transforms volume. The authors utilize the determinant of the Jacobian matrix $J = \nabla_z G(z)$. Since $J$ is typically rectangular (mapping from low to high dimensions), Singular Value Decomposition (SVD) is used to compute the product of non-zero singular values, representing the volume change in the manifold's tangent space.

Training with Wasserstein Autoencoders (WAE)

While applicable to various architectures, the researchers utilize Wasserstein Autoencoders for training. WAEs offer a more stable latent distribution matching compared to standard VAEs, reducing the "blurriness" in the generated manifold.

Key Insights: Beyond "Lucky" Proxies

The researchers argue that reconstruction error is often a "lucky" proxy; it works because anomalies happen to fall into regions where the model's failure to generalize results in high error, not because of a principled probabilistic model.

Visual comparison of (a) reconstruction error, (b) latent space likelihood, and (c) the proposed hybrid score. The proposed score (c) provides a more concentrated and theoretically justified density estimate around the data manifold.

By explicitly modeling the manifold's geometry, the proposed score avoids the "blind spots" where reconstruction error might be low for out-of-distribution samples. Furthermore, the score's performance is tied to the "Manifold Assumption," showing optimal results when the latent dimensionality (typically 4–6) matches the intrinsic structure of the data.

Experimental Results

The proposed score was evaluated against standard reconstruction error using the Area Under the Curve (AUC) on ten UCI benchmark datasets, including breast-cancer, cardio, and thyroid (Haberman).

AUC performance comparison across ten benchmark datasets. The top plot shows results with supervised model selection (using labeled anomalies), while the bottom plot shows the more challenging unsupervised scenario. The proposed score (red) consistently outperforms reconstruction error (blue).

Performance Summary

  • Supervised Selection: The proposed score achieved higher AUC on all ten problems when a small set of labeled anomalies was available for hyperparameter tuning.
  • Unsupervised Selection: In the realistic case where no labels are available, the proposed score was superior in nine out of ten datasets.
  • Robustness: The proposed method exhibited lower variance across different hyperparameter settings, as evidenced by the tighter box plots in the results.

Conclusion

This work provides a theoretically grounded alternative to reconstruction error for anomaly detection. By incorporating the Jacobian determinant, the proposed score accurately reflects the likelihood of samples relative to a learned manifold. While computationally more intensive due to SVD calculations, its superior performance and robustness in unsupervised settings make it a significant advancement for real-world anomaly detection tasks.

Summary updated

BibTeX
@misc{smidl2019anomaly,
  author = {Václav Smídl and Jan Bím and Tomás Pevný},
  title = {{Anomaly scores for generative models}},
  year = {2019},
  eprint = {1905.11890},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1905.11890},
}
Figure