SOURCE. An, J. and Cho, S. (2015), "Variational Autoencoder based Anomaly Detection using Reconstruction Probability", Special Lecture on IE 2:1-18, SNU Data Mining Center.
Usage
Vaean(
X,
vae = NULL,
latent_dim = 1,
n_samples = 32,
alpha = 0.1,
encoder_sd = 0,
decoder_scale = NULL,
threshold = NULL,
skip = 0
)Arguments
- X
n-by-d data matrix.
- vae
list with
Wand optionallycenter, or NULL.- latent_dim
k in 1..d, used only when
vaeis NULL.- n_samples
L, latent draws per point.
- alpha
Tail fraction in [0, 1] for the threshold quantile.
- encoder_sd
sigma_z, non-negative.
- decoder_scale
sigma_x; NULL uses the Tipping-Bishop residual.
- threshold
Explicit cut on the log reconstruction probability.
- skip
Offset into the shared deterministic stream.
Value
List with reconstruction_probability, log_rp,
anomaly, threshold, n_anomalies, W,
center, decoder_scale, eigenvalues, n,
d, latent_dim, n_samples.
Details
Algorithm 4 is the whole method. For each point x_i: encode to (mu_z, sigma_z); draw z^(1)...z^(L) from N(mu_z, diag(sigma_z^2)); decode each to (mu_x, sigma_x); the reconstruction probability is (1/L) sum_l p(x_i | mu_x^(l), sigma_x^(l)); flag x_i when it falls below a threshold. Their Section 4 point is that this is a probability, not a reconstruction error: the decoder variance makes the score comparable across dimensions of different scale.
MODEL. A reference implementation cannot ship trained weights and an untrained autoencoder detects nothing, so the default encoder/decoder are the LINEAR-GAUSSIAN instance, whose optimum is closed form: the ML decoder subspace of a linear-Gaussian latent model is the principal subspace and the residual variance is the mean discarded eigenvalue – Tipping, M.E. and Bishop, C.M. (1999), "Probabilistic Principal Component Analysis", JRSS-B 61(3):611-622, doi:10.1111/1467-9868.00196, Section 3.2. So W = top-k eigenvectors of the sample covariance, mu_z(x) = W'(x - xbar), mu_x(z) = W z + xbar. Using the closed-form optimum in place of stochastic training is this implementation's choice, stated rather than attributed.
z^(l) comes from the shared deterministic normal stream, so both arms hold the same draws.
THRESHOLD. alpha is a tail fraction: the cut is the type-7
alpha-quantile of the log reconstruction probabilities unless
threshold is given.
ANCHOR. With latent_dim = d and encoder_sd = 0 the map
W W' is the identity, reconstruction is exact, and the log
reconstruction probability is exactly -d/2 log(2 pi s^2) everywhere.
