DDPM公式推导(二)

2 Background

扩散模型【53】是一种以 p θ ( x 0 ) : = ∫ p θ ( x 0 : T ) d x 1 : T p_\theta\left(\mathbf{x}_0\right):=\int p_\theta\left(\mathbf{x}_{0: T}\right) d \mathbf{x}_{1: T} pθ(x0):=pθ(x0:T)dx1:T 形式的潜在变量模型,其中 x 1 , … , x T \mathbf{x}_1, \ldots, \mathbf{x}_T x1,,xT 是与数据 x 0 ∼ q ( x 0 ) \mathbf{x}_0 \sim q\left(\mathbf{x}_0\right) x0q(x0) 同维度的潜变量。联合分布 p θ ( x 0 : T ) p_\theta\left(\mathbf{x}_{0: T}\right) pθ(x0:T) 被称为反向过程,其定义为从 p ( x T ) = N ( x T ; 0 , I ) p\left(\mathbf{x}_T\right)=\mathcal{N}\left(\mathbf{x}_T ; \mathbf{0}, \mathbf{I}\right) p(xT)=N(xT;0,I) 开始的学习高斯过渡的马尔科夫链:

p θ ( x 0 : T ) : = p ( x T ) ∏ t = 1 T p θ ( x t − 1 ∣ x t ) , p θ ( x t − 1 ∣ x t ) : = N ( x t − 1 ; μ θ ( x t , t ) , Σ θ ( x t , t ) ) ( 1 ) p_\theta\left(\mathbf{x}_{0: T}\right):=p\left(\mathbf{x}_T\right) \prod_{t=1}^T p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right), \quad p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right):=\mathcal{N}\left(\mathbf{x}_{t-1} ; \boldsymbol{\mu}_\theta\left(\mathbf{x}_t, t\right), \mathbf{\Sigma}_\theta\left(\mathbf{x}_t, t\right)\right) \quad(1) pθ(x0:T):=p(xT)t=1Tpθ(xt1xt),pθ(xt1xt):=N(xt1;μθ(xt,t),Σθ(xt,t))(1)

将扩散模型与其他类型的潜在变量模型区别开来的是,近似后验 q ( x 1 : T ∣ x 0 ) q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) q(x1:Tx0)(被称为前向过程或扩散过程)固定为一个马尔科夫链,该链根据方差调度 β 1 , … , β T \beta_1, \ldots, \beta_T β1,,βT 逐渐向数据添加高斯噪声:

q ( x 1 : T ∣ x 0 ) : = ∏ t = 1 T q ( x t ∣ x t − 1 ) , q ( x t ∣ x t − 1 ) : = N ( x t ; 1 − β t x t − 1 , β t I ) ( 2 ) q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right):=\prod_{t=1}^T q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right), \quad q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right):=\mathcal{N}\left(\mathbf{x}_t ; \sqrt{1-\beta_t} \mathbf{x}_{t-1}, \beta_t \mathbf{I}\right)\quad(2) q(x1:Tx0):=t=1Tq(xtxt1),q(xtxt1):=N(xt;1βt xt1,βtI)(2)

训练过程主要是通过优化变分下界(也称作证据下界,或ELBO)的负对数似然性来完成的:

E [ − log ⁡ p θ ( x 0 ) ] ≤ E q [ − log ⁡ p θ ( x 0 : T ) q ( x 1 : T ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t ≥ 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t ∣ x t − 1 ) ] = : L ( 3 ) \mathbb{E}\left[-\log p_\theta\left(\mathbf{x}_0\right)\right] \leq \mathbb{E}_q\left[-\log \frac{p_\theta\left(\mathbf{x}_{0: T}\right)}{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}\right]=\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t \geq 1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right)}\right]=: L \quad(3) E[logpθ(x0)]Eq[logq(x1:Tx0)pθ(x0:T)]=Eq[logp(xT)t1logq(xtxt1)pθ(xt1xt)]=:L(3)

可以通过重参数化【33】学习前向过程的方差 β t \beta_t βt,或者将其视为恒定的超参数,并通过选择高斯条件下的 p θ ( x t − 1 ∣ x t ) p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right) pθ(xt1xt),确保反向过程的表达力,因为当 β t \beta_t βt 很小的时候,这两个过程具有相同的函数形式【53】。前向过程的一个显著特性是,它允许在任意时间步长 t t t 以封闭形式采样 x t \mathbf{x}_t xt:使用符号 α t : = 1 − β t \alpha_t:=1-\beta_t αt:=1βt α ˉ t : = ∏ s = 1 t α s \bar{\alpha}_t:=\prod_{s=1}^t \alpha_s αˉt:=s=1tαs,我们有:

