LaTex2Web logo

Documents Live, a web authoring and publishing system

If you see this, something is wrong

Table of contents

First published on Tuesday, Jun 23, 2026 and last modified on Tuesday, Jun 23, 2026 by François Chaplais.

Like what you see? Register!
The Little Book of Generative AI Foundations: An Intuitive Mathematical Primer

Tianhua Chen School of Computing and Engineering University of Huddersfield Email

1 Preface

2 Linear Algebra Foundations: From PCA to Autoencoders

2.3.1.1 The standard basis and the identity transformation.

\[ \hat{e}_1 = \begin{bmatrix}1 \\ 0\end{bmatrix}, ~~ \hat{e}_2 = \begin{bmatrix}0 \\ 1\end{bmatrix}. \]
\[ I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}, \]

2.3.1.2 Example: a \( 90^\circ\) rotation.

\[ R = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}. \]
\[ \hat{e}_1 \mapsto \begin{bmatrix}0 \\ 1\end{bmatrix}, ~~ \hat{e}_2 \mapsto \begin{bmatrix}-1 \\ 0\end{bmatrix}. \]

2.3.1.3 Beyond rotations: general linear transformations.

\[ A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}. \]

2.3.2.1 Matrix–vector multiplication: the column-combination view.

\[ Ax = a\,v_1 + b\,v_2. \]
\[ x = a\,\hat{e}_1 + b\,\hat{e}_2, \]
\[ Ax = \sum_{j=1}^n x_j\,a_j, \]

2.3.2.2 Matrix–vector multiplication: the row-by-column view.

2.3.2.3 Extending to matrix–matrix multiplication.

\[ AB = \big[\,A b_1 \;\; A b_2 \;\; \cdots \;\; A b_p\,\big], \]
\[ (AB)v = A(Bv). \]

2.4.1 Eigenvalues and eigenvectors.

\[ A v = \lambda v \]

2.4.2 Eigen-decomposition: expressing a matrix in its natural coordinate system.

\[ A [\, v_1 \; v_2 \; \cdots \; v_d \,] = [\, A v_1 \; A v_2 \; \cdots \; A v_d \,] = [\, \lambda_1 v_1 \; \lambda_2 v_2 \; \cdots \; \lambda_d v_d \,]. \]
\[ A V = V \Lambda, \]
\[ V = [\, v_1 \; v_2 \; \cdots \; v_d \,], ~~ \Lambda = \begin{bmatrix} \lambda_1 & 0 & \cdots & 0 \\ 0 & \lambda_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_d \end{bmatrix}. \]
\[ A = V \Lambda V^{-1}. \]

2.4.3 The special case of symmetric matrices.

2.5.1.1 Centring the data and defining projected variance.

\[ \frac{1}{n}\sum_{i=1}^n x^{(i)} = 0. \]
\[ v^\top x^{(i)}, \]
\[ (v^\top x^{(i)})\,v. \]
\[ \frac{1}{n}\sum_{i=1}^n v^\top x^{(i)} = v^\top \left(\frac{1}{n}\sum_{i=1}^n x^{(i)}\right) = 0. \]
\[ \mathrm{Var}(v^\top X) = \frac{1}{n}\sum_{i=1}^n \bigl(v^\top x^{(i)}\bigr)^2. \]

2.5.1.2 Covariance matrix form.

\[ \mathrm{Var}(v^\top X) = \frac{1}{n}\sum_{i=1}^n v^\top x^{(i)} (x^{(i)})^\top v = v^\top \left( \frac{1}{n}\sum_{i=1}^n x^{(i)} (x^{(i)})^\top \right) v. \]
\[ \Sigma = \frac{1}{n} \sum_{i=1}^n x^{(i)} (x^{(i)})^\top. \]
\[ \mathrm{Var}(v^\top X) = v^\top \Sigma\, v. \]
\[ \max_{v \in \mathbb{R}^d} \; v^\top \Sigma v ~ \text{subject to} ~ v^\top v = 1. \]
\[ \Sigma = U \Lambda U^\top, ~~ \Lambda = \mathrm{diag}(\lambda_1,\ldots,\lambda_d), \]
\[ \lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_d \ge 0. \]

2.5.2.1 Step 1: Change of basis to the eigenvector coordinates.

\[ \tilde{v} = U^\top v. \]
\[ \tilde{v}^\top \tilde{v} = (U^\top v)^\top (U^\top v) = v^\top U U^\top v = v^\top v. \]
\[ \tilde{v}^\top \tilde{v} = 1. \]

2.5.2.2 Step 2: Diagonalising the objective.

\[ v^\top \Sigma v = v^\top U \Lambda U^\top v = (U^\top v)^\top \Lambda (U^\top v) = \tilde{v}^\top \Lambda \tilde{v}. \]
\[ \tilde{v}^\top \Lambda \tilde{v} = \sum_{i=1}^d \lambda_i \tilde{v}_i^2. \]

2.5.2.3 Step 3: Bounding the variance.

\[ \sum_{i=1}^d \lambda_i \tilde{v}_i^2 \le \lambda_1 \sum_{i=1}^d \tilde{v}_i^2 = \lambda_1. \]

2.5.2.4 Step 4: Optimal direction.

\[ \tilde{v} = [1,\,0,\,\ldots,\,0]^\top. \]
\[ v = U \tilde{v} = u_1, \]

2.5.2.5 Subsequent principal components.

\[ u_k^\top u_j = 0 ~~ \text{for all } j < k. \]
\[ U_k = [\,u_1\;u_2\;\cdots\;u_k\,] \in \mathbb{R}^{d \times k} \]

2.5.3.1 Projection (encoding).

\[ z = U_k^\top x \in \mathbb{R}^k. \]

2.5.3.2 Reconstruction (decoding).

\[ \hat{x} = U_k z = U_k U_k^\top x. \]
\[ U_k U_k^\top = I, \]

2.5.3.3 Explained variance ratio.

\[ \sum_{i=1}^d \lambda_i, \]
\[ \sum_{i=1}^k \lambda_i. \]
\[ \text{Explained Variance Ratio} = \frac{\sum_{i=1}^k \lambda_i}{\sum_{i=1}^d \lambda_i}, \]

2.6.1.1 Trace of the covariance matrix.

\[ \mathrm{Tr}(A) = \sum_{i=1}^d a_{ii}. \]
\[ \mathrm{Tr}(\Sigma) = \sum_{i=1}^d \Sigma_{ii} = \sum_{i=1}^d \mathrm{Var}(X_i), \]

2.6.1.2 Similarity transformations.

\[ v_A = A^{-1} v. \]
\[ T_A = A^{-1} T A, \]

2.6.1.3 Trace invariance under change of basis.

\[ \mathrm{Tr}(BC) = \mathrm{Tr}(CB), \]
\[ \mathrm{Tr}(T_A) = \mathrm{Tr}(A^{-1} T A) = \mathrm{Tr}(T). \]

2.6.2.1 Covariance of the transformed data.

\[ \tilde{\Sigma} = \mathrm{Cov}(Z) = \mathrm{Cov}(XU). \]
\[ \mathrm{Cov}(Y) = \mathbb{E}\big[(Y - \mathbb{E}[Y])^\top (Y - \mathbb{E}[Y])\big]. \]
\[ \mathbb{E}[Z] = \mathbb{E}[XU] = \mathbb{E}[X]U = 0. \]
\[ \tilde{\Sigma} = \mathbb{E}\big[(Z - \mathbb{E}[Z])^\top (Z - \mathbb{E}[Z])\big] = \mathbb{E}[Z^\top Z]. \]
\[ \tilde{\Sigma} = \mathbb{E}[(XU)^\top (XU)] = U^\top \mathbb{E}[X^\top X] U = U^\top \Sigma U. \]
\[ \mathrm{Cov}(X) = \Sigma, ~~ \mathrm{Cov}(Z) = U^\top \Sigma U. \]
\[ \Sigma \;\longmapsto\; U^\top \Sigma U, \]

2.6.2.2 Consequences of the similarity transformation.

\[ \mathrm{Tr}(\Sigma) = \mathrm{Tr}(U^\top \Sigma U) = \mathrm{Tr}(\Lambda), \]
\[ U^\top \Sigma U = \Lambda = \mathrm{diag}(\lambda_1,\ldots,\lambda_d). \]

2.6.3.1 The SVD viewpoint.

\[ A = U S V^\top, \]
\[ A v_i = \sigma_i u_i, ~~ A^\top u_i = \sigma_i v_i, \]
\[ z_i = U_k^\top x_i, \]
\[ \hat{x}_i = U_k z_i = U_k U_k^\top x_i, \]
\[ \|x_i - \hat{x}_i\|^2 = \|x_i - U_k U_k^\top x_i\|^2. \]
\[ L(U_k) = \sum_{i=1}^n \|x_i - U_k U_k^\top x_i\|^2. \]
\[ \min_{U_k^\top U_k = I_k} \; \sum_{i=1}^n \|x_i - U_k U_k^\top x_i\|^2, \]
\[ x \;\longrightarrow\; z = U_k^\top x \;\longrightarrow\; \hat{x} = U_k z. \]

2.7.1.1 Autoencoders as learned encoder–decoder models.

\[ x \;\longrightarrow\; z = q_\phi(x) \;\longrightarrow\; \hat{x} = p_\theta(z). \]
\[ \min_{\phi,\theta}\; \|p_\theta(q_\phi(x)) - x\|^2, \]
\[ \min_{\phi,\theta}\; \sum_{i=1}^n \|p_\theta(q_\phi(x_i)) - x_i\|^2. \]
\[ \min_{U_k^\top U_k = I_k} \sum_{i=1}^n \|U_k U_k^\top x_i - x_i\|^2. \]

2.7.2.1 1. Linearity.

\[ q_\phi(x) = W_q x, ~~ p_\theta(z) = W_p z, \]
\[ \hat{x} = W_p W_q x. \]

2.7.2.2 2. Subspace versus basis.

2.7.2.3 Subspaces and column spaces.

\[ \mathrm{Span}(v_1,\ldots,v_k) = \left\{ \sum_{i=1}^k \alpha_i v_i : \alpha_i \in \mathbb{R} \right\}. \]
\[ \mathrm{Span}\left( \begin{bmatrix}1\\ 0\end{bmatrix}, \begin{bmatrix}0\\ 1\end{bmatrix} \right) = \mathrm{Span}\left( \begin{bmatrix}1\\ 1\end{bmatrix}, \begin{bmatrix}1\\ -1\end{bmatrix} \right) = \mathbb{R}^2. \]
\[ \mathcal{R}(A) = \{Az : z \in \mathbb{R}^k\}. \]

2.7.2.4 Subspace recovery under reconstruction loss.

\[ \hat{x} = W_p W_q x, \]
\[ \hat{x} \in \mathcal{R}(W_p). \]
\[ W_p = QR, \]
\[ p_\theta(z) = W_p z, \]
\[ \{\hat{x} = W_p z : z \in \mathbb{R}^k\}. \]
\[ \mathcal{M}_\theta = \{p_\theta(z) : z \in \mathbb{R}^k\}, \]

2.7.3.1 Nonlinear encoder and decoder.

\[ z = q_\phi(x), \]
\[ \hat{x} = p_\theta(z). \]
\[ x \;\longrightarrow\; z \;\longrightarrow\; \hat{x}, \]

2.7.3.2 Why deterministic autoencoders are not yet generative models.

3 Probabilistic PCA: A Bridge to Latent-Variable Generative Modelling

3.3.1 PPCA as a latent-variable generative model.

3.3.2 Conditional distribution of the observation.

\[ \mathbf{x} = \mathbf{W}\mathbf{z} + \boldsymbol{\mu} + \boldsymbol{\epsilon} \]
\[ \mathbf{x}\mid \mathbf{z} \sim \mathcal{N}\bigl(\mathbf{W}\mathbf{z} + \boldsymbol{\mu},\; \alpha^2 \mathbf{I}\bigr). \]
\[ \mathbf{x} = \mathbf{W} z + \boldsymbol{\mu} + \boldsymbol{\epsilon}, ~~ \boldsymbol{\epsilon} \sim \mathcal{N}(\mathbf{0}, \alpha^2 \mathbf{I}_2). \]

3.3.3 Connection with PCA: the zero-noise limit.

\[ \mathbf{x} = \mathbf{W}\mathbf{z} + \boldsymbol{\mu} + \boldsymbol{\epsilon}, ~~ \mathbf{z} \sim \mathcal{N}(\mathbf{0}, \mathbf{I}), ~~ \boldsymbol{\epsilon} \sim \mathcal{N}(\mathbf{0}, \alpha^2 \mathbf{I}). \]
\[ p(\mathbf{x}\mid \mathbf{z}) = \mathcal{N}\bigl(\mathbf{x}\mid \mathbf{W}\mathbf{z}+\boldsymbol{\mu},\; \alpha^2 \mathbf{I}\bigr) \]
\[ \mathbf{x} = \mathbf{W}\mathbf{z} + \boldsymbol{\mu}. \]
\[ \{\mathbf{x}_1,\dots,\mathbf{x}_N\}. \]
\[ \sum_{i=1}^N \log p(\mathbf{x}_i). \]
\[ \frac{1}{N}\sum_{i=1}^N \log p(\mathbf{x}_i), \]
\[ \mathbb{E}_{q(\mathbf{x})}\big[\log p(\mathbf{x})\big]. \]
\[ \max_{\mathbf{W},\boldsymbol{\mu},\alpha} \; \mathbb{E}_{q(\mathbf{x})}\big[\log p(\mathbf{x}; \mathbf{W}, \boldsymbol{\mu}, \alpha)\big]. \]
\[ p(\mathbf{x}) = \int p(\mathbf{x}\mid \mathbf{z})\,p(\mathbf{z})\,d\mathbf{z}. \]
\[ p(\mathbf{x}) = \int \mathcal{N}\bigl(\mathbf{x}\mid \mathbf{W}\mathbf{z}+\boldsymbol{\mu}, \alpha^2\mathbf{I}\bigr) \; \mathcal{N}\bigl(\mathbf{z}\mid \mathbf{0}, \mathbf{I}\bigr) \,d\mathbf{z}. \]
\[ \mathbf{x} = \mathbf{W}\mathbf{z} + \boldsymbol{\mu} + \boldsymbol{\epsilon}, ~~ \mathbf{z}\sim\mathcal{N}(\mathbf{0},\mathbf{I}), ~~ \boldsymbol{\epsilon}\sim\mathcal{N}(\mathbf{0},\alpha^2\mathbf{I}), \]
\[ p(\mathbf{x},\mathbf{z})=p(\mathbf{x}\mid\mathbf{z})p(\mathbf{z}) \]

3.4.2.1 Mean.

\[ \mathbb{E}[\mathbf{x}] = \mathbb{E}[\mathbf{W}\mathbf{z} + \boldsymbol{\mu} + \boldsymbol{\epsilon}] = \mathbf{W}\,\mathbb{E}[\mathbf{z}] + \boldsymbol{\mu} + \mathbb{E}[\boldsymbol{\epsilon}] = \boldsymbol{\mu}, \]

3.4.2.2 Covariance.

\[ \mathbf{x}=\mathbf{W}\mathbf{z}+\boldsymbol{\mu}+\boldsymbol{\epsilon}, \]
\[ \operatorname{Cov}[\mathbf{x}] = \operatorname{Cov}[\mathbf{W}\mathbf{z}+\boldsymbol{\epsilon}]. \]
\[ \operatorname{Cov}[a+b] = \operatorname{Cov}[a] + \operatorname{Cov}[b] + \operatorname{Cov}[a,b] + \operatorname{Cov}[b,a]. \]
\[ \operatorname{Cov}[\mathbf{x}] = \operatorname{Cov}[\mathbf{W}\mathbf{z}] + \operatorname{Cov}[\boldsymbol{\epsilon}] + \operatorname{Cov}[\mathbf{W}\mathbf{z},\boldsymbol{\epsilon}] + \operatorname{Cov}[\boldsymbol{\epsilon},\mathbf{W}\mathbf{z}]. \]
\[ \operatorname{Cov}[\mathbf{W}\mathbf{z},\boldsymbol{\epsilon}] = \mathbf{0}, ~~ \operatorname{Cov}[\boldsymbol{\epsilon},\mathbf{W}\mathbf{z}] = \mathbf{0}. \]
\[ \operatorname{Cov}[\mathbf{x}] = \operatorname{Cov}[\mathbf{W}\mathbf{z}] + \operatorname{Cov}[\boldsymbol{\epsilon}]. \]
\[ \operatorname{Cov}[\mathbf{W}\mathbf{z}] = \mathbf{W}\operatorname{Cov}[\mathbf{z}]\,\mathbf{W}^\top. \]
\[ \operatorname{Cov}[\mathbf{x}] = \mathbf{W}\operatorname{Cov}[\mathbf{z}]\,\mathbf{W}^\top + \operatorname{Cov}[\boldsymbol{\epsilon}]. \]
\[ \operatorname{Cov}[\mathbf{z}] = \mathbf{I}, ~~ \operatorname{Cov}[\boldsymbol{\epsilon}] = \alpha^2\mathbf{I}, \]
\[ \operatorname{Cov}[\mathbf{x}] = \mathbf{W}\mathbf{W}^\top + \alpha^2\mathbf{I}. \]
\[ p(\mathbf{x}) = \mathcal{N}\bigl( \mathbf{x}\mid \boldsymbol{\mu}, \mathbf{W}\mathbf{W}^\top + \alpha^2\mathbf{I} \bigr). \]

