# 2、扩散模型DDPM开源代码的剖析【对应公式与作者给的开源项目，diffusion model】

L simple ( θ ) = E t , x 0 , ϵ [ ∥ ϵ − ϵ θ ( α ˉ t x 0 + 1 − α ˉ t ϵ , t ) ∥ 2 ] L_{\text{simple}}(\theta) = \mathbb{E}_{t,x_0, \epsilon} \Bigg[ \bigg\Vert \epsilon - \textcolor{lightgreen}{\epsilon_\theta}(\sqrt{\bar\alpha_t} x_0 + \sqrt{1-\bar\alpha_t}\epsilon, t) \bigg\Vert^2 \Bigg]

# 3、【DDIM加速采样方法】公式推导加代码分析。Denoising Diffusion Implicit Models

x τ i − 1 = α τ i − 1 ( x τ i − 1 − α τ i ϵ θ ( x τ i ) α τ i ) + 1 − α τ i − 1 − σ τ i 2 ⋅ ϵ θ ( x τ i ) + σ τ i ϵ τ i x_{\tau_{i-1}} = \sqrt{\alpha_{\tau_{i-1}}}\Bigg( \frac{x_{\tau_i} - \sqrt{1 - \alpha_{\tau_i}}\epsilon_\theta(x_{\tau_i})}{\sqrt{\alpha_{\tau_i}}} \Bigg) \\ + \sqrt{1 - \alpha_{\tau_{i- 1}} - \sigma_{\tau_i}^2} \cdot \epsilon_\theta(x_{\tau_i}) \\ + \sigma_{\tau_i} \epsilon_{\tau_i} 其中 ϵ τ i \epsilon_{\tau_i} 是随机噪声，
τ \tau [ 1 , 2 , … , T ] [1,2,\dots,T] 的子序列，长度为 S S ，和
σ τ i = η 1 − α τ i − 1 1 − α τ i 1 − α τ i α τ i − 1 \sigma_{\tau_i} = \eta \sqrt{\frac{1 - \alpha_{\tau_{i-1}}}{1 - \alpha_{\tau_i}}} \sqrt{1 - \frac{\alpha_{\tau_i}}{\alpha_{\tau_{i-1}}}} 请注意，DDIM 论文中的 α t \alpha_t 是指来自 DDPM α ˉ t {\color{lightgreen}\bar\alpha_t}