Explanation of the Approximate Inference and MCMC Simulator — What the Pile of Footprints and the Bell Are Computing

This page explains, in the order words → formulas → calculation procedure, what the “traveler’s footprints” and the “ways of tracing with a bell” seen in the simulator correspond to in the language of probability, and with what formulas they are computed. The procedure, the conditions of the calculation, and the questions for checking for the detailed view are also collected here.

1. About this page

The Approximate Inference and MCMC Simulator compares two ways of handling a probability distribution that is hard to handle with formulas (for example, a posterior distribution): copying it by walking around with random numbers (Markov chain Monte Carlo, MCMC), and tracing it with a distribution of a simple shape (the Laplace approximation and variational inference). It covers Chapter 20 (approximate inference) and Chapter 21 (sampling methods).

The simulator has two views.

Scene A is computed with the same functions as ② of the detailed view, and Scene B with the same functions as ①. We recommend reading in this order: try the simple view, check what it really shows in Section 2, read the formulas in Section 3, and operate the detailed view with the procedure in Section 4.

2. What the simple view really shows

The “shape of the hills” and the “shape with two humps” in the simple view are curves of the probability density of a probability distribution. The horizontal axis is the value x, the vertical axis is how likely that value is, and the area under the curve is 1. The higher the hill, the more likely that value is to appear. The scale of the vertical axis is omitted in the simple view.

2.1 Scene A: Can walking around copy the shape of the hills?

The traveler’s way of walking is the Metropolis–Hastings algorithm (MH algorithm) itself. The target shape is the same double well as the default of ② in the detailed view, p̃(x) = exp[−2(x2 − 1)2] (barrier b = 2), with two hills of the same height at x = ±1 and a valley at x = 0. The sequence of footprints left by the traveler is the MCMC sample, and the fact that the pile of counted footprints (the histogram) gets close to the target shape is what it means that MCMC can copy a distribution.

Table 1: Words on the screen in Scene A and the corresponding terms and symbols
Words on the screenTermSymbol or formula
Top: target shape (the hills in the top picture), dotted = target shapeTarget distribution (the unnormalized density and the normalized density)p̃(x) = exp[−b(x2 − 1)2], b = 2. p(x) = p̃(x)/Z
Traveler (where the traveler is)Current state of the chainx(t)
Traveler’s step size: Small / Just right / BigProposal width (the standard deviation of the Gaussian random-walk proposal)s = 0.03, 1, 10
Candidate (the spot to try next)Proposalx′ = x + sε, ε ~ 𝒩(0, 1)
Candidate is ○ × as highAcceptance ratio (capped at 1, it is the acceptance probability)r = p̃(x′)/p̃(x), acceptance probability min(1, r)
Random drawUniform random numberu ∈ [0, 1)
Go / stayAcceptance / rejectionIf u < min(1, r), then x ← x′
Footprint (a step that could not move also leaves one, in place)Sample (on rejection, the current value is counted once more)x(1), …, x(N)
Pile of footprintsHistogram of the samples (heights scaled to area 1; 48 bins)—
Fraction that movedAcceptance ratenumber of acceptances / N
Fraction on the left hill (target 0.50)Fraction of samples with x < 0, and its true probabilityP(x < 0) = 0.50

The rule written in the picture, “go higher always; go lower with chance = height ratio (half as high: 1 time in 2),” puts the acceptance probability min(1, r) into words (the proposal x′ = x + sε is a symmetric proposal, equally likely to go and to come back, so the acceptance probability is decided by the height ratio alone). Because only the height ratio is used, multiplying the whole hill by any factor does not change the walk. Therefore the traveler can walk with the unnormalized density p̃(x) as it is, without knowing the number Z that scales the area to 1. Because the traveler also moves to a lower spot with probability r, the traveler does not stay at the top of a hill but sometimes goes down into the valley and crosses it to the other hill. Therefore, with enough steps, footprints are left in proportion to the height of the hills (Section 3.2). “Just 1 step (look closely)” shows the candidate, the two heights, and the value of the random draw in turn, and shows how this rule decides one step.

Numbers from “Try it” (all are values after walking 2000 steps from the starting point):

For reference, the effective sample size for the same 2000 steps (Seff of Section 3.4; no burn-in) is about 216 for the just-right step size and about 51 for the too-big step size. For the too-small step size, summing the autocorrelation up to half the series length still does not meet the truncation condition (“series too short”), so the effective sample size cannot be given reliably. The acceptance rate 0.45 is close to the one-dimensional rule of thumb 0.44 in Section 21.8 of the text, but this rule of thumb was reported for a unimodal Gaussian target and does not necessarily apply as it is to a target with two hills.