3.4.2.3 Interpreting the covariance structure.

\[ \mathbf{C} = \mathbf{W}\mathbf{W}^\top + \alpha^2\mathbf{I} \]
\[ \mathbf{W}\mathbf{W}^\top \]
\[ \operatorname{Cov}(\mathbf{W}\mathbf{z}) = \mathbf{W}\operatorname{Cov}(\mathbf{z})\mathbf{W}^\top = \mathbf{W}\mathbf{W}^\top, ~~ \text{because } \operatorname{Cov}(\mathbf{z})=\mathbf{I}. \]
\[ \operatorname{rank}(\mathbf{W}\mathbf{W}^\top)\le k. \]
\[ \mathbf{W}=[\,w_1\;\;w_2\;\;\cdots\;\;w_k\,], \]
\[ \mathbf{W}\mathbf{W}^\top=\sum_{j=1}^k w_j w_j^\top, \]
\[ \alpha^2\mathbf{I} \]
\[ p(\mathbf{x}) = \mathcal{N}\bigl( \mathbf{x}\mid \boldsymbol{\mu}, \mathbf{W}\mathbf{W}^\top + \alpha^2\mathbf{I} \bigr), \]
\[ \max_{\mathbf{W},\boldsymbol{\mu},\alpha} \; \mathbb{E}_{q(\mathbf{x})}\big[\log p(\mathbf{x})\big]. \]
\[ \nabla_{\mathbf{W}} \log p(\mathbf{x}) = 0, ~~ \nabla_{\boldsymbol{\mu}} \log p(\mathbf{x}) = 0, ~~ \frac{\partial}{\partial \alpha} \log p(\mathbf{x}) = 0. \]
\[ \theta \leftarrow \theta + \eta \,\nabla_\theta \mathbb{E}_{q(\mathbf{x})}\big[\log p(\mathbf{x};\theta)\big], \]
\[ \log p(\mathbf{x}) = \log \int p(\mathbf{x},\mathbf{z})\,d\mathbf{z} \]
\[ p(\mathbf{x},\mathbf{z}) \]
\[ p(\mathbf{x};\theta)=\int p(\mathbf{x},\mathbf{z};\theta)\,d\mathbf{z} \]
\[ p(\mathbf{x};\theta) = \int p(\mathbf{x}\mid\mathbf{z};\theta)\,p(\mathbf{z})\,d\mathbf{z} = \int p(\mathbf{x},\mathbf{z};\theta)\,d\mathbf{z}. \]
\[ \max_\theta \sum_i \log p(\mathbf{x}^{(i)};\theta) = \max_\theta \sum_i \log \int p(\mathbf{x}^{(i)},\mathbf{z};\theta)\,d\mathbf{z}. \]
\[ f(\mathbb{E}[X]) \le \mathbb{E}[f(X)]. \]
\[ f(\mathbb{E}[X]) \ge \mathbb{E}[f(X)]. \]
\[ \log \mathbb{E}[X] \ge \mathbb{E}[\log X]. \]
\[ \log \int (\cdots)\,d\mathbf{z}, \]
\[ \int Q(\mathbf{z})\,d\mathbf{z} = 1. \]
\[ p(\mathbf{x};\theta) = \int p(\mathbf{x},\mathbf{z};\theta)\,d\mathbf{z} = \int Q(\mathbf{z}) \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})}\,d\mathbf{z} = \mathbb{E}_{\mathbf{z}\sim Q} \left[ \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} \right]. \]
\[ \log p(\mathbf{x};\theta) = \log \mathbb{E}_{\mathbf{z}\sim Q} \left[ \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} \right]. \]
\[ \log p(\mathbf{x};\theta) = \log \mathbb{E}_{\mathbf{z}\sim Q} \left[ \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} \right]. \]
\[ \log \mathbb{E}_{\mathbf{z}\sim Q} \left[ \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} \right] \ge \mathbb{E}_{\mathbf{z}\sim Q} \left[ \log \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} \right]. \]
\[ \log p(\mathbf{x};\theta) \ge \mathbb{E}_{\mathbf{z}\sim Q} \left[ \log \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} \right]. \]
\[ \mathcal{L}(Q,\theta;\mathbf{x}) = \mathbb{E}_{\mathbf{z}\sim Q} \left[ \log \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} \right]. \]
\[ \mathcal{L}(Q,\theta;\mathbf{x}) = \mathbb{E}_{Q}\big[\log p(\mathbf{x},\mathbf{z};\theta)\big] - \mathbb{E}_{Q}\big[\log Q(\mathbf{z})\big]. \]
\[ \frac{p(\mathbf{x},\mathbf{z};\theta)}{Q(\mathbf{z})} = c ~~ \text{for all }\mathbf{z}, \]
\[ p(\mathbf{x};\theta) = \int p(\mathbf{x},\mathbf{z};\theta)\,d\mathbf{z} = c \int Q(\mathbf{z})\,d\mathbf{z} = c. \]
\[ c = p(\mathbf{x};\theta). \]
\[ Q(\mathbf{z}) = \frac{p(\mathbf{x},\mathbf{z};\theta)}{p(\mathbf{x};\theta)} = p(\mathbf{z}\mid \mathbf{x};\theta), \]
\[ \log p(\mathbf{x};\theta) = \log \int p(\mathbf{x},\mathbf{z};\theta)\,d\mathbf{z}, \]
\[ \mathcal{L}(Q,\theta;\mathbf{x}) = \mathbb{E}_{Q}\big[\log p(\mathbf{x},\mathbf{z};\theta)\big] - \mathbb{E}_{Q}\big[\log Q(\mathbf{z})\big], \]

3.7.1.1 E-step (Expectation step).

\[ Q(\mathbf{z}) = p(\mathbf{z}\mid \mathbf{x};\theta^{(t)}). \]
\[ Q^{(t)}(\mathbf{z}) = p(\mathbf{z}\mid \mathbf{x};\theta^{(t)}). \]

3.7.1.2 M-step (Maximisation step).

\[ \theta^{(t+1)} = \arg\max_{\theta} \mathcal{L}(Q^{(t)},\theta;\mathbf{x}). \]
\[ -\mathbb{E}_{Q^{(t)}}[\log Q^{(t)}(\mathbf{z})] \]
\[ \theta^{(t+1)} = \arg\max_{\theta} \mathbb{E}_{Q^{(t)}}\big[\log p(\mathbf{x},\mathbf{z};\theta)\big]. \]
\[ \boxed{ \begin{aligned} \text{E-step:}~ &Q^{(t)}(\mathbf{z}) = p(\mathbf{z}\mid \mathbf{x};\theta^{(t)}),\\ \text{M-step:}~ &\theta^{(t+1)} = \arg\max_{\theta} \mathbb{E}_{Q^{(t)}}\big[\log p(\mathbf{x},\mathbf{z};\theta)\big]. \end{aligned}} \]

3.7.1.3 Why EM does not decrease the likelihood.

\[ p(\mathbf{z}\mid \mathbf{x}) = \mathcal{N}\bigl( \mathbf{z}\mid \mathbf{M}^{-1}\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}), \alpha^2\mathbf{M}^{-1} \bigr), ~~ \mathbf{M}=\mathbf{W}^\top\mathbf{W}+\alpha^2\mathbf{I}. \]
\[ \mathbb{E}[\mathbf{z}] = \mathbf{M}^{-1}\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}), \]
\[ \mathbb{E}[\mathbf{z}\mathbf{z}^\top] = \alpha^2\mathbf{M}^{-1} + \mathbb{E}[\mathbf{z}]\,\mathbb{E}[\mathbf{z}]^\top. \]

4 The Variational Autoencoder: From Probabilistic Latent Variables to Variational Inference

\[ \mathbf{x} \;\xrightarrow{\text{encoder}}\; \mathbf{z} \;\xrightarrow{\text{decoder}}\; \hat{\mathbf{x}}. \]
\[ f_{\text{enc}}:\mathbf{x}\mapsto \mathbf{z}. \]
\[ q_{\phi}(\mathbf{z}\mid \mathbf{x}), \]
\[ p_{\theta}(\mathbf{z}\mid \mathbf{x}), \]
\[ q_{\phi}(\mathbf{z}\mid \mathbf{x}) = \mathcal{N}\bigl( \mathbf{z}\mid \boldsymbol{\mu}_{\phi}(\mathbf{x}), \operatorname{diag}(\boldsymbol{\sigma}_{\phi}^2(\mathbf{x})) \bigr), \]
\[ q_{\phi}(\mathbf{z}\mid \mathbf{x}) = \mathcal{N}\bigl( \mathbf{z}\mid \boldsymbol{\mu}_{\phi}(\mathbf{x}), \boldsymbol{\sigma}_{\phi}^2(\mathbf{x})\mathbf{I} \bigr). \]
\[ \mathbf{x} \;\longrightarrow\; \bigl(\boldsymbol{\mu}_{\phi}(\mathbf{x}), \boldsymbol{\sigma}_{\phi}(\mathbf{x})\bigr) \;\longrightarrow\; q_{\phi}(\mathbf{z}\mid \mathbf{x}). \]
\[ \mathbf{z}\sim q_{\phi}(\mathbf{z}\mid \mathbf{x}). \]
\[ f_{\text{dec}}:\mathbf{z}\mapsto \hat{\mathbf{x}}, \]
\[ p_{\theta}(\mathbf{x}\mid \mathbf{z}), \]
\[ p_{\theta}(\mathbf{x}\mid \mathbf{z}) = \mathcal{N}\bigl( \mathbf{x}\mid \boldsymbol{\mu}_{\theta}(\mathbf{z}), \sigma^2 \mathbf{I} \bigr), \]

4.3.3.1 The latent prior.

\[ p(\mathbf{z}). \]
\[ p(\mathbf{z})=\mathcal{N}(\mathbf{0},\mathbf{I}). \]
\[ \mathbf{z}\sim p(\mathbf{z}), \]
\[ \mathbf{x}\sim p_{\theta}(\mathbf{x}\mid \mathbf{z}). \]

4.3.3.2 Why this creates a new difficulty.

\[ p(\mathbf{z}), ~~ q_{\phi}(\mathbf{z}\mid \mathbf{x}), ~~ p_{\theta}(\mathbf{x}\mid \mathbf{z}), \]
\[ p_{\theta}(\mathbf{x}) = \int p_{\theta}(\mathbf{x},\mathbf{z})\,d\mathbf{z} = \int p_{\theta}(\mathbf{x}\mid \mathbf{z})\,p(\mathbf{z})\,d\mathbf{z}, \]
\[ \max_{\theta}\sum_i \log p_{\theta}(\mathbf{x}^{(i)}). \]
\[ \log p_{\theta}(\mathbf{x}) = \log \int p_{\theta}(\mathbf{x}\mid \mathbf{z})\,p(\mathbf{z})\,d\mathbf{z} \]
\[ p_{\theta}(\mathbf{z}\mid \mathbf{x}) = \frac{p_{\theta}(\mathbf{x}\mid \mathbf{z})\,p(\mathbf{z})} {p_{\theta}(\mathbf{x})}. \]
\[ Q(\mathbf{z}) \;\longrightarrow\; q_{\phi}(\mathbf{z}\mid \mathbf{x}), \]
\[ \log p_{\theta}(\mathbf{x}) \geq \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log \frac{p_{\theta}(\mathbf{x},\mathbf{z})} {q_{\phi}(\mathbf{z}\mid \mathbf{x})} \right]. \]
\[ \mathcal{L}(\mathbf{x};\theta,\phi) = \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log \frac{p_{\theta}(\mathbf{x},\mathbf{z})} {q_{\phi}(\mathbf{z}\mid \mathbf{x})} \right]. \]

4.4.2.1 First form of the ELBO: joint-density form.

\[ \mathcal{L}(\mathbf{x};\theta,\phi) = \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log \frac{p_{\theta}(\mathbf{x},\mathbf{z})} {q_{\phi}(\mathbf{z}\mid \mathbf{x})} \right]. \]
\[ \mathcal{L}(\mathbf{x};\theta,\phi) = \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} [\log p_{\theta}(\mathbf{x},\mathbf{z})] - \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} [\log q_{\phi}(\mathbf{z}\mid \mathbf{x})]. \]

4.4.2.2 Second form of the ELBO: exact likelihood minus posterior mismatch.

\[ p_{\theta}(\mathbf{x},\mathbf{z}) = p_{\theta}(\mathbf{z}\mid \mathbf{x})\,p_{\theta}(\mathbf{x}), \]
\[ \begin{aligned} \mathcal{L}(\mathbf{x};\theta,\phi) &= \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log \frac{p_{\theta}(\mathbf{z}\mid \mathbf{x})\,p_{\theta}(\mathbf{x})} {q_{\phi}(\mathbf{z}\mid \mathbf{x})} \right] \\ &= \log p_{\theta}(\mathbf{x}) - \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log \frac{q_{\phi}(\mathbf{z}\mid \mathbf{x})} {p_{\theta}(\mathbf{z}\mid \mathbf{x})} \right]. \end{aligned} \]
\[ \boxed{ \mathcal{L}(\mathbf{x};\theta,\phi) = \log p_{\theta}(\mathbf{x}) - \mathrm{KL}\bigl( q_{\phi}(\mathbf{z}\mid \mathbf{x}) \,\|\,\, p_{\theta}(\mathbf{z}\mid \mathbf{x}) \bigr). } \]
\[ \mathrm{KL}\bigl( q_{\phi}(\mathbf{z}\mid \mathbf{x}) \,\|\,\, p_{\theta}(\mathbf{z}\mid \mathbf{x}) \bigr)\ge 0, \]
\[ \mathcal{L}(\mathbf{x};\theta,\phi)\le \log p_{\theta}(\mathbf{x}), \]

4.4.2.3 Third form of the ELBO: reconstruction plus regularisation.

\[ p_{\theta}(\mathbf{x},\mathbf{z}) = p_{\theta}(\mathbf{x}\mid \mathbf{z})\,p(\mathbf{z}). \]
\[ \begin{aligned} \mathcal{L}(\mathbf{x};\theta,\phi) &= \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log \frac{p_{\theta}(\mathbf{x}\mid \mathbf{z})\,p(\mathbf{z})} {q_{\phi}(\mathbf{z}\mid \mathbf{x})} \right] \\ &= \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log p_{\theta}(\mathbf{x}\mid \mathbf{z}) \right] + \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log p(\mathbf{z})-\log q_{\phi}(\mathbf{z}\mid \mathbf{x}) \right]. \end{aligned} \]
\[ \boxed{ \mathcal{L}(\mathbf{x};\theta,\phi) = \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log p_{\theta}(\mathbf{x}\mid \mathbf{z}) \right] - \mathrm{KL}\bigl( q_{\phi}(\mathbf{z}\mid \mathbf{x}) \,\|\,\, p(\mathbf{z}) \bigr). } \]
\[ \mathbf{z}\sim p(\mathbf{z}), ~~ \mathbf{x}\sim p_{\theta}(\mathbf{x}\mid \mathbf{z}), \]

4.4.2.4 What the ELBO achieves.

