liveBook · Manning

Variational autoencoder

As explained in Machine Learning Algorithms in Depth

A variational autoencoder is a generative neural network that learns an approximate latent-variable posterior and reconstructs observations from sampled latent representations.

A variational autoencoder (VAE) is a generative encoder–decoder model. An ordinary autoencoder compresses an input through a bottleneck and reconstructs it; a VAE instead encodes the input as parameters of a distribution, samples a latent value, and decodes that sample. Training also structures the latent space so sampled points can produce valid outputs. section 11.1

Figure 11.2 Variational autoencoder architecture, showing an encoder, a sampling layer, and a decoder
figure

The architecture diagram locates the sampling layer between the encoder and decoder. section 11.1

Let x be an observation and z a latent variable. The trainable encoder qϕ(z|x) approximates a posterior distribution; the trainable decoder pθ(x|z) describes reconstructions; and p(z) is the latent prior. The evidence lower bound (ELBO) balances reconstruction from sampled z against a KL-divergence penalty that draws the approximate posterior toward the prior. Thus, optimizing reconstruction alone is not the VAE objective. section 11.1 section 11.1.1

Time-series anomaly detection

Train an LSTM-VAE on nonanomalous sensor signals. For each of n sensors, a Gaussian output uses a mean and variance, giving 2n output parameters. The sampled joint latent representation is encouraged to approximate a standard normal distribution. At detection time, a drop in an input’s log likelihood under the learned normal behavior can be thresholded as an anomaly; a square-wave signal illustrates the result. The detector and its custom loss are implemented from scratch with Keras/TensorFlow using the NAB dataset. section 11.1.1

How Machine Learning Algorithms in Depth covers it

How deep it goes
Defines encoder, decoder, prior, and ELBO terms, then implements an LSTM-VAE detector with a custom loss.
Examples
Works through an LSTM-VAE anomaly detector on the NAB dataset and a square-wave signal.
What it assumes
Builds on encoder–decoder autoencoders while defining the latent variable, encoder and decoder distributions, and prior.
What you can do after
Build it from scratch with Keras/TensorFlow to flag time-series anomalies by thresholding drops in log likelihood.
How it connects
Connects autoencoders, approximate posterior distributions, KL divergence, Gaussian likelihoods, and LSTMs.

Also explained in

Compare how 13 books explain variational autoencoder →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Algorithms in Depth. The section links point to the parts of the book it draws on.