# 伴随方法

伴随方法通过求解一个辅助线性方程——伴随方程——来计算单个标量目标函数对众多输入参数的梯度。其成本本质上与参数数量无关：只需额外求解一次与前向问题规模相当的系统，而有限差分则需要对每个参数各做一次前向求解。据报告，计算一个目标函数及其完整梯度的成本约为一次目标函数评估的2至5倍，且梯度是精确的而非近似值。<sup>[1](https://twister.caps.ou.edu/OBAN2019/Giering_recipe4adjoint.pdf)</sup> 在神经网络中，同样的计算被称为反向传播；在自动微分中，则称为反向模式微分。<sup>[2](https://math.mit.edu/~stevenj/18.336/adjoint.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 计算内容 | 通过一次伴随求解，计算单个标量目标函数对所有参数的梯度<sup>[2](https://math.mit.edu/~stevenj/18.336/adjoint.pdf)</sup> |
| 成本与参数的关系 | 几乎与模型参数数量无关；只需额外求解一个线性系统<sup>[3](https://adsabs.harvard.edu/pdf/2006GeoJI.167..495P)</sup> |
| 成本与前向运行的关系 | 约为一次目标函数评估的2至5倍<sup>[1](https://twister.caps.ou.edu/OBAN2019/Giering_recipe4adjoint.pdf)</sup>；通过自动微分实现的离散伴随为2至20次原始模拟<sup>[4](https://drops.dagstuhl.de/storage/04dagstuhl-reports/volume04/issue09/14371/DagRep.4.9.1/DagRep.4.9.1.pdf)</sup> |
| 与有限差分的比较 | 至少需要 \( n + 1 \) 次前向运行；对于 \( n = 10^{6} \) 且单次模拟耗时1分钟的情形，伴随方法需1至100分钟，而有限差分需近两年<sup>[5](https://www.sciencedirect.com/science/article/pii/S0010465515004099)</sup> |
| 线性性 | 伴随方程始终是线性的，即使前向方程非线性<sup>[6](https://www.oden.utexas.edu/media/reports/2023/2304.pdf)</sup> |
| 等价关系 | 反向传播 = 伴随方法 = 反向模式自动微分<sup>[2](https://math.mit.edu/~stevenj/18.336/adjoint.pdf)</sup><sup> • </sup><sup>[7](https://mml-book.github.io/neurips2020/10-adjoint.pdf)</sup> |
| 主要局限 | 时间相关问题需存储前向轨迹；若不加以控制，10分钟的运行约需1太字节<sup>[8](https://epubs.siam.org/doi/10.1137/1.9780898717761.ch12)</sup> |

## 工作原理

对于前向模型 \( g(x, p) = 0 \)，其中状态为 \( x \)、参数为 \( p \)、目标函数为 \( f(x) \)，构造拉格朗日量 \( L(x, p, \lambda) \equiv f(x) + \lambda^{T} g(x, p) \)，其中 \( \lambda \) 汇集了拉格朗日乘子。选择 \( \lambda \) 使其满足伴随方程 \( g_{x}^{T} \lambda = -f_{x} \)，即可消去状态敏感度 \( x_{p} \)，留下梯度 \( \frac{df}{dp} = \lambda^{T} g_{p} \)。<sup>[9](https://cs.stanford.edu/~ambrad/adjoint_tutorial.pdf)</sup> 对于线性系统 \( Ax = b \)，等价形式为 \( \frac{dg}{dp} = g_{p} - \lambda^{T}(A_{p}x - b_{p}) \)。<sup>[2](https://math.mit.edu/~stevenj/18.336/adjoint.pdf)</sup>

即使前向模型是非线性的，伴随方程也是线性的<sup>[6](https://www.oden.utexas.edu/media/reports/2023/2304.pdf)</sup>，且伴随问题与原系统具有相同的规模、条件数和特征值谱；LU分解 \( A = LU \) 直接给出 \( A^{T} = U^{T}L^{T} \)，因此伴随求解并不比前向求解更难。<sup>[2](https://math.mit.edu/~stevenj/18.336/adjoint.pdf)</sup>

## 实现方式

基本的优化循环包含四个步骤<sup>[10](https://www.crewes.org/Documents/ResearchReports/2010/CRR201091.pdf)</sup>：求解前向问题以获得残差和目标函数 \( E(p) \)；求解伴随问题并与前向解结合得到 \( \nabla_{p} E(p) \)；执行线搜索确定步长 \( \alpha \)；更新模型 \( p^{(k+1)} = p^{(k)} - \alpha \nabla_{p} E(p) \)。对于时间相关问题，计算一次梯度需要对模型方程在观测窗口内进行一次前向积分，然后对伴随方程进行一次反向积分。<sup>[11](https://ui.adsabs.harvard.edu/abs/1987QJRMS.113.1311T/abstract)</sup>

离散伴随通过自动微分构建。在前向评估过程中，磁带记录算子的求值顺序，梯度则通过沿该记录顺序反向传播余切量，以无矩阵的向量-雅可比乘积形式计算。<sup>[12](https://pmc.ncbi.nlm.nih.gov/articles/PMC13080004/)</sup> 软件实现包括dolfin-adjoint，它计算泛函对已声明的控制变量（如初始条件）的梯度<sup>[13](https://dolfin-adjoint-doc.readthedocs.io/en/latest/documentation/tutorial.html)</sup>，以及基于PyTorch Autograd、JAX或源代码转换构建的可微模拟器。<sup>[14](https://mpan31415.github.io/assets/pdf/papers/2024/IEEEAccess24_DiffSim.pdf)</sup>

## 起源

伴随方法源自拉格朗日对偶问题，其主要思想与庞特里亚金最大值原理相关<sup>[15](http://www.nature.com/articles/s42005-024-01606-9.pdf)</sup>；一个相关的早期里程碑是L. S. 庞特里亚金（L. S. Pontryagin）及其同事的著作《最优过程的数学理论》（*The Mathematical Theory of Optimal Processes*，1965年，OR）。<sup>[16](https://doi.org/10.2307/3006724)</sup> 在气象学中，塔拉格朗（Talagrand）和库尔捷（Courtier）（1987年，《皇家气象学会季刊》）证明了伴随方程可计算距离函数对模型初始条件的梯度，并将该理论应用于涡度方程，在豪尔维茨波上取得了成功的实验。<sup>[11](https://ui.adsabs.harvard.edu/abs/1987QJRMS.113.1311T/abstract)</sup><sup> • </sup><sup>[17](https://doi.org/10.1002/qj.49711347812)</sup>

在地球物理学中，伴随状态对应于反向传播的波场，最小二乘失配函数的梯度充当偏移算子。<sup>[3](https://adsabs.harvard.edu/pdf/2006GeoJI.167..495P)</sup> 在计算方面，安德烈亚斯·格里万克（Andreas Griewank）1992年发表在《优化方法与软件》上的论文实现了反向自动微分中时间和空间复杂度的对数增长，这构成了检查点技术的基础。<sup>[18](https://doi.org/10.1080/10556789208805505)</sup> 在机器学习中，Chen、Rubanova、Bettencourt和Duvenaud（2018年，arXiv）使用伴随敏感度方法训练神经常微分方程，以恒定内存成本在时间上反向求解一个增广ODE。<sup>[19](https://papers.nips.cc/paper/2018/file/69386f6bb1dfed68692a24c8686939b9-Paper.pdf)</sup><sup> • </sup><sup>[20](https://doi.org/10.48550/arxiv.1806.07366)</sup>

## 变体

**连续伴随与离散伴随。** 连续伴随方法解析地推导原始数学模型的伴随，然后对其进行离散化；其成本约为2次原始模拟，但数学上可能具有挑战性，且与原始离散化在数值上可能不一致。<sup>[4](https://drops.dagstuhl.de/storage/04dagstuhl-reports/volume04/issue09/14371/DagRep.4.9.1/DagRep.4.9.1.pdf)</sup> 离散伴随对离散化后的模型进行微分，通常通过对代码进行算法微分来实现；其成本在2至20次原始模拟之间，有时更多，但与网格点数量无关。<sup>[4](https://drops.dagstuhl.de/storage/04dagstuhl-reports/volume04/issue09/14371/DagRep.4.9.1/DagRep.4.9.1.pdf)</sup>

**检查点调度。** 离线最优策略在Revolve库中实现，被ADOL-C、ADtool、Tapenade和dolfin-adjoint等自动微分工具采用。<sup>[21](https://arxiv.org/pdf/2106.13879)</sup> 多级多层检查点技术由Guillaume Aupy、Julien Herrmann、Paul Hovland和Yves Robert研究（2016年，《SIAM科学计算杂志》）。<sup>[22](https://doi.org/10.1137/15m1019222)</sup>

## 应用

**天气与海洋。** 气象学和海洋学中的伴随模型服务于资料同化、模型调优、敏感度分析和奇异向量计算<sup>[1](https://twister.caps.ou.edu/OBAN2019/Giering_recipe4adjoint.pdf)</sup>，伴随方法被认为是四维变分资料同化（4D-Var）不可或缺的工具。<sup>[12](https://pmc.ncbi.nlm.nih.gov/articles/PMC13080004/)</sup>

**地震成像。** 全波形反演建立在伴随状态方法之上，反向模式自动微分在数学上与之等价；这一等价关系构成了ADSeismic库的基础，用于速度模型估计、破裂成像和震源反演。<sup>[23](https://arxiv.org/pdf/2003.06027)</sup>

**气动设计。** 伴随设计已应用于势流、欧拉方程和纳维-斯托克斯方程，涵盖二维翼型、三维机翼和完整飞机配置。<sup>[24](https://people.maths.ox.ac.uk/gilesm/files/ftc00.pdf)</sup> 连续伴随以约两次流场计算的代价获得完整的梯度信息，且与设计参数数量无关。<sup>[25](https://www.sciengine.com/doi/pdf/6c4b54f6f8544412a8e2ba70f38ff0e8)</sup>

**机器学习与模拟。** 神经常微分方程通过伴随敏感度方法经由任意ODE求解器计算梯度。<sup>[19](https://papers.nips.cc/paper/2018/file/69386f6bb1dfed68692a24c8686939b9-Paper.pdf)</sup><sup> • </sup><sup>[20](https://doi.org/10.48550/arxiv.1806.07366)</sup> 可微模拟器计算标量目标函数对众多模拟参数的梯度，使用反向模式自动微分。<sup>[14](https://mpan31415.github.io/assets/pdf/papers/2024/IEEEAccess24_DiffSim.pdf)</sup>

## 局限与替代方案

**选择微分模式。** 前向（切线性）算法对于多输出少参数的情形更高效；伴随算法适用于少输出多参数的情形。<sup>[26](https://ar5iv.labs.arxiv.org/html/1202.5229)</sup> 前向敏感度分析在变量数量上是二次时间复杂度的，而伴随敏感度分析是线性的。<sup>[19](https://papers.nips.cc/paper/2018/file/69386f6bb1dfed68692a24c8686939b9-Paper.pdf)</sup> 与有限差分相比，伴随梯度的成本为2至5次评估且是精确的；对于 \( n = 10^{6} \) 个参数和1分钟的模拟，伴随自动微分需1至100分钟，而有限差分至少需要 \( 10^{6} + 1 \) 分钟，近两年。<sup>[1](https://twister.caps.ou.edu/OBAN2019/Giering_recipe4adjoint.pdf)</sup><sup> • </sup><sup>[5](https://www.sciencedirect.com/science/article/pii/S0010465515004099)</sup>

**内存。** 保存一次10分钟评估的所有中间结果（以每秒数亿次运算运行）大约需要1太字节<sup>[8](https://epubs.siam.org/doi/10.1137/1.9780898717761.ch12)</sup>，因为存储量随问题规模和时间步数线性增长。<sup>[21](https://arxiv.org/pdf/2106.13879)</sup> 检查点伴随将运行时间最多增至原来的2倍，同时将内存降至 \( N \cdot C \)，其中 \( C \) 为检查点数量。<sup>[27](https://arxiv.org/pdf/1812.01892)</sup>

**失效模式。** 在洛伦兹吸引子等混沌系统中，前向和伴随计算中使用的线性化方程产生的解会指数增长，导致有限时间平均的敏感度发散。<sup>[26](https://ar5iv.labs.arxiv.org/html/1202.5229)</sup> 反向求解增广系统可能引入前向过程中不存在的失稳，如在扩散系统中；一种变通方法是在前向过程中以更高的内存成本保存额外的备份状态。<sup>[15](http://www.nature.com/articles/s42005-024-01606-9.pdf)</sup> 盲目地将自动微分应用于牛顿法或GMRES等迭代求解器会反向传播经过每个中间迭代，成本高昂，且自动微分工具无法在没有手动提供向量-雅可比乘积的情况下对调用外部库的代码进行微分。<sup>[2](https://math.mit.edu/~stevenj/18.336/adjoint.pdf)</sup>

## References

1. [Recipes for Adjoint Code Construction (Giering et al.)](https://twister.caps.ou.edu/OBAN2019/Giering_recipe4adjoint.pdf)
2. [Notes on Adjoint Methods for 18.335 (Steven G. Johnson, MIT)](https://math.mit.edu/~stevenj/18.336/adjoint.pdf)
3. [A review of the adjoint-state method for computing the gradient of a functional with geophysical applications](https://adsabs.harvard.edu/pdf/2006GeoJI.167..495P)
4. [Adjoint Methods in Computational Science, Engineering, and Finance (Dagstuhl seminar report)](https://drops.dagstuhl.de/storage/04dagstuhl-reports/volume04/issue09/14371/DagRep.4.9.1/DagRep.4.9.1.pdf)
5. [GPU-accelerated adjoint algorithmic differentiation](https://www.sciencedirect.com/science/article/pii/S0010465515004099)
6. [Adjoint Operators in Computational Sciences, Engineering, and Mathematics (Oden Institute Report 23-04)](https://www.oden.utexas.edu/media/reports/2023/2304.pdf)
7. [Method of Adjoints (Machine Learning: A Probabilistic Perspective, chapter draft / NeurIPS 2020 tutorial, Ong & Deisenroth)](https://mml-book.github.io/neurips2020/10-adjoint.pdf)
8. [Evaluating Derivatives, 2nd ed., Ch. 12: Reversal Schedules and Checkpointing (Griewank & Walther, 2008)](https://epubs.siam.org/doi/10.1137/1.9780898717761.ch12)
9. [The adjoint method (tutorial)](https://cs.stanford.edu/~ambrad/adjoint_tutorial.pdf)
10. [Tutorial on the continuous and discrete adjoint state method and basic implementation](https://www.crewes.org/Documents/ResearchReports/2010/CRR201091.pdf)
11. [Variational Assimilation of Meteorological Observations With the Adjoint Vorticity Equation. I: Theory (Talagrand & Courtier, 1987)](https://ui.adsabs.harvard.edu/abs/1987QJRMS.113.1311T/abstract)
12. [Fast automated adjoints for spectral PDE solvers (Dedalus)](https://pmc.ncbi.nlm.nih.gov/articles/PMC13080004/)
13. [dolfin-adjoint tutorial: First steps](https://dolfin-adjoint-doc.readthedocs.io/en/latest/documentation/tutorial.html)
14. [A Review of Differentiable Simulators (IEEE Access, 2024)](https://mpan31415.github.io/assets/pdf/papers/2024/IEEEAccess24_DiffSim.pdf)
15. [Adjoint methods for parameter estimation in differential equations (adoptODE tutorial, Communications Physics 2024)](http://www.nature.com/articles/s42005-024-01606-9.pdf)
16. [M. L. Chambers and colleagues (1965). The Mathematical Theory of Optimal Processes. OR.](https://doi.org/10.2307/3006724)
17. [Olivier Talagrand, Philippe Courtier (1987). Variational Assimilation of Meteorological Observations With the Adjoint Vorticity Equation. I: Theory. Quarterly Journal of the Royal Meteorological Society.](https://doi.org/10.1002/qj.49711347812)
18. [Andreas Griewank (1992). Achieving logarithmic growth of temporal and spatial complexity in reverse automatic differentiation. Optimization methods & software.](https://doi.org/10.1080/10556789208805505)
19. [Neural Ordinary Differential Equations (NeurIPS 2018)](https://papers.nips.cc/paper/2018/file/69386f6bb1dfed68692a24c8686939b9-Paper.pdf)
20. [Chen, Ricky T. Q. and colleagues (2018). Neural Ordinary Differential Equations. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1806.07366)
21. [Optimal checkpointing for adjoints of multistage time-stepping schemes (CAMS)](https://arxiv.org/pdf/2106.13879)
22. [Guillaume Aupy and colleagues (2016). Optimal Multistage Algorithm for Adjoint Computation. SIAM Journal on Scientific Computing.](https://doi.org/10.1137/15m1019222)
23. [A General Approach to Seismic Inversion with Automatic Differentiation (ADSeismic)](https://arxiv.org/pdf/2003.06027)
24. [An Introduction to the Adjoint Approach to Design (Giles & Pierce)](https://people.maths.ox.ac.uk/gilesm/files/ftc00.pdf)
25. [Continuous adjoint method for aerodynamic design optimization (external and internal flows)](https://www.sciengine.com/doi/pdf/6c4b54f6f8544412a8e2ba70f38ff0e8)
26. [Forward and Adjoint Sensitivity Computation of Chaotic Dynamical Systems](https://ar5iv.labs.arxiv.org/html/1202.5229)
27. [Performance and Scalability of Discrete Local Sensitivity Analysis via Automatic Differentiation versus Continuous Adjoint Sensitivity Analysis](https://arxiv.org/pdf/1812.01892)

---
*Initially written Sep 29, 2026 · Reviewed: Sep 30, 2026 · Edited: Sep 30, 2026 · Last review: Sep 30, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数学分析与数学模型 › Numerical analysis and computation

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/adjoint-method

English original: https://www.edgepedia.org/adjoint-method
