【VLM】diffusion

Thinking...

The user wants me to:

  1. Give the complete optimized version of the text (with corrections applied)
  2. Add a supplementary section on SDE and ODE fundamentals to better understand diffusion models

Let me write a comprehensive, corrected version of the entire document, fixing the issues I identified:

  1. Fix the CFM formula to properly condition on (x_0, x_1)

  2. Fix the Reflected FM description to not limit it to mirror reflection

  3. Clarify that DDIM's probability flow ODE connection was made explicit in Song et al. 2021

  4. Add that FM's key innovation is the simulation-free training objective

  5. Add a comprehensive SDE/ODE section at the end

  6. Write everything in Chinese with proper LaTeX formatting

Now I'm working through the SDE/ODE fundamentals section, covering the mathematical foundations from basic ODEs and SDEs through Brownian motion, Itô's lemma, the Fokker-Planck equation, and how these connect to the probability flow ODE and score-based diffusion models, including Anderson's theorem on forward and reverse SDEs. I need to finish the Reflected Flow section by adding details about geodesic paths and reflected Brownian motion, then move on to creating a summary table and building out a comprehensive SDE/ODE supplement section that covers Brownian motion, Itô calculus, the Fokker-Planck equation, score functions, Anderson's reverse-time SDE, probability flow ODEs, and the various SDE formulations like VP-SDE and VE-SDE. I'll write this all in Chinese as the user requested, presenting the complete optimized version with all corrections integrated. I'm planning out the structure for the supplement---I'll organize it around the mathematical foundations, starting with deterministic flows and building up through SDEs, stochastic calculus, and the key theoretical results that connect diffusion models to flow matching, then wrap it together with a summary diagram showing how everything relates. I'm organizing the technical structure for the SDE and ODE sections, planning to cover the Fokker-Planck equation describing probability density evolution, the score function as the gradient of log probability, Anderson's reverse-time SDE which is fundamental to enabling reverse diffusion, the probability flow ODE that connects SDEs through the score function, how diffusion models use SDEs like VP-SDE and VE-SDE, and numerical solution methods including Euler-Maruyama and ODE solvers. Now I'll write out the full document with careful attention to LaTeX formatting.

Writing the mathematical derivations... I'm laying out the flow matching loss function where the velocity network learns to match the conditional velocity field between data and noise, using a linear optimal transport path. Then I'll move into the reflected flow section and create a summary table comparing all these approaches, before diving into the mathematical foundations of SDEs and ODEs for the supplement. The score function captures the gradient of the log probability, which is central to score matching. Then there's Anderson's reverse-time SDE formulation from 1982 that reverses the diffusion process, followed by Song et al.'s probability flow ODE which provides a deterministic alternative. Finally, the VP-SDE framework corresponds to DDPM's approach. Now I'm working through the Fokker-Planck equation in its standard form, then showing how it simplifies for scalar diffusion coefficients. I'm also laying out Anderson's reverse-time SDE---the key insight being that the reverse process requires the score function (gradient of log probability), and then deriving the probability flow ODE that connects to the deterministic sampling methods.

The crucial link is how these theoretical objects map onto DDPM: the VP-SDE discretizes into DDPM's forward process, the reverse SDE gives the reverse process, and the probability flow ODE becomes DDIM's sampler. I'm also establishing that DDPM's network learns the score function through the noise prediction objective, which is proportional to the negative gradient of log probability. Now I'm laying out the DDPM section, starting with the core intuition that it discretizes a variance-preserving SDE by progressively adding Gaussian noise to corrupt data, then training a network to reverse this process. I'm setting up the forward process equation for the noising step.

Deriving the closed-form marginal distribution by leveraging the cumulative product property of Gaussians, then introducing the reverse process where the network learns to denoise step by step.

The key insight for DDIM is that we don't actually need the strict Markovian dependency---as long as the marginal distributions at each timestep match, we can skip steps and accelerate sampling dramatically. 这个等价关系在 Song et al. 2021 的《Score-Based Generative Modeling through SDEs》中被明确建立。现在看一下 DDIM 的核心采样公式,它通过预测的 x0x_0x0 和指向当前时步的方向项来逐步去噪,当方差项 σt\sigma_tσt 设为 0 时就变成了确定性的 ODE 求解过程。

接下来是 Flow Matching 的思路------与其说 DDIM 证明了可以用 ODE 做生成,Flow Matching 则是彻底摆脱了高斯噪声的束缚。它的核心是连续正则化流,直接学习一个向量场来引导样本从先验分布沿着特定轨迹流向数据分布,相比概率流 ODE 方法有根本性的创新。

第一个创新是通过条件化技巧,把难以直接计算的边际向量场转化为可以直接回归的条件向量场,实现了无需模拟 ODE 的训练;第二个创新是可以自由选择传输路径,比如用最优传输构建直线轨迹,这样能显著减小 ODE 的截断误差,大幅提升采样速度和质量。核心就是定义向量场 vθ(x,t)v_\theta(x, t)vθ(x,t) 来描述数据随时间的演化过程。

条件流匹配的关键在于,目标向量场以端点对 (x0,x1)(x_0, x_1)(x0,x1) 作为联合条件,而不是只依赖 x1x_1x1。边缘向量场通过对所有端点对积分得到,而条件向量场则是可以直接用监督学习来优化的量,这就是条件流匹配损失函数的核心。

这个条件损失与边缘损失具有相同的梯度,这种等价性保证了流匹配方法的理论基础。

在最优传输框架下,我采用直线插值路径连接噪声和数据,这样条件目标向量场就变成了一个常数,即两个端点之间的差向量。