\[ \mathcal{L}(\mathbf{x};\theta,\phi) = \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log p_{\theta}(\mathbf{x}\mid \mathbf{z}) \right] - \mathrm{KL}\bigl( q_{\phi}(\mathbf{z}\mid \mathbf{x}) \,\|\,\, p(\mathbf{z}) \bigr). \]
\[ \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log p_{\theta}(\mathbf{x}\mid \mathbf{z}) \right]. \]
\[ \mathbf{z}\sim q_{\phi}(\mathbf{z}\mid \mathbf{x}), \]

4.5.1 The reparameterisation trick.

\[ q_{\phi}(\mathbf{z}\mid \mathbf{x}) = \mathcal{N}\bigl( \mathbf{z}\mid \boldsymbol{\mu}_{\phi}(\mathbf{x}), \operatorname{diag}(\boldsymbol{\sigma}_{\phi}^2(\mathbf{x})) \bigr), \]
\[ \boldsymbol{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I}), \]
\[ \mathbf{z} = \boldsymbol{\mu}_{\phi}(\mathbf{x}) + \boldsymbol{\sigma}_{\phi}(\mathbf{x})\odot \boldsymbol{\epsilon}. \]
\[ \mathbf{z}=\mathbf{z}(\mathbf{x},\phi,\boldsymbol{\epsilon}). \]

4.5.2 Joint optimisation of encoder and decoder.

\[ (\theta,\phi) ~\longmapsto~ \max \; \mathcal{L}(\mathbf{x};\theta,\phi). \]

4.5.3 A variant: \(\beta\)-VAE.

\[ \mathcal{L}_{\beta} = \mathbb{E}_{q_{\phi}(\mathbf{z}\mid \mathbf{x})} \left[ \log p_{\theta}(\mathbf{x}\mid \mathbf{z}) \right] - \beta\, \mathrm{KL}\bigl( q_{\phi}(\mathbf{z}\mid \mathbf{x}) \,\|\,\, p(\mathbf{z}) \bigr). \]

5 Denoising Diffusion Probabilistic Models

\[ \mathbf{x}_1,\mathbf{x}_2,\dots,\mathbf{x}_T. \]

5.3.1.1 A step-by-step Gaussian noising process.

\[ q(\mathbf{x}_t\mid \mathbf{x}_{t-1}) = \mathcal{N}\bigl( \mathbf{x}_t \mid \sqrt{1-\beta_t}\,\mathbf{x}_{t-1}, \beta_t\mathbf{I} \bigr), \]
\[ \mathbf{x}_t = \sqrt{1-\beta_t}\,\mathbf{x}_{t-1} + \sqrt{\beta_t}\,\mathbf{z}_t, ~~ \mathbf{z}_t\sim\mathcal{N}(\mathbf{0},\mathbf{I}). \]

5.3.1.2 A closed-form link between \( \mathbf{x}_t\) and \( \mathbf{x}_0\) .

\[ \mathbf{x}_t = \sqrt{1-\beta_t}\,\mathbf{x}_{t-1} + \sqrt{\beta_t}\,\mathbf{z}_t, ~~ \mathbf{z}_t\sim\mathcal{N}(\mathbf{0},\mathbf{I}), \]
\[ \begin{aligned} \mathbf{x}_1 &= \sqrt{1-\beta_1}\,\mathbf{x}_0 + \sqrt{\beta_1}\,\mathbf{z}_1,\\ \mathbf{x}_2 &= \sqrt{1-\beta_2}\,\mathbf{x}_1 + \sqrt{\beta_2}\,\mathbf{z}_2. \end{aligned} \]
\[ \mathbf{x}_2 = \sqrt{(1-\beta_2)(1-\beta_1)}\,\mathbf{x}_0 + \sqrt{1-\beta_2}\sqrt{\beta_1}\,\mathbf{z}_1 + \sqrt{\beta_2}\,\mathbf{z}_2. \]
\[ \alpha_t = 1-\beta_t, ~~ \bar{\alpha}_t = \prod_{s=1}^{t}\alpha_s. \]
\[ \prod_{s=1}^{t}\sqrt{1-\beta_s} = \prod_{s=1}^{t}\sqrt{\alpha_s} = \sqrt{\bar{\alpha}_t}. \]
\[ \mathbf{x}_t = \sqrt{\bar{\alpha}_t}\,\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\,\boldsymbol{\epsilon}, ~~ \boldsymbol{\epsilon}\sim\mathcal{N}(\mathbf{0},\mathbf{I}). \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_0) = \mathcal{N}\left( \mathbf{x}_t \mid \sqrt{\bar{\alpha}_t}\,\mathbf{x}_0,\, (1-\bar{\alpha}_t)\mathbf{I} \right). \]
\[ q(\mathbf{x}_{0:T}) = q(\mathbf{x}_0)\,q(\mathbf{x}_{1:T}\mid \mathbf{x}_0). \]
\[ q(\mathbf{x}_{0:T}) = q(\mathbf{x}_0) \prod_{t=1}^{T} q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_{t-2},\dots,\mathbf{x}_0). \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_{t-2},\dots,\mathbf{x}_0) = q(\mathbf{x}_t\mid \mathbf{x}_{t-1}). \]
\[ q(\mathbf{x}_{0:T}) = q(\mathbf{x}_0)\prod_{t=1}^{T}q(\mathbf{x}_t\mid \mathbf{x}_{t-1}). \]
\[ \mathbf{x}_0 \longrightarrow \mathbf{x}_1 \longrightarrow \cdots \longrightarrow \mathbf{x}_T, \]
\[ \mathbf{x}_T \longrightarrow \mathbf{x}_{T-1} \longrightarrow \cdots \longrightarrow \mathbf{x}_0. \]
\[ \begin{aligned} p_\theta(\mathbf{x}_{0:T}) &= p_\theta(\mathbf{x}_0,\mathbf{x}_{1:T}) \\ &= p_\theta(\mathbf{x}_0\mid \mathbf{x}_{1:T})\,p_\theta(\mathbf{x}_{1:T}) \\ &= p_\theta(\mathbf{x}_0\mid \mathbf{x}_{1:T})\, p_\theta(\mathbf{x}_1\mid \mathbf{x}_{2:T})\, p_\theta(\mathbf{x}_{2:T}) \\ &= p_\theta(\mathbf{x}_0\mid \mathbf{x}_{1:T})\, p_\theta(\mathbf{x}_1\mid \mathbf{x}_{2:T})\, p_\theta(\mathbf{x}_2\mid \mathbf{x}_{3:T})\, \cdots\, p_\theta(\mathbf{x}_{T-1}\mid \mathbf{x}_T)\, p(\mathbf{x}_T). \end{aligned} \]
\[ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_{t:T}) = p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t). \]
\[ p_\theta(\mathbf{x}_{0:T}) = p(\mathbf{x}_T)\prod_{t=1}^{T} p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t). \]
\[ p(\mathbf{x}_T)=\mathcal{N}(\mathbf{0},\mathbf{I}), \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_{t-1}) \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t) = \frac{ q(\mathbf{x}_t\mid \mathbf{x}_{t-1})\,q(\mathbf{x}_{t-1}) }{ q(\mathbf{x}_t) }. \]
\[ p_\theta(\mathbf{x}_0) = \int p_\theta(\mathbf{x}_{0:T})\,d\mathbf{x}_{1:T}. \]
\[ p_\theta(\mathbf{x}_{0:T}) = p(\mathbf{x}_T)\prod_{t=1}^{T} p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t). \]

5.4.3.1 Recasting the ELBO in the diffusion setting

\[ p(\mathbf{x}) = \int p(\mathbf{x},\mathbf{z})\,d\mathbf{z}, \]
\[ \mathbf{x}\;\longrightarrow\;\mathbf{x}_0, ~~ \mathbf{z}\;\longrightarrow\;\mathbf{x}_{1:T}. \]
\[ p_\theta(\mathbf{x}_0) = \int p_\theta(\mathbf{x}_{0:T})\,d\mathbf{x}_{1:T}. \]
\[ q(\mathbf{x}_{1:T}\mid \mathbf{x}_0), \]
\[ Q(\mathbf{Z}) \;\longrightarrow\; q(\mathbf{x}_{1:T}\mid \mathbf{x}_0). \]

5.4.3.2 The diffusion ELBO.

\[ \log p_\theta(\mathbf{x}_0) \ge \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_{0:T}) }{ q(\mathbf{x}_{1:T}\mid \mathbf{x}_0) } \right]. \]
\[ \mathbb{E}_{q(\mathbf{x}_0)} \left[ \log p_\theta(\mathbf{x}_0) \right] \ge \mathbb{E}_{q(\mathbf{x}_0)} \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_{0:T}) }{ q(\mathbf{x}_{1:T}\mid \mathbf{x}_0) } \right]. \]

5.5.1.1 Substituting the forward and reverse chains.

\[ p_\theta(\mathbf{x}_{0:T}) = p(\mathbf{x}_T)\prod_{t=1}^{T} p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t), \]
\[ q(\mathbf{x}_{1:T}\mid \mathbf{x}_0) = \prod_{t=1}^{T} q(\mathbf{x}_t\mid \mathbf{x}_{t-1}). \]
\[ q(\mathbf{x}_{1:T}\mid \mathbf{x}_0) = \prod_{t=1}^{T} q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0). \]
\[ \begin{aligned} \mathcal{L}_{\mathrm{ELBO}} &= \mathbb{E}_{q(\mathbf{x}_0)} \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log \frac{ p(\mathbf{x}_T)\prod_{t=1}^{T} p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ \prod_{t=1}^{T} q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0) } \right]. \end{aligned} \]
\[ \begin{aligned} \mathcal{L}_{\mathrm{ELBO}} &= \mathbb{E}_{q(\mathbf{x}_0)} \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log p(\mathbf{x}_T) + \sum_{t=1}^{T} \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0) } \right]. \end{aligned} \]

5.5.1.2 What should the learned denoising process approximate?

\[ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t). \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0), \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0) = \frac{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0)\, q(\mathbf{x}_t\mid \mathbf{x}_0) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) }. \]
\[ \begin{aligned} \mathcal{L}_{\mathrm{ELBO}} &= \mathbb{E}_{q(\mathbf{x}_0)} \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log p(\mathbf{x}_T) + \sum_{t=1}^{T} \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t)\, q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0)\, q(\mathbf{x}_t\mid \mathbf{x}_0) } \right]. \end{aligned} \]
\[ \begin{aligned} \mathcal{L}_{\mathrm{ELBO}} &= \mathbb{E}_{q(\mathbf{x}_0)} \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log p(\mathbf{x}_T) + \sum_{t=1}^{T} \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) } + \sum_{t=1}^{T} \log \frac{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) }{ q(\mathbf{x}_t\mid \mathbf{x}_0) } \right]. \end{aligned} \]
\[ \begin{aligned} \sum_{t=1}^{T} \log \frac{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) }{ q(\mathbf{x}_t\mid \mathbf{x}_0) } &= \log \frac{q(\mathbf{x}_0\mid \mathbf{x}_0)}{q(\mathbf{x}_1\mid \mathbf{x}_0)} + \log \frac{q(\mathbf{x}_1\mid \mathbf{x}_0)}{q(\mathbf{x}_2\mid \mathbf{x}_0)} +\cdots+ \log \frac{q(\mathbf{x}_{T-1}\mid \mathbf{x}_0)}{q(\mathbf{x}_T\mid \mathbf{x}_0)} \\ &= \log\left[ \frac{q(\mathbf{x}_0\mid \mathbf{x}_0)}{q(\mathbf{x}_1\mid \mathbf{x}_0)} \cdot \frac{q(\mathbf{x}_1\mid \mathbf{x}_0)}{q(\mathbf{x}_2\mid \mathbf{x}_0)} \cdots \frac{q(\mathbf{x}_{T-1}\mid \mathbf{x}_0)}{q(\mathbf{x}_T\mid \mathbf{x}_0)} \right] \\ &= \log\left[ \frac{q(\mathbf{x}_0\mid \mathbf{x}_0)}{q(\mathbf{x}_T\mid \mathbf{x}_0)} \right] = \log q(\mathbf{x}_0\mid \mathbf{x}_0) -\log q(\mathbf{x}_T\mid \mathbf{x}_0). \end{aligned} \]
\[ \begin{aligned} \mathcal{L}_{\mathrm{ELBO}} &= \mathbb{E}_{q(\mathbf{x}_0)} \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log p(\mathbf{x}_T) - \log q(\mathbf{x}_T\mid \mathbf{x}_0) + \sum_{t=1}^{T} \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) } \right] +\text{const}. \end{aligned} \]
\[ \mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \big[ \log p(\mathbf{x}_T)-\log q(\mathbf{x}_T\mid \mathbf{x}_0) \big]. \]
\[ \begin{aligned} &\mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \big[ \log p(\mathbf{x}_T)-\log q(\mathbf{x}_T\mid \mathbf{x}_0) \big] \\ &~~= \mathbb{E}_{q(\mathbf{x}_T\mid \mathbf{x}_0)} \big[ \log p(\mathbf{x}_T)-\log q(\mathbf{x}_T\mid \mathbf{x}_0) \big] \\ &~~= -\mathbb{E}_{q(\mathbf{x}_T\mid \mathbf{x}_0)} \left[ \log \frac{q(\mathbf{x}_T\mid \mathbf{x}_0)}{p(\mathbf{x}_T)} \right] \\ &~~= -\mathrm{KL}\bigl( q(\mathbf{x}_T\mid \mathbf{x}_0)\,\|\,p(\mathbf{x}_T) \bigr). \end{aligned} \]
\[ \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) } \]
\[ \begin{aligned} &\mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_0\mid \mathbf{x}_1) }{ q(\mathbf{x}_0\mid \mathbf{x}_1,\mathbf{x}_0) } \right] = \mathbb{E}_{q(\mathbf{x}_1\mid \mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_0\mid \mathbf{x}_1) }{ q(\mathbf{x}_0\mid \mathbf{x}_1,\mathbf{x}_0) } \right]. \end{aligned} \]
\[ \mathbb{E}_{q(\mathbf{x}_1\mid \mathbf{x}_0)} \big[ \log p_\theta(\mathbf{x}_0\mid \mathbf{x}_1) \big]. \]
\[ \begin{aligned} &\mathbb{E}_{q(\mathbf{x}_{1:T}\mid \mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) } \right] \\ &~~= \mathbb{E}_{q(\mathbf{x}_{t-1},\mathbf{x}_t\mid \mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) } \right] \\ &~~= \mathbb{E}_{q(\mathbf{x}_t\mid \mathbf{x}_0)} \mathbb{E}_{q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) } \right]. \end{aligned} \]
\[ \begin{aligned} &\mathbb{E}_{q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0)} \left[ \log \frac{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) }{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) } \right] \\ &~~= -\mathbb{E}_{q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0)} \left[ \log \frac{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) }{ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) } \right] \\ &~~= -\mathrm{KL}\big( q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \,\|\,\, p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \big). \end{aligned} \]
\[ - \mathbb{E}_{q(\mathbf{x}_t\mid \mathbf{x}_0)} \Big[ \mathrm{KL}\big( q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \,\|\,\, p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \big) \Big]. \]
\[ \begin{aligned} -\mathcal{L}_{\mathrm{ELBO}} = \mathbb{E}_{q(\mathbf{x}_0)} \Big[ &\underbrace{ \mathrm{KL}\bigl( q(\mathbf{x}_T\mid \mathbf{x}_0)\,\|\,p(\mathbf{x}_T) \bigr) }_{\text{prior-matching term}} \\ &+ \sum_{t=2}^{T} \underbrace{ \mathbb{E}_{q(\mathbf{x}_t\mid \mathbf{x}_0)} \Big[ \mathrm{KL}\big( q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \,\|\,\, p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \big) \Big] }_{\text{step-wise denoising terms}} \\ &- \underbrace{ \mathbb{E}_{q(\mathbf{x}_1\mid \mathbf{x}_0)} \big[ \log p_\theta(\mathbf{x}_0\mid \mathbf{x}_1) \big] }_{\text{reconstruction term}} \Big]. \end{aligned} \]
\[ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0). \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) = \frac{ q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0)\, q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) }{ q(\mathbf{x}_t\mid \mathbf{x}_0) }. \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0) = q(\mathbf{x}_t\mid \mathbf{x}_{t-1}) = \mathcal{N}\bigl( \mathbf{x}_t \mid \sqrt{\alpha_t}\,\mathbf{x}_{t-1}, (1-\alpha_t)\mathbf{I} \bigr), \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) = \mathcal{N}\bigl( \mathbf{x}_{t-1}\mid \sqrt{\bar{\alpha}_{t-1}}\,\mathbf{x}_0, (1-\bar{\alpha}_{t-1})\mathbf{I} \bigr), \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_0) = \mathcal{N}\bigl( \mathbf{x}_t\mid \sqrt{\bar{\alpha}_t}\,\mathbf{x}_0, (1-\bar{\alpha}_t)\mathbf{I} \bigr). \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) = \mathcal{N}\bigl( \mathbf{x}_{t-1}\mid \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\mathbf{x}_0), \tilde{\beta}_t\mathbf{I} \bigr), \]
\[ \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\mathbf{x}_0) = \frac{ \sqrt{\bar{\alpha}_{t-1}}\,\beta_t }{ 1-\bar{\alpha}_t }\,\mathbf{x}_0 + \frac{ \sqrt{\alpha_t}(1-\bar{\alpha}_{t-1}) }{ 1-\bar{\alpha}_t }\,\mathbf{x}_t, \]
\[ \tilde{\beta}_t = \frac{ 1-\bar{\alpha}_{t-1} }{ 1-\bar{\alpha}_t }\,\beta_t. \]
\[ \mathbf{x}_t = \sqrt{\bar{\alpha}_t}\,\mathbf{x}_0 + \sqrt{1-\bar{\alpha}_t}\,\boldsymbol{\epsilon}, ~~ \boldsymbol{\epsilon}\sim \mathcal{N}(\mathbf{0},\mathbf{I}). \]
\[ \mathbf{x}_0 = \frac{1}{\sqrt{\bar{\alpha}_t}} \Bigl( \mathbf{x}_t-\sqrt{1-\bar{\alpha}_t}\,\boldsymbol{\epsilon} \Bigr). \]
\[ \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\mathbf{x}_0) = \frac{ \sqrt{\bar{\alpha}_{t-1}}\,\beta_t }{ 1-\bar{\alpha}_t }\,\mathbf{x}_0 + \frac{ \sqrt{\alpha_t}(1-\bar{\alpha}_{t-1}) }{ 1-\bar{\alpha}_t }\,\mathbf{x}_t, \]
\[ \begin{aligned} \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\boldsymbol{\epsilon}) &= \frac{ \sqrt{\bar{\alpha}_{t-1}}\,\beta_t }{ 1-\bar{\alpha}_t } \cdot \frac{1}{\sqrt{\bar{\alpha}_t}} \Bigl( \mathbf{x}_t-\sqrt{1-\bar{\alpha}_t}\,\boldsymbol{\epsilon} \Bigr) + \frac{ \sqrt{\alpha_t}(1-\bar{\alpha}_{t-1}) }{ 1-\bar{\alpha}_t }\,\mathbf{x}_t. \end{aligned} \]
\[ \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\boldsymbol{\epsilon}) = \frac{1}{\sqrt{\alpha_t}} \left( \mathbf{x}_t - \frac{\beta_t}{\sqrt{1-\bar{\alpha}_t}}\, \boldsymbol{\epsilon} \right). \]
\[ \boxed{ \begin{aligned} q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\boldsymbol{\epsilon}) &= \mathcal{N}\left( \mathbf{x}_{t-1}\mid \frac{1}{\sqrt{\alpha_t}} \left( \mathbf{x}_t - \frac{\beta_t}{\sqrt{1-\bar{\alpha}_t}}\, \boldsymbol{\epsilon} \right), \tilde{\beta}_t\mathbf{I} \right). \end{aligned} } \]
\[ \boldsymbol{\epsilon}_\theta(\mathbf{x}_t,t) \]
\[ p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) = \mathcal{N}\bigl( \mathbf{x}_{t-1}\mid \boldsymbol{\mu}_\theta(\mathbf{x}_t,t), \tilde{\beta}_t\mathbf{I} \bigr), \]
\[ \boldsymbol{\mu}_\theta(\mathbf{x}_t,t) = \frac{1}{\sqrt{\alpha_t}} \left( \mathbf{x}_t - \frac{\beta_t}{\sqrt{1-\bar{\alpha}_t}}\, \boldsymbol{\epsilon}_\theta(\mathbf{x}_t,t) \right). \]
\[ \mathbb{E}_{q(\mathbf{x}_t\mid \mathbf{x}_0)} \Big[ \mathrm{KL}\big( q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \,\|\,\, p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \big) \Big]. \]
\[ \mathrm{KL}\big( q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \,\|\,\, p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \big) \propto \bigl\| \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\boldsymbol{\epsilon}) - \boldsymbol{\mu}_\theta(\mathbf{x}_t,t) \bigr\|^2. \]
\[ \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\boldsymbol{\epsilon}) - \boldsymbol{\mu}_\theta(\mathbf{x}_t,t) = \frac{\beta_t}{\sqrt{\alpha_t}\sqrt{1-\bar{\alpha}_t}} \Bigl( \boldsymbol{\epsilon} - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t,t) \Bigr). \]
\[ \mathrm{KL}\big( q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \,\|\,\, p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t) \big) \propto \bigl\| \boldsymbol{\epsilon} - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t,t) \bigr\|^2. \]
\[ \boxed{ \mathcal{L}_{\mathrm{simple}} = \mathbb{E}_{t,\mathbf{x}_0,\boldsymbol{\epsilon}} \Bigl[ \bigl\| \boldsymbol{\epsilon} - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t,t) \bigr\|^2 \Bigr] } \]
\[ \mathbf{x}_T\sim\mathcal{N}(\mathbf{0},\mathbf{I}), \]
\[ \mathbf{x}_{t-1}\sim p_\theta(\mathbf{x}_{t-1}\mid \mathbf{x}_t). \]