q ( x t ∣ x 0 ) = N ( x t ; α ˉ t x 0 , ( 1 − α ˉ t ) I ) ( 4 ) q\left(\mathbf{x}_t \mid \mathbf{x}_0\right)=\mathcal{N}\left(\mathbf{x}_t ; \sqrt{\bar{\alpha}_t} \mathbf{x}_0,\left(1-\bar{\alpha}_t\right) \mathbf{I}\right)\quad(4) q(xtx0)=N(xt;αˉt x0,(1αˉt)I)(4)

因此,我们可以通过使用随机梯度下降优化 L L L的随机项进行高效训练。进一步的改进来自于通过将 L L L(3)重写为以下格式来降低方差:
E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) ⏟ L T + ∑ t > 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) ⏟ L t − 1 − log ⁡ p θ ( x 0 ∣ x 1 ) ⏟ L 0 ] ( 5 ) \mathbb{E}_q[\underbrace{D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)}_{L_T}+\sum_{t>1} \underbrace{D_{\mathrm{KL}}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)}_{L_{t-1}} \underbrace{-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}_{L_0}]\quad(5) Eq[LT DKL(q(xTx0)p(xT))+t>1Lt1 DKL(q(xt1xt,x0)pθ(xt1xt))L0 logpθ(x0x1)](5)
(详情请参见附录A。这些项的标签用于第3节。)公式(5)使用KL散度直接将 p θ ( x t − 1 ∣ x t ) p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right) pθ(xt1xt)与条件于 x 0 \mathbf{x}_0 x0时可以处理的前向过程后验进行比较:
q ( x t − 1 ∣ x t , x 0 ) = N ( x t − 1 ; μ ~ t ( x t , x 0 ) , β ~ t I ) ( 6 )  where  μ ~ t ( x t , x 0 ) : α ˉ t − 1 β t 1 − α ˉ t x 0 + α t ( 1 − α ˉ t − 1 ) 1 − α ˉ t x t  and  β ~ t : = 1 − α ˉ t − 1 1 − α ˉ t β t ( 7 ) \begin{aligned} q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) & =\mathcal{N}\left(\mathbf{x}_{t-1} ; \tilde{\boldsymbol{\mu}}_t\left(\mathbf{x}_t, \mathbf{x}_0\right), \tilde{\beta}_t \mathbf{I}\right) \quad(6)\\ \text { where } \quad \tilde{\boldsymbol{\mu}}_t\left(\mathbf{x}_t, \mathbf{x}_0\right) & : \frac{\sqrt{\bar{\alpha}_{t-1}} \beta_t}{1-\bar{\alpha}_t} \mathbf{x}_0+\frac{\sqrt{\alpha_t}\left(1-\bar{\alpha}_{t-1}\right)}{1-\bar{\alpha}_t} \mathbf{x}_t \quad \text { and } \quad \tilde{\beta}_t:=\frac{1-\bar{\alpha}_{t-1}}{1-\bar{\alpha}_t} \beta_t \quad(7) \end{aligned} q(xt1xt,x0) where μ~t(xt,x0)=N(xt1;μ~t(xt,x0),β~tI)(6):1αˉtαˉt1 βtx0+1αˉtαt (1αˉt1)xt and β~t:=1αˉt1αˉt1βt(7)
因此,公式(5)中的所有KL散度都是高斯间的比较,所以它们可以以Rao-Blackwellized的方式通过封闭形式的表达式计算,而不是使用高方差的蒙特卡洛估计。