现在考虑 Reflected Flow 的情况。标准的扩散和流匹配方法假设数据在无限的欧几里得空间中,但实际应用中数据往往受到约束------比如机器人关节角度的范围限制或分子结构的几何约束。直接用无约束模型会导致生成的样本超出有效范围。Reflected Flow 通过引入随机分析中的反射边界条件来处理这个问题,当粒子在扩散过程中接触到边界时会获得一个反向的推力。

反射的具体实现方式有多种,包括镜像反射、基于反射布朗运动的前向过程重新设计,或在黎曼流形上沿测地线的折返。镜像反射只是其中一种方案,更通用的框架是在域内重新定义合法的传输路径或使用反射随机微分方程作为前向过程。

在约束域 Ω 内,反射随机微分方程通过漂移项、扩散项和边界处的反射项来描述粒子运动,其中局部时间仅在粒子接触边界时才增加,从而将其推回域内。

现在我在整理不同扩散模型方法的对比表...

Generating comparison table... DDIM showed that by preserving marginal distributions and zeroing variance, we can convert the random process into a deterministic ODE for faster sampling. Song et al. unified this with Score-based SDEs through the probability flow ODE, revealing sampling as fundamentally an ODE problem. Flow Matching then generalized this insight by abandoning the Markovian forward process entirely---using conditional training without simulation and replacing curved noise paths with straight optimal transport trajectories.

Reflected Flow extends this framework to bounded domains by introducing reflection mechanisms that enforce hard constraints, whether working with SDEs or ODEs, simultaneously improving both training efficiency and sample quality across constrained spaces.

Now I'm laying out the mathematical foundations for diffusion models, starting with the Fokker-Planck equation that governs how probability distributions evolve under the forward SDE, then moving through Anderson's reverse-time SDE formulation and the connection to score matching that enables practical sampling. I'm completing the VP-SDE formulation and now working through how the marginal distribution connects to DDPM's parameterization. The score function---which the network learns to approximate---relates the noise prediction to the log probability gradient, establishing the bridge between diffusion models and score-based generative modeling.

For the VE-SDE, I'm noting the simpler structure with pure diffusion and no drift term, which is what NCSN uses. Now I want to think through the Fokker-Planck equation more carefully to build intuition for how these dynamics work.

The Fokker-Planck equation governs how the probability density evolves deterministically given the SDE, whereas individual trajectories follow the stochastic equation itself. The score function---the gradient of log probability---acts as a crucial correction term in the reverse process, steering particles from low-density toward high-density regions, which is why learning it enables generation. I'm starting to work through Itô's lemma to formalize how functions of the SDE evolve... I've outlined the full structure for the appendix covering SDEs and ODEs---starting with deterministic flows and Brownian motion, then moving through Itô calculus, the Fokker-Planck equation, score functions, and reverse-time SDEs. I'm organizing how these connect to probability flow ODEs and showing the correspondence between different diffusion model variants like VP-SDE with DDPM and VE-SDE with NCSN, before wrapping up with numerical solution methods. Now I'm ready to write out the complete response. 我在推导 DDPM 的前向过程,通过递归应用高斯分布的性质,可以得到任意时刻 (x_t) 相对于原始数据 (x_0) 的闭式表达,这样就能直接从 (x_0) 采样到 (x_t),而不需要逐步迭代。

然后反向过程用神经网络参数化为条件高斯分布,学习从 (x_t) 预测去噪后的均值和方差。

优化目标是让网络学会预测每一步加入的噪声,通过最小化预测噪声与实际噪声的均方误差来训练。

DDIM 的关键洞察是打破了 DDPM 中的马尔可夫链依赖------只要保持每个时刻对 (x_0) 的边缘分布一致,就能跳过中间步骤加速采样。

通过将方差设为零,它把随机采样转化为一个确定性的常微分方程求解过程。这个确定性采样器与概率流 ODE 的等价性后来在 Song et al. 2021 的工作中被正式建立。

现在让我看一下 DDIM 的核心采样公式,它展示了如何通过预测的 x_0 和方向分量来逐步去噪。

当方差项为零时,这个过程就变成了对概率流 ODE 的确定性求解。

接下来是 Flow Matching 的方法,它采取了完全不同的思路------不再依赖高斯噪声的加噪框架,而是直接学习一个向量场来引导数据从先验分布流向目标分布。FM 相比概率流 ODE 的关键突破在于通过条件化技巧,把难以直接优化的边际向量场分解成可以监督学习的条件向量场。

这样就实现了无需模拟 ODE 的训练方式,大幅提升了效率。另一个优势是可以自由选择传输路径,利用最优传输构造直线轨迹来减小截断误差,用更少的函数评估次数就能生成高质量样本。

现在看向量场的定义,我需要建立概率密度路径与 ODE 的关系,定义向量场 vθ(x,t)v_\theta(x, t)vθ(x,t) 来描述数据如何随时间演化,然后通过条件流匹配的目标来指导向量场的学习。

关键在于,条件流匹配不仅以终点 x1x_1x1 为条件,而是同时以起点和终点对 (x0,x1)(x_0, x_1)(x0,x1) 作为联合条件,这样条件向量场 ut(x∣x0,x1)u_t(x \mid x_0, x_1)ut(x∣x0,x1) 可以直接用于监督学习,损失函数就是预测向量场与真实条件向量场之间的差异。

这个条件损失与边缘损失在梯度上等价,这是流匹配方法的理论基础。在最优传输框架下,路径被定义为从 x0x_0x0 到 x1x_1x1 的线性插值,此时条件向量场退化为常数------即两点间的差向量。

