Normalizing flows are probabilistic generative models, learning a probability model by transforming a simple distribution into a more complex one using a deep network. Normalizing flows can both sample from this distribution and evaluate the probability of new examples. However, they require specialized architecture; each layer must be invertible (transform data in both directions).

Normalizing flows can be used for generative applications, as well as for approximating other density models.

Intuition

See 1D Normalizing Flows Intuition for an example.

Formulation

We aim to transform a multivariate base distribution to a model distribution with a deep neural network.

  • The invertibility requirement means that the latent space must be the same size as the data space (a continuous invertible map between ordinary Euclidean spaces requires equal dimensions).

Consider applying a function to a random variable with base density , where is a deep network. The resulting variable has a new distribution. A sample can be drawn from this distribution by drawing a sample from the base density and passing it through the neural network so that .

As we’ve seen from the 1D example, the likelihood of a sample under this distribution is:

where is the latent variable that created .

  • The first term is the inverse of the determinant of the Jacobian matrix , which contains elements at position .
    • Just as the absolute derivative measured the change of area at a point on a 1D function where the function was applied, the absolute determinant measures the change in volume at a point in the multivariate function.
  • The second term is the probability of the latent variable under the base density.

Forward and inverse mapping

In practice, the forward mapping is usually defined by a neural network, consisting of a series of layers with parameters , which are composed together as:

The inverse mapping (normalizing direction) is defined by the composition of the inverse of each layer applied in the opposite order:

The base density is usually defined as a multivariate standard normal (i.e., with mean zero and identity covariance). Hence, the effect of each subsequent inverse layer is to gradually move or “flow” the data density toward this normal distribution. This gives rise to the name “normalizing flows”.

The Jacobian of the forward mapping can be expressed as:

where we are abusing notation to make the output of the function . The absolute determinant of this Jacobian can be computed by taking the product of the individual absolute determinants:

The absolute determinant of the Jacobian of the inverse mapping is found by applying the same rule to the inverse mapping equation above:

The determinant can either be computed as the product of the determinants in this expression, or just the inverse of the original determinant:

Training

We train normalizing flows with a dataset of training examples using the negative log-likelihood criterion:

where , is measured under the base distribution, and the determinant is calculated as above.

Architecture

The theory of normalizing flows is straightforward. However, for this to be practical, we need neural network layers that have four properties:

  1. Collectively, the set of network layers must be sufficiently expressive to map a multivariate standard normal distribution to an arbitrary density.
  2. The network layers must be invertible; each must define a unique one-to-one mapping from any input point to an output point (bijective).
  3. It must be possible to compute the inverse of each layer efficiently. We need to do this every time we evaluate the likelihood. This happens repeatedly during training, so there must be a closed-form solution or a fast algorithm for the inverse.
  4. It also must be possible to evaluate the determinant of the efficiently for either the forward or inverse mapping.

With these requirements in mind, we can now describe different invertible network layers or flows for use in these models. We start with linear and elementwise flows. These are easy to invert, and it’s possible to compute the determinant of their Jacobians, but neither is sufficiently expressive to describe arbitrary transformations of the base density. However, they form the building blocks of coupling, autoregressive, and residual flows, which are all more expressive.

dl
Normalizing flows
?

  • Generative model where we map a base distribution to a model distribution with a deep neural network.
  • They can both evaluate the likelihood of samples exactly and generate new samples.
  • Architectural requirement: Layers must be invertible.

+++

Why do normalizing flow model layers have to be invertible?
?

  • Forward transformation to generate samples
  • Inverse (normalizing) transformation to evaluate likelihood of data.
  • Training is done by maximizing the likelihood, requiring evaluation of the inverse transformation and its Jacobian determinant.

+++