Normalizing Flows are probabilistic generative models; they fit a probability distribution to training data.

Consider modeling a 1D distribution . Normalizing flows start with a simple tractable base distribution over a latent variable and apply a function , where the parameters are chosen so that has the desired distribution. We can then easily generate a new example ; we draw from the base density and pass this through the function so that .

Measuring probability

Measuring the probability of a data point is more challenging. Consider applying a function to a random variable with known density :

  • The probability density will decrease in areas that are stretched by the function and increase in areas that are compressed so that the area under the under the new distribution remains one.
  • The degree to which a function stretches or compresses its input depends on the magnitude of its gradient.
  • If a small change to the input causes a large change in the output, it stretches the function. If a small change to the input causes a smaller change in the output, it compresses the function.

  • Intuition: if a small region of the base density corresponds to a large region of the model density, the height of the model density’s large region must be smaller such that probability mass stays constant.

More precisely, the probability of data under the transformed distribution is:

where is the latent variable that created . The term is the original probability of this latent variable under the base density. This is moderated according to the magnitude of the derivative of the function. If it is greater than one, the probability decreases; if it is smaller, the probability increases.

Forward and inverse mappings

To draw samples form the distribution, we need the forward mapping , but to measure the likelihood, we need to compute the inverse . Hence, we need to choose so that it is invertible.

  • The forward mapping is sometimes called the generative direction.
  • The base density is usually chosen to be a standard normal distribution. Hence, the inverse mapping is called the normalizing direction since this takes the complex distribution over and turns it into a normal distribution over .

Learning

To learn the distribution, we find parameters that maximize the likelihood of the training data or equivalently minimize the negative log-likelihood:

where we have assumed that the data are independent and identically distributed in the first line and used the likelihood equation from above in the third line.

Essentially, during training, we observe , and then calculate (hence the requirement for invertible layers) so that we can calculate the and terms.