6 Calculus Foundations for Continuous Time Generative Modelling

\[ x_{t+\Delta t}\approx x_t+\text{small update}. \]
\[ x_{t+\Delta t}=x_t+\alpha f(x_t)\Delta t+\beta\,\text{noise}, \]
\[ \text{discrete updates} \;\longrightarrow\; \text{continuous motion} \;\longrightarrow\; \text{density evolution}. \]
\[ dx=\frac{dx}{dt}\,dt. \]
\[ \text{change}=\text{rate}\times\text{duration}. \]
\[ x(t+\Delta t)\approx x(t)+\frac{dx}{dt}\,\Delta t. \]

6.3.2.1 One-dimensional contraction.

\[ \frac{dx}{dt}=-\alpha x, ~~ \alpha>0. \]
\[ \begin{aligned} \frac{dx}{dt}=-\alpha x &\;\Longrightarrow\; \frac{1}{x}\frac{dx}{dt}=-\alpha \;\Longrightarrow\; \frac{d}{dt}\log|x|=-\alpha \\ &\;\Longrightarrow\; \log|x(t)|=-\alpha t + C \;\Longrightarrow\; x(t)=Ce^{-\alpha t}. \end{aligned} \]
\[ \boxed{ x(t)=x_0e^{-\alpha t}. } \]

6.3.2.2 Extension to multiple dimensions.

\[ x(t)= \begin{bmatrix} x_1(t)\\ x_2(t) \end{bmatrix}. \]
\[ \frac{d}{dt}x(t)=Ax(t), \]
\[ A= \begin{bmatrix} -\alpha_1 & 0\\ 0 & -\alpha_2 \end{bmatrix}, ~~ \alpha_1,\alpha_2>0. \]
\[ \frac{d}{dt} \begin{bmatrix} x_1(t)\\ x_2(t) \end{bmatrix} = \begin{bmatrix} -\alpha_1 & 0\\ 0 & -\alpha_2 \end{bmatrix} \begin{bmatrix} x_1(t)\\ x_2(t) \end{bmatrix}, \]
\[ \dot{x}_1(t)=-\alpha_1x_1(t), ~~ \dot{x}_2(t)=-\alpha_2x_2(t). \]
\[ x_1(t)=x_1(0)e^{-\alpha_1 t}, ~~ x_2(t)=x_2(0)e^{-\alpha_2 t}. \]
\[ x(t)=e^{At}x(0), \]
\[ e^{At} = \begin{bmatrix} e^{-\alpha_1 t} & 0\\ 0 & e^{-\alpha_2 t} \end{bmatrix}. \]
\[ A=\mathrm{diag}(-\alpha_1,-\alpha_2,\dots,-\alpha_d) \]
\[ W_t-W_0 = \sum_{k=0}^{n-1}\bigl(W_{(k+1)\Delta t}-W_{k\Delta t}\bigr) = \sum_{k=0}^{n-1}\Delta W_k, ~~ \Delta W_k:=W_{(k+1)\Delta t}-W_{k\Delta t}. \]
\[ W_t=\sum_{k=0}^{n-1}\Delta W_k. \]
\[ W_{t+\Delta t}-W_t \approx \sqrt{\Delta t}\,\varepsilon_t, ~~ \varepsilon_t\sim\mathcal{N}(0,1). \]
\[ dX_t=-\alpha X_t\,dt+\sigma\,dW_t, ~~ \alpha>0,~\sigma>0. \]
\[ X_{t+\Delta t} \approx X_t-\alpha X_t\,\Delta t+\sigma\sqrt{\Delta t}\,\varepsilon_t, ~~ \varepsilon_t\sim\mathcal{N}(0,1). \]
\[ X_t = X_0e^{-\alpha t} + \sigma \int_0^t e^{-\alpha(t-s)}\,dW_s. \]
\[ \text{particle motion} \;\longrightarrow\; \text{transport of probability mass} \;\longrightarrow\; \text{deterministic density evolution}. \]
\[ x_t=\phi_t(x_0), \]
\[ p_0(x_0)\,dx_0. \]
\[ p_0(x_0)\,dx_0=p_t(x_t)\,dx_t. \]
\[ p_t(x_t) = p_0(x_0) \left| \det\left(\frac{\partial x_t}{\partial x_0}\right) \right|^{-1}. \]
\[ \frac{dx}{dt}=f(x,t), \]
\[ p(x,t)\,\Delta x. \]
\[ p(x,t)f(x,t). \]
\[ p(x,t)f(x,t), \]
\[ p(x+\Delta x,t)f(x+\Delta x,t). \]
\[ \frac{\partial}{\partial t}p(x,t)\,\Delta x = p(x,t)f(x,t)-p(x+\Delta x,t)f(x+\Delta x,t). \]
\[ \frac{\partial}{\partial t}p(x,t) = \frac{p(x,t)f(x,t)-p(x+\Delta x,t)f(x+\Delta x,t)}{\Delta x}. \]
\[ \frac{\partial}{\partial t}p(x,t) = - \frac{p(x+\Delta x,t)f(x+\Delta x,t)-p(x,t)f(x,t)}{\Delta x}. \]
\[ \boxed{ \partial_t p(x,t) = -\partial_x\bigl(p(x,t)f(x,t)\bigr). } \]
\[ \partial_t p = -\bigl(f\,\partial_x p + p\,\partial_x f\bigr). \]
\[ \frac{dx(t)}{dt}=f(x(t),t). \]
\[ p(x(t),t). \]
\[ \frac{d}{dt}p(x(t),t) = \partial_t p(x(t),t) + \frac{dx(t)}{dt}\,\partial_x p(x(t),t). \]
\[ \frac{d}{dt}p(x(t),t) = \partial_t p + f\,\partial_x p. \]
\[ \partial_t p = -\partial_x(pf) = -(f\,\partial_x p + p\,\partial_x f). \]
\[ \frac{d}{dt}p(x(t),t) = -(f\,\partial_x p + p\,\partial_x f)+f\,\partial_x p. \]
\[ \frac{d}{dt}p(x(t),t) = -p(x(t),t)\,\partial_x f(x(t),t). \]
\[ \frac{d}{dt}\log p(x(t),t) = -\partial_x f(x(t),t). \]
\[ \boxed{ \frac{d}{dt}\log p(x(t),t) = -\partial_x f(x(t),t). } \]
\[ \frac{dx}{dt}=v(x,t), \]
\[ v(x,t)= \begin{bmatrix} v_1(x,t)\\ v_2(x,t)\\ \vdots\\ v_d(x,t) \end{bmatrix}. \]
\[ x(t+dt)=x(t)+v(x(t),t)\,dt. \]
\[ x\mapsto x+v(x,t)\,dt. \]
\[ \frac{\partial x(t+dt)}{\partial x} = I+\frac{\partial v}{\partial x}dt. \]
\[ J_v(x,t)=\frac{\partial v}{\partial x}, \]
\[ \frac{\partial x(t+dt)}{\partial x}=I+J_v(x,t)\,dt. \]
\[ p(x,t)\,dV(t) = p(x+v(x,t)dt,t+dt)\,dV(t+dt). \]
\[ dV(t+dt)=\bigl(1+(\nabla\cdot v)\,dt\bigr)dV(t), \]
\[ p(x,t) = p(x+vdt,t+dt)\bigl(1+(\nabla\cdot v)\,dt\bigr). \]
\[ \dot{x}(t)=v(x(t),t), \]
\[ \boxed{ \frac{d}{dt}\log p(x(t),t) = -\nabla\cdot v(x(t),t). } \]
\[ dX_t=\sigma\,dW_t. \]
\[ X_{t+\Delta t}-X_t \sim \mathcal{N}(0,\sigma^2\Delta t). \]
\[ p(x,t+\Delta t) = \int p(y,t)\, \frac{1}{\sqrt{2\pi \sigma^2\Delta t}} \exp\left( -\frac{(x-y)^2}{2\sigma^2\Delta t} \right)dy. \]
\[ \eta\sim \mathcal{N}(0,\sigma^2\Delta t). \]
\[ \eta=x-y, ~~\text{so that}~~ y=x-\eta. \]
\[ p(x,t+\Delta t) = \int p(x-\eta,t)\,G_{\Delta t}(\eta)\,d\eta, \]
\[ G_{\Delta t}(\eta) = \frac{1}{\sqrt{2\pi \sigma^2\Delta t}} \exp\left( -\frac{\eta^2}{2\sigma^2\Delta t} \right) \]
\[ \int G_{\Delta t}(\eta)\,d\eta=1, \]
\[ p(x,t+\Delta t)=\mathbb{E}_{\eta}\bigl[p(x-\eta,t)\bigr]. \]
\[ \begin{aligned} p(x-\eta,t) &= \sum_{k=0}^{\infty} \frac{\partial_x^{\,k}p(x,t)}{k!}(-\eta)^k \\ &= p(x,t) -\eta\,\partial_x p(x,t) +\frac{(-\eta)^2}{2!}\partial_{xx}p(x,t) +\frac{(-\eta)^3}{3!}\partial_{xxx}p(x,t) +\cdots \\ &= p(x,t)-\eta\,\partial_x p(x,t) +\frac{\eta^2}{2}\partial_{xx}p(x,t) +O(\eta^3). \end{aligned} \]
\[ p(x,t+\Delta t) = \mathbb{E}_{\eta}\bigl[p(x-\eta,t)\bigr] = p(x,t) - \mathbb{E}[\eta]\partial_x p(x,t) + \frac{1}{2}\mathbb{E}[\eta^2]\partial_{xx}p(x,t) +\cdots. \]
\[ \mathbb{E}[\eta]=0, \]
\[ \mathbb{E}[\eta^2]=\sigma^2\Delta t, \]
\[ p(x,t+\Delta t) = p(x,t)+\frac{\sigma^2\Delta t}{2}\partial_{xx}p(x,t)+o(\Delta t). \]
\[ \boxed{ \partial_t p(x,t)=\frac{\sigma^2}{2}\partial_{xx}p(x,t). } \]
\[ dX_t=f(X_t,t)\,dt+\sigma\,dW_t. \]
\[ \boxed{ \partial_t p(x,t) = -\partial_x\bigl(f(x,t)p(x,t)\bigr) + \frac{\sigma^2}{2}\partial_{xx}p(x,t). } \]
\[ -\nabla\cdot\bigl(p(x,t)v(x,t)\bigr), \]
\[ \frac{\sigma^2}{2}\Delta p(x,t), \]
\[ \Delta p = \nabla\cdot(\nabla p) = \sum_{i=1}^d \frac{\partial^2 p}{\partial x_i^2}. \]
\[ \boxed{ \partial_t p(x,t) = -\nabla\cdot\bigl(p(x,t)v(x,t)\bigr) + \frac{\sigma^2}{2}\Delta p(x,t). } \]

7 Score-Based Generative Modelling and Continuous-Time Diffusion

