Chapter 8 Application: Gaussian Variational Inference
In Chapters 6 and 7 we studied two gradient flows of the KL divergence to the standard normal distribution . In this chapter we replace by a distribution that is not Gaussian. The problem of finding the normal distribution closest to is called Gaussian variational inference in statistics and machine learning. Since the target distribution is not Gaussian, we no longer obtain closed formulas as in the previous two chapters. Even so, much can still be proved about the equations of the gradient flows for the two metrics, their stationary points and their rates of convergence. This chapter does the following.
- •
-
•
We find the gradient flows of for the Wasserstein metric and for the Fisher metric. The two flows have the same stationary points (Section 8.3).
-
•
When is strongly log-concave, there is a unique minimiser, and the Wasserstein gradient flow converges at the uniform rate (Section 8.4).
-
•
For the Fisher gradient flow the inverse of the covariance matrix can be bounded, but there is no uniform rate (Section 8.5).
-
•
We compare the update rules obtained by discretising the two flows in time (Section 8.6).
-
•
We describe the relation with Langevin dynamics (Section 8.7).
We use the following.
- •
- •
- •
- •
- •
- •
We do not treat stochastic algorithms that estimate expectations by random sampling, approximation by Gaussian mixtures, or gradient flows on the space of all probability distributions. For gradient flows in Gaussian variational inference see Lambert et al. [LCB+22] and Chen et al. [CHH+24a]; for discretised algorithms see Diao et al. [DBC+23] and Khan and Rue [KR23]. Langevin dynamics is treated in Chapter 5 of Why Pictures Emerge from Noise [KEI26b].
8.1 Setting Up the Problem
Throughout this chapter we take the target distribution as follows. Let be of class with bounded. Assume further that , and put
Since is bounded, grows at most linearly and at most quadratically. Hence all the Gaussian expectations that appear below are finite.
Let and put
If is the density of , then and
The latter follows from and . Therefore
| (8.1) |
When , that is, and , we have , so (Proposition 1.6). We use the following two Gaussian expectations:
is a symmetric matrix. and are functions of , but we often omit the arguments.
Definition 8.1 (Gaussian variational inference).
The problem of minimising over is called Gaussian variational inference. We write its infimum as
By Lemma 1.4, , so is finite. Note, however, that is the infimum over normal distributions, a different quantity from . If is not Gaussian, then for every normal distribution , so (Lemma 1.4). Hence in this case provided the infimum is attained. The infimum is attained if is strongly log-concave (Proposition 8.9 (2)). The KL divergence is taken in the same direction as before in this book: the normal distribution is the first argument.
Let us explain the motivation for this problem. In Bayesian statistics, from the density of a prior distribution of a parameter and the likelihood of an observation , one forms the posterior distribution
The numerator can be computed, but the integral in the denominator is hard to compute when is large. Putting , we have . In (8.1), appears only in the constant term . So can be minimised without knowing . The normal distribution at the minimiser gives an approximation of .
Example 8.2 (Logistic likelihood).
Let , take the prior , and let the likelihood of the observation be . Then
Differentiating gives
Hence , and is not constant. Therefore is not Gaussian. Figure 8.1 is drawn for this .
8.2 Derivatives of Gaussian Expectations
To compute the derivative of , we need to differentiate with respect to . The following lemma does this. From now on, denotes a random variable with law .
Lemma 8.3 (Derivatives of Gaussian expectations).
Let be of class with bounded. Let , and , and put . For sufficiently small, , and
In particular, gives the derivative with respect to the mean, and gives the derivative with respect to the covariance matrix.
We have written the derivative with respect to the covariance matrix as a derivative in the direction . The reason is that the entries of a symmetric matrix are not independent, so writing it with entrywise partial derivatives invites mistakes.
Proof.
Let be the density of , and put and .
Step 1. We find at . Differentiating in by the same computation as in the proof of Proposition 5.10 gives
On the other hand, and . Comparing the two, we obtain
| (8.3) |
Step 2. We show that we may differentiate under the integral sign. If with sufficiently small, the eigenvalues of are at least and at most some constant. Then there are constants with . Moreover, is times a polynomial in of degree at most whose coefficients are bounded for . Since is bounded, . Hence, by the dominated convergence theorem, .
Step 3. We integrate by parts. By (8.3), what we must show is
Integrating by parts on each line parallel to the -axis, the boundary terms are products of or with or . The former grow at most polynomially and the latter decay like a Gaussian, so the boundary terms vanish. All the integrands that appear are integrable, so by Fubini’s theorem we may integrate the identities on the lines. This proves the lemma. ∎
Proof.
To consider gradient flows we also need to be of class (Definition 2.9). In fact , and are in . Differentiating the density any number of times in gives times a polynomial in . Its coefficients are continuous functions of . As ranges over a compact subset of , the bound holds uniformly. Since , and grow at most quadratically, we may therefore differentiate under the integral sign any number of times, as in Step 2 of the proof of Lemma 8.3.
8.3 The Two Gradient Flows
We first compute for . Using the coordinates , put and . Setting in (8.4) gives
Since the Wasserstein metric is (Example 5.12), the gradient flow is
| (8.5) |
Since the matrix of the Fisher metric is (Proposition 3.10), the gradient flow is
| (8.6) |
When , we have and , and we recover the equations of the OU flow and the FR flow of Chapter 6. The same holds for general .
Theorem 8.5 (The two gradient flows of ).
Let .
-
1.
The gradient with respect to is
and the symmetric matrix that corresponds to this tangent vector under Lemma 5.9 is . The gradient flow is
(8.7) -
2.
The gradient with respect to is
and the gradient flow is
(8.8) This is equivalent to
(8.9) - 3.
For each initial value , each of the two flows exists and is unique up to some time .
From now on we call the flow in (1) the W flow for and the flow in (2) the FR flow for . When , the W flow is the OU flow and the FR flow is the FR flow of Chapter 6. In the second equation of (8.9), the term becomes when and cancels . For general there is no such cancellation.
Proof.
We prove (1). Put . The matrix is symmetric and satisfies . By the uniqueness in Lemma 5.9, it is the symmetric matrix corresponding to . By the computation following Definition 5.11, for a tangent vector ,
By Proposition 8.4, the right-hand side equals . Hence , and the gradient flow is (8.7).
We prove (2). As in the proof of Theorem 6.5, writing the quadratic form of Proposition 3.10 as an inner product gives
Substituting , we get and . So the right-hand side equals (Proposition 8.4), and the gradient flow is (8.8). We show the equivalence. Since , the equation is equivalent to . In that case
so is equivalent to the second equation of (8.9).
We prove (3). If , then and . Substituting, (8.7) becomes , , and (8.8) becomes , . These are (6.2) and (6.4).
Finally, as we saw at the end of the previous section, and are of class . Hence the two vector fields are , and the last claim follows from the existence and uniqueness of solutions of ordinary differential equations. ∎
Let us look at the velocity field of the W flow on . Applying Proposition 5.10 with and the symmetric matrix corresponding to , the velocity field is
| (8.10) |
When , this is the velocity field of Proposition 6.3. Equations (8.7) and (8.8) are the same equations as (4.24) and (4.18) of Chen et al. [CHH+24a].
Proposition 8.6 (Stationary points).
For , the following three conditions are equivalent.
-
1.
is a stationary point of the W flow, that is, the right-hand side of (8.7) is .
-
2.
is a stationary point of the FR flow.
-
3.
and .
These are the critical points of , that is, the points where .
Proof.
The vector field of a gradient flow is , and the metric is positive definite at each point, so is equivalent to (Definition 2.7). Hence (1) and (2) are each equivalent to . By (8.4), (3) implies . Conversely, suppose . Taking , we get for all , so . Taking and , we get . This is the sum of the squares of the entries of the symmetric matrix , so . ∎
Remark 8.7 (Difference from the Laplace approximation).
Suppose has a minimiser and is positive definite. Another way to approximate by a normal distribution is to take the quadratic approximation at , namely . This is called the Laplace approximation. The condition of Proposition 8.6 replaces and not by their values at but by their averages over . Therefore the two approximations differ in general (Figure 8.1, Problem 4). When is quadratic, is constant and the two agree.
8.4 Convexity and Convergence of the W Flow
In this section we treat the case where is -strongly log-concave. The key is the convexity of along the displacement interpolation of Chapter 5. For , the displacement interpolation was a geodesic of the Wasserstein metric (Proposition 5.7). The following lemma holds for general . Its proof does not use the fact that the displacement interpolation is a geodesic.
Lemma 8.8 (Convexity along displacement interpolation).
Suppose that for all , for some . Let and , and let be the matrix in (5.3). Put and , and let
Then is of class on an open interval containing , and for ,
By Proposition 5.7, are the mean and covariance matrix of the displacement interpolation from to .
Proof.
Let be the eigenvalues of . The eigenvalues of are , so is positive definite for in some open interval containing . Put and , and for put . Then . By (8.1),
where is a constant independent of .
Step 1 (the term ). is affine in , with . Hence
As ranges over a compact interval contained in , the functions and are dominated by an integrable function independent of . Hence can be differentiated twice under the integral sign, and its second derivative is at least . By Theorem 5.4 (2), .
Step 2 (the term ). We have , and
Combining the two, we obtain . ∎
From this convexity we obtain the existence and uniqueness of the minimiser and the global existence of the two flows. From now on we equip with the Euclidean norm . We use the following fact about ordinary differential equations. If the maximal interval to which a solution can be extended is with , then the solution does not stay in any compact set as . This is a basic fact of the theory of ordinary differential equations.
Proposition 8.9 (Minimiser and global solutions).
Suppose that for all , for some .
-
1.
For each , the set is compact.
-
2.
has a unique minimiser . It is the unique critical point of , and .
-
3.
The W flow and the FR flow exist for all from every initial value.
-
4.
Both flows converge to as .
We write for the normal distribution at the minimiser, and for we put . By Proposition 8.6, is the unique point satisfying and .
Proof.
Step 1. We prove (1). By Taylor’s formula with integral remainder and , we have . Since , letting be the eigenvalues of , (8.1) gives
| (8.11) |
where is a constant. The function is bounded below on and tends to as and as . Hence at points where , we have and each lies in some interval . The set is a bounded closed subset of contained in . Since is continuous, is a closed subset of the compact set , and hence compact.
Step 2. We prove (2). By (1), attains its minimum on the nonempty compact set . This is the minimum over all of . A minimiser is a point of an open set, so it is a critical point. Next, let be a critical point and a different point. Take as in Lemma 8.8. Since is a curve, is the value of at its initial velocity, which is . From ,
| (8.12) |
Since , we have . Indeed, if , then almost surely for the coupling of Theorem 5.4 (2), so . Hence . That is, a critical point is a strict minimiser, and so there is exactly one critical point and exactly one minimiser.
Step 3. We prove (3). Both flows are gradient flows of , so by Proposition 2.10, does not increase along them. Hence, as long as it exists, a solution stays in the compact set . By the fact about ordinary differential equations stated above, the solution exists for all .
Step 4. We prove (4). Let be one of the flows and write for its metric. stays in the compact set . On the norm of the vector field is at most some . By Proposition 2.10, for all ,
Suppose there is a sequence with . Then is not a critical point. So for some , every point at distance at most from lies in and satisfies there. For with , we have for . Passing to a subsequence so that the intervals are pairwise disjoint, the integral above receives at least from each interval. This contradicts the boundedness of the integral. Hence is the only accumulation point of , and since is compact, . ∎
In Figure 8.1 the two flows head for the same minimiser but take different paths. As in the case of Chapter 6, the same function has different gradient-flow orbits under different metrics.
The following inequality says that the size of the gradient controls the gap between and its infimum.
Proposition 8.10 (Lower bound by the gradient).
Suppose that for all , for some . Then for all ,
where
Proof.
The formula for the length of the gradient follows from in Theorem 8.5 (1) and Definition 5.11. Let and take any . With the notation of Lemma 8.8, put .
This proof does not use the existence of a minimiser. When and , we have , and the claim becomes . This is the inequality obtained from (1) and (2) of Theorem 7.1.
Theorem 8.11 (Convergence of the W flow).
Suppose that for all , for some . Let be the W flow, and write . Then for all ,
When , and , equality holds for all .
Proof.
By Proposition 8.9 (3), the W flow exists for all . By Proposition 2.10 and Proposition 8.10,
Hence , which gives the claim. This is the same argument as Grönwall’s inequality.
We check the example of equality. If , then , and . The W flow is , , and starting from it gives and . Since is Gaussian, . By Proposition 1.6, , so . ∎
8.5 The FR Flow
For the FR flow, the inverse of the covariance matrix can be bounded above and below. is also called the precision matrix.
Proposition 8.13 (Bounds on the precision matrix).
Suppose that satisfies (8.2). Let be the FR flow starting from . Then for all ,
In particular, if and are the smallest and largest eigenvalues of , then
Proof.
By Proposition 8.9 (3), the FR flow exists for all . By (8.9),
Taking expectations in gives . Hence, for any unit vector , . Integrating this over gives
Multiplying by gives the first claim. We prove the second. Taking to be a unit eigenvector of for its smallest eigenvalue, the first claim and give . The largest eigenvalue is handled in the same way, using . ∎
That is, the eigenvalues of approach the interval at the rate . However, an eigenvalue that is initially outside need not enter in finite time. For example, when we have , and never becomes if (Theorem 6.5).
Remark 8.14 (Rate of convergence of the FR flow).
The FR flow has no uniform bound corresponding to Theorem 8.11 for the W flow.
- 1.
-
2.
The following is known (not proved in this book). Under (8.2) and (with ), decreases at the rate . Here , which depends on . For , the decay rate near the minimiser is at least a constant multiple of . Moreover, depending on the target distribution, convergence can be arbitrarily slow. See Chen et al. [CHH+24a, Propositions 4.13, 4.15, 4.16].
On the other hand, if is Gaussian, then is the KL divergence within the Gaussian family. So by the first half of Theorem 6.5, the natural parameter of the FR flow satisfies . This rate does not depend on the covariance matrix of (Problem 2).
8.6 Discretisation in Time
In actual computation, the flows are discretised in time. The simplest scheme is the Euler method with step size . The resulting update rule depends on the coordinates in which the Euler method is applied. The FR flow behaves well when discretised in the coordinates of (8.9). Up to constant factors, these coordinates are the natural parameter of Chapter 4 (Example 4.2).
Proposition 8.15 (One step of the natural gradient method).
Suppose that for all , for some . Let and , and let and be their values at . Put
| (8.13) |
-
1.
is positive definite. is the result of one Euler step of size applied to (8.9).
-
2.
Let and , and let , that is, . If , then equals the value at time of the FR flow starting from . If , then .
Proof.
We prove (1). Since , is the sum of the positive semidefinite matrix and the positive definite matrix , and so is positive definite. Putting and , (8.9) reads , . One Euler step is
is the first equation of (8.13). Also . Hence .
We prove (2). Since and , the FR flow becomes , . Its solution is , . On the other hand, the Euler step of (1) is , . Setting , the two agree. When , we have and . ∎
The update (8.13) is the update rule of Khan and Rue [KR23, Section 1.3.2, eq. (12)] for normal distributions. In their notation, and . The view that it is the Euler method for the FR flow is this book’s own computation. As in Remark 6.8, the FR flow is the continuous-time version of the natural gradient method.
The Euler method for the W flow behaves differently.
Proposition 8.16 (One Euler step of the W flow).
Suppose that for all , for some . Let and , and put
-
1.
. Consequently, if is the largest eigenvalue of and , then .
-
2.
Let . Then and . We have for all only when . Moreover, if and , then does not coincide with the value at any time of the OU flow starting from .
Proof.
We prove (1). Expanding the right-hand side gives
The first term is positive semidefinite. Since , the eigenvalues of have absolute value at most , so . Hence, for a unit vector , . Therefore is positive definite, and so is .
We prove (2). Substituting and gives the first claim. If , then is positive semidefinite and is positive definite, so is positive definite. If , then taking with makes negative definite. Finally, suppose that for some , equals the value of the OU flow. Since , . Comparing covariance matrices gives , and since , . Hence , which gives . This contradicts . ∎
The last claim of (2) needs both and . For example, if and , the two agree at time . In contrast with Proposition 8.15 (2), the Euler method for the W flow does not in general follow the flow exactly, even when . Moreover, for general , no step-size condition independent of can guarantee (Problem 3).
Remark 8.17 (Convergence of algorithms).
The following is known about the convergence of algorithms obtained by discretising the W flow (not proved in this book).
-
•
Lambert et al. [LCB+22, Theorem 2] studied an update rule in which the expectations are replaced by a single sample and an operation clipping the eigenvalues is added. Under , and , the distribution after updates satisfies .
- •
8.7 Relation with Langevin Dynamics
The Langevin equation for is
If , this is the equation of the OU process. What is known about this equation is collected in Remark 8.18 at the end of this section. Below we compare the corresponding Fokker–Planck equation with the W flow.
As in Chapter 6, the Fokker–Planck equation can be written as the continuity equation for the velocity field . If is the density of , then
On the other hand, by (8.10) the velocity field of the W flow is . That is, is obtained from by replacing with the affine function . If is quadratic, then , so the two velocity fields agree. If is not quadratic, then is not affine, and neither is . In this sense, the W flow of Gaussian variational inference can be regarded as the flow of the Fokker–Planck equation constrained to stay within the Gaussian family.
Remark 8.18 (Langevin dynamics as a gradient flow).
Under suitable regularity conditions, the following is known (not proved in this book).
-
1.
The density of the law of the solution of the Langevin equation satisfies the Fokker–Planck equation , and is its stationary distribution. If is uniformly positive definite, the law of Langevin dynamics approaches exponentially fast in . See Chapter 5 of Why Pictures Emerge from Noise [KEI26b]. There, assumptions such as being of class are imposed.
- 2.
-
3.
If is -strongly log-concave, then for every initial distribution. Chen et al. [CHH+24b, Proposition 2.2] state this as a classical result.
- 4.
The quantity in (3) tends to as . On the other hand, in Theorem 8.11 is the gap to the best value among normal distributions. The two are different quantities.
Problems
-
1.
Hint: , and . Differentiate .
-
2.
Let , and , and let . Show that for the W flow, and . Show that for the FR flow, and . Check that the rate of the W flow depends on , whereas the rate of the FR flow does not.
Hint: For the W flow , and for the FR flow , satisfy first-order linear differential equations with constant coefficients. A comparison for general is in Chen et al. [CHH+24a, Propositions 4.11, 4.12].
-
3.
Let , and . The eigenvalues of are and , so . Show that for and , the matrix of Proposition 8.16 is not positive definite. Further, for the same and (), show that for every , is not positive definite once is large enough. On the other hand, show that if and , then for all .
Hint: , whose determinant is . For , , and the coefficient of in its determinant is . For , .
-
4.
Let and . The minimiser of is , and the Laplace approximation is . Show that the minimiser of satisfies and .
-
5.
Show that if is Gaussian, the FR flow for is given by and moves along the e-geodesic joining and .