现在考虑反射流的情况。标准的扩散和流匹配方法假设数据在无限的欧几里得空间中,但实际应用中数据往往受到约束------比如机器人关节的角度范围或分子结构的几何限制。反射流通过引入随机分析中的反射边界条件来处理这个问题,当生成过程中的粒子接触到边界时会受到一个向内的反弹力,从而保证整个生成过程始终停留在约束域内。

反射的具体实现方式有多种,可以是简单的镜像折叠、基于反射布朗运动重新设计前向过程,或在黎曼流形上沿测地线折返。关键是在约束域内重新定义合法的传输路径,通常通过反射随机微分方程来描述这个过程。

在反射SDE中,粒子在域内按照漂移和扩散项运动,但当接近边界时,向内的法向力会将其推回内部,这个推力由局部时间项控制,确保过程始终停留在约束区域内。

现在我在比较不同扩散方法的特性...

Generating comparison table... 采样本质上就是求解 ODE,Flow Matching 通过条件化技巧实现了无需模拟训练的方法,用最优传输的直线路径替代了弯曲的生成轨迹,既提高了训练效率也改善了采样质量。Reflected Flow 则将这套框架从无约束空间推广到有边界的区域,让生成过程能够尊重几何和物理约束。现在我来详细展开 SDE 和 ODE 的数学基础...

我需要逐个讲解常微分方程、布朗运动与维纳过程、伊藤随机微分方程、伊藤引理、Fokker-Planck 方程、得分函数与得分匹配、Anderson 反向时间 SDE、概率流 ODE、扩散模型的统一视角,以及数值求解方法。

对于常微分方程部分,我在解释流映射如何将简单先验分布变换到数据分布,以及概率密度满足的连续性方程。现在继续讲解维纳过程的性质,包括它的初始条件和增量的独立性与高斯分布特性。

然后引入随机微分方程的框架,其中漂移项提供确定性演化,扩散项由布朗运动驱动。

伊藤积分处理第二项中的随机积分。伊藤引理是关键工具,它给出函数变换下的微分规则,包括一个额外的二阶项,这反映了随机过程的非光滑性。

然后我转向焦克-普朗克方程,它描述了随机微分方程解的概率密度如何随时间演化,漂移项和扩散项分别对应确定性和随机效应。

现在我定义分数函数作为对数概率密度的梯度,对于高斯分布它指向均值。分数匹配目标通过最小化预测分数与真实分数之间的差异来训练模型。接下来我需要推导安德森的反向时间随机微分方程... The probability flow ODE removes the stochasticity entirely by converting the noise term into a deterministic drift correction using the score function, while preserving the same marginal distributions as the SDE. For the VP-SDE used in DDPM, the forward process applies a variance-preserving schedule with drift and diffusion coefficients based on (\beta(t)), giving a Gaussian marginal distribution at each timestep that depends on the cumulative schedule integral. Now I'm working through the numerical integration methods for both SDEs and ODEs---the Euler-Maruyama approach adds stochastic noise at each step for the diffusion process, while the deterministic ODE solver uses standard Euler or Runge-Kutta methods without the noise term.

Let me verify Anderson's 1982 framework for the reverse-time diffusion equation. For a forward SDE with drift and diffusion terms, the reverse process running backward in time involves the score function---the gradient of the log probability---which appears in the drift term alongside the negated forward drift. So the reverse SDE in the Song et al. convention has time running backwards, and there's also a probability flow ODE that replaces the stochastic term with a deterministic drift adjustment. The key formulations are the forward SDE with drift and diffusion, the reverse SDE with the score function term, and the deterministic ODE variant that removes the noise.

Now I'm thinking about how to connect this to the broader mathematical framework---specifically how the Fokker-Planck equation relates to the continuity equation for these diffusion processes.

The key insight is that in the ODE case, we have a pure continuity equation without diffusion, but when we add the score-weighted drift term to account for the stochastic component, we recover the full Fokker-Planck equation with its diffusion term. This is why the probability flow ODE and the original SDE share the same marginal distributions at each timestep.

I should also bring in denoising score matching as the practical bridge---it's what connects these theoretical score functions to actual neural network training, which is essential for understanding how these methods work in practice.

Now I'm ready to write out the full document with all three frameworks clearly explained. 现在我要写出完整的内容。让我验证一下 VE-SDE 和 VP-SDE 的具体形式------VE-SDE 只有扩散项,边际分布是标准高斯,对应 NCSN;而 VP-SDE 既有漂移项又有扩散项,边际分布中的方差由 αˉt\bar\alpha_tαˉt 控制,这就是 DDPM 的数学基础。

当 t→Tt \to Tt→T 时,αˉT≈0\bar\alpha_T \approx 0αˉT≈0,所以最终分布趋向标准正态分布。关键的连接点在于噪声预测:从前向过程的转移核出发,我们可以用 xt=αˉtx0+1−αˉtϵx_t = \sqrt{\bar\alpha_t}x_0 + \sqrt{1-\bar\alpha_t}\epsilonxt=αˉt x0+1−αˉt ϵ 这个形式来表示,然后通过计算对数概率的梯度得到 score 函数。

这个 score 与噪声项 ϵ\epsilonϵ 成反比,所以训练一个噪声预测网络 ϵθ\epsilon_\thetaϵθ 就能近似 score,进而用于反向 SDE 的采样过程。

现在我要推导概率流 ODE,它通过移除随机项来给出确定性的生成路径。

完成了 VP-SDE 的推导后,我可以看到 DDIM 采样器实际上就是这个概率流 ODE 在离散时间上的实现。现在我有了所有的关键部分,可以开始写完整的回答了。

我会用大的 markdown 文档来组织,分成多个部分和子部分。在 SDE 部分的总结中,我想展示完整的连接链:VP-SDE → Fokker-Planck 方程 → 得分函数 → 反向 SDE/概率流 ODE → DDPM(离散化)/ DDIM(概率流 ODE)。这样能清楚地展示所有内容如何相互关联。