Where the analogy fits and where it does not

Where it fits: each step of the traveler computes the proposal, the acceptance ratio, the random draw, and acceptance/rejection with the same function as ② of the detailed view (mhStep). The starting point (x = −1.2327, the 5 % point of the target shape) and the sequence of random numbers are also the same as chain 1 of ② (seed 20261112, initial values “Spread”), so with the same step size the sequence of footprints is the same as chain 1 of ② in the detailed view. Leaving a footprint in place on a step that could not move corresponds to counting the same value once more in the sample when the MH algorithm rejects.

Where it does not fit: a real traveler looks at the destination and chooses it, but this traveler’s candidate is decided by random numbers, and whether to go is decided by a random draw after looking at the height of the candidate. The “height” of a hill is a probability density, not the height of terrain. In the language of physics, if we view p̃(x) = exp(−E/kBT), the high parts of the hills correspond to low-energy places (the bottoms of the wells). The walking motion of the traveler (the motion of jumping to the candidate) is for show in the picture and is not used in the calculation.

2.2 Scene B: What if you trace a two-humped shape with one bell?

The shape to trace is the default “Bimodal” target of ① in the detailed view (w = 0.6, d = 6): a mixture of two Gaussians with standard deviation 1, with weight 0.6 at x = −3 and 0.4 at x = 3. The bell is a Gaussian q(x) = 𝒩(x | m, s2). The two ways of tracing correspond to the two directions of the KL divergence, which measures the mismatch between p and q.

Table 2: Words on the screen in Scene B and the corresponding terms and symbols
Words on the screenTermSymbol or formula
Green = shape to traceTarget distribution (Gaussian mixture)p(x) = 0.6 𝒩(x | −3, 1) + 0.4 𝒩(x | 3, 1)
Bell (thick line)Approximating distribution (the family of Gaussians)q(x) = 𝒩(x | m, s2)
Middle of the bell, Width of the bellMean and standard deviation of qm, s
Don’t spill over (no cover where there is none)The q that minimizes KL(q‖p) (the q that maximizes the ELBO; variational inference)Searched for numerically with the Nelder–Mead method
Don’t miss any (cover all that is there)The q that minimizes KL(p‖q)m = 𝔼p[x], s2 = Varp[x]
Where tracing starts: From the left / From the middle / From the rightInitial value for KL(q‖p) minimization(m, s) = (−3, 2.5), (−0.6, 4), (3, 2.5)
/ hatching (spill-over)Where the bell is more than 3 times as high as the shapeq(x) > 3p(x)
\ hatching (missed)Where the shape is more than 3 times as high as the bellp(x) > 3q(x)
Estimated probability on the right (x > 0) (True shape: 0.40)Probability under q, and the true probability under p1 − Φ(−m/s). True value 0.6Φ(−3) + 0.4Φ(3) = 0.40
Size of the mismatch with the whole shape (“What we learned”)KL(q‖p) (unit: nat)—

The results of tracing (the bell after pressing “▶ Trace with the bell”) are as follows.

Table 3: Results of tracing in Scene B
Way of tracing, starting placeMiddle mWidth sKL(q‖p)Probability on the right
Don’t spill over, From the left−2.991.020.510.00
Don’t spill over, From the middle−0.472.700.850.43
Don’t spill over, From the right2.981.030.911.00
Don’t miss any (independent of the starting place)−0.603.100.940.42

With “Don’t spill over,” starting from the left the bell settles on the big left hump, starting from the right it settles on the right hump, and starting from the middle it stops as a wide bell straddling both. Each of these is a local minimum of KL(q‖p), and the smallest is when it settles on the left hump (0.51). “Don’t miss any” is the bell that matches the mean and variance, with KL(p‖q) = 0.46. In this case the middle of the bell is in the valley (x = −0.6), where the height of the bell is 0.13 but the height of the true shape is only 0.0137 (Example 20.8 of the text).

Where the analogy fits and where it does not

Where it fits: the traced bell is found with the same functions as ① of the detailed view (minKLqp, momentMatch). The starting bells have the same centers as the initial values of ① in the detailed view (near the left and right peaks, and wide from the center), and only their widths are changed (widened from 1 to 2.5 for “From the left” and “From the right,” and narrowed slightly from 4.66 to 4 for “From the middle,” so that motion can be seen when the button is pressed). The bell it ends up at is the same as when starting from the initial values of ① in the detailed view (the tests confirm a difference of 10−6 or less). “Don’t spill over” and “Don’t miss any” put into words the facts that the integrand of KL(q‖p), q ln(q/p), is large where q ≫ p, and that the integrand of KL(p‖q), p ln(p/q), is large where p ≫ q (Section 3.3).