\[ s(x)=\nabla_x \log p(x). \]
\[ s(x,t)=\nabla_x \log p(x,t). \]
\[ s(x) = \frac{d}{dx}\log p(x) = \frac{p'(x)}{p(x)}. \]
\[ p(x) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left( -\frac{(x-\mu)^2}{2\sigma^2} \right). \]
\[ \log p(x) = -\frac{(x-\mu)^2}{2\sigma^2} -\frac{1}{2}\log(2\pi\sigma^2). \]
\[ \frac{d}{dx}\log p(x) = -\frac{x-\mu}{\sigma^2}. \]
\[ \boxed{ s(x) = -\frac{x-\mu}{\sigma^2}. } \]
\[ p(x)=\mathcal{N}(\mu,\Sigma), \]
\[ \boxed{ \nabla_x \log p(x) = -\Sigma^{-1}(x-\mu). } \]
\[ \frac{dx}{dt} = \nabla_x \log p(x), \]
\[ \boxed{ dX_t = \nabla_x \log p^\ast(X_t)\,dt + \sqrt{2}\,dW_t, } \]
\[ \boxed{ x_{k+1} = x_k + \epsilon\,\nabla_x \log p^\ast(x_k) + \sqrt{2\epsilon}\,\xi_k, ~~ \xi_k\sim\mathcal{N}(0,I), } \]
\[ \epsilon\,\nabla_x \log p^\ast(x_k), \]
\[ \sqrt{2\epsilon}\,\xi_k \]
\[ dX_t = \nabla_x \log p^\ast(X_t)\,dt + \sqrt{2}\,dW_t, \]
\[ v(x)=\nabla_x \log p^\ast(x), \]
\[ \partial_t p(x,t) = -\nabla\cdot\bigl(p(x,t)v(x,t)\bigr) + \frac{\sigma^2}{2}\Delta p(x,t), \]
\[ \boxed{ \partial_t p(x,t) = -\nabla\cdot\bigl(p(x,t)\nabla_x \log p^\ast(x)\bigr) + \Delta p(x,t). } \]
\[ \nabla_x\log p^\ast(x)=-x, \]
\[ dX_t=-X_t\,dt+\sqrt{2}\,dW_t, \]
\[ \partial_t p(x,t) = \mathcal{L}[p(x,t)]. \]
\[ \mathcal{L}[p^\ast(x)]=0. \]
\[ \partial_t p(x,t)=0 ~~ \text{when} ~~ p(x,t)=p^\ast(x). \]
\[ \partial_t p(x,t) = -\nabla\cdot\bigl(p(x,t)\nabla_x \log p^\ast(x)\bigr) + \Delta p(x,t). \]
\[ p(x,t)=p^\ast(x). \]
\[ -\nabla\cdot\bigl(p^\ast(x)\nabla_x \log p^\ast(x)\bigr) + \Delta p^\ast(x). \]
\[ p^\ast(x)\nabla_x \log p^\ast(x) = \nabla_x p^\ast(x), \]
\[ \nabla_x \log p^\ast(x) = \frac{\nabla_x p^\ast(x)}{p^\ast(x)}. \]
\[ -\nabla\cdot(\nabla_x p^\ast(x)) + \Delta p^\ast(x). \]
\[ \nabla\cdot(\nabla_x p^\ast) = \Delta p^\ast. \]
\[ -\Delta p^\ast(x)+\Delta p^\ast(x)=0. \]
\[ \boxed{ \partial_t p(x,t)=0 ~~ \text{when} ~~ p(x,t)=p^\ast(x). } \]
\[ \boxed{ dX_t = \nabla_x \log p^\ast(X_t)\,dt + \sqrt{2}\,dW_t. } \]
\[ dX_t = \nabla_x \log p^\ast(X_t)\,dt + \sqrt{2}\,dW_t, \]
\[ s_{\text{data}}(x) = \nabla_x \log p_{\text{data}}(x). \]
\[ \mathcal{J}(\theta) = \mathbb{E}_{x\sim p_{\text{data}}} \left[ \left\| s_\theta(x)-s_{\text{data}}(x) \right\|_2^2 \right]. \]
\[ s_\theta(x)=s_{\text{data}}(x) \]
\[ \begin{aligned} \mathcal{J}(\theta) &= \mathbb{E}_{p_{\text{data}}} \left[ \bigl(s_\theta(x)-s_{\text{data}}(x)\bigr)^\top \bigl(s_\theta(x)-s_{\text{data}}(x)\bigr) \right] \\ &= \mathbb{E}_{p_{\text{data}}} \left[ \|s_\theta(x)\|_2^2 - 2s_\theta(x)^\top s_{\text{data}}(x) + \|s_{\text{data}}(x)\|_2^2 \right]. \end{aligned} \]
\[ \mathbb{E}_{p_{\text{data}}} \left[ \|s_{\text{data}}(x)\|_2^2 \right], \]
\[ \tilde{\mathcal{J}}(\theta) = \mathbb{E}_{p_{\text{data}}} \left[ \|s_\theta(x)\|_2^2 \right] - 2 \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)^\top s_{\text{data}}(x) \right]. \]
\[ \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)^\top s_{\text{data}}(x) \right], \]
\[ s_{\text{data}}(x) = \frac{d}{dx}\log p_{\text{data}}(x) = \frac{1}{p_{\text{data}}(x)} \frac{d}{dx}p_{\text{data}}(x). \]
\[ \begin{aligned} \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)s_{\text{data}}(x) \right] &= \int s_\theta(x) \frac{d}{dx}\log p_{\text{data}}(x) p_{\text{data}}(x) \,dx \\ &= \int s_\theta(x) \frac{1}{p_{\text{data}}(x)} \frac{d}{dx}p_{\text{data}}(x) p_{\text{data}}(x) \,dx \\ &= \int s_\theta(x) \frac{d}{dx}p_{\text{data}}(x) \,dx. \end{aligned} \]
\[ u(x)=s_\theta(x), ~~ v'(x)=\frac{d}{dx}p_{\text{data}}(x), ~~ v(x)=p_{\text{data}}(x). \]
\[ \int s_\theta(x) \frac{d}{dx}p_{\text{data}}(x) \,dx = \bigl[ s_\theta(x)p_{\text{data}}(x) \bigr]_{-\infty}^{\infty} - \int \frac{d}{dx}s_\theta(x) p_{\text{data}}(x) \,dx. \]
\[ \int s_\theta(x) \frac{d}{dx}p_{\text{data}}(x) \,dx = - \int \frac{d}{dx}s_\theta(x) p_{\text{data}}(x) \,dx. \]
\[ \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)s_{\text{data}}(x) \right] = - \mathbb{E}_{p_{\text{data}}} \left[ \frac{d}{dx}s_\theta(x) \right]. \]
\[ \begin{aligned} \tilde{\mathcal{J}}(\theta) &= \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)^2 \right] - 2 \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)s_{\text{data}}(x) \right] \\ &= \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)^2 \right] + 2 \mathbb{E}_{p_{\text{data}}} \left[ \frac{d}{dx}s_\theta(x) \right]. \end{aligned} \]
\[ \boxed{ \mathcal{L}_{\text{SM}}(\theta) = \mathbb{E}_{p_{\text{data}}} \left[ \frac{1}{2}s_\theta(x)^2 + \frac{d}{dx}s_\theta(x) \right]. } \]
\[ s_{\text{data}}(x) = \nabla_x\log p_{\text{data}}(x), \]
\[ \begin{aligned} \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)^\top s_{\text{data}}(x) \right] &= \int s_\theta(x)^\top \nabla_x\log p_{\text{data}}(x) p_{\text{data}}(x) \,dx \\ &= \int s_\theta(x)^\top \nabla_x p_{\text{data}}(x) \,dx. \end{aligned} \]
\[ v(x)= \begin{bmatrix} v_1(x)\\ \vdots\\ v_d(x) \end{bmatrix}, \]
\[ \nabla_x\cdot v(x) = \sum_{i=1}^d \frac{\partial v_i(x)}{\partial x_i}. \]
\[ \nabla_x\cdot \bigl(p_{\text{data}}(x)s_\theta(x)\bigr) = s_\theta(x)^\top\nabla_x p_{\text{data}}(x) + p_{\text{data}}(x)\nabla_x\cdot s_\theta(x). \]
\[ s_\theta(x)^\top\nabla_x p_{\text{data}}(x) = \nabla_x\cdot \bigl(p_{\text{data}}(x)s_\theta(x)\bigr) - p_{\text{data}}(x)\nabla_x\cdot s_\theta(x). \]
\[ \int s_\theta(x)^\top\nabla_x p_{\text{data}}(x) \,dx = - \int p_{\text{data}}(x) \nabla_x\cdot s_\theta(x) \,dx. \]
\[ \boxed{ \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)^\top s_{\text{data}}(x) \right] = - \mathbb{E}_{p_{\text{data}}} \left[ \nabla_x\cdot s_\theta(x) \right]. } \]
\[ \mathbb{E}_{p_{\text{data}}} \left[ s_\theta(x)s_{\text{data}}(x) \right] = - \mathbb{E}_{p_{\text{data}}} \left[ \frac{d}{dx}s_\theta(x) \right]. \]
\[ \tilde{\mathcal{J}}(\theta) = \mathbb{E}_{p_{\text{data}}} \left[ \|s_\theta(x)\|_2^2 + 2\nabla_x\cdot s_\theta(x) \right]. \]
\[ \boxed{ \mathcal{L}_{\text{SM}}(\theta) = \mathbb{E}_{p_{\text{data}}} \left[ \frac{1}{2} \|s_\theta(x)\|_2^2 + \nabla_x\cdot s_\theta(x) \right]. } \]
\[ x\sim p_{\text{data}}(x), \]
\[ \tilde{x} = x+\varepsilon, ~~ \varepsilon\sim\mathcal{N}(0,\sigma^2 I). \]
\[ p(\tilde{x}\mid x) = \mathcal{N}(\tilde{x};x,\sigma^2 I). \]
\[ p_\sigma(\tilde{x}) = \int p_{\text{data}}(x) p(\tilde{x}\mid x) \,dx. \]
\[ s_\sigma(\tilde{x}) = \nabla_{\tilde{x}}\log p_\sigma(\tilde{x}). \]
\[ \nabla_{\tilde{x}}\log p_\sigma(\tilde{x}) = \frac{1}{p_\sigma(\tilde{x})} \nabla_{\tilde{x}}p_\sigma(\tilde{x}). \]
\[ \begin{aligned} \nabla_{\tilde{x}}p_\sigma(\tilde{x}) &= \nabla_{\tilde{x}} \int p_{\text{data}}(x) p(\tilde{x}\mid x) \,dx \\ &= \int p_{\text{data}}(x) \nabla_{\tilde{x}}p(\tilde{x}\mid x) \,dx, \end{aligned} \]
\[ s_\sigma(\tilde{x}) = \frac{ \int p_{\text{data}}(x) \nabla_{\tilde{x}}p(\tilde{x}\mid x) \,dx }{ \int p_{\text{data}}(x) p(\tilde{x}\mid x) \,dx }. \]
\[ p(x\mid\tilde{x}) = \frac{ p_{\text{data}}(x)p(\tilde{x}\mid x) }{ p_\sigma(\tilde{x}) }. \]
\[ s_\sigma(\tilde{x}) = \int p(x\mid\tilde{x}) \nabla_{\tilde{x}}\log p(\tilde{x}\mid x) \,dx, \]
\[ s_\sigma(\tilde{x}) = \mathbb{E}_{x\sim p(x\mid\tilde{x})} \left[ \nabla_{\tilde{x}}\log p(\tilde{x}\mid x) \right]. \]
\[ p(\tilde{x}\mid x) = \mathcal{N}(\tilde{x};x,\sigma^2 I). \]
\[ \log p(\tilde{x}\mid x) = -\frac{1}{2\sigma^2} \|\tilde{x}-x\|_2^2 +\text{constant}. \]
\[ \nabla_{\tilde{x}}\log p(\tilde{x}\mid x) = -\frac{1}{\sigma^2}(\tilde{x}-x) = \frac{1}{\sigma^2}(x-\tilde{x}). \]
\[ \boxed{ s_\sigma(\tilde{x}) = \frac{1}{\sigma^2} \mathbb{E}_{x\sim p(x\mid\tilde{x})} \left[ x-\tilde{x} \right]. } \]
\[ x\sim p_{\text{data}}(x), ~~ \tilde{x}=x+\varepsilon, ~~ \varepsilon\sim\mathcal{N}(0,\sigma^2 I). \]
\[ s_\sigma(\tilde{x}) = \frac{1}{\sigma^2} \mathbb{E}_{x\sim p(x\mid\tilde{x})} \left[ x-\tilde{x} \right]. \]
\[ p(x\mid\tilde{x}) = \frac{ p(\tilde{x}\mid x)p_{\text{data}}(x) }{ p_\sigma(\tilde{x}) }, \]
\[ p_\sigma(\tilde{x}) = \int p_{\text{data}}(x)p(\tilde{x}\mid x)\,dx. \]
\[ \mathbb{E}_{\tilde{x}\sim p_\sigma} \left[ \left\| s_\theta(\tilde{x}) - s_\sigma(\tilde{x}) \right\|_2^2 \right], \]
\[ p_{\text{data}}(x)p(\tilde{x}\mid x). \]
\[ U=\tilde{x}, \]
\[ Y= \frac{1}{\sigma^2}(x-\tilde{x}). \]
\[ \boxed{ \mathcal{L}_{\text{DSM}}(\theta) = \mathbb{E}_{x\sim p_{\text{data}},\, \tilde{x}\sim p(\tilde{x}\mid x)} \left[ \left\| s_\theta(\tilde{x}) - \frac{1}{\sigma^2}(x-\tilde{x}) \right\|_2^2 \right]. } \]
\[ s_\theta^\star(\tilde{x}) = \mathbb{E} \left[ \frac{1}{\sigma^2}(x-\tilde{x}) \;\middle|\; \tilde{x} \right]. \]
\[ s_\sigma(\tilde{x}) = \frac{1}{\sigma^2} \mathbb{E} \left[ x-\tilde{x} \;\middle|\; \tilde{x} \right]. \]
\[ \boxed{ s_\theta^\star(\tilde{x})=s_\sigma(\tilde{x}). } \]
\[ \frac{1}{\sigma^2}(x-\tilde{x}). \]
\[ \tilde{x}=x+\varepsilon, \]
\[ x-\tilde{x}=-\varepsilon. \]
\[ \mathcal{L}_{\text{DSM}}(\theta) = \mathbb{E}_{x\sim p_{\text{data}},\, \varepsilon\sim\mathcal{N}(0,\sigma^2 I)} \left[ \left\| s_\theta(x+\varepsilon) + \frac{\varepsilon}{\sigma^2} \right\|_2^2 \right]. \]
\[ \begin{aligned} \text{single noisy score} &\;\longrightarrow\; \text{many noisy scores} \\ &\;\longrightarrow\; \text{annealed reverse sampling} \;\longrightarrow\; \text{continuous-time score-guided diffusion}. \end{aligned} \]
\[ \tilde{x}=x+\varepsilon, ~~ \varepsilon\sim\mathcal{N}(0,\sigma^2I), \]
\[ s_\theta(\tilde{x},\sigma) \approx \nabla_{\tilde{x}}\log p_\sigma(\tilde{x}). \]
\[ \frac{1}{\sigma^2}(x-\tilde{x}) = -\frac{\varepsilon}{\sigma^2}. \]
\[ \sigma_1>\sigma_2>\cdots>\sigma_K>0 \]
\[ p_{\sigma_k}(\tilde{x}) = \int p_{\text{data}}(x) \mathcal{N}(\tilde{x};x,\sigma_k^2I) \,dx. \]
\[ s_\theta(\tilde{x},\sigma_k) \approx \nabla_{\tilde{x}}\log p_{\sigma_k}(\tilde{x}). \]
\[ \boxed{ \mathcal{L}_{\text{MS-DSM}}(\theta) = \mathbb{E}_{k} \mathbb{E}_{x\sim p_{\text{data}},\, \tilde{x}\sim\mathcal{N}(x,\sigma_k^2I)} \left[ \left\| s_\theta(\tilde{x},\sigma_k) - \frac{1}{\sigma_k^2}(x-\tilde{x}) \right\|_2^2 \right]. } \]
\[ \mathcal{L}_{\text{MS-DSM}}(\theta) = \mathbb{E}_{k} \mathbb{E}_{x\sim p_{\text{data}},\, \varepsilon\sim\mathcal{N}(0,\sigma_k^2I)} \left[ \left\| s_\theta(x+\varepsilon,\sigma_k) + \frac{\varepsilon}{\sigma_k^2} \right\|_2^2 \right]. \]
\[ s_\theta^\star(\tilde{x},\sigma_k) = \nabla_{\tilde{x}}\log p_{\sigma_k}(\tilde{x}). \]
\[ s_\theta(x,\sigma_k) \approx \nabla_x\log p_{\sigma_k}(x), ~~ k=1,\dots,K, \]
\[ \sigma_1>\sigma_2>\cdots>\sigma_K. \]
\[ x^{(0)}\sim\mathcal{N}(0,\sigma_1^2I), \]
\[ \boxed{ x \leftarrow x + \epsilon_k s_\theta(x,\sigma_k) + \sqrt{2\epsilon_k}\,\xi, ~~ \xi\sim\mathcal{N}(0,I). } \]
\[ \text{random noise} \;\longrightarrow\; \text{coarse data region} \;\longrightarrow\; \text{local structure} \;\longrightarrow\; \text{fine detail}. \]
\[ p_{\sigma_1},p_{\sigma_2},\dots,p_{\sigma_K}, \]
\[ p_t(x), ~~ 0\leq t\leq T. \]
\[ s_\theta(x,\sigma_k) \approx \nabla_x\log p_{\sigma_k}(x) \]
\[ s_\theta(x,t) \approx \nabla_x\log p_t(x). \]
\[ \text{finite noise scales} ~\longrightarrow~ \text{continuous family of noisy densities} ~\longrightarrow~ \text{a forward diffusion process}. \]
\[ \boxed{ dX_t = f(X_t,t)\,dt + g(t)\,dW_t. } \]
\[ \partial_t p_t(x) = -\nabla_x\cdot\bigl(p_t(x)f(x,t)\bigr) + \frac{1}{2}g(t)^2\Delta p_t(x), \]
\[ p_0(x) \approx p_{\text{data}}(x), ~~ p_T(x) \approx \text{simple noise distribution}. \]
\[ dX_t = f(X_t,t)\,dt + g(t)\,dW_t, \]
\[ \boxed{ dX_t = \left[ f(X_t,t) - g(t)^2\nabla_x\log p_t(X_t) \right]dt + g(t)\,d\bar{W}_t. } \]
\[ -g(t)^2\nabla_x\log p_t(X_t). \]
\[ s_\theta(x,t) \approx \nabla_x\log p_t(x), ~~ 0\leq t\leq T. \]
\[ X_T\sim p_T, \]
\[ x_t = \sqrt{\bar{\alpha}_t}\,x_0 + \sqrt{1-\bar{\alpha}_t}\,\varepsilon, ~~ \varepsilon\sim\mathcal{N}(0,I), \]
\[ q(x_t\mid x_0) = \mathcal{N} \left( x_t; \sqrt{\bar{\alpha}_t}\,x_0, (1-\bar{\alpha}_t)I \right). \]
\[ \log q(x_t\mid x_0) = -\frac{1}{2(1-\bar{\alpha}_t)} \left\| x_t-\sqrt{\bar{\alpha}_t}x_0 \right\|_2^2 + \text{constant}. \]
\[ \nabla_{x_t}\log q(x_t\mid x_0) = -\frac{1}{1-\bar{\alpha}_t} \left( x_t-\sqrt{\bar{\alpha}_t}x_0 \right). \]
\[ x_t-\sqrt{\bar{\alpha}_t}x_0 = \sqrt{1-\bar{\alpha}_t}\,\varepsilon, \]
\[ \boxed{ \nabla_{x_t}\log q(x_t\mid x_0) = -\frac{1}{\sqrt{1-\bar{\alpha}_t}}\, \varepsilon. } \]
\[ -\frac{1}{\sqrt{1-\bar{\alpha}_t}}, \]
\[ \nabla_{x_t}\log q_t(x_t), \]
\[ x_0 \rightarrow x_1 \rightarrow \cdots \rightarrow x_T, \]
\[ x_T \rightarrow x_{T-1} \rightarrow \cdots \rightarrow x_0. \]
\[ q_t(x_t), ~~ t=0,\dots,T. \]
\[ \nabla_{x_t}\log q_t(x_t). \]
\[ q_0,q_1,\dots,q_T \]
\[ p_t(x), ~~ 0\leq t\leq T, \]
\[ \nabla_x\log p_t(x). \]
\[ \text{learn how noisy samples should be locally corrected,} \]