用户要求的结构是先给出完整优化后的原始文档,然后在末尾补充 SDE 和 ODE 的相关知识,所以我需要确保先完成修正后的文档部分,再加上新的补充章节。

现在开始写完整的回复,注意数学公式要用 (...) 或 ......... 的格式,不能用单个美元符号。

以下是完整优化后的文档(已修正上一轮评审指出的所有问题),以及末尾新增的 SDE 与 ODE 基础补充章节。


从 Diffusion 到 Reflected Flow:系统梳理

从扩散模型(Diffusion)到流匹配(Flow Matching),再到引入几何与边界约束的反射流(Reflected Flow),这一系列发展的本质是在寻找更高效、更灵活、更符合物理或几何约束的概率分布变换路径


1. DDPM(Denoising Diffusion Probabilistic Models)

思路: DDPM 的核心思想是对 VP-SDE(方差保持随机微分方程)的马尔可夫链离散化近似。它通过在数据中逐步添加高斯噪声来破坏结构(前向过程),然后训练神经网络逆转这一过程(反向过程),从纯噪声中恢复原始数据。

前向过程(加噪):

q(xt∣xt−1)=N ⁣(xt;  1−βt xt−1,  βtI)q(x_t \mid x_{t-1}) = \mathcal{N}\!\left(x_t;\; \sqrt{1-\beta_t}\, x_{t-1},\; \beta_t \mathbf{I}\right)q(xt∣xt−1)=N(xt;1−βt xt−1,βtI)

利用高斯分布的累积乘积性质,令 (\bar{\alpha}t = \prod{s=1}^{t}(1-\beta_s)),可以写出任意时刻 (t) 的闭合形式边缘分布:

q(xt∣x0)=N ⁣(xt;  αˉt x0,  (1−αˉt)I)q(x_t \mid x_0) = \mathcal{N}\!\left(x_t;\; \sqrt{\bar{\alpha}_t}\, x_0,\; (1-\bar{\alpha}_t)\mathbf{I}\right)q(xt∣x0)=N(xt;αˉt x0,(1−αˉt)I)

反向过程(去噪):

pθ(xt−1∣xt)=N ⁣(xt−1;  μθ(xt,t),  Σθ(xt,t))p_\theta(x_{t-1} \mid x_t) = \mathcal{N}\!\left(x_{t-1};\; \mu_\theta(x_t, t),\; \Sigma_\theta(x_t, t)\right)pθ(xt−1∣xt)=N(xt−1;μθ(xt,t),Σθ(xt,t))

优化目标(简化版), 网络实质上是在预测每个时间步加入的噪声 (\epsilon):

LDDPM=Et, x0, ϵ ⁣[∥ϵ−ϵθ(xt,t)∥2]L_{\mathrm{DDPM}} = \mathbb{E}{t,\, x_0,\, \epsilon}\!\left[\left\|\epsilon - \epsilon\theta(x_t, t)\right\|^2\right]LDDPM=Et,x0,ϵ[∥ϵ−ϵθ(xt,t)∥2]


2. DDIM(Denoising Diffusion Implicit Models)

思路: DDPM 的前向过程严格依赖马尔可夫假设,导致采样须逐步进行,极其缓慢。DDIM 的突破在于:只要保证每个时刻的边缘分布 (q(x_t \mid x_0)) 与 DDPM 相同,前向过程就不需要是马尔可夫的。通过将方差参数 (\sigma_t) 设为 (0),DDIM 将随机采样过程变成了确定性常微分方程(ODE)的求解过程,从而支持跳步采样。

需要特别说明的是,DDIM 原文中并未使用"概率流 ODE(probability flow ODE)"这一术语;(\sigma_t = 0) 的确定性采样器与 VP-SDE 概率流 ODE 的明确等价关系,是在 Song et al. 2021(Score-Based Generative Modeling through SDEs)中被纳入统一连续时间框架后才正式阐明的。

DDIM 采样公式:

xt−1=αˉt−1(xt−1−αˉt  ϵθ(xt,t)αˉt)⏟x^0:  预测的 x0+1−αˉt−1−σt2  ϵθ(xt,t)⏟指向 xt 的方向分量+σtϵx_{t-1} = \sqrt{\bar{\alpha}{t-1}} \underbrace{\left(\frac{x_t - \sqrt{1-\bar{\alpha}t}\;\epsilon\theta(x_t, t)}{\sqrt{\bar{\alpha}t}}\right)}{\hat{x}0:\;\text{预测的 }x_0} + \underbrace{\sqrt{1-\bar{\alpha}{t-1} - \sigma_t^2}\;\epsilon\theta(x_t, t)}_{\text{指向 }x_t\text{ 的方向分量}} + \sigma_t \epsilonxt−1=αˉt−1 x^0:预测的 x0 (αˉt xt−1−αˉt ϵθ(xt,t))+指向 xt 的方向分量 1−αˉt−1−σt2 ϵθ(xt,t)+σtϵ

当 (\sigma_t = 0) 时,采样过程完全确定,等价于对 VP-SDE 概率流 ODE 的数值积分。


3. Flow Matching(FM)

思路: Flow Matching 直接跳出了"加高斯噪声"的框架。FM 的核心是连续正则化流(CNF),它直接回归一个向量场,指导粒子从先验分布沿指定轨迹流向目标数据分布。