Where it does not fit: even the “Don’t spill over” way of tracing does not make the spill-over zero. The factor 3 at the boundary of the hatching is a value chosen to make the picture easy to read and is not used in the calculation (the KL weights and adds up the mismatch everywhere). The smooth motion of the bell from the starting bell to the traced result is for show in the picture (the center m and ln s are moved at the same rate) and is not the path followed by the optimization (the Nelder–Mead method). The Laplace approximation and the ELBO bars in ① of the detailed view are not shown in the simple view.

3. How it works

3.1 Why approximations and random numbers are needed

For the posterior distribution of Bayesian estimation, p(θ | 𝒟) = p(𝒟, θ)/p(𝒟), even when the numerator p(𝒟, θ) can be written as a formula, the integral in the denominator (the marginal likelihood) p(𝒟) = ∫ p(𝒟, θ) dθ usually cannot be solved. In this simulator, what corresponds to the numerator is written as the unnormalized density p̃(x), and what corresponds to the denominator as Z. There are two ways to handle the distribution without knowing Z. One is to make samples from p and obtain means and probabilities as sample averages (MCMC; Chapter 21; Scene A). The other is to choose a distribution q of an easy-to-handle form and search for one close to p (the Laplace approximation and variational inference; Chapter 20; Scene B).

3.2 Why the Metropolis–Hastings algorithm can copy the shape

In the MH algorithm, a candidate x′ is made from the current point x, the ratio r = p̃(x′)/p̃(x) is computed, and the chain moves to the candidate with probability min(1, r) (Section 21.6 of the text). Because r is a ratio, the unknown Z cancels and is not needed. A candidate in the direction in which p̃ increases (r ≥ 1) is always accepted, and a candidate in the direction in which it decreases is accepted with probability r. By not only climbing the hill but sometimes going down, the chain visits even the tails of the distribution in the right proportions.

The one-step transition T(x′ | x) made in this way satisfies, if the proposal is symmetric (the probability of proposing x′ from x equals the probability of proposing x from x′), for x ≠ x′

p(x)T(x′∣x)=q(x′∣x)min(p~(x),p~(x′))Z=p(x′)T(x∣x′)

(detailed balance; here q(x′ | x) is the probability density of the proposal and is different from the bell q of Scene B). This holds because the middle expression is symmetric in x and x′. When detailed balance holds, a traveler who starts from p is still distributed according to p after one step, so p is a distribution that does not change (the stationary distribution). Furthermore, if the chain can go from anywhere to anywhere in some number of steps (irreducibility) and has no rule that makes it return to the same place with a fixed period (aperiodicity), then wherever it starts, the fraction of footprints approaches p as the number of steps increases (Section 21.5 of the text). Counting the current value once more as a sample on rejection is to count the “stay in place” part of this transition T; if it is not counted, the distribution is distorted.

However, “approaches” refers to what happens when the number of steps is made large enough. With the too-small step size of Scene A, it takes a great many steps to reach the other side of the valley, and 2000 steps copy only one of the hills. It is not that the traveler cannot leave the hill: walking on with the same sequence of random numbers, this traveler crosses the valley for the first time at step 5,289 (even so, after 20000 steps the fraction on the left hill is 0.80, still far from the target 0.50). With a too-big step size, most candidates land beyond the foot of the hills and are rejected, and the traveler keeps staying at the same spot. In both cases, even though there are 2000 footprints, the number converted to independent samples (the effective sample size) is small (Section 21.8 of the text). The two steps in Example 21.6 of the text (candidate −1.6350 is rejected with r = 0.00634 and u = 0.7392; candidate −0.6667 is accepted with r = 0.926 and u = 0.7207) are the first two steps of chain 1 with the default of ② in the detailed view (s = 0.3), and they come from the same sequence of random numbers as the traveler of Scene A.

3.3 The two directions of the KL: an approximation that does not spill over and one that does not miss any

How far a distribution q is from p is measured with the KL divergence. The KL has different values and different properties depending on its direction (Section 20.7 of the text).

When a p with two peaks is approximated by a q with one peak, something goes wrong in either direction. With KL(q‖p), one of the peaks is missed (the probability on the right is estimated as 0.00 or 1.00); with KL(p‖q), the valley, which has almost no probability, is treated as the most likely value. Which is better depends on what the approximation is used for (Section 20.10 of the text).