8 Exact Density Models: Normalising Flows and Autoregressive Factorisations

\[ \boxed{ p_Y(y) = p_X(f^{-1}(y)) \left| \frac{d f^{-1}(y)}{dy} \right|. } \]

8.3.1.1 A simple geometric example.

\[ x=f^{-1}(y)=\frac{y}{2}, \]
\[ \frac{d f^{-1}(y)}{dy} = \frac{1}{2}. \]
\[ p_Y(y) = p_X\left(\frac{y}{2}\right)\frac{1}{2}. \]
\[ p_Y(y)=\frac{1}{2}, ~~ 0\leq y\leq 2. \]

8.3.1.2 The higher-dimensional case: from stretching lengths to stretching volumes.

\[ f(x)=Ax, ~~ A= \begin{bmatrix} 2 & 0\\ 0 & 3 \end{bmatrix}. \]
\[ p_Y(y) = p_X(A^{-1}y)\frac{1}{|\det A|}. \]

8.3.1.3 The Jacobian as a local linear lens.

\[ f:\mathbb{R}^d\to\mathbb{R}^d, \]
\[ [J_f(x)]_{ij} = \frac{\partial f_i(x)}{\partial x_j}. \]
\[ f(x+\delta x) \approx f(x)+J_f(x)\delta x. \]
\[ \boxed{ p_Y(y) = p_X(f^{-1}(y)) \left| \det J_{f^{-1}}(y) \right|= p_X(x) \frac{1}{|\det J_f(x)|}, ~~ y=f(x). } \]
\[ f(x) = x+u\,h(w^\top x+b), \]
\[ h:\mathbb{R}\to\mathbb{R} \]
\[ w^\top x+b \]

8.3.2.1 Jacobian derivation.