FM 相比概率流 ODE 方法的根本创新有两点。第一,通过条件化技巧 将难以直接计算的边际向量场 (u_t(x)) 分解为可直接监督学习的条件向量场,从而实现无需模拟 ODE 的训练(simulation-free training)------这是训练效率上的根本突破,而非单纯的路径几何优化。第二,可以自由选择传输路径:使用最优传输(OT)构建直线轨迹,大幅减小 ODE 求解的截断误差,用更少的函数评估次数(NFE)获得高质量样本。

概率密度路径与 ODE, 定义向量场 (v_\theta(x, t)),数据随时间演化满足:

dxdt=vθ(x,t)\frac{dx}{dt} = v_\theta(x, t)dtdx=vθ(x,t)

条件流匹配(CFM), 目标向量场以端点对 ((x_0, x_1)) 为联合条件,而非仅以 (x_1) 为条件。边缘向量场 (u_t(x)) 通过对 ((x_0, x_1)) 边缘化得到,但条件向量场 (u_t(x \mid x_0, x_1)) 可直接用于监督:

LCFM(θ)=Et,  (x0,x1)∼q(x0,x1),  x∼pt(x∣x0,x1) ⁣[∥vθ(x,t)−ut(x∣x0,x1)∥2]L_{\mathrm{CFM}}(\theta) = \mathbb{E}{t,\;(x_0,x_1)\sim q(x_0,x_1),\;x \sim p_t(x\mid x_0,x_1)}\!\left[\left\|v\theta(x, t) - u_t(x \mid x_0, x_1)\right\|^2\right]LCFM(θ)=Et,(x0,x1)∼q(x0,x1),x∼pt(x∣x0,x1)[∥vθ(x,t)−ut(x∣x0,x1)∥2]

该条件损失与边缘损失 (|v_\theta(x,t)-u_t(x)|^2) 具有相同的梯度,这一等价性是 FM 方法在理论上成立的核心支撑。

最优传输路径(OT-Flow), 定义从噪声 (x_0) 到数据 (x_1) 的直线插值路径:

xt=(1−t)x0+t x1x_t = (1-t)x_0 + t\, x_1xt=(1−t)x0+tx1

对应的条件目标向量场为常数速度:

ut(xt∣x0,x1)=x1−x0u_t(x_t \mid x_0, x_1) = x_1 - x_0ut(xt∣x0,x1)=x1−x0


4. Reflected Flow

思路: 标准 Diffusion 和 Flow Matching 假设数据分布在整个欧几里得空间 (\mathbb{R}^d) 中。在很多实际场景下(如机器人关节角度受限、分子生成中的几何约束),数据位于有边界的域 (\Omega) 或特定流形上,无约束模型生成的样本容易越界。

Reflected Flow 引入随机分析中的反射边界条件(Skorokhod 反射问题),当粒子触碰边界时获得向内推力,确保生成过程严格遵守约束。需要说明的是,"反射"在不同工作中有不同的具体实现:可以是镜像反射(将超出边界的直线轨迹折叠回域内),可以是以反射布朗运动为前向过程重新设计整个扩散链,也可以是在黎曼流形上沿测地线折返。镜像反射只是众多方案之一,更一般的框架是在域内重新定义合法的传输路径,或直接以反射随机微分方程作为前向过程。

反射随机微分方程(Reflected SDE), 在域 (\Omega) 内过程被描述为:

dXt=μ(Xt,t) dt+σ(Xt,t) dWt+n(Xt) dLtdX_t = \mu(X_t, t)\,dt + \sigma(X_t, t)\,dW_t + \mathbf{n}(X_t)\,dL_tdXt=μ(Xt,t)dt+σ(Xt,t)dWt+n(Xt)dLt

其中 (\mathbf{n}(X_t)) 是边界处的向内单位法向量,局部时间 (L_t)(Local Time)仅在 (X_t \in \partial\Omega) 时增加,提供将粒子推回 (\Omega) 内的力。


总结:区别与联系

维度 DDPM DDIM Flow Matching Reflected Flow
数学框架 SDE / 马尔可夫链 ODE / 隐式非马尔可夫 CNF / 无模拟 ODE 向量场回归 带局部时间的 Reflected SDE/ODE
轨迹特性 弯曲、随机游走 弯曲,取决于加噪策略 可自定义,OT 情形为直线 受限于域 (\Omega),边界处折返
训练目标 预测噪声 (\epsilon) 预测噪声 (\epsilon) 预测条件速度场 (u_t(x!\mid!x_0,x_1)) 预测含边界反射信息的速度场
核心优势 理论完善,多样性好 采样加速,确定性生成 无模拟训练,路径短,易扩展 严格几何/物理安全性保证

DDPM 确立了"破坏-重建"范式,但马尔可夫 SDE 离散化步数多、效率低。DDIM 证明了打破马尔可夫假设并令方差为零,即可将采样退化为确定性 ODE,实现跳步加速;Song et al. 2021 进一步将其与 VP-SDE 的概率流 ODE 在连续时间框架下统一。既然采样本质是 ODE,Flow Matching 彻底泛化了这一思想:通过条件化技巧实现无模拟训练,并以 OT 直线路径替代弯曲路径,同时提升训练效率与采样质量。Reflected Flow 则是对所有框架的空间泛化,将生成过程从无约束的 (\mathbb{R}^d) 推广到有边界的合法域 (\Omega),反射机制是使其满足硬约束的关键修正。



附录:SDE 与 ODE 基础------理解扩散模型的数学基石


A.1 常微分方程(ODE)与连续性方程

常微分方程(Ordinary Differential Equation, ODE)描述的是一个确定性系统的演化,其基本形式为:

dxdt=f(x,t),x(0)=x0\frac{dx}{dt} = f(x, t), \quad x(0) = x_0dtdx=f(x,t),x(0)=x0