上篇文章DDPM公式推导(一)已经推导了式(2)和式(4),下面我们来推导式(3)
设概率模型的分布为 p ( x ; θ ) p(\mathbf{x} ; \theta) p(x;θ) ,其中 θ \theta θ 为分布 p p p 的参数, x \mathbf{x} x 代表观察到的随机变量,在这里就是图像,准确的说 x \mathbf{x} x 是包含 D D D 个像素的高维张量,其每个分量都代表一个像素,因此 x \mathbf{x} x 是多元随机变量。为了区别于其他分布,模型的分布表示为 p θ ( x ) p_\theta(\mathbf{x}) pθ(x)
补充知识–最大似然估计
在深度学习中,估计模型参数的一种常用方法是最大似然估计。似然 (likelihood) 这个词是从贝叶斯公式中而来。如果有给定观测随机变量 X X X 和假设 Y Y Y ,则根据贝叶斯公式有:
P ( Y ∣ X ) = P ( X ∣ Y ) P ( Y ) P ( X ) P(Y \mid X)=\frac{P(X \mid Y) P(Y)}{P(X)} P(YX)=P(X)P(XY)P(Y)
其中等式左侧 P ( Y ∣ X ) P(Y \mid X) P(YX) 是给定数据 X X X 的情况下假设 Y Y Y 成立的概率,称为后验概率,右侧分子中 P ( Y ) P(Y) P(Y) 称为假设的先验概率,而 P ( X ∣ Y ) P(X \mid Y) P(XY) 在假设 Y Y Y X X X 出现的概率,称为似然。而分母 P ( X ) P(X) P(X) 称为数据或证据,主要作用是归一化后验概率,使概率积分为 1 ,一般用 α \alpha α 代替,因此可以简写如下:
P ( Y ∣ X ) = α P ( X ∣ Y ) P ( Y ) P(Y \mid X)=\alpha P(X \mid Y) P(Y) P(YX)=αP(XY)P(Y)
如果所有可能的假设 Y Y Y 都有等概率的可能性,则 P ( Y ) P(Y) P(Y) 为常数,因此要使后验 P ( Y ∣ X ) P(Y \mid X) P(YX) 最大,需要似然 P ( X ∣ Y ) P(X \mid Y) P(XY) 最大,这就是最大似然估计。
p θ ( x ) p_\theta(\mathbf{x}) pθ(x)定义为似然,模型参数 θ \theta θ 本身也是随机变量,可以被视为一种假设,显然 θ \theta θ 是未知的, x \mathbf{x} x 是观察到的随机变量,是已知的,那么就有给定已知的 x \mathbf{x} x 下假设 θ \theta θ 的后验概率 p ( θ ∣ x ) p(\theta \mid \mathbf{x}) p(θx) 。设真实分布的参数为 Θ \Theta Θ ,则显然有 p ( Θ ∣ x ) = 1 p(\Theta \mid \mathbf{x})=1 p(Θx)=1 (在给定 x \mathbf{x} x 下真实分布的参数 Θ \Theta Θ 必然存在),因此 p ( θ ∣ x ) ≤ p ( Θ ∣ x ) = 1 p(\theta \mid x) \leq p(\Theta \mid x)=1 p(θx)p(Θx)=1 ,进而得到这样的推论:后验概率 p ( θ ∣ x ) p(\theta \mid \mathbf{x}) p(θx) 越大,就越接近真实分布,因此目标就是最大化 p ( θ ∣ x ) p(\theta \mid \mathbf{x}) p(θx) 。用贝叶斯公式表示 p ( θ ∣ x ) p(\theta \mid \mathbf{x}) p(θx) 就有:
p ( θ ∣ x ) = α p ( x ∣ θ ) p ( θ ) p(\theta \mid \mathbf{x})=\alpha p(\mathbf{x} \mid \theta) p(\theta) p(θx)=αp(xθ)p(θ)
由于 p ( x ∣ θ ) p(\mathbf{x} \mid \theta) p(xθ) 是给定 θ \theta θ 下生成 x \mathbf{x} x 的条件概率分布,而这与 p θ ( x ) p_\theta(\mathbf{x}) pθ(x) 原始定义 p ( x ; θ ) p(\mathbf{x} ; \theta) p(x;θ) 的意义相同,因此两者是等价的。因此,最大化似然就是最大化 p θ ( x ) p_\theta(\mathbf{x}) pθ(x)
由于对数有很好的数学性质,可以将乘除法变为加减法,降低求导的复杂度,减小计算量,同时还可以防止计算机在数值计算时的溢出,并且不会影响估计的结果。通常使用对数似然来进行估计,即 log ⁡ p θ ( x ) \log p_\theta(\mathbf{x}) logpθ(x),DDPM 的训练目标是使对数似然最大的模型参数 θ \theta θ ,可以表示为:
θ = arg ⁡ max ⁡ θ log ⁡ p θ ( x ) \theta=\underset{\theta}{\arg \max } \log p_\theta(\mathbf{x}) θ=θargmaxlogpθ(x)
x 0 \mathbf{x}_0 x0代入扩散模型可以表示为:
p θ ( x 0 ) : = ∫ p θ ( x 0 : T ) d x 1 : T p_\theta\left(\mathbf{x}_0\right):=\int p_\theta\left(\mathbf{x}_{0: T}\right) d \mathbf{x}_{1: T} pθ(x0):=pθ(x0:T)dx1:T
取log,得:
log ⁡ p θ ( x 0 ) = log ⁡ ∫ p θ ( x 0 , x 1 : T ) d x 1 : T \log p_\theta\left(\mathbf{x}_0\right)=\log \int p_\theta\left(\mathbf{x}_0, \mathbf{x}_{1: T}\right) d \mathbf{x}_{1: T} logpθ(x0)=logpθ(x0,x1:T)dx1:T
但是这种高维积分难以处理,因此引入变分推断来解决这个问题
知识补充-变分推断
Variational Inference(变分推断)用一个已知的、易于处理和采样 (tractable) 的分布(例如高斯分布或指数分布) 去近似一个未知复杂的难以处理的分布。在数学上变分推断常用 KL-Divergence ( K L \mathrm{KL} KL 散度,符号 D K L \mathcal{D}_{K L} DKL ) 来近似,KL散度表示两个分布的相似度,值域是标量,值越小两个分布越接近,并且 KL 散度有个性质是 D K L ≥ 0 \mathcal{D}_{K L} \geq 0 DKL0 (通过 Jensen 不等式证明)。KL 散度公式如下:
D K L ( q ( x ) ∥ p ( x ) ) = ∫ q ( x ) log ⁡ q ( x ) p ( x ) d x = ∫ log ⁡ q ( x ) p ( x ) q ( x ) d x = E q [ log ⁡ q ( x ) p ( x ) ] \begin{aligned} \mathcal{D}_{K L}(q(x) \| p(x)) & =\int q(x) \log \frac{q(x)}{p(x)} d x \\ & =\int \log \frac{q(x)}{p(x)} q(x)d x\\ & =\mathbb{E}_q\left[\log \frac{q(x)}{p(x)}\right] \end{aligned} DKL(q(x)p(x))=q(x)logp(x)q(x)dx=logp(x)q(x)q(x)dx=Eq[logp(x)q(x)]
积分改写为期望, 下标 q q q 表示 x ∼ q ( x ) x \sim q(x) xq(x)
因此,通过变分推断使模型分布 p θ ( x 0 ) p_\theta\left(\mathbf{x}_0\right) pθ(x0) 尽可能接近真实分布 q ( x 0 ) q\left(\mathbf{x}_0\right) q(x0) ,最小化两个分布的 KL 散度,因此 DDPM 的训练目标就从最大化对数似然切换到最小化 KL 散度,如下:
θ = arg ⁡ min ⁡ θ D K L ( q ( x 0 ) ∥ p θ ( x 0 ) ) \theta=\underset{\theta}{\arg \min } \mathcal{D}_{K L}\left(q\left(\mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_0\right)\right) θ=θargminDKL(q(x0)pθ(x0))
但是现在真实分布 q ( x 0 ) q\left(\mathbf{x}_0\right) q(x0)是未知的,因此人为定义了前向过程 q ( x t ∣ x t − 1 ) q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right) q(xtxt1),而前向过程的目的是构建一个从数据 x 0 \mathbf{x}_0 x0 到噪声 x T \mathbf{x}_T xT 的路径,使得数据逐步被加噪直至完全变成高斯噪声。通过这个过程,我们可以从任意时刻 t t t 的噪声状态 x t \mathbf{x}_t xt 推导出其在初始数据 x 0 \mathbf{x}_0 x0 上的后验分布 q ( x t − 1 ∣ x t , x 0 ) q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) q(xt1xt,x0) 。然后,我们训练一个模型 p θ ( x t − 1 ∣ x t ) p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right) pθ(xt1xt) 来近似这个后验分布。因此前向过程相当于一个中间桥梁,让我们可以让 p θ ( x 0 ) p_\theta\left(\mathbf{x}_0\right) pθ(x0)去接近 q ( x 0 ) q\left(\mathbf{x}_0\right) q(x0)
后验分布是已知的,代入即可
θ = arg ⁡ min ⁡ θ D K L ( q ( x 1 : T ∣ x 0 ) ∥ p θ ( x 1 : T ∣ x 0 ) ) \theta=\underset{\theta}{\arg \min } \mathcal{D}_{K L}\left(q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)\right) θ=θargminDKL(q(x1:Tx0)pθ(x1:Tx0))
这样就有:
D K L ( q ( x 1 : T ∣ x 0 ) ∥ p θ ( x 1 : T ∣ x 0 ) ) = E q [ log ⁡ q ( x 1 : T ∣ x 0 ) p θ ( x 1 : T ∣ x 0 ) ] = E q [ log ⁡ q ( x 1 : T ∣ x 0 ) p θ ( x 0 ) p θ ( x 0 : T ) ] = E q [ log ⁡ q ( x 1 : T ∣ x 0 ) p θ ( x 0 : T ) + log ⁡ p θ ( x 0 ) ] = E q [ log ⁡ q ( x 1 : T ∣ x 0 ) p θ ( x 0 : T ) ] + E q [ log ⁡ p θ ( x 0 ) ]   \begin{array}{rlrl} \mathcal{D}_{K L}(q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) )& =\mathbb{E}_q\left[\log \frac{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}{p_\theta\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}\right] & \\ & =\mathbb{E}_q\left[\log \frac{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) p_{\theta}(\mathbf{x}_0)}{p_\theta(\mathbf{x}_{0: T})}\right] & & \\ & =\mathbb{E}_q\left[\log \frac{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}{p_\theta(\mathbf{x}_{0: T})}+\log p_{\theta}(\mathbf{x}_0)\right] & \\ & =\mathbb{E}_q\left[\log \frac{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}{p_\theta(\mathbf{x}_{0: T})}\right]+\mathbb{E}_q[\log p_{\theta}(\mathbf{x}_0)] & \ \end{array} DKL(q(x1:Tx0)pθ(x1:Tx0))=Eq[logpθ(x1:Tx0)q(x1:Tx0)]=Eq[logpθ(x0:T)q(x1:Tx0)pθ(x0)]=Eq[logpθ(x0:T)q(x1:Tx0)+logpθ(x0)]=Eq[logpθ(x0:T)q(x1:Tx0)]+Eq[logpθ(x0)] 
期望下标 q q q表示 x 1 : T ∼ q ( x 1 : T ∣ x 0 ) \mathbf{x}_{1: T} \sim q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) x1:Tq(x1:Tx0)
将等式两边重新整理有:
E q [ log ⁡ p θ ( x 0 ) ] = D K L ( q ( x 1 : T ∣ x 0 ) ∥ p θ ( x 1 : T ∣ x 0 ) ) − E q [ log ⁡ q ( x 1 : T ∣ x 0 ) p θ ( x 0 : T ) ] E q [ log ⁡ p θ ( x 0 ) ] ≥ − E q [ log ⁡ q ( x 1 : T ∣ x 0 ) p θ ( x 0 : T ) ] E q [ log ⁡ p θ ( x 0 ) ] ≥ E q [ log ⁡ p θ ( x 0 : T ) q ( x 1 : T ∣ x 0 ) ] E q [ − log ⁡ p θ ( x 0 ) ] ≤ E q [ − log ⁡ p θ ( x 0 : T ) q ( x 1 : T ∣ x 0 ) ] \begin{aligned} & \mathbb{E}_q[\log p_{\theta}(\mathbf{x}_0)]=\mathcal{D}_{K L}(q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right) )-\mathbb{E}_q\left[\log \frac{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}{p_\theta(\mathbf{x}_{0: T})}\right] \\ & \mathbb{E}_q[\log p_{\theta}(\mathbf{x}_0)] \geq-\mathbb{E}_q\left[\log \frac{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}{p_\theta(\mathbf{x}_{0: T})}\right] \\ & \mathbb{E}_q[\log p_{\theta}(\mathbf{x}_0)] \geq \mathbb{E}_q\left[\log \frac{p_\theta(\mathbf{x}_{0: T})}{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}\right] \\ & \mathbb{E}_q[-\log p_{\theta}(\mathbf{x}_0)] \leq \mathbb{E}_q\left[-\log \frac{p_\theta(\mathbf{x}_{0: T})}{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}\right]\\ \end{aligned} Eq[logpθ(x0)]=DKL(q(x1:Tx0)pθ(x1:Tx0))Eq[logpθ(x0:T)q(x1:Tx0)]Eq[logpθ(x0)]Eq[logpθ(x0:T)q(x1:Tx0)]Eq[logpθ(x0)]Eq[logq(x1:Tx0)pθ(x0:T)]Eq[logpθ(x0)]Eq[logq(x1:Tx0)pθ(x0:T)]
将式(1)式(2)代入得:
E q [ − log ⁡ p θ ( x 0 ) ] ≤ E q [ − log ⁡ p ( x T ) ∏ t = 1 T p θ ( x t − 1 ∣ x t ) ∏ t = 1 T q ( x t ∣ x t − 1 ) ] = E q [ − log ⁡ p ( x T ) − log ⁡ ∏ t = 1 T p θ ( x t − 1 ∣ x t ) q ( x t ∣ x t − 1 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t ≥ 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t ∣ x t − 1 ) ] \begin{aligned} \mathbb{E}_q\left[-\log p_\theta\left(\mathbf{x}_0\right)\right] & \leq \mathbb{E}_q\left[-\log \frac{p\left(\mathbf{x}_T\right) \prod_{t=1}^T p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{\prod_{t=1}^T q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right)}\right] \\ &= \mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right) - \log \prod_{t=1}^T \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t \geq 1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right)}\right] \end{aligned} Eq[logpθ(x0)]Eq[logt=1Tq(xtxt1)p(xT)t=1Tpθ(xt1xt)]=Eq[logp(xT)logt=1Tq(xtxt1)pθ(xt1xt)]=Eq[logp(xT)t1logq(xtxt1)pθ(xt1xt)]
在不等式右侧,把负号提出,在数学上被称为变分下界 (VLB) (或称证据下界 ELBO),由于两边取负,不等式符号反转,因此在这里就成为变分上界,统称变分界。
就这样,我们推出了式(3),从而得出结论:最大化对数似然等价于最小化变分上界。即:
θ = arg ⁡ min ⁡ θ L \theta=\underset{\theta}{\arg \min } L θ=θargminL
在式(3)中,我们需要考虑从初始状态 x 0 \mathbf{x}_0 x0 到最终状态 x T \mathbf{x}_T xT 的所有时间步 t t t ,并对所有时间步的所有中间状态进行联合期望计算。这种联合期望会包含所有时间步的误差,导致较高的方差。
因此需要降低方差:
L = E q [ − log ⁡ p θ ( x 0 : T ) q ( x 1 : T ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t ≥ 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t ∣ x t − 1 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t ∣ x t − 1 ) − log ⁡ p θ ( x 0 ∣ x 1 ) q ( x 1 ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t ∣ x t − 1 , x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) q ( x 1 ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 , x 0 ) q ( x t , x t − 1 , x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) q ( x 1 ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 , x 0 ) q ( x t − 1 , ∣ x t , x 0 ) q ( x t , x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) q ( x 1 ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 , ∣ x 0 ) q ( x 0 ) q ( x t − 1 , ∣ x t , x 0 ) q ( x t , ∣ x 0 ) q ( x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) q ( x 1 ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 ∣ x t , x 0 ) ⋅ q ( x t − 1 ∣ x 0 ) q ( x t ∣ x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) q ( x 1 ∣ x 0 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 ∣ x t , x 0 ) − ∑ t > 1 log ⁡ q ( x t − 1 ∣ x 0 ) + ∑ t > 1 log ⁡ q ( x t ∣ x 0 ) + log ⁡ q ( x 1 ∣ x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 ∣ x t , x 0 ) − ∑ t > 1 log ⁡ q ( x t − 1 ∣ x 0 ) + ∑ t ≥ 1 log ⁡ q ( x t ∣ x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) ] = E q [ − log ⁡ p ( x T ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 ∣ x t , x 0 ) + log ⁡ q ( x T ∣ x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) ] = E q [ − log ⁡ p ( x T ) q ( x T ∣ x 0 ) − ∑ t > 1 log ⁡ p θ ( x t − 1 ∣ x t ) q ( x t − 1 ∣ x t , x 0 ) − log ⁡ p θ ( x 0 ∣ x 1 ) ] = E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) + ∑ t > 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) − log ⁡ p θ ( x 0 ∣ x 1 ) ] \begin{aligned} L & =\mathbb{E}_q\left[-\log \frac{p_\theta\left(\mathbf{x}_{0: T}\right)}{q\left(\mathbf{x}_{1: T} \mid \mathbf{x}_0\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t \geq 1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_t \mid \mathbf{x}_{t-1}\right)}-\log \frac{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}{q\left(\mathbf{x}_1 \mid \mathbf{x}_0\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_{t} \mid \mathbf{x}_{t-1}, \mathbf{x}_0\right)} -\log \frac{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}{q\left(\mathbf{x}_1 \mid \mathbf{x}_0\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t \right)q\left(\mathbf{x}_{t-1}, \mathbf{x}_0\right)}{q\left(\mathbf{x}_{t} ,\mathbf{x}_{t-1}, \mathbf{x}_0\right)} -\log \frac{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}{q\left(\mathbf{x}_1 \mid \mathbf{x}_0\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t \right)q\left(\mathbf{x}_{t-1}, \mathbf{x}_0\right)}{q\left(\mathbf{x}_{t-1} , \mid \mathbf{x}_{t}, \mathbf{x}_0\right)q\left(\mathbf{x}_t,\mathbf{x}_0\right)} -\log \frac{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}{q\left(\mathbf{x}_1 \mid \mathbf{x}_0\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t \right)q\left(\mathbf{x}_{t-1}, \mid \mathbf{x}_0\right)q\left(\mathbf{x}_0\right)}{q\left(\mathbf{x}_{t-1} , \mid \mathbf{x}_{t}, \mathbf{x}_0\right)q\left(\mathbf{x}_t, \mid \mathbf{x}_0\right)q\left(\mathbf{x}_0\right)} -\log \frac{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}{q\left(\mathbf{x}_1 \mid \mathbf{x}_0\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right)} \cdot \frac{q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_0\right)}{q\left(\mathbf{x}_t \mid \mathbf{x}_0\right)}-\log \frac{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}{q\left(\mathbf{x}_1 \mid \mathbf{x}_0\right)}\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right)} -\sum_{t>1} \log q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_0\right)+\sum_{t>1} \log q\left(\mathbf{x}_t \mid \mathbf{x}_0\right)+\log q\left(\mathbf{x}_1 \mid \mathbf{x}_0\right)-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right)} -\sum_{t>1} \log q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_0\right)+\sum_{t \geq 1} \log q\left(\mathbf{x}_t \mid \mathbf{x}_0\right)-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right] \\ & =\mathbb{E}_q\left[-\log p\left(\mathbf{x}_T\right)-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right)} +\log q\left(\mathbf{x}_T \mid \mathbf{x}_0\right)-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right] \\ & =\mathbb{E}_q\left[-\log \frac{p\left(\mathbf{x}_T\right)}{q\left(\mathbf{x}_T \mid \mathbf{x}_0\right)}-\sum_{t>1} \log \frac{p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)}{q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right)}-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right]\\ &=\mathbb{E}_q\left[D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)+\sum_{t>1} D_{\mathrm{KL}}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right] \end{aligned} L=Eq[logq(x1:Tx0)pθ(x0:T)]=Eq[logp(xT)t1logq(xtxt1)pθ(xt1xt)]=Eq[logp(xT)t>1logq(xtxt1)pθ(xt1xt)logq(x1x0)pθ(x0x1)]=Eq[logp(xT)t>1logq(xtxt1,x0)pθ(xt1xt)logq(x1x0)pθ(x0x1)]=Eq[logp(xT)t>1logq(xt,xt1,x0)pθ(xt1xt)q(xt1,x0)logq(x1x0)pθ(x0x1)]=Eq[logp(xT)t>1logq(xt1,xt,x0)q(xt,x0)pθ(xt1xt)q(xt1,x0)logq(x1x0)pθ(x0x1)]=Eq[logp(xT)t>1logq(xt1,xt,x0)q(xt,x0)q(x0)pθ(xt1xt)q(xt1,x0)q(x0)logq(x1x0)pθ(x0x1)]=Eq[logp(xT)t>1logq(xt1xt,x0)pθ(xt1xt)q(xtx0)q(xt1x0)logq(x1x0)pθ(x0x1)]=Eq[logp(xT)t>1logq(xt1xt,x0)pθ(xt1xt)t>1logq(xt1x0)+t>1logq(xtx0)+logq(x1x0)logpθ(x0x1)]=Eq[logp(xT)t>1logq(xt1xt,x0)pθ(xt1xt)t>1logq(xt1x0)+t1logq(xtx0)logpθ(x0x1)]=Eq[logp(xT)t>1logq(xt1xt,x0)pθ(xt1xt)+logq(xTx0)logpθ(x0x1)]=Eq[logq(xTx0)p(xT)t>1logq(xt1xt,x0)pθ(xt1xt)logpθ(x0x1)]=Eq[DKL(q(xTx0)p(xT))+t>1DKL(q(xt1xt,x0)pθ(xt1xt))logpθ(x0x1)]
现在可以得到 L L L:
L = E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) + ∑ t > 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) − log ⁡ p θ ( x 0 ∣ x 1 ) ] L=\mathbb{E}_q\left[D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)+\sum_{t>1} D_{\mathrm{KL}}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right] L=Eq[DKL(q(xTx0)p(xT))+t>1DKL(q(xt1xt,x0)pθ(xt1xt))logpθ(x0x1)]
就这样,推出了式(5),式(5)将式(3)分解为多个时间步的KL散度项,每个项只对应特定时间步的损失。

  • L T L_T LT : 这个项衡量的是从真实数据到最终噪声状态的KL散度,即最后一步的误差。
  • L t − 1 L_{t-1} Lt1 : 每个这样的项衡量的是从一个中间状态 x t \mathbf{x}_t xt 到前一个状态 x t − 1 \mathbf{x}_{t-1} xt1 的KL散度。具体来说, 它衡量的是模型生成的分布 p θ ( x t − 1 ∣ x t ) p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right) pθ(xt1xt) 与真实的后验分布 q ( x t − 1 ∣ x t , x 0 ) q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) q(xt1xt,x0) 之间的差异。
  • L 0 L_0 L0 : 这个项衡量的是从初始数据 x 0 \mathbf{x}_0 x0 到第一个中间状态 x 1 \mathbf{x}_1 x1 的对数概率。