3.4 Formulas and algorithms computed in the detailed view

The target is given by an unnormalized density p̃(x), and p(x) = p̃(x)/Z. This corresponds to the posterior distribution of Chapter 20, p(θ | 𝒟) = p(𝒟, θ)/p(𝒟) (x ↔ θ, p̃ ↔ p(𝒟, θ), Z ↔ p(𝒟)).

Skewed unimodal: p~(x)=xa−1(1−x)b−1(0<x<1),Z=B(a,b)Bimodal: p~(x)=we−(x+d/2)2/2+(1−w)e−(x−d/2)2/2,Z=2πDouble well: p~(x)=exp[−b(x2−1)2],b=EbkBT

The Laplace approximation expands ln p̃ to second order around the chosen mode x*. The approximation of the marginal likelihood Z (p(𝒟) in Chapter 20) also follows from this expansion. The curvature is written Λ (the same letter as in Chapter 20; it is the precision of the Gaussian).

q(x)=𝒩(x∣x*,Λ−1),Λ=−d2dx2lnp~(x)|x=x*lnZ≈lnp~(x*)+12ln2πΛ

The KL divergence has different values and different properties depending on its direction (the unit is the nat).

KL(q‖p)=∫q(x)lnq(x)p(x)dx,KL(p‖q)=∫p(x)lnp(x)q(x)dxlnZ=ELBO(q)+KL(q‖p),ELBO(q)=𝔼q[lnp~(x)]−𝔼q[lnq(x)]≤lnZ

The Gaussian that minimizes KL(p‖q), q = 𝒩(x | m, s2), has m = 𝔼p[x] and s2 = Varp[x] (matching the mean and variance). The q that minimizes KL(q‖p) (= the q that maximizes the ELBO) has no closed form, so it is searched for numerically over (m, ln s) with the Nelder–Mead method. If the objective function has several local minima, the destination depends on the initial value.

Metropolis–Hastings algorithm: from the current point x, make a proposal x′ = x + sε (ε ~ 𝒩(0, 1)); if a uniform random number u ∈ [0, 1) satisfies u < min(1, r), accept (x ← x′); otherwise reject (x stays, and the same value is counted once more in the sample). Because the proposal is symmetric, q(x | x′) = q(x′ | x) cancels, and Z cancels too, so it is not needed.

r=p~(x′)q(x∣x′)p~(x)q(x′∣x)=p~(x′)p~(x),acceptance probability min(1,r)

The autocorrelation function ρk is computed for the samples x1, …, xS of a chain (after burn-in) with the standard estimator whose denominator is divided by S (computed by FFT; the tests confirm that it agrees with the direct sum). The integrated autocorrelation time τint (the same symbol as in Chapter 21; a subscript is added because τ alone would be confused with the temperature in Chapters 26 and 27) and the effective sample size are

τint=1+2∑k=1kcρk,Seff=Sτint

Truncation rule: the upper limit kc of the sum is determined by Sokal’s automatic window. Add terms for k = 1, 2, …; when k ≥ 5 τint(k) holds for the first time, that k is taken as kc (τint(k) is the partial sum up to that k). If the condition is not met even after summing up to half the series length, “series too short” is displayed, and τint and the effective sample size may be underestimated. The effective sample size over all chains is the sum over the chains. The Monte Carlo standard error (MCSE) of the mean is √(variance / effective sample size).

Definition of R̂: this is split-R̂ (the form in Gelman et al., Bayesian Data Analysis, 3rd ed., Section 11.4; no rank normalization). Split each chain after burn-in into a first half and a second half to get M = 2 × (number of chains) sequences, let n be their length, W the mean of the within-chain variances, and B the spread of the chain means. Then

B=nM−1∑j=1M(x¯j−x¯)2,R^=n−1nW+BnW

R̂ is displayed only when there are two or more chains. It is close to 1 if the chains look at the same distribution and becomes large if each chain looks at a different region. As a rule of thumb, suspect non-convergence if it exceeds 1.01 (the older rule of thumb was 1.1). However, R̂ ≈ 1 is only a necessary condition for convergence.

In the three-state example, from the proposal Qij = q(j | i) (1/2 for each of the other two states), the transition matrix Tij = Qij min(1, p̃jQji / (p̃iQij)) (j ≠ i), Tii = 1 − Σj≠i Tij is built. Rows are the “current state,” columns are the “next state,” and each row sums to 1.