\[ f(x)=x+u\,h(w^\top x+b). \]
\[ a=w^\top x+b, ~~ f(x)=x+u\,h(a). \]
\[ \frac{\partial f(x)}{\partial x} = I+u\,h'(a)\frac{\partial a}{\partial x}. \]
\[ J_f(x) = I+u\,w^\top h'(a). \]
\[ J_f(x) = I+u\psi(x)^\top, ~~ \psi(x):=h'(w^\top x+b)w. \]
\[ \det(I+uv^\top)=1+v^\top u, \]
\[ \det J_f(x) = 1+\psi(x)^\top u. \]
\[ \boxed{ \det J_f(x) = 1+h'(w^\top x+b)\,w^\top u. } \]
\[ \log|\det J_f(x)| = \log\left| 1+h'(w^\top x+b)\,w^\top u \right|. \]

8.3.2.2 Invertibility condition.

\[ f(x)=x+u\,h(w^\top x+b), \]
\[ \det J_f(x) = 1+h'(w^\top x+b)\,w^\top u. \]
\[ 0\leq h'(a)\leq 1, \]
\[ w^\top u>-1. \]
\[ 1+h'(a)\,w^\top u>0 \]
\[ x=(x_1,x_2), \]
\[ \begin{aligned} y_1 &= x_1,\\ y_2 &= x_2\odot \exp(s(x_1)) + t(x_1), \end{aligned} \]

8.4.1.1 Jacobian determinant.

\[ y= \begin{bmatrix} y_1\\ y_2 \end{bmatrix} = \begin{bmatrix} x_1\\ x_2\odot \exp(s(x_1))+t(x_1) \end{bmatrix}. \]
\[ J = \frac{\partial y}{\partial x} = \begin{bmatrix} \frac{\partial y_1}{\partial x_1} & \frac{\partial y_1}{\partial x_2} \\ \frac{\partial y_2}{\partial x_1} & \frac{\partial y_2}{\partial x_2} \end{bmatrix}. \]
\[ \frac{\partial y_1}{\partial x_1}=I, ~~ \frac{\partial y_1}{\partial x_2}=0. \]
\[ y_{2,i} = x_{2,i}\exp(s_i(x_1))+t_i(x_1). \]
\[ \frac{\partial y_{2,i}}{\partial x_{2,j}} = \left\{ \begin{array}{ll} \exp(s_i(x_1)), & i=j,\\ 0, & i\neq j. \end{array}\right. \]
\[ \frac{\partial y_2}{\partial x_2} = \operatorname{diag}\big(\exp(s(x_1))\big). \]
\[ J = \begin{bmatrix} I & 0\\ * & \operatorname{diag}\big(\exp(s(x_1))\big) \end{bmatrix}. \]
\[ \det J = \det(I)\, \det\left( \operatorname{diag}\big(\exp(s(x_1))\big) \right). \]
\[ \det J = \prod_i \exp(s_i(x_1)). \]
\[ \boxed{ \log|\det J| = \sum_i s_i(x_1). } \]

8.4.1.2 Invertibility.

\[ \begin{aligned} y_1 &= x_1,\\ y_2 &= x_2\odot \exp(s(x_1)) + t(x_1), \end{aligned} \]
\[ x_1=y_1. \]
\[ y_2 = x_2\odot \exp(s(y_1)) + t(y_1). \]
\[ x_2 = \bigl(y_2-t(y_1)\bigr)\odot \exp(-s(y_1)). \]
\[ \boxed{ \begin{aligned} x_1 &= y_1,\\ x_2 &= \bigl(y_2-t(y_1)\bigr)\odot \exp(-s(y_1)). \end{aligned} } \]
\[ f_1,f_2,\dots,f_K \]
\[ z_0\sim p_Z(z_0), \]
\[ z_k=f_k(z_{k-1}), ~~ k=1,\dots,K, \]
\[ x=z_K. \]
\[ x = f_K\circ f_{K-1}\circ \cdots \circ f_1(z_0). \]
\[ z_0 \xrightarrow{f_1} z_1 \xrightarrow{f_2} \cdots \xrightarrow{f_K} z_K=x, \]
\[ x=z_K \xrightarrow{f_K^{-1}} z_{K-1} \xrightarrow{f_{K-1}^{-1}} \cdots \xrightarrow{f_1^{-1}} z_0. \]

8.4.2.1 Likelihood evaluation: data to base space.

\[ x=z_K \xrightarrow{f_K^{-1}} z_{K-1} \xrightarrow{} \cdots \xrightarrow{f_1^{-1}} z_0. \]
\[ p_{Z_k}(z_k) = p_{Z_{k-1}}(z_{k-1}) \left| \det J_{f_k}(z_{k-1}) \right|^{-1}. \]
\[ \boxed{ p_X(x) = p_Z(z_0) \prod_{k=1}^K \left| \det J_{f_k}(z_{k-1}) \right|^{-1}. } \]
\[ \boxed{ \log p_X(x) = \log p_Z(z_0) - \sum_{k=1}^K \log \left| \det J_{f_k}(z_{k-1}) \right|. } \]

8.4.2.2 Sampling: base space to data space.

\[ z_0\sim p_Z(z_0), \]
\[ z_0 \xrightarrow{f_1} z_1 \xrightarrow{f_2} \cdots \xrightarrow{f_K} z_K=x. \]

8.4.2.3 Composition, mixing, and expressiveness.

\[ z\mapsto Pz, \]
\[ z\mapsto Az, \]
\[ \text{mix coordinates} ~\longrightarrow~ \text{apply tractable nonlinear deformation} ~\longrightarrow~ \text{mix again}. \]
\[ x=(x_1,x_2,\dots,x_d) \]
\[ p(a,b)=p(a\mid b)p(b). \]
\[ p(x_1,\dots,x_d) = p(x_d\mid x_1,\dots,x_{d-1})p(x_1,\dots,x_{d-1}). \]
\[ \begin{aligned} p(x_1,\dots,x_d) &= p(x_d\mid x_1,\dots,x_{d-1}) p(x_{d-1}\mid x_1,\dots,x_{d-2}) \cdots p(x_2\mid x_1)p(x_1). \end{aligned} \]
\[ \boxed{ p(x_1,\dots,x_d) = \prod_{i=1}^d p(x_i\mid x_{<i}), } \]
\[ x_{<i}:=(x_1,\dots,x_{i-1}), \]
\[ p_\theta(x) = \prod_{i=1}^d p_\theta(x_i\mid x_{<i}). \]
\[ p_\theta(x_i\mid x_{<i}), ~~ i=1,\dots,d, \]
\[ p_\theta(x_i\mid x_{<i}) = \mathcal{N}\left( x_i; \mu_i(x_{<i}), \sigma_i^2(x_{<i}) \right), \]
\[ p_\theta(x_i\mid x_{<i}) = \operatorname{Categorical}\left(\pi_i(x_{<i})\right). \]
\[ p_\theta(x) = \prod_{i=1}^d p_\theta(x_i\mid x_{<i}), \]
\[ x_1\sim p_\theta(x_1), \]
\[ x_2\sim p_\theta(x_2\mid x_1), \]
\[ x_3\sim p_\theta(x_3\mid x_1,x_2), \]
\[ x_d\sim p_\theta(x_d\mid x_1,\dots,x_{d-1}). \]
\[ x=(x_1,\dots,x_d) \]
\[ x=(x_1,\dots,x_d), \]
\[ \log p_\theta(x) = \sum_{i=1}^d \log p_\theta(x_i\mid x_{<i}). \]
\[ \log p_\theta(x_1), ~ \log p_\theta(x_2\mid x_1), ~ \dots, ~ \log p_\theta(x_d\mid x_{<d}). \]
\[ x_1\sim p_\theta(x_1), \]
\[ x_2\sim p_\theta(x_2\mid x_1), \]
\[ \cdots \]
\[ x_d\sim p_\theta(x_d\mid x_{<d}). \]
\[ D_{ij}=0 ~~ \text{whenever} ~~ j\geq i. \]
\[ D = \begin{pmatrix} 0 & 0 & 0 & \cdots & 0 \\ \ast & 0 & 0 & \cdots & 0 \\ \ast & \ast & 0 & \cdots & 0 \\ \vdots & \vdots & \vdots & \ddots & 0 \\ \ast & \ast & \ast & \cdots & 0 \end{pmatrix}, \]

9 Beyond Likelihoods: Generative Adversarial Networks and Energy-Based Models

\[ \textit{do we need to compute probabilities at all in order to generate realistic data?} \]
\[ x = G_\theta(z), ~~ z \sim p(z), \]
\[ z \longmapsto G_\theta(z) \]
\[ \textit{how can we tell whether those samples are good?} \]
\[ x\sim p_{\text{data}}(x), ~~ x=G_\theta(z),~ z\sim p(z). \]
\[ D_\phi:\mathbb{R}^d\to(0,1), \]
\[ D_\phi(x)\approx 1 ~\text{for real data,} ~~ D_\phi(G_\theta(z))\approx 0 ~\text{for generated data.} \]
\[ \boxed{ \min_\theta \max_\phi \;\; \mathbb{E}_{x \sim p_{\text{data}}} \big[\log D_\phi(x)\big] + \mathbb{E}_{z \sim p(z)} \big[\log (1 - D_\phi(G_\theta(z)))\big]. } \]
\[ p_{\text{data}}(x) ~~\text{and}~~ p_\theta(x). \]
\[ \mathbb{E}_{x \sim p_{\text{data}}}\big[\log D(x)\big] + \mathbb{E}_{x \sim p_\theta}\big[\log(1 - D(x))\big]. \]
\[ \int p_{\text{data}}(x)\log D(x)\,dx + \int p_\theta(x)\log(1-D(x))\,dx. \]
\[ p_{\text{data}}(x)\log D(x) + p_\theta(x)\log(1-D(x)) \]
\[ \frac{p_{\text{data}}(x)}{D(x)} - \frac{p_\theta(x)}{1-D(x)}. \]
\[ \frac{p_{\text{data}}(x)}{D(x)} = \frac{p_\theta(x)}{1-D(x)}. \]
\[ \boxed{ D^*(x) = \frac{p_{\text{data}}(x)} {p_{\text{data}}(x)+p_\theta(x)}. } \]
\[ V(G_\theta,D) = \mathbb{E}_{x \sim p_{\text{data}}}\big[\log D(x)\big] + \mathbb{E}_{x \sim p_\theta}\big[\log(1-D(x))\big]. \]
\[ D^*(x) = \frac{p_{\text{data}}(x)} {p_{\text{data}}(x)+p_\theta(x)}, \]
\[ V(G_\theta,D^*) = -\log 4 + 2\,\mathrm{JS}\left(p_{\text{data}}\,\|\,p_\theta\right), \]
\[ \mathrm{KL}(p\,\|\,q) = \int p(x)\log\frac{p(x)}{q(x)}\,dx. \]
\[ \mathrm{KL}(p\,\|\,q) \neq \mathrm{KL}(q\,\|\,p), \]
\[ m(x) = \frac{1}{2}\big(p(x)+q(x)\big). \]
\[ \boxed{ \mathrm{JS}(p\,\|\,q) = \frac{1}{2}\mathrm{KL}(p\,\|\,m) + \frac{1}{2}\mathrm{KL}(q\,\|\,m). } \]
\[ \mathrm{JS}(p\,\|\,q) = \mathrm{JS}(q\,\|\,p), \]
\[ 0 \leq \mathrm{JS}(p\,\|\,q) \leq \log 2. \]
\[ \mathrm{JS}\left(p_{\text{data}}\,\|\,p_\theta\right). \]
\[ p_\theta(x)=p_{\text{data}}(x). \]
\[ D^*(x)=\frac{1}{2} \]
\[ \min_\theta \max_\phi \; \mathbb{E}_{x \sim p_{\text{data}}}\big[\log D_\phi(x)\big] + \mathbb{E}_{z \sim p(z)}\big[\log (1 - D_\phi(G_\theta(z)))\big]. \]
\[ \mathbb{E}_{z \sim p(z)} \big[\log (1 - D_\phi(G_\theta(z)))\big]. \]
\[ D_\phi(G_\theta(z))\approx 0. \]
\[ 1-D_\phi(G_\theta(z))\approx 1, ~~ \log(1-D_\phi(G_\theta(z)))\approx 0. \]
\[ \min_\theta \; \mathbb{E}_{z \sim p(z)} \big[ -\log D_\phi(G_\theta(z)) \big]. \]
\[ D_\phi(G_\theta(z))\approx 0, \]
\[ -\log D_\phi(G_\theta(z)) \]
\[ \boxed{ W(p,q) = \sup_{\|f\|_{L} \le 1} \left( \mathbb{E}_{x \sim p}[f(x)] - \mathbb{E}_{x \sim q}[f(x)] \right). } \]
\[ \|f\|_{L}\leq 1 \]
\[ \mathbb{E}_{x \sim p}[f(x)] - \mathbb{E}_{x \sim q}[f(x)] \]
\[ W(p_{\text{data}},p_\theta) = \sup_{\|f\|_{L}\leq 1} \left( \mathbb{E}_{x\sim p_{\text{data}}}[f(x)] - \mathbb{E}_{x\sim p_\theta}[f(x)] \right). \]
\[ x=G_\theta(z), ~~ z\sim p(z), \]
\[ \mathbb{E}_{x\sim p_\theta}[f(x)] = \mathbb{E}_{z\sim p(z)}[f(G_\theta(z))]. \]
\[ \boxed{ \min_\theta \max_{\phi \in \mathcal{L}} \; \mathbb{E}_{x \sim p_{\text{data}}}[f_\phi(x)] - \mathbb{E}_{z \sim p(z)}[f_\phi(G_\theta(z))], } \]
\[ D_\phi(x)\in(0,1) \]
\[ f_\phi(x)\in\mathbb{R}, \]
\[ \lambda \, \mathbb{E}_{\hat{x}} \left[ \big(\|\nabla_{\hat{x}} f_\phi(\hat{x})\|_2-1\big)^2 \right] \]
\[ \nabla_{\hat{x}} f_\phi(\hat{x}) \]
\[ E_\theta(x)\in\mathbb{R} \]
\[ \text{low energy} ~\Longleftrightarrow~ \text{plausible configurations}, ~~ \text{high energy} ~\Longleftrightarrow~ \text{implausible configurations}. \]
\[ E_\theta:\mathbb{R}^d\to\mathbb{R}. \]
\[ \tilde{E}_\theta(x)=E_\theta(x)+c, \]
\[ \textit{where should the model place low-energy regions in the data space?} \]
\[ p_\theta(x) = \frac{1}{Z_\theta} \exp\big(-E_\theta(x)\big), \]
\[ Z_\theta = \int \exp\big(-E_\theta(x)\big)\,dx \]
\[ E_\theta(x)~\text{small} ~\Longrightarrow~ p_\theta(x)~\text{large}, ~~ E_\theta(x)~\text{large} ~\Longrightarrow~ p_\theta(x)~\text{small}. \]
\[ Z_\theta = \int \exp\big(-E_\theta(x)\big)\,dx. \]
\[ p_\theta(x) \propto \exp\big(-E_\theta(x)\big), \]
\[ x\sim p_{\text{data}}(x). \]
\[ E_\theta(x) ~\text{small for}~ x\sim p_{\text{data}}. \]
\[ E_\theta(x) ~\text{low on data}, ~~ E_\theta(x) ~\text{high away from data}. \]
\[ \nabla_x E_\theta(x). \]
\[ -\nabla_x E_\theta(x) \]
\[ p_\theta(x) = \frac{1}{Z_\theta}\exp(-E_\theta(x)), \]
\[ \mathbb{E}_{x\sim p_{\text{data}}} \big[\log p_\theta(x)\big]. \]
\[ \log p_\theta(x) = -E_\theta(x)-\log Z_\theta, \]
\[ \mathbb{E}_{x\sim p_{\text{data}}} \big[\log p_\theta(x)\big] = -\mathbb{E}_{x\sim p_{\text{data}}} \big[E_\theta(x)\big] - \log Z_\theta. \]
\[ \text{lower energy on data} ~~ \text{and} ~~ \text{control energy elsewhere}. \]
\[ -\nabla_\theta \mathbb{E}_{x\sim p_{\text{data}}} \big[E_\theta(x)\big] = - \mathbb{E}_{x\sim p_{\text{data}}} \big[\nabla_\theta E_\theta(x)\big]. \]
\[ Z_\theta = \int \exp(-E_\theta(x))\,dx. \]
\[ \begin{aligned} \nabla_\theta \log Z_\theta &= \frac{1}{Z_\theta} \nabla_\theta \int \exp(-E_\theta(x))\,dx \\ &= \frac{1}{Z_\theta} \int \exp(-E_\theta(x)) \big(-\nabla_\theta E_\theta(x)\big)\,dx \\ &= - \mathbb{E}_{x\sim p_\theta} \big[\nabla_\theta E_\theta(x)\big]. \end{aligned} \]
\[ -\nabla_\theta \log Z_\theta = \mathbb{E}_{x\sim p_\theta} \big[\nabla_\theta E_\theta(x)\big]. \]
\[ \boxed{ \nabla_\theta \mathbb{E}_{x\sim p_{\text{data}}} \big[\log p_\theta(x)\big] = - \mathbb{E}_{x\sim p_{\text{data}}} \big[\nabla_\theta E_\theta(x)\big] + \mathbb{E}_{x\sim p_\theta} \big[\nabla_\theta E_\theta(x)\big]. } \]
\[ \text{data term} ~ - \mathbb{E}_{p_{\text{data}}} \big[\nabla_\theta E_\theta(x)\big], ~~ \text{model term} ~ + \mathbb{E}_{p_\theta} \big[\nabla_\theta E_\theta(x)\big]. \]
\[ \mathbb{E}_{x\sim p_\theta} \big[\nabla_\theta E_\theta(x)\big] \]
\[ p_\theta(x) \propto \exp(-E_\theta(x)). \]
\[ \nabla_x E_\theta(x) \]
\[ -\nabla_x E_\theta(x) \]
\[ \nabla_x\log p(x) = -\nabla_x E(x). \]
\[ x_{t+1} = x_t - \eta\nabla_x E_\theta(x_t), \]
\[ \boxed{ x_{t+1} = x_t - \eta \nabla_x E_\theta(x_t) + \sqrt{2\eta}\,\xi_t, ~~ \xi_t\sim\mathcal{N}(0,I). } \]
\[ -\eta\nabla_x E_\theta(x_t) \]
\[ \sqrt{2\eta}\,\xi_t \]
\[ s(x) = \nabla_x\log p(x). \]
\[ p_\theta(x) = \frac{1}{Z_\theta}\exp(-E_\theta(x)). \]
\[ \log p_\theta(x) = -E_\theta(x)-\log Z_\theta. \]
\[ \nabla_x\log Z_\theta=0. \]
\[ \boxed{ \nabla_x\log p_\theta(x) = -\nabla_xE_\theta(x). } \]
\[ x ~\longmapsto~ -\nabla_xE_\theta(x). \]
\[ s_\theta(x) \approx \nabla_x\log p(x). \]
\[ s_\theta(x) \approx \nabla_x\log p_{\text{data}}(x). \]
\[ s_\theta(x) = \nabla_x\log p_\theta(x) = -\nabla_xE_\theta(x). \]
\[ J_{\mathrm{SM}}(\theta) = \mathbb{E}_{x\sim p_{\text{data}}} \left[ \frac{1}{2}\|s_\theta(x)\|_2^2 + \nabla_x\cdot s_\theta(x) \right]. \]
\[ s_\theta(x)=-\nabla_xE_\theta(x) \]
\[ \boxed{ J_{\mathrm{SM}}(\theta) = \mathbb{E}_{x\sim p_{\text{data}}} \left[ \frac{1}{2} \|\nabla_xE_\theta(x)\|_2^2 - \nabla_x^2E_\theta(x) \right], } \]
\[ \nabla_x^2E_\theta(x) = \sum_{j=1}^d \frac{\partial^2E_\theta(x)}{\partial x_j^2} \]
\[ \nabla_x\log Z_\theta=0. \]
\[ p_\theta(x)\propto \exp(-E_\theta(x)), \]
\[ \nabla_x\log p_\theta(x) = -\nabla_xE_\theta(x). \]
\[ s_\theta(x,t) \approx \nabla_x\log p_t(x), \]
\[ E_t(x) = -\log p_t(x)+C_t, \]
\[ \nabla_x\log p_t(x) = -\nabla_xE_t(x). \]
\[ s_\theta(x,t) \approx -\nabla_xE_t(x), \]
\[ \text{coarse energy landscapes} ~\longrightarrow~ \text{fine data-level energy landscape}. \]

Closing Remarks

Appendix

A Gaussian Algebra and Completing the Square

A.1 Completing the square.

\[ -\frac12 (\text{variable} - \text{mean})^\top (\text{precision}) (\text{variable} - \text{mean}) +\text{constant}, \]
\[ -\frac12 \mathbf{x}^\top A \mathbf{x} + \mathbf{b}^\top \mathbf{x} = -\frac12 (\mathbf{x}-A^{-1}\mathbf{b})^\top A (\mathbf{x}-A^{-1}\mathbf{b}) +\frac12 \mathbf{b}^\top A^{-1}\mathbf{b}. \]
\[ \begin{aligned} &-\frac12 (\mathbf{x}-A^{-1}\mathbf{b})^\top A (\mathbf{x}-A^{-1}\mathbf{b}) +\frac12 \mathbf{b}^\top A^{-1}\mathbf{b} \\ &~~= -\frac12 \mathbf{x}^\top A \mathbf{x} +\mathbf{b}^\top \mathbf{x} -\frac12 \mathbf{b}^\top A^{-1}\mathbf{b} +\frac12 \mathbf{b}^\top A^{-1}\mathbf{b} \\ &~~= -\frac12 \mathbf{x}^\top A \mathbf{x}+\mathbf{b}^\top \mathbf{x}. \end{aligned} \]

A.2 Step 1: Start from the joint density.

\[ p(\mathbf{z})=\mathcal{N}(\mathbf{z}\mid \mathbf{0},\mathbf{I}), ~~ p(\mathbf{x}\mid \mathbf{z}) = \mathcal{N}(\mathbf{x}\mid \mathbf{Wz}+\boldsymbol{\mu},\alpha^2\mathbf{I}). \]
\[ p(\mathbf{x},\mathbf{z}) = p(\mathbf{x}\mid \mathbf{z})\,p(\mathbf{z}). \]
\[ \log p(\mathbf{x},\mathbf{z}) = -\frac{1}{2\alpha^2}\|\mathbf{x}-\boldsymbol{\mu}-\mathbf{Wz}\|^2 -\frac12 \|\mathbf{z}\|^2 +\text{const}. \]

A.3 Step 2: Expand the quadratic in \(\mathbf{z}\).

\[ \|\mathbf{x}-\boldsymbol{\mu}-\mathbf{Wz}\|^2 = (\mathbf{x}-\boldsymbol{\mu})^\top(\mathbf{x}-\boldsymbol{\mu}) -2\,\mathbf{z}^\top \mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}) +\mathbf{z}^\top \mathbf{W}^\top\mathbf{W}\mathbf{z}. \]
\[ \log p(\mathbf{x},\mathbf{z}) = -\frac{1}{2\alpha^2}(\mathbf{x}-\boldsymbol{\mu})^\top(\mathbf{x}-\boldsymbol{\mu}) +\frac{1}{\alpha^2}\mathbf{z}^\top\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}) -\frac12 \mathbf{z}^\top \Bigl(\frac{1}{\alpha^2}\mathbf{W}^\top\mathbf{W}+\mathbf{I}\Bigr)\mathbf{z} +\text{const}. \]

A.4 Step 3: Complete the square.

\[ \mathbf{M} = \mathbf{W}^\top\mathbf{W}+\alpha^2\mathbf{I}, ~~ \mathbf{m} = \mathbf{M}^{-1}\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}). \]
\[ \frac{1}{\alpha^2}\mathbf{W}^\top\mathbf{W}+\mathbf{I} = \frac{1}{\alpha^2}\mathbf{M}, \]
\[ -\frac{1}{2\alpha^2}\mathbf{z}^\top\mathbf{M}\mathbf{z} + \frac{1}{\alpha^2}\mathbf{z}^\top\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}). \]
\[ A=\frac{1}{\alpha^2}\mathbf{M}, ~~ \mathbf{b}=\frac{1}{\alpha^2}\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}). \]
\[ -\frac{1}{2\alpha^2}\mathbf{z}^\top\mathbf{M}\mathbf{z} + \frac{1}{\alpha^2}\mathbf{z}^\top\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}) = -\frac{1}{2\alpha^2}(\mathbf{z}-\mathbf{m})^\top\mathbf{M}(\mathbf{z}-\mathbf{m}) +\frac{1}{2\alpha^2}\mathbf{m}^\top\mathbf{M}\mathbf{m}. \]
\[ \log p(\mathbf{x},\mathbf{z}) = -\frac{1}{2\alpha^2}(\mathbf{z}-\mathbf{m})^\top\mathbf{M}(\mathbf{z}-\mathbf{m}) -\frac{1}{2\alpha^2}(\mathbf{x}-\boldsymbol{\mu})^\top(\mathbf{x}-\boldsymbol{\mu}) +\frac{1}{2\alpha^2}\mathbf{m}^\top\mathbf{M}\mathbf{m} +\text{const}. \]

A.5 Why this identifies a Gaussian posterior.

\[ -\frac{1}{2\alpha^2}(\mathbf{z}-\mathbf{m})^\top\mathbf{M}(\mathbf{z}-\mathbf{m}), \]

A.6 Step 4: Read off the posterior \(p(\mathbf{z}\mid \mathbf{x})\).

\[ p(\mathbf{z}\mid \mathbf{x}) = \mathcal{N}\bigl( \mathbf{z}\mid \mathbf{m}, \alpha^2\mathbf{M}^{-1} \bigr), \]
\[ p(\mathbf{z}\mid \mathbf{x}) = \mathcal{N}\bigl( \mathbf{z}\mid \mathbf{M}^{-1}\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}), \alpha^2\mathbf{M}^{-1} \bigr), ~~ \mathbf{M}=\mathbf{W}^\top\mathbf{W}+\alpha^2\mathbf{I}. \]

A.7 Step 5: Integrate out \(\mathbf{z}\) to obtain \(p(\mathbf{x})\).

