learned proposals · ELBO · stochastic gradients · VAEs
2026-07-01
\[\newcommand\grad{\nabla}\] \[\newcommand\given{\,|\,}\] \[\newcommand\Given{\,\|\,}\]
Today we will denote the latent variables by \(z\) and the observed data by \(x\). A probabilistic program defines a joint over latents and data: \[ p_\theta(x,z) = p(z)\,p_\theta(x \given z). \]
A model gives a joint \(p_\theta(x,z)=p(z)\,p_\theta(x \given z)\), and we introduce a guide \(q_\phi(z \given x)\).
What role does the guide play?
A) It defines a map from observations to the most probable latent execution.
B) It defines an alternative joint model \(\hat{p}_\theta(x,z)\) whose posterior is easier to sample.
C) It defines a distribution from which latent executions are proposed, using the observations.
D) It guides the estimation of the evidence by directly predicting \(p_\theta(x)\). which is usually intractable.
The model defines the target.
The guide defines how candidate latent executions are proposed:
\[z \sim q_\phi(z \given x).\]
The guide does not replace the model. It is part of the inference mechanism.
Likelihood weighting samples latent variables from the prior, \(z \sim p(z),\) and scores the observation. Now suppose we instead sample
\[z \sim q_\phi(z \given x).\]
What has changed relative to likelihood weighting?
A) The target distribution has changed from the posterior under the model to the posterior under the guide.
B) The observation has been incorporated into the sampler, so the importance correction is no longer needed.
C) The proposal distribution has changed.
D) The proposal is now equivalent to likelihood weighting whenever it assigns nonzero mass wherever the prior does.
For importance sampling with proposal \(q(z \given x)\) and weight \(w(z)=\dfrac{p_\theta(x,z)}{q(z \given x)}\),
which proposal would make the weights constant?
A) \(q(z\given x)=p(z)\), since the prior is the model’s own distribution over latents.
B) \(q(z\given x)=p_\theta(z\given x)\), since the proposal would match the normalized target over latents.
C) \(q(z\given x)\propto p_\theta(x\given z)\), since the proposal should favor latents that explain the observation.
D) \(q(z\given x)\) should concentrate near maximizers of \(p_\theta(x,z)\), since high-density traces dominate posterior expectations.
The ideal proposal is the posterior:
\[q^\star(z \given x)=p_\theta(z \given x).\]
Then
\[w(z) = \frac{p_\theta(x,z)}{p_\theta(z \given x)} = p_\theta(x),\]
which does not depend on \(z\).
This is ideal but unavailable, because sampling from \(p_\theta(z \given x)\) is the inference problem itself.
The two KL directions are
\[\mathrm{KL}(q_\phi \Given p_\theta) = \mathbb{E}_{q_\phi(z \given x)}\!\left[\log q_\phi(z \given x) - \log p_\theta(z \given x)\right],\]
and
\[\mathrm{KL}(p_\theta \Given q_\phi) = \mathbb{E}_{p_\theta(z \given x)}\!\left[\log p_\theta(z \given x) - \log q_\phi(z \given x)\right].\]
The first is often more mode-seeking; the second is often more mode-covering.
Why does ordinary VI naturally lead to the first direction?
A) Its expectation is over the model posterior, which makes it more faithful to all posterior modes.
B) It avoids the need to evaluate either the guide density or the model density.
C) It is the only direction whose value is finite for both discrete and continuous latent variables.
D) Its expectation is over the guide, which is the distribution we can sample from and evaluate during inference.
Ordinary VI uses expectations under the guide:
\[z \sim q_\phi(z \given x).\]
That is operationally available because we control \(q_\phi\).
The inclusive direction would require expectations under
\[p_\theta(z \given x),\]
which is exactly the posterior we are trying to approximate.
For fixed \(\theta\), suppose we want to fit \(q_\phi(z \given x)\) by minimizing \(\mathbb{E}_{q_\phi(z \given x)}\!\left[\log q_\phi(z \given x) - \log p_\theta(z \given x)\right].\)
But, the ELBO is: \[ \mathbb{E}_{q_\phi(z \given x)}\!\left[\log p_\theta(x,z) - \log q_\phi(z \given x)\right].\]
Why do we usually optimize the ELBO instead of this KL directly?
A) The KL requires samples from \(q_\phi(z \given x)\), while the ELBO can be optimized without sampling latent variables.
B) The KL contains the unknown evidence term \(\log p_\theta(x)\), while the ELBO removes this term without changing the optimizer over \(\phi\).
C) The KL is only useful for guide learning, while the ELBO is only useful for learning the generative model.
D) The KL uses \(\log p_\theta(x,z)\), while the ELBO avoids evaluating the joint density.
Start from
\[\mathrm{KL}(q_\phi \Given p_\theta) = \mathbb{E}_{q_\phi}\!\left[\log q_\phi(z \given x) - \log p_\theta(x,z)\right] + \log p_\theta(x).\]
Rearrange:
\[\log p_\theta(x) = \mathcal{L}(\theta,\phi) + \mathrm{KL}(q_\phi \Given p_\theta),\]
where
\[\mathcal{L}(\theta,\phi) = \mathbb{E}_{q_\phi(z \given x)}\!\left[\log p_\theta(x,z) - \log q_\phi(z \given x)\right].\]
For fixed \(\theta\), \(\log p_\theta(x)\) does not depend on \(\phi\), so maximizing \(\mathcal{L}\) minimizes the exclusive KL.
The ELBO is
\[\mathcal{L}(\theta,\phi) = \mathbb{E}_{q_\phi(z \given x)}\!\left[\log p_\theta(x,z) - \log q_\phi(z \given x)\right].\]
We want to estimate \(\nabla_\phi \mathcal{L}(\theta,\phi)\).
What is the main difficulty?
A) The parameter \(\phi\) affects the density inside the expectation and also the distribution that generates \(z\).
B) The parameter \(\phi\) only appears in the term \(\log q_\phi(z \given x)\), so the model term gives no gradient signal.
C) The sampled value \(z\) blocks all gradients, so the expectation has no well-defined derivative.
D) The parameter \(\phi\) can be differentiated only when \(q_\phi\) is exactly equal to the posterior.
Score-function
\[\nabla_\phi \mathbb{E}_{q_\phi(z)}[f(z)] = \mathbb{E}_{q_\phi(z)}\!\left[f(z)\,\nabla_\phi \log q_\phi(z)\right]\]
Reparameterization
There exists a distribution \(q(\epsilon)\) and a function \(g_\phi\) such that
\[\epsilon \sim q(\epsilon) \implies g_\phi(\epsilon, x) \sim q_\phi(z \given x).\]
\[\nabla_\phi \mathbb{E}_{q_\phi(z \given x)}[f(z)] = \nabla_\phi \mathbb{E}_{\epsilon}\!\left[f(g_\phi(\epsilon,x))\right]\]
Reparameterization is the standard route for Gaussian latent VAEs.
Suppose we know part of the data-generating structure and write \(z \sim p(z)\), but the relation between latent structure and observations is complex. We therefore write \[ x \sim p_\theta(x \given z), \]
where \(p_\theta(x \given z)\) is represented by a neural network.
What is gained by making this part of the model deep?
A) We can use the neural network to replace posterior inference with a direct prediction of \(z\) from \(x\).
B) We can keep explicit latent structure while learning a flexible conditional distribution from \(z\) to \(x\).
C) We can avoid specifying a probability model for \(x\), since the neural network only needs to simulate observations.
D) We can make the posterior tractable by choosing a sufficiently expressive decoder distribution.
\[p_\theta(x,z)=p(z)\,p_\theta(x \given z).\]
Deep probabilistic programming does not mean replacing the probabilistic model with a neural network.
It means:
Deep probabilistic programming
The single most important aspect of deep probabilistic programming: the ability to partially specify the generative model; encoding the parts of the model you do know, and letting model learning and generic deep neural network function approximation take care of the rest.
Suppose a model uses
\[ \eta_\theta(z)=f_\theta(z), \qquad x \sim p(x;\eta_\theta(z)), \]
where \(p(x;\eta)\) is a known distribution family.
What is the main reason for this pattern?
A) The distribution family is used to make the posterior analytically tractable.
B) The neural network is only needed because the latent variable \(z\) is not directly observable.
C) The program still needs a distribution object that supports sampling and scoring observed values.
D) The distribution family is used so that the model no longer needs a guide.
A probabilistic program needs distributions with operations like:
\[ x \sim p_\theta(x \given z) \]
and
\[ \log p_\theta(x \given z). \]
A neural network can make the distribution flexible by predicting parameters,
\[ \eta_\theta(z) = f_\theta(z), \qquad p_\theta(x \given z)=p(x;\eta_\theta(z)), \]
while the chosen family \(p(x;\eta)\) supplies:
So the network does not usually replace the probability distribution. It parameterizes one.
We are not limited to very simple families.
Start with a base distribution that we know how to sample and score:
\[ u \sim p_0(u). \]
Apply an invertible neural transformation: \(x = T_\theta(u).\)
Then samples are easy:
\[ u \sim p_0(u), \qquad x = T_\theta(u). \]
And densities are available by change of variables:
\[ \log p_\theta(x) = \log p_0(T_\theta^{-1}(x)) + \log \Bigl| \det \frac{\partial T_\theta^{-1}(x)}{\partial x} \Bigr|. \]
A normalizing flow is a more expressive distribution family supporting the two needed operations:
Suppose that for each observation \(x\) we want to infer the latent \(z\).
\[ p_\theta(z \given x). \]
A guide shares parameters across observations:
\[ \lambda_\phi(x) = \text{network}_\phi(x), \qquad q_\phi(z \given x) = q(z;\lambda_\phi(x)). \]
Instead of solving a new inference problem from scratch for every \(x\), we learn a function that maps observations to proposal distributions over latents.
A variational autoencoder uses
\[z \sim p(z), \qquad x \sim p_\theta(x \given z), \qquad z \sim q_\phi(z \given x).\]
The terms \(p_\theta(x \given z)\) and \(q_\phi(z \given x)\) are often called the decoder and encoder.
How should we interpret these two networks in probabilistic-programming terms?
A) The decoder is part of the generative model, while the encoder is a learned guide for posterior inference.
B) The encoder is part of the generative model, while the decoder is a learned guide for posterior inference.
C) The encoder and decoder are two parameterizations of the same posterior distribution, trained from opposite directions.
D) The decoder defines the prior over \(z\), while the encoder defines the marginal distribution over \(x\).
Model:
\[p_\theta(x,z)=p(z)\,p_\theta(x \given z).\]
Guide:
\[q_\phi(z \given x).\]
Objective:
\[\mathcal{L}(\theta,\phi) = \mathbb{E}_{q_\phi(z \given x)}\!\left[\log p_\theta(x,z) - \log q_\phi(z \given x)\right].\]
Common Gaussian guide:
\[q_\phi(z \given x) = \mathcal{N}\!\left(\mu_\phi(x),\,\operatorname{diag}(\sigma_\phi^2(x))\right),\]
with reparameterization
\[z = \mu_\phi(x) + \sigma_\phi(x)\odot\epsilon, \qquad \epsilon \sim \mathcal{N}(0,I).\]
Solutions
Solutions
Introduction to Probabilistic Programming