在 Lipschitz 条件下,上述方程有唯一解,可用流映射(flow map)(\Phi_t: x_0 \mapsto x(t)) 表示。对于生成建模,我们希望这个流映射能将简单的先验分布(如标准正态分布 (p_0 = \mathcal{N}(0, \mathbf{I})))变换为复杂的数据分布 (p_1)。

当概率密度 (p_t(x)) 随向量场 (f(x,t)) 演化时,它所满足的方程叫做连续性方程(Continuity Equation),也称无源守恒方程:

∂pt∂t+∇x⋅(f(x,t) pt(x))=0\frac{\partial p_t}{\partial t} + \nabla_x \cdot \bigl(f(x,t)\, p_t(x)\bigr) = 0∂t∂pt+∇x⋅(f(x,t)pt(x))=0

这是 Flow Matching 的理论基础:只要学到正确的向量场 (f),就能驱动概率密度从 (p_0) 演化到 (p_1),且概率总量严格守恒。


A.2 维纳过程与布朗运动

维纳过程(Wiener Process)({W_t}_{t \ge 0}) 是随机微分方程中随机驱动力的数学本体,它满足以下四条性质:

第一,初始值为零:(W_0 = 0);第二,路径几乎处处连续;第三,增量独立:对于任意 (s < t),(W_t - W_s) 与 (\mathcal{F}_s)((s) 时刻之前的全部信息)独立;第四,增量服从高斯分布:(W_t - W_s \sim \mathcal{N}(0,, (t-s)\mathbf{I}))。

直觉上,在每个无穷小时间步 (dt) 内,过程受到一个随机扰动 (dW_t),其方差正比于时间步长:(dW_t \sim \mathcal{N}(0, dt\cdot\mathbf{I}))。这个"方差随时间积累"的性质使得布朗运动的路径虽然连续,却处处不可微,这也是它与普通积分的本质区别所在。


A.3 伊藤随机微分方程(Itô SDE)

伊藤 SDE 在 ODE 的确定性漂移之上叠加了由维纳过程驱动的随机扰动:

dXt=f(Xt,t)⏟漂移(drift) dt+g(Xt,t)⏟扩散系数(diffusion) dWtdX_t = \underbrace{f(X_t, t)}{\text{漂移(drift)}}\,dt + \underbrace{g(X_t, t)}{\text{扩散系数(diffusion)}}\,dW_tdXt=漂移(drift) f(Xt,t)dt+扩散系数(diffusion) g(Xt,t)dWt

其积分形式为:

Xt=X0+∫0tf(Xs,s) ds+∫0tg(Xs,s) dWsX_t = X_0 + \int_0^t f(X_s, s)\,ds + \int_0^t g(X_s, s)\,dW_sXt=X0+∫0tf(Xs,s)ds+∫0tg(Xs,s)dWs

右侧第二项是伊藤积分 ,因为被积函数 (g) 在每个微小区间内须在区间左端点估值(与黎曼积分的中点估值不同),这一选择带来了与普通微积分不同的链式法则。

在扩散模型中,漂移系数 (f) 控制数据均值的演化,扩散系数 (g) 控制噪声注入的强度。


A.4 伊藤引理:随机链式法则

设 (\phi(X_t, t)) 是关于随机过程的光滑函数,伊藤引理给出其微分形式:

dϕ=(∂ϕ∂t+∇xϕ⋅f+12tr⁡ ⁣(g⊤∇x2ϕ  g))dt+∇xϕ⋅g dWtd\phi = \left(\frac{\partial \phi}{\partial t} + \nabla_x \phi \cdot f + \frac{1}{2}\operatorname{tr}\!\left(g^\top \nabla^2_x \phi\; g\right)\right)dt + \nabla_x \phi \cdot g\,dW_tdϕ=(∂t∂ϕ+∇xϕ⋅f+21tr(g⊤∇x2ϕg))dt+∇xϕ⋅gdWt

与普通链式法则相比,多出了二阶项 (\frac{1}{2}\operatorname{tr}(g^\top \nabla^2_x \phi; g)),这来自于布朗运动的二次变差性质:((dW_t)^2 = dt)(在均方意义下)。这一"伊藤修正项"是随机微积分区别于确定性微积分的核心特征,也是推导 Fokker-Planck 方程的关键工具。


A.5 Fokker-Planck 方程:概率密度的演化

Fokker-Planck 方程(也称前向 Kolmogorov 方程)描述了在 SDE 驱动下概率密度函数 (p_t(x)) 随时间的演化。对于漂移为 (f(x,t))、标量扩散系数为 (g(t)) 的 SDE,Fokker-Planck 方程为:

∂pt(x)∂t=−∇x⋅[f(x,t) pt(x)]+g(t)22 Δxpt(x)\frac{\partial p_t(x)}{\partial t} = -\nabla_x \cdot \bigl[f(x,t)\, p_t(x)\bigr] + \frac{g(t)^2}{2}\, \Delta_x p_t(x)∂t∂pt(x)=−∇x⋅[f(x,t)pt(x)]+2g(t)2Δxpt(x)

方程右侧由两项组成:第一项 (-\nabla_x \cdot (f p_t)) 是对流项 ,描述漂移对分布的搬运;第二项 (\frac{g^2}{2}\Delta_x p_t) 是扩散项,描述噪声注入导致的分布弥散。

将 Fokker-Planck 方程与连续性方程对比,可以得到一个深刻的洞见:SDE 驱动下的概率密度演化,等价于一个"有效向量场" (\tilde{f}(x,t)) 驱动的 ODE,只需令

f~(x,t)=f(x,t)−g(t)22 ∇xlog⁡pt(x)\tilde{f}(x,t) = f(x,t) - \frac{g(t)^2}{2}\, \nabla_x \log p_t(x)f~(x,t)=f(x,t)−2g(t)2∇xlogpt(x)

