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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/27693.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Nginx实战:故障处理_后端服务正常,nginx偶发502(Bad Gateway)

一、故障场景 用户访问服务偶发报错【502 Bad Gateway】,但是服务后端正常运行。架构如下: #mermaid-svg-4dDszusKEuPgIPlt {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-4dDszusKEuPgIPlt…

Qt项目天气预报(1) - ui界面搭建

ui中部 效果演示 ui效果 显示效果 控件列表 配合右图查看 居中对齐-label 设置label居中对齐(别傻傻的空格对齐了) 间距配置 widget03 外围的widget对象: 包含label 和 widget0301,如下图 widget0301 内围的widget对象,如下图 样式表 widget03 …

自养号测评全揭秘:沃尔玛卖家如何实现销量稳步增长

在沃尔玛这片激烈的商业战场上,我作为一位销售者,深知在这个竞争激烈的市场中,测评对于提升产品排名、权重以及销量的关键作用。随着测评需求的不断增长,我们意识到,寻找可靠的测评服务不再是简单的选择,而…

数组模拟单链表和双链表

目录 单链表 初始化 头插 删除 插入 双链表 初始化 插入右和插入左 删除 单链表 单链表主要有三个接口:头插,删除,插入(由于单链表的性质,插入接口是在结点后面插入) 初始化 int e[N], ne[N]; …

【scikit-learn入门指南】:机器学习从零开始

1. 简介 scikit-learn是一款用于数据挖掘和数据分析的简单高效的工具,基于NumPy、SciPy和Matplotlib构建。它能够进行各种机器学习任务,如分类、回归和聚类。 2. 安装scikit-learn 在开始使用scikit-learn之前,需要确保已经安装了scikit-le…

pyinstall打包exe报错

1- 报错 Please install pywin32-ctypes. 前提:python安装路径中已经安装了pywin32-ctypes。 运行pyinstaller报错 PyInstaller cannot check for assembly dependencies. Please install pywin32-ctypes. 解决思路: python安装路径下Lib\site-packa…

算法:位运算题目练习

目录 常见的位运算的操作总结 ①基础位操作 ②给一个数n,确定它的二进制表示中的第x位是0还是1 ③将一个数n的二进制表示的第x位修改成1 ④将一个数n的二进制表示的第x位修改成0 ⑤位图的思想 ⑥提取一个数n二进制表示中最右侧的1 ⑦干掉一个数n二进制表示中…

JVM 根可达算法

Java中的垃圾 Java中"垃圾"通常指的是不再被程序使用和引用的对象,具体表现在没有被栈、JNI指针和永久代对象所引用的对象。Java作为一种面向对象的编程语言,它使用自动内存管理机制,其中垃圾收集器负责检测和回收不再被程序引用的…

响应式德米拉数字内容交易系统素材下载站模板

★模板说明★ 该数字交易系统设计非常完美,两种响应式模式,可打开边栏模式和盒子模式;八种网站颜色,四种风格颜色可供用户自行选择,还可在网站选背景图片;完美的分成系统、充值功能、个人中心等等都以html…

可重复读(Repeatable Read) 隔离级别-幻读

幻读通常发生在范围查询中,下面通过一个简单的例子来说明幻读现象: 假设有一个名为 employees 的表,其中包含员工的ID和部门ID: CREATE TABLE employees (id INT,department_id INT,name VARCHAR(255) );现在有两个并发事务 A 和…

警示:AGI竞赛之未来十年

后新冠时代,人类智商普遍下降,人工智能赶超人类智能指日可待。 最近几天,AI领域悄悄流行一份AGI白皮书,虽然有些危言耸听,甚至包含以中国为竞争对手的阴谋论。下面是主要思想: 在过去的一年里&#xff1a…

速盾:被攻击后开ddos防御还有效吗?

在网络世界中,DDOS(分布式拒绝服务)攻击是一种常见且具有极大破坏力的网络攻击手段。当网站或系统遭受此类攻击后,一个关键的问题便是此时开启 DDOS 防御是否仍然有效。作为一名专业程序员,以下是对这一问题的深入分析…

6.11 作业

以下是一个简单的比喻,将多态概念与生活中的实际情况相联系: 比喻:动物园的讲解员和动物表演 想象一下你去了一家动物园,看到了许多不同种类的动物,如狮子、大象、猴子等。现在,动物园里有一位讲解员&…

找我设计官网的不多了,看到漂亮大气的,还是忍不住分享出来。

现在有客户找我做官网设计,我说:要么搞个高大上个性化定制的,要么就选个模板得了,几千元的网站不上不下,不如不做。 分享一批高大上的网站给老铁们看看。

功能强大的API函数FindFirstFile使用介绍(附源码)

在处理文件的相关代码中,会频繁使用到Windows系统API函数FindFirstFile,这个函数功能很强大,很多功能都不开它。本文就根据我们在项目中使用该函数的情况,来大概地梳理一下使用FindFirstFile都可以实现哪些常用的功能。 1、FindFirstFile函数声明与WIN32_FIND_DATA结构体 我…

C++ 33 之 const 修饰静态成员

#include <iostream> #include <string.h> using namespace std;// 定义静态const数据成员时&#xff0c;最好在类内部初始化,避免在类外重复初始化&#xff0c;也为了代码的可读性和可维护性class Students03{ public:// 两种写法都可以const static int s_a 10;…

开源模型应用落地-LangChain高阶-LCEL-表达式语言(六)

一、前言 尽管现在的大语言模型已经非常强大,可以解决许多问题,但在处理复杂情况时,仍然需要进行多个步骤或整合不同的流程才能达到最终的目标。然而,现在可以利用langchain来使得模型的应用变得更加直接和简单。 LCEL是什么? LCEL是一种非常灵活和强大的语言,可以帮助您更…

openjudge_2.5基本算法之搜索_7221:拯救公主

题目 7221:拯救公主 总时间限制: 1000ms 内存限制: 65536kB 描述 多灾多难的公主又被大魔王抓走啦&#xff01;国王派遣了第一勇士阿福去拯救她。 身为超级厉害的术士&#xff0c;同时也是阿福的好伙伴&#xff0c;你决定祝他一臂之力。你为阿福提供了一张大魔王根据地的地图…

如何完美解决升级 IntelliJ IDEA 最新版之后遇到 Git 记住密码功能失效的问题

&#x1f6e0;️ 如何完美解决升级 IntelliJ IDEA 最新版之后遇到 Git 记住密码功能失效的问题 摘要 在这篇文章中&#xff0c;我们将详细探讨如何解决在升级到 IntelliJ IDEA 最新版&#xff08;2024.1.3 Ultimate Edition&#xff09;后遇到的 Git 记住密码功能失效的问题。…

FPGA - Verilog题目: 非整数倍数据位宽转换24to128

题目描述&#xff1a; 实现数据位宽转换电路&#xff0c;实现24bit数据输入转换为128bit数据输出。其中&#xff0c;先到的数据应置于输出的高bit位。 电路的接口如下图所示。valid_in用来指示数据输入data_in的有效性&#xff0c;valid_out用来指示数据输出data_out的有效性…