liveBook · Manning

Kullback–Leibler divergence

As explained in Causal AI

Kullback–Leibler divergence quantifies the difference between two probability distributions.

When a posterior distribution cannot be sampled or evaluated directly, variational inference uses an approximating distribution and shifts it toward the target. KL divergence quantifies how differently the two distributions behave. section 5.2.3

In the variational autoencoder workflow:

  • The guide represents Q(Z|X, is-handwritten, digit), approximating P(Z|image, is-handwritten, digit). section 5.2.3
  • Training minimizes KL divergence between Q and P as part of the negative ELBO objective. section 5.2.3
  • Stochastic variational inference performs this optimization on randomly selected data batches. section 5.2.3
Listing 5.13 Set up the training procedure
from pyro.infer import SVI, Trace_ELBO
from pyro.optim import Adam

pyro.clear_param_store()     #1
vae = VAE()    #2
train_loader, test_loader = setup_dataloaders(batch_size=256)    #3
svi_adam = Adam({"lr": 1.0e-3})     #4
model = vae.training_model    #5
guide = vae.training_guide    #5
svi = SVI(model, guide, svi_adam, loss=Trace_ELBO())     #5

A Pyro setup connects the divergence objective to SVI, Adam optimization, and Trace_ELBO. section 5.2.3

How Causal AI covers it

How deep it goes
Defines the measure operationally and connects it to negative ELBO, but does not derive its mathematical formula.
Examples
Uses Q(Z|X, is-handwritten, digit) and P(Z|image, is-handwritten, digit) as approximating and target distributions.
What you can do after
Apply it via Pyro's Trace_ELBO within stochastic variational inference training.
How it connects
Connects variational inference, ELBO, stochastic variational inference, variational autoencoders, encoders, and guide functions.

Also explained in

Compare how 12 books explain Kullback–Leibler divergence →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Causal AI. The section links point to the parts of the book it draws on.