满足连续性方程。这正是概率流 ODE 的核心思想,留待 A.8 节详述。


A.6 得分函数与去噪得分匹配

得分函数(Score Function) 定义为对数概率密度关于 (x) 的梯度:

st(x)=∇xlog⁡pt(x)s_t(x) = \nabla_x \log p_t(x)st(x)=∇xlogpt(x)

它是一个向量场,在空间中每一点指向概率密度增大最快的方向。对于高斯分布 (\mathcal{N}(\mu, \sigma^2\mathbf{I})),得分函数为 (-\frac{x-\mu}{\sigma^2}),即指向均值的方向。

得分函数之所以在生成建模中如此重要,是因为它完全决定了概率分布的形状,且无需知道归一化常数。然而直接估计 (\nabla_x \log p_t(x)) 需要已知真实分布,Vincent(2011)提出的**去噪得分匹配(Denoising Score Matching, DSM)**给出了一个可实际操作的训练目标:

LDSM=Et, x0, xt ⁣[∥sθ(xt,t)−∇xtlog⁡q(xt∣x0)∥2]\mathcal{L}{\mathrm{DSM}} = \mathbb{E}{t,\, x_0,\, x_t}\!\left[\left\|s_\theta(x_t, t) - \nabla_{x_t} \log q(x_t \mid x_0)\right\|^2\right]LDSM=Et,x0,xt[∥sθ(xt,t)−∇xtlogq(xt∣x0)∥2]

由于条件分布 (q(x_t \mid x_0)) 是已知的高斯分布,其得分 (\nabla_{x_t} \log q(x_t \mid x_0)) 可以解析计算。对于 DDPM 的前向过程,令 (x_t = \sqrt{\bar{\alpha}_t}, x_0 + \sqrt{1-\bar{\alpha}_t}, \epsilon),则:

∇xtlog⁡q(xt∣x0)=−ϵ1−αˉt\nabla_{x_t} \log q(x_t \mid x_0) = -\frac{\epsilon}{\sqrt{1-\bar{\alpha}_t}}∇xtlogq(xt∣x0)=−1−αˉt ϵ

因此,DDPM 的噪声预测网络 (\epsilon_\theta(x_t, t)) 与得分估计网络之间存在简单的线性关系:

sθ(xt,t)=∇xtlog⁡pt(xt)≈−ϵθ(xt,t)1−αˉts_\theta(x_t, t) = \nabla_{x_t} \log p_t(x_t) \approx -\frac{\epsilon_\theta(x_t, t)}{\sqrt{1-\bar{\alpha}_t}}sθ(xt,t)=∇xtlogpt(xt)≈−1−αˉt ϵθ(xt,t)

这揭示了 DDPM 训练的真实意义:预测噪声 (\epsilon) 本质上就是在学习得分函数,两者在数学上完全等价。


A.7 Anderson 反向时间 SDE

Anderson(1982)证明了一个奠基性定理:任何正向 SDE 过程都存在一个时间反转的 SDE,且两者具有相同的边缘分布序列。

正向 SDE:

dXt=f(Xt,t) dt+g(t) dWtdX_t = f(X_t, t)\,dt + g(t)\,dW_tdXt=f(Xt,t)dt+g(t)dWt

对应的反向时间 SDE(从 (T) 到 (0) 运行):

dXt=[f(Xt,t)−g(t)2 ∇xlog⁡pt(Xt)] dtˉ+g(t) dWˉtdX_t = \Bigl[f(X_t, t) - g(t)^2\, \nabla_x \log p_t(X_t)\Bigr]\,d\bar{t} + g(t)\,d\bar{W}_tdXt=[f(Xt,t)−g(t)2∇xlogpt(Xt)]dtˉ+g(t)dWˉt

其中 (d\bar{t}) 表示反向时间的无穷小步长,(\bar{W}_t) 是独立的反向时间维纳过程。

反向漂移由两部分组成:原始漂移 (f(X_t, t)) 加上一个"得分修正项" (-g(t)^2, \nabla_x \log p_t(X_t))。这个修正项的直觉意义是:它将粒子从低概率密度区域推向高概率密度区域,起到了"去噪"的作用。由于真实的得分函数未知,我们用神经网络 (s_\theta(x, t) \approx \nabla_x \log p_t(x)) 近似,从而将反向过程变为可以实际采样的过程。这就是扩散模型生成采样的数学本质。


A.8 概率流 ODE(Probability Flow ODE)

对比 Fokker-Planck 方程与连续性方程,Song et al.(2021)指出:可以从正向 SDE 中提取出一个确定性的 ODE,使其驱动的概率密度演化与原 SDE 完全相同(即任意时刻的边缘分布 (p_t) 相同):

dxdt=f(x,t)−12 g(t)2 ∇xlog⁡pt(x)\frac{dx}{dt} = f(x, t) - \frac{1}{2}\,g(t)^2\, \nabla_x \log p_t(x)dtdx=f(x,t)−21g(t)2∇xlogpt(x)

与反向 SDE 相比,概率流 ODE 将扩散系数减半(从 (g^2) 到 (\frac{1}{2}g^2)),消除了随机项,转变为纯确定性轨迹。两者具有相同边缘分布这一性质,从 Fokker-Planck 方程的角度来看,正是因为这两种演化方式对应的"有效向量场"都使概率密度满足同一个方程。

这一发现统一了 DDPM(随机采样)与 DDIM(确定性采样)的理论框架,并将 Flow Matching 纳入其中:Flow Matching 中学习的向量场 (v_\theta) 正是数据分布所对应的概率流 ODE 的向量场,只是通过更直接、更高效的训练方式获得。