3.5 Calculation procedure of the simple view

  1. A: Set the target shape p̃(x) = exp[−2(x2 − 1)2] and the step size s, and prepare one chain with x(0) = −1.2327 (the 5 % point of p) and seed 20261112.
  2. A: At each step, draw one ε (Gaussian random number) and one u (uniform random number), compute x′ = x + sε and ln r = ln p̃(x′) − ln p̃(x), and accept if u < min(1, r). Whether accepted or rejected, add the x after that step to the footprints.
  3. A: Count the footprints in 48 bins and draw them with heights scaled to area 1. The dotted line is p(x) = p̃(x)/Z (Z is a numerical integral on a grid). The fraction that moved is the number of acceptances / the number of steps walked, and the fraction on the left hill is the fraction of footprints with x < 0.
  4. B: The “Don’t spill over” way of tracing minimizes KL(q‖p) with the Nelder–Mead method, starting from the (m, ln s) of the starting bell. “Don’t miss any” determines q by integrating the mean and variance of p on a grid.
  5. B: Draw q and p on the same grid (401 points), and put / hatching where q > 3p and \ hatching where p > 3q (neither is put where the height is less than 1 % of the maximum of the picture). The probability on the right is 1 − Φ(−m/s).

The calculations of the simple view call the same functions as the detailed view (makeTarget, mhInit, mhStep, minKLqp, momentMatch, klPQ, and qTerms in inference-mcmc.model.js). The only calculations added for the simple view are counting the footprints (acceptance rate, fraction on the left hill, number of valley crossings), deciding where to put the hatching, and the intermediate shapes of the moving bell in the picture (inference-mcmc.easy.js).

4. How to use the detailed view

The detailed view has two tabs: ① (Comparing Approximate Distributions) and ② (Metropolis–Hastings Algorithm). In both, the figures and the “Putting the current numbers into the formula” box are on the left, and the controls and readouts are on the right.

4.1 Procedure and what to observe

  1. In Tab ①, start with the default (skewed unimodal Beta(3, 9)). What to observe: the Laplace approximation is centered at the mode x* = 0.2, and its variance is 1/Λ = 1/62.5 = 0.016. The true mean is 0.25 and the true variance is 0.01442. The Laplace approximation misses the long right tail and puts probability 0.0569 on the left side x < 0 (where p = 0), so KL(q‖p) is ∞.
  2. Set the target to “Bimodal” and switch “Initial value for KL(q‖p) minimization” among “Near the left peak,” “Near the right peak,” and “Wide, from the center.” What to observe: the q that minimizes KL(q‖p) falls into one of three local solutions depending on the starting point: the left peak, the right peak, or a wide shape covering both (for the default w = 0.6, d = 6, KL(q‖p) = 0.507, 0.911, 0.846). The q that minimizes KL(p‖q) is centered in the low-probability region between the two peaks and covers both.
  3. Switch “q to put into the formula” and read “Putting the current numbers into the formula” below. What to observe: ELBO + KL(q‖p) gives the same ln Z for every q. In the ELBO bar figure, the gap from ln Z (the hatched band) is KL(q‖p).
  4. Turn on “Overlay a manually moved q” and move m and s. What to observe: the closer q is to p, the closer the ELBO gets to ln Z. KL(q‖p) and KL(p‖q) are in general different values.
  5. In Tab ②, with the default (double well b = 2, s = 0.3, four chains), press “Advance 1000 steps” twice. What to observe: the histogram approaches the true density; also read the acceptance rate, τint, the effective sample size, and R̂.
  6. Set the proposal width s to 0.01 and to 10, and start over with the same seed. What to observe: for too small an s, the acceptance rate is high but the trace moves slowly and τint is large. For too large an s, the acceptance rate is low and the trace becomes flat steps. In both cases the effective sample size is small.
  7. Press “Barrier example (b = 12)” (s = 0.3, four chains, spread initial values, 2000 steps with the default seed). What to observe: each of the four chains stays in the well it started in; each chain’s trace looks settled and τint is small, yet R̂ is large, about 9.9. Setting burn-in to 50 % changes nothing. If you set the initial values to “All at the same point,” R̂ ≈ 1.00, but the mean stays at −0.98, far from the true value 0.
  8. Open “Build the Metropolis transition matrix for a three-state discrete distribution” below Tab ②. What to observe: for p̃ = (2, 3, 5), each row of the transition matrix sums to 1, piTij = pjTji (detailed balance), and pT = p (stationary distribution).