\[ p(\mathbf{x}) = \int p(\mathbf{x},\mathbf{z})\,d\mathbf{z}. \]
\[ p(\mathbf{x}) = \mathcal{N}\bigl( \mathbf{x}\mid \boldsymbol{\mu}, \mathbf{W}\mathbf{W}^\top+\alpha^2\mathbf{I} \bigr). \]
\[ p(\mathbf{z}\mid \mathbf{x}) = \mathcal{N}\bigl( \mathbf{z}\mid \mathbf{M}^{-1}\mathbf{W}^\top(\mathbf{x}-\boldsymbol{\mu}), \alpha^2\mathbf{M}^{-1} \bigr) \]
\[ p(\mathbf{x}) = \mathcal{N}\bigl( \mathbf{x}\mid \boldsymbol{\mu}, \mathbf{W}\mathbf{W}^\top+\alpha^2\mathbf{I} \bigr). \]

B Diffusion Reverse-Posterior Derivations

\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) = \frac{ q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0)\, q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) }{ q(\mathbf{x}_t\mid \mathbf{x}_0) }. \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \propto q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0)\, q(\mathbf{x}_{t-1}\mid \mathbf{x}_0). \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_{t-1},\mathbf{x}_0) = q(\mathbf{x}_t\mid \mathbf{x}_{t-1}), \]
\[ q(\mathbf{x}_t\mid \mathbf{x}_{t-1}) = \mathcal{N}\bigl( \mathbf{x}_t\mid \sqrt{\alpha_t}\,\mathbf{x}_{t-1}, (1-\alpha_t)\mathbf{I} \bigr), \]
\[ q(\mathbf{x}_{t-1}\mid \mathbf{x}_0) = \mathcal{N}\bigl( \mathbf{x}_{t-1}\mid \sqrt{\bar{\alpha}_{t-1}}\,\mathbf{x}_0, (1-\bar{\alpha}_{t-1})\mathbf{I} \bigr). \]
\[ \begin{aligned} q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) &\propto \exp\left( -\frac{1}{2(1-\alpha_t)} \left\| \mathbf{x}_t-\sqrt{\alpha_t}\,\mathbf{x}_{t-1} \right\|^2 \right) \\ &~~\times \exp\left( -\frac{1}{2(1-\bar{\alpha}_{t-1})} \left\| \mathbf{x}_{t-1}-\sqrt{\bar{\alpha}_{t-1}}\,\mathbf{x}_0 \right\|^2 \right). \end{aligned} \]
\[ \begin{aligned} q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \propto \exp\Bigg( &-\frac{1}{2(1-\alpha_t)} \left\| \mathbf{x}_t-\sqrt{\alpha_t}\,\mathbf{x}_{t-1} \right\|^2 \\ &-\frac{1}{2(1-\bar{\alpha}_{t-1})} \left\| \mathbf{x}_{t-1}-\sqrt{\bar{\alpha}_{t-1}}\,\mathbf{x}_0 \right\|^2 \Bigg). \end{aligned} \]
\[ \begin{aligned} \left\| \mathbf{x}_t-\sqrt{\alpha_t}\,\mathbf{x}_{t-1} \right\|^2 &= \mathbf{x}_t^\top\mathbf{x}_t -2\sqrt{\alpha_t}\,\mathbf{x}_t^\top \mathbf{x}_{t-1} +\alpha_t\,\mathbf{x}_{t-1}^\top \mathbf{x}_{t-1}. \end{aligned} \]
\[ \begin{aligned} \left\| \mathbf{x}_{t-1}-\sqrt{\bar{\alpha}_{t-1}}\,\mathbf{x}_0 \right\|^2 &= \mathbf{x}_{t-1}^\top \mathbf{x}_{t-1} -2\sqrt{\bar{\alpha}_{t-1}}\,\mathbf{x}_{t-1}^\top \mathbf{x}_0 +\bar{\alpha}_{t-1}\,\mathbf{x}_0^\top\mathbf{x}_0. \end{aligned} \]
\[ \begin{aligned} q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) \propto \exp\Bigg( &-\frac{1}{2} \left[ \frac{\alpha_t}{1-\alpha_t} + \frac{1}{1-\bar{\alpha}_{t-1}} \right] \mathbf{x}_{t-1}^\top \mathbf{x}_{t-1} \\ &+ \left[ \frac{\sqrt{\alpha_t}}{1-\alpha_t}\,\mathbf{x}_t^\top + \frac{\sqrt{\bar{\alpha}_{t-1}}}{1-\bar{\alpha}_{t-1}}\,\mathbf{x}_0^\top \right] \mathbf{x}_{t-1} \Bigg). \end{aligned} \]
\[ -\frac12 A\,\mathbf{x}_{t-1}^\top \mathbf{x}_{t-1} + \mathbf{b}^\top \mathbf{x}_{t-1}, \]
\[ A = \frac{\alpha_t}{1-\alpha_t} + \frac{1}{1-\bar{\alpha}_{t-1}}, ~~ \mathbf{b} = \frac{\sqrt{\alpha_t}}{1-\alpha_t}\,\mathbf{x}_t + \frac{\sqrt{\bar{\alpha}_{t-1}}}{1-\bar{\alpha}_{t-1}}\,\mathbf{x}_0. \]
\[ -\frac12 A\,\mathbf{x}^\top\mathbf{x} + \mathbf{b}^\top\mathbf{x} = -\frac12 A \left\| \mathbf{x}-A^{-1}\mathbf{b} \right\|^2 +\text{constant}, \]
\[ \tilde{\beta}_t = A^{-1}, \]
\[ \tilde{\boldsymbol{\mu}}_t = A^{-1}\mathbf{b}. \]
\[ \begin{aligned} A &= \frac{\alpha_t}{1-\alpha_t} + \frac{1}{1-\bar{\alpha}_{t-1}} \\ &= \frac{ \alpha_t(1-\bar{\alpha}_{t-1}) + (1-\alpha_t) }{ (1-\alpha_t)(1-\bar{\alpha}_{t-1}) }. \end{aligned} \]
\[ \alpha_t - \alpha_t\bar{\alpha}_{t-1} + 1 - \alpha_t = 1-\bar{\alpha}_t. \]
\[ A = \frac{ 1-\bar{\alpha}_t }{ \beta_t(1-\bar{\alpha}_{t-1}) }, \]
\[ \boxed{ \tilde{\beta}_t = A^{-1} = \frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t}\,\beta_t. } \]
\[ \tilde{\boldsymbol{\mu}}_t = A^{-1}\mathbf{b} = \tilde{\beta}_t \left( \frac{\sqrt{\alpha_t}}{1-\alpha_t}\,\mathbf{x}_t + \frac{\sqrt{\bar{\alpha}_{t-1}}}{1-\bar{\alpha}_{t-1}}\,\mathbf{x}_0 \right). \]
\[ \begin{aligned} \tilde{\boldsymbol{\mu}}_t &= \frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t}\beta_t \left( \frac{\sqrt{\alpha_t}}{\beta_t}\,\mathbf{x}_t + \frac{\sqrt{\bar{\alpha}_{t-1}}}{1-\bar{\alpha}_{t-1}}\,\mathbf{x}_0 \right) \\ &= \frac{\sqrt{\alpha_t}(1-\bar{\alpha}_{t-1})}{1-\bar{\alpha}_t}\,\mathbf{x}_t + \frac{\sqrt{\bar{\alpha}_{t-1}}\beta_t}{1-\bar{\alpha}_t}\,\mathbf{x}_0. \end{aligned} \]
\[ \boxed{ \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\mathbf{x}_0) = \frac{ \sqrt{\bar{\alpha}_{t-1}}\,\beta_t }{ 1-\bar{\alpha}_t }\,\mathbf{x}_0 + \frac{ \sqrt{\alpha_t}(1-\bar{\alpha}_{t-1}) }{ 1-\bar{\alpha}_t }\,\mathbf{x}_t. } \]
\[ \boxed{ q(\mathbf{x}_{t-1}\mid \mathbf{x}_t,\mathbf{x}_0) = \mathcal{N}\Bigl( \mathbf{x}_{t-1}\mid \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\mathbf{x}_0), \tilde{\beta}_t\mathbf{I} \Bigr), } \]
\[ \tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t,\mathbf{x}_0) = \frac{ \sqrt{\bar{\alpha}_{t-1}}\,\beta_t }{ 1-\bar{\alpha}_t }\,\mathbf{x}_0 + \frac{ \sqrt{\alpha_t}(1-\bar{\alpha}_{t-1}) }{ 1-\bar{\alpha}_t }\,\mathbf{x}_t, \]
\[ \tilde{\beta}_t = \frac{ 1-\bar{\alpha}_{t-1} }{ 1-\bar{\alpha}_t }\,\beta_t. \]

References

[1] Tianhua Chen Probabilistic Latent Variable Models: Principles and Foundations for Modern Generative AI 2025 SSRN preprint, originally posted May 2025

[2] Tianhua Chen From Classical Probabilistic Latent Variable Models to Modern Generative AI: A Unified Perspective 2025

[3] Karl Pearson On Lines and Planes of Closest Fit to Systems of Points in Space The London, Edinburgh, and Dublin Philosophical Magazine and Journal of Science 1901 2 11 559–572

[4] Harold Hotelling Analysis of a Complex of Statistical Variables into Principal Components Journal of Educational Psychology 1933 24 6–7

[5] Gilbert Strang Introduction to Linear Algebra Wellesley-Cambridge Press 2016 5

[6] Ian T. Jolliffe and Jorge Cadima Principal Component Analysis: A Review and Recent Developments Philosophical Transactions of the Royal Society A 2016 374 2065 20150202

[7] Pierre Baldi and Kurt Hornik Neural Networks and Principal Component Analysis: Learning from Examples Without Local Minima Neural Networks 1989 2 1 53–58

[8] Geoffrey E. Hinton and Ruslan R. Salakhutdinov Reducing the Dimensionality of Data with Neural Networks Science 2006 313 5786 504–507

[9] Michael E. Tipping and Christopher M. Bishop Probabilistic Principal Component Analysis Journal of the Royal Statistical Society: Series B 1999 61 3 611–622

[10] A. P. Dempster and N. M. Laird and D. B. Rubin Maximum Likelihood from Incomplete Data via the EM Algorithm Journal of the Royal Statistical Society: Series B 1977 39 1 1–22

[11] Christopher M. Bishop Pattern Recognition and Machine Learning Springer 2006 New York

[12] Kevin P. Murphy Machine Learning: A Probabilistic Perspective MIT Press 2012 Cambridge, MA

[13] Diederik P. Kingma and Max Welling Auto-Encoding Variational Bayes International Conference on Learning Representations 2014

[14] Danilo Jimenez Rezende and Shakir Mohamed and Daan Wierstra Stochastic Backpropagation and Approximate Inference in Deep Generative Models Proceedings of the 31st International Conference on Machine Learning 2014 32 2 1278–1286

[15] Irina Higgins and Loic Matthey and Arka Pal and Christopher Burgess and Xavier Glorot and Matthew Botvinick and Shakir Mohamed and Alexander Lerchner beta-VAE International Conference on Learning Representations 2017

[16] Diederik P. Kingma and Max Welling An Introduction to Variational Autoencoders Foundations and Trends in Machine Learning 2019 12 4 307–392 10.1561/2200000056

[17] Jonathan Ho and Ajay Jain and Pieter Abbeel Denoising Diffusion Probabilistic Models Advances in Neural Information Processing Systems 2020 33 6840–6851

[18] Jascha Sohl-Dickstein and Eric A. Weiss and Niru Maheswaranathan and Surya Ganguli Deep Unsupervised Learning using Nonequilibrium Thermodynamics Proceedings of the 32nd International Conference on Machine Learning 2015 37 2256–2265

[19] Alexander Quinn Nichol and Prafulla Dhariwal Improved Denoising Diffusion Probabilistic Models Proceedings of the 38th International Conference on Machine Learning 2021 8162–8171

[20] Bernt Øksendal Stochastic Differential Equations: An Introduction with Applications Springer 2003 6

[21] Hannes Risken The Fokker–Planck Equation: Methods of Solution and Applications Springer 1996 2

[22] Lawrence C. Evans Partial Differential Equations American Mathematical Society 2010 2

[23] Aapo Hyvärinen Estimation of Non-Normalized Statistical Models by Score Matching Journal of Machine Learning Research 2005 6 695–709

[24] Pascal Vincent A Connection Between Score Matching and Denoising Autoencoders Neural Computation 2011 23 7 1661–1674

[25] Yang Song and Stefano Ermon Generative Modeling by Estimating Gradients of the Data Distribution Advances in Neural Information Processing Systems 2019

[26] Yang Song and Jascha Sohl-Dickstein and Diederik P. Kingma and Abhishek Kumar and Stefano Ermon and Ben Poole Score-Based Generative Modeling through Stochastic Differential Equations International Conference on Learning Representations 2021

[27] Danilo Jimenez Rezende and Shakir Mohamed Variational Inference with Normalizing Flows Proceedings of the 32nd International Conference on Machine Learning 2015

[28] Laurent Dinh and David Krueger and Yoshua Bengio NICE International Conference on Learning Representations Workshop 2015

[29] Laurent Dinh and Jascha Sohl-Dickstein and Samy Bengio Density Estimation using Real NVP International Conference on Learning Representations 2017

[30] Mathieu Germain and Karol Gregor and Iain Murray and Hugo Larochelle MADE Proceedings of the 32nd International Conference on Machine Learning 2015

[31] Aaron van den Oord and Nal Kalchbrenner and Koray Kavukcuoglu Pixel Recurrent Neural Networks Proceedings of the 33rd International Conference on Machine Learning 2016

[32] Aaron van den Oord and Sander Dieleman and Heiga Zen and Karen Simonyan and Oriol Vinyals and Alex Graves and Nal Kalchbrenner and Andrew Senior and Koray Kavukcuoglu WaveNet arXiv preprint arXiv:1609.03499 2016

[33] Durk P. Kingma and Prafulla Dhariwal Glow: Generative Flow with Invertible 1x1 Convolutions Advances in Neural Information Processing Systems 2018

[34] George Papamakarios and Eric Nalisnick and Danilo Jimenez Rezende and Shakir Mohamed and Balaji Lakshminarayanan Normalizing Flows for Probabilistic Modeling and Inference Journal of Machine Learning Research 2021 22 57 1–64

[35] Ian Goodfellow and Jean Pouget-Abadie and Mehdi Mirza and Bing Xu and David Warde-Farley and Sherjil Ozair and Aaron Courville and Yoshua Bengio Generative Adversarial Nets Advances in Neural Information Processing Systems 2014 27

[36] Martin Arjovsky and Soumith Chintala and Léon Bottou Wasserstein Generative Adversarial Networks Proceedings of the 34th International Conference on Machine Learning 2017 214–223 PMLR

[37] Ishaan Gulrajani and Faruk Ahmed and Martin Arjovsky and Vincent Dumoulin and Aaron Courville Improved Training of Wasserstein GANs Advances in Neural Information Processing Systems 2017 30

[38] Yann LeCun and Sumit Chopra and Raia Hadsell and Marc'Aurelio Ranzato and Fu Jie Huang A Tutorial on Energy-Based Learning Predicting Structured Data MIT Press 2006 Bakir, Gökhan and Hofmann, Thomas and Schölkopf, Bernhard and Smola, Alexander J. and Taskar, Ben and Vishwanathan, S. V. N.

[39] John J. Hopfield Neural Networks and Physical Systems with Emergent Collective Computational Abilities Proceedings of the National Academy of Sciences 1982 79 8 2554–2558

[40] David H. Ackley and Geoffrey E. Hinton and Terrence J. Sejnowski A Learning Algorithm for Boltzmann Machines Cognitive Science 1985 9 1 147–169

[41] Yaron Lipman and Ricky T. Q. Chen and Heli Ben-Hamu and Maximilian Nickel and Matt Le Flow Matching for Generative Modeling International Conference on Learning Representations 2023

[42] Xingchao Liu and Chengyue Gong and Qiang Liu Flow Straight and Fast: Learning to Generate and Transfer Data with Rectified Flow International Conference on Learning Representations 2023

[43] Yang Song and Prafulla Dhariwal and Mark Chen and Ilya Sutskever Consistency Models Proceedings of the 40th International Conference on Machine Learning 2023 32211–32252 PMLR