A.9 扩散模型的 SDE 统一视角

Song et al.(2021)将现有的扩散模型统一纳入连续时间 SDE 框架,定义了两种典型的前向 SDE:

VP-SDE(方差保持,对应 DDPM):

dXt=−12β(t)Xt dt+β(t) dWtdX_t = -\frac{1}{2}\beta(t)X_t\,dt + \sqrt{\beta(t)}\,dW_tdXt=−21β(t)Xtdt+β(t) dWt

其边缘分布可以解析求得:令 (\bar{\alpha}(t) = e{-\int_0t \beta(s)ds}),则:

pt(xt∣x0)=N ⁣(xt;  αˉ(t) x0,  (1−αˉ(t))I)p_t(x_t \mid x_0) = \mathcal{N}\!\left(x_t;\; \sqrt{\bar{\alpha}(t)}\, x_0,\;\bigl(1 - \bar{\alpha}(t)\bigr)\mathbf{I}\right)pt(xt∣x0)=N(xt;αˉ(t) x0,(1−αˉ(t))I)

令 (\bar{\alpha}_t = e{-\int_0t \beta(s)ds}),这与 DDPM 离散前向过程的边缘分布形式完全吻合,说明 DDPM 是 VP-SDE 的 Euler-Maruyama 离散化版本。当 (t \to T) 时 (\bar{\alpha}(T) \approx 0),分布趋近于标准正态,为采样提供了初始噪声。

VE-SDE(方差爆炸,对应 NCSN/NCSNv2):

dXt=d[σ2(t)]dt dWtdX_t = \sqrt{\frac{d\left[\sigma^2(t)\right]}{dt}}\,dW_tdXt=dtd[σ2(t)] dWt

其边缘分布为 (p_t(x_t \mid x_0) = \mathcal{N}(x_t;, x_0,, \sigma^2(t)\mathbf{I})),即方差随时间单调增大直至"爆炸",数据均值始终保持在 (x_0)。

两类 SDE 的比较: VP-SDE 同时压缩均值、增大方差,保持总方差(均值平方 + 方差)大致守恒;VE-SDE 只增大方差、不改变均值,最终分布的方差远大于 1。前者更适合图像等有界数据的生成(收敛到标准正态),后者在理论分析上更简洁。

核心链路总结:

正向 VP-SDE 通过 Fokker-Planck 方程确定了每个时刻的边缘分布 (p_t),去噪得分匹配使神经网络 (\epsilon_\theta) 学到了这些分布的得分函数,有了得分函数便可以构造反向时间 SDE(对应 DDPM 随机采样)或概率流 ODE(对应 DDIM 确定性采样),而 DDPM 和 DDIM 的具体算法不过是在离散时间步上对这两条路径的数值近似。


A.10 数值求解方法

对于 SDE,最常用的是 Euler-Maruyama 方法,它将时间步 (h) 内的连续演化近似为:

Xt+h≈Xt+f(Xt,t) h+g(t)h  ξ,ξ∼N(0,I)X_{t+h} \approx X_t + f(X_t, t)\,h + g(t)\sqrt{h}\;\xi, \quad \xi \sim \mathcal{N}(0, \mathbf{I})Xt+h≈Xt+f(Xt,t)h+g(t)h ξ,ξ∼N(0,I)

这是一阶方法,对 SDE 的强收敛阶为 (\mathcal{O}(\sqrt{h})),弱收敛阶为 (\mathcal{O}(h))。DDPM 的每个去噪步骤本质上就是一个 Euler-Maruyama 步。

对于 ODE,最简单的是 Euler 方法

xt+h≈xt+f(xt,t) hx_{t+h} \approx x_t + f(x_t, t)\,hxt+h≈xt+f(xt,t)h

更高阶的 Runge-Kutta 方法(如 RK4、Dormand-Prince)通过在一个步长内多次评估向量场来提高精度,这正是 DDIM 跳步采样(用少步数获得高质量结果)在理论上优于 DDPM 逐步采样的数学原因:ODE 的收敛阶为 (\mathcal{O}(h^p))((p) 阶方法),而 SDE 的强收敛阶只有 (\mathcal{O}(\sqrt{h})),确定性轨迹天然对大步长更鲁棒。

这也解释了为什么 Flow Matching 选择直线路径如此关键:ODE 轨迹越直(曲率越低),高阶数值方法越能准确追踪,单步误差越小,所需的 NFE 就越少。

相关推荐
FrontAI1 小时前
深入浅出 LangGraph —— 第8章:人机交互:中断与审批流程
人工智能·langchain·人机交互·ai agent·langgraph
mahtengdbb11 小时前
三阶段压缩瓶颈改进YOLOv26特征提取效率与通道自适应能力提升
人工智能·yolo·目标跟踪
嵌入式小企鹅1 小时前
CPU需求变化、RISC-V安全方案、DeepSeek V4适配、太空算力动态
人工智能·驱动开发·华为·开源·算力·risc-v
HyperAI超神经1 小时前
利用堆叠集成学习,英国研究团队实现251颗盾牌座δ型星星震学指数高精度预测
人工智能·机器学习·集成学习
AI刀刀1 小时前
手机deepseek怎么导出pdf
人工智能·ai·pdf·豆包·deepseek·ds随心转
专注&突破1 小时前
用AI学习graphify
人工智能·学习
wayz111 小时前
Day 16 编程实战:PCA主成分分析与技术指标降维
人工智能·算法·机器学习
超梦dasgg1 小时前
SpringAi学习
人工智能·学习·ai编程
05大叔1 小时前
贝叶斯,支持向量机,深度学习
人工智能·分类·数据挖掘