继续化简:
L = E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) + ∑ t > 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) − log ⁡ p θ ( x 0 ∣ x 1 ) ] = E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) + ∑ t > 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) − log ⁡ p θ ( x 0 ∣ x 1 ) q ( x 0 ∣ x 1 , x 0 ) ⋅ q ( x 0 ∣ x 1 , x 0 ) ] = E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) + ∑ t > 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) + log ⁡ q ( x 0 ∣ x 1 , x 0 ) p θ ( x 0 ∣ x 1 ) − log ⁡ q ( x 0 ∣ x 1 , x 0 ) ] = E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) + ∑ t > 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) + D K L ( q ( x 0 ∣ x 1 , x 0 ) ∥ p θ ( x 0 ∣ x 1 ) ) − log ⁡ q ( x 0 ∣ x 1 , x 0 ) ] = E q [ D K L ( q ( x T ∣ x 0 ) ∥ p ( x T ) ) ⏟ 与  θ  无关项  + ∑ t ≥ 1 D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) ⏟ L t − log ⁡ q ( x 0 ∣ x 1 , x 0 ) ⏟ 与  θ  无关项  ] \begin{aligned} L&=\mathbb{E}_q\left[D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)+\sum_{t>1} D_{\mathrm{KL}}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)-\log p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right]\\ &=\mathbb{E}_q\left[D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)+\sum_{t>1} \mathcal{D}_{K L}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)-\log \frac{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}{q\left(\mathbf{x}_0 \mid \mathbf{x}_1, \mathbf{x}_0\right)} \cdot q\left(\mathbf{x}_0 \mid \mathbf{x}_1, \mathbf{x}_0\right)\right]\\ &=\mathbb{E}_q\left[D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)+\sum_{t>1} \mathcal{D}_{K L}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)+\log \frac{q\left(\mathbf{x}_0 \mid \mathbf{x}_1, \mathbf{x}_0\right)}{p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)}-\log q\left(\mathbf{x}_0 \mid \mathbf{x}_1, \mathbf{x}_0\right)\right]\\ &=\mathbb{E}_q\left[D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)+\sum_{t>1} \mathcal{D}_{K L}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)+\mathcal{D}_{K L}\left(q\left(\mathbf{x}_0 \mid \mathbf{x}_1, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_0 \mid \mathbf{x}_1\right)\right)-\log q\left(\mathbf{x}_0 \mid \mathbf{x}_1, \mathbf{x}_0\right)\right]\\ &=\mathbb{E}_q\left[\underbrace{D_{\mathrm{KL}}\left(q\left(\mathbf{x}_T \mid \mathbf{x}_0\right) \| p\left(\mathbf{x}_T\right)\right)}_{\text {与 } \theta \text { 无关项 }}+\sum_{t \geq 1} \underbrace{\mathcal{D}_{K L}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)}_{L_t}-\underbrace{\log q\left(\mathbf{x}_0 \mid \mathbf{x}_1, \mathbf{x}_0\right)}_{\text {与 } \theta \text { 无关项 }}\right]\\ \end{aligned} L=Eq[DKL(q(xTx0)p(xT))+t>1DKL(q(xt1xt,x0)pθ(xt1xt))logpθ(x0x1)]=Eq[DKL(q(xTx0)p(xT))+t>1DKL(q(xt1xt,x0)pθ(xt1xt))logq(x0x1,x0)pθ(x0x1)q(x0x1,x0)]=Eq[DKL(q(xTx0)p(xT))+t>1DKL(q(xt1xt,x0)pθ(xt1xt))+logpθ(x0x1)q(x0x1,x0)logq(x0x1,x0)]=Eq[DKL(q(xTx0)p(xT))+t>1DKL(q(xt1xt,x0)pθ(xt1xt))+DKL(q(x0x1,x0)pθ(x0x1))logq(x0x1,x0)]=Eq  θ 无关项  DKL(q(xTx0)p(xT))+t1Lt DKL(q(xt1xt,x0)pθ(xt1xt)) θ 无关项  logq(x0x1,x0)
与参数 θ \theta θ 无关梯度为0,因此不作为训练目标。这样 L t − 1 L_{t-1} Lt1 L 0 L_0 L0 合并为 L t L_t Lt 就有:
L t = E q [ D K L ( q ( x t − 1 ∣ x t , x 0 ) ∥ p θ ( x t − 1 ∣ x t ) ) ] L_t=\mathbb{E}_q\left[\mathcal{D}_{K L}\left(q\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t, \mathbf{x}_0\right) \| p_\theta\left(\mathbf{x}_{t-1} \mid \mathbf{x}_t\right)\right)\right] Lt=Eq[DKL(q(xt1xt,x0)pθ(xt1xt))]
最终模型目标就是最小化 L t L_t Lt ,即:
θ = arg ⁡ min ⁡ θ L t \theta=\underset{\theta}{\arg \min } L_t θ=θargminLt

相关推荐

  1. DDPM公式推导

    2024-06-15 19:56:04       23 阅读
  2. DDPM扩散模型数学推导

    2024-06-15 19:56:04       38 阅读
  3. 公式推导

    2024-06-15 19:56:04       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-15 19:56:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-15 19:56:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-15 19:56:04       82 阅读
  4. Python语言-面向对象

    2024-06-15 19:56:04       91 阅读

热门阅读

  1. 力扣第204题“计数质数”

    2024-06-15 19:56:04       27 阅读
  2. (一)PHP 变量

    2024-06-15 19:56:04       27 阅读
  3. docker

    docker

    2024-06-15 19:56:04      24 阅读
  4. php环境变量$_ENV详解

    2024-06-15 19:56:04       35 阅读
  5. 新视野大学英语2 词组 6.15

    2024-06-15 19:56:04       33 阅读
  6. 大数据计算入门指南

    2024-06-15 19:56:04       25 阅读