I am trying to perform outlier detection using VAE. Before I was performing the same task using normal autoencoder and I used reconstruction error. I trained the network, then I passed new samples as input and marked those with high reconstruction error as outliers.

I know that similar things can be done with VAE, but I was wondering if I could somehow use information from LATENT SPACE? An encoder is learning to get means and STDs that are close to a normal distribution and then decoder to sample from those and recreate input...

But I was wondering if now after training I can pass a new sample through just ENCODER, obtain latent space variables and based on them decide somehow if the sample is outlier or no?

I thought about sampling from obtained distribution, checking how far from 0 is the point and if far then marking this sample as an outlier, but using sampling feels a bit random. Or maybe most outlying samples should return after encoding most "unnormal" mean and std?

Thank you for any explanations.


One concern I would have about this approach is that I believe it's been shown that powerful enough decoders may essentially ignore the stochasticity of the latent space, so your encodings may not need to be very good.

That said, let's assume you got a good reconstruction with a weak decoder. I would say this is doable in that case. I would think a good measure would be to just measure the mean Kullback-Leibler Divergence between your candidate outlier and either some representative subset of known good encodings of that class (e.g. training data - but if you can take a peek at decent production embeddings, should be fine too), or to approximate the whole latent cluster's mean and covariance matrix and KLD against that.

It's more or less the same approach as training the VAE in the first place, only you're comparing against the cluster parameters as your ideal, rather than the (0, 1) Standard Normal parameters.

The first approach seems like it could be a bit more robust, but is far more of a pain to actually crunch the numbers for, the latter introduces the risk that your estimate of the cluster parameters is off. Finally, if you're feeling like something really cheap and simple and likely to go off the rails, you could just use a plain Euclidean distance from the mean, but that's really hacky.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.