With the keyboard, Tab moves to buttons and sliders, Enter (or Space) presses a button, and the arrow keys move a slider. The tabs can be switched with ← and →.

5. Conditions of the calculation

5.1 Data and random-number conditions

5.2 Conditions fixed in the simple view

5.3 Simplifications

5.4 Conditions under which results become unstable

6. Questions for checking

Questions 1 and 2 can be answered with the simple view alone. Questions 3–6 use the detailed view.

  1. In Scene A of the simple view, with the “Small” step size the fraction that moved is as high as 0.96, yet the pile of footprints does not take the target shape. Why? Why can we not say that the higher the fraction that moved, the better?
    Sample answer

    Because each step is small, the candidate appears right next to the current spot and has almost the same height. So the traveler can go almost every time, but the distance moved in one step is short, and in 2000 steps the traveler cannot reach the right hill on the other side of the valley. The footprints are left only on the left hill, and the fraction on the left hill becomes 1.00 (target 0.50). A high fraction that moved does not mean “moved a lot”; it is also the flip side of “moved only a little.” With a too-big step size, conversely, the fraction that moved is as low as 0.07, and footprints pile up at the same spots. The step size that copies the shape well is the just-right one in between.

  2. In Scene B of the simple view, how does the estimated probability on the right (x > 0) differ between the “Don’t spill over” and the “Don’t miss any” ways of tracing? State the weakness of each.
    Sample answer

    With “Don’t spill over,” the bell settles on one of the humps, so the estimate is 0.00 when starting from the left and 1.00 when starting from the right, far from the true 0.40 (one hump is missed). With “Don’t miss any,” the bell covers both, so the estimate is 0.42, close to the truth, but the middle of the bell lands in the valley (x = −0.6), where there is almost none of the shape, and an unlikely value is treated as the most likely value.

  1. What are the mean and variance of the Laplace approximation of Beta(3, 9)? Compared with the true mean and variance, in which direction is the approximation distorted?
    Sample answer

    The mode is x* = (a − 1)/(a + b − 2) = 2/10 = 0.2, and Λ = 2/0.22 + 8/0.82 = 50 + 12.5 = 62.5, so the mean is 0.2 and the variance is 1/62.5 = 0.016. The true mean is 3/12 = 0.25 and the variance is 27/1872 ≈ 0.01442. Because the Laplace approximation is centered at the mode, it misses the weight of the long right tail and underestimates the mean. It also puts probability 0.0569 on the left side x < 0. KL(p‖q) is 0.12884, which is larger than that of the Gaussian with matched mean and variance (0.048117).

  2. For the bimodal target, where are the q that minimizes KL(q‖p) and the q that minimizes KL(p‖q) placed? Why?
    Sample answer

    KL(q‖p) is an expectation under q, so if q puts probability where p is almost 0, ln(q/p) becomes large and is penalized heavily. Therefore it moves toward one peak, and its variance is also smaller (by default, the left peak: m = −2.988, s = 1.019). KL(p‖q) is an expectation under p, so it is penalized where p has probability but q is close to 0, and it spreads to cover both peaks (m = −0.6, s2 = 9.64; its center lies in the low-probability valley).

  3. What is the difference between the ELBO and ln Z? What does maximizing the ELBO amount to?
    Sample answer

    The difference is KL(q‖p) ≥ 0 (ln Z = ELBO + KL(q‖p)). Since ln Z does not depend on q, maximizing the ELBO is the same as minimizing KL(q‖p). For Beta(3, 9), ln Z = ln B(3, 9) = −6.2046, and the ELBO of the (truncated) q that minimizes KL(q‖p) is −6.2437; the difference 0.039178 is KL(q‖p).

  4. In the barrier example (b = 12), the trace of each chain looks settled and τint is small. Why can we not say the chains have converged? How does R̂ capture this?
    Sample answer

    Every chain sees only the well it started in and does not know the probability (one half) of the other well. Within a well the chain mixes well, so τint is small (about 4) and does not change even when burn-in is discarded. R̂ compares the between-chain spread B with the within-chain variance W; because the chain means split into −0.98 and +0.98, it gives a large value of about 9.9. However, if all four chains start from the same well, R̂ ≈ 1 while the overall mean is −0.98, and even R̂ does not notice.

7. Corresponding sections of the text and references

References (from the end of Chapters 20 and 21):

Back to the Approximate Inference and MCMC Simulator | Machine Learning — From Probability to GPT (Contents) | Equations are typeset with the browser’s built-in MathML (no external library).