Generalization of partitioned Runge–Kutta methods for adjoint systems
Abstract
This study computes the gradient of a function of numerical solutions of ordinary differential equations (ODEs) with respect to the initial condition. The adjoint method computes the gradient approximately by solving the corresponding adjoint system numerically. In this context, Sanz-Serna [SIAM Rev., 58 (2016), pp. 3–33] showed that when the initial value problem is solved by a Runge–Kutta (RK) method, the gradient can be exactly computed by applying an appropriate RK method to the adjoint system. Focusing on the case where the initial value problem is solved by a partitioned RK (PRK) method, this paper presents a numerical method, which can be seen as a generalization of PRK methods, for the adjoint system that gives the exact gradient.
keywords:
adjoint method , partitioned Runge–Kutta method , geometric integrationMSC:
[2010] 65K10 , 65L05 , 65L09 , 65P101 Introduction
We consider a system of ordinary differential equations (ODEs) of the form
(1) |
with the initial condition , where is assumed to be sufficiently smooth. We denote the numerical approximation at by , where is the step size. Let be a differentiable function. This paper is concerned with the computation of , i.e. the gradient of with respect to the initial condition .
Calculating the gradient is a fundamental task when solving optimization problems such as
(2) |
A simple method of obtaining an approximation for the gradient is to compare with the numerical approximation corresponding to a perturbed initial condition. For example, may be regarded as an approximation of the th component of the gradient, where is a small scalar constant, and is the th column of the -dimensional identity matrix. However, this approach becomes computationally expensive when the dimensionality or the number of time steps is large. Further, the approximation accuracy could deteriorate significantly due to the discretization error. Alternatively, the adjoint method has been widely used in various fields such as variational data assimilation in meteorology and oceanography [4], inversion problems in seismology [5], optimal design in aerodynamics [6], and neural networks [2]. In this approach, the gradient is approximated by integrating the so-called adjoint system numerically. This approach is usually more efficient than the aforementioned approach using perturbed initial conditions; however, the approximation accuracy may still be limited when the collected discretization errors are large.
Recently, Sanz-Serna showed that the gradient can be computed exactly when the original system is integrated by a Runge–Kutta (RK) method [14]: the intended exact gradient is obtained by applying an appropriate RK method to the adjoint system. Note that even if the numerical integration of the original system (1) is not sufficiently accurate, a sufficiently accurate approximation or the exact computation of the gradient is often required. We provide two examples:
-
1.
The forward propagation of several deep neural networks is interpreted as a discretization of ODEs. For example, the Residual Network (ResNet), which is commonly used in pattern recognition tasks such as image classification, can be seen as an explicit Euler discretization [3]. Also, neural network architectures based on symplectic integrators for Hamiltonian systems have been developed recently, which avoid numerical instabilities [8]. Since the output of such neural networks is not the exact solution of ODE but its numerical approximation, their training is formulated as an optimization problem of the form (2). In other words, the backpropagation algorithm [7] is a special case of the adjoint method in this context.
-
2.
Let us consider solving the optimization problem of the form (2). If we apply the Newton method, we need to solve a linear system having the Hessian of the objective function with respect to the initial state as the coefficient matrix. When the linear system is solved by a Krylov subspace method such as the conjugate gradient (CG) method, the Hessian-vector multiplication needs to be computed. The adjoint method can be used to approximate the Hessian-vector multiplication [17, 18].111More precisely, the Hessian-vector multiplication is approximately computed by solving the so-called second-order adjoint system numerically. However, this approach usually results in applying the CG method to a non-symmetric linear system even though the exact Hessian is always symmetric, and consequently, its convergence is not always guaranteed. Symmetry can be ideally attained if the Hessian-vector multiplication is computed exactly [10]. We note that the need for computing the exact Hessian-vector multiplication also arises in the context of uncertainty quantification (see, e.g. [11, 16]).
To the best of authors’ knowledge, an algorithm that systematically computes the exact gradient has been developed only for the cases where the ODE system (1) is discretized by using RK methods; similar algorithms should be developed for other types of numerical methods. We note that while it may not be so difficult to construct an algorithm for a specific ODE solver, providing a recipe for a particular class of numerical methods is useful for practitioners. Among others, we focus on the class of partitioned RK (PRK) methods. A straightforward conjecture would be that the exact gradient is obtained by applying an appropriate PRK method to the adjoint system. Indeed, our previous report showed that this conjecture is true for the Störmer–Verlet method [13]. However, except for some special cases, this conjecture does not hold in general. In this study, we shall show that the exact gradient can be computed by a certain generalization of PRK methods.
2 Preliminaries
In this section, we review the adjoint method and the approach proposed by Sanz-Serna [14].
2.1 Adjoint method
Let be the solution to the system (1) for the perturbed initial condition . By linearising the system (1) at , we see that as it follows that , where solves the variational system
(3) |
The corresponding adjoint system, which is often introduced by using Lagrange multipliers, is given by
(4) |
Here, is the transpose of the Jacobian . For any solutions to (3) and (4), we see that ; thus, it follows that for all , so in particular,
(5) |
Because of the chain rule and the fact , we have
(6) |
By comparing (6) with (5), it is concluded that the solution to the adjoint system (4) with satisfies . In other words, solving the adjoint system (4) backwardly with the final condition gives .
Now, we compute the gradient .222As a particular case of , , here, we consider . The above discussion indicates that approximating the solution to the adjoint system (4) with the final condition gives an approximation of at . In general, the approximation accuracy depends on the accuracy of the numerical integrators for both the original system (1) and adjoint system (4).
2.2 Exact gradient calculation
In the following, we assume that is the approximation obtained by applying an RK method to the original system (1). In this case, Sanz-Serna showed in [14] that the gradient can be computed exactly (up to round-off in practical computation) by applying an appropriate RK method to the adjoint system (4). Below, we briefly review the procedure. The obvious argument will often be omitted.
Suppose that the original system (1) has been discretized by an -stage RK method characterized by and :
(7) | ||||
(8) | ||||
(9) |
with the initial condition . The pair of and will be simply denoted by . Correspondingly, the variational system (3) is discretized by the same RK method
(10) | ||||
(11) | ||||
(12) |
so that . We discretize the adjoint system (4) with an -stage RK method, which may differ from the RK method , characterized by the coefficients :
(13) |
with the final condition .
Combining the chain rule with , we see that . Therefore, if the approximation of the solution to the adjoint system (4) satisfies , in particular , it is concluded that . The theory of geometric numerical integration [9] tells us that if an RK method is chosen for the adjoint system such that the pair of the RK methods for the original and adjoint systems satisfies the condition for a partitioned RK (PRK) method to be canonical, the property is guaranteed and the gradient is exactly obtained as shown in Theorem 1. We note that the canonical numerical methods are well-known in the context of geometric numerical integration. For more details, we refer the reader to [9, Chapter VI] (for PRK methods, see also [1, 15]).
Theorem 1 ([14]).
Remark 1.
The conditions in Theorem 1 indicate that , which makes sense only when every weight is nonzero. However, for some RK methods one or more of the weights vanish. In such cases, the above conditions cannot be used to find an appropriate RK method for the adjoint system. We refer the reader to Appendix in [14] for a workaround.
3 Partitioned Runge–Kutta methods
We now restrict our attention to the system of ODEs in the partitioned form
(16) |
Suppose that this system has been discretized by a PRK method characterized by the pairs and :
(17) | ||||
(18) | ||||
(19) |
For clarity, every component of and is assumed to be nonzero. We discretize the variational system expressed as
(20) |
by the same PRK method
(21a) | ||||
(21b) | ||||
(21c) |
The corresponding adjoint system of (16) is written as
(22) |
for which the following final condition
(23) |
is imposed. We consider discretizing the adjoint system by the following formula
(24a) | ||||
(24b) | ||||
(24c) |
We note that the above formula ((24a), (24b), (24c)) does not necessarily belong to the class of PRK methods, and thus refer to the formula as a generalized PRK (GPRK) method.333This kind of generalization is only applicable for partitioned systems in which the vector field is decomposed into two parts. The formula falls into a PRK method only when the coefficients satisfy
(25) |
The following theorem shows that the gradient can be computed exactly by an appropriate GPRK method.
Theorem 2.
Assume that the original system (16) is solved by a PRK method characterized by and , and the coefficients of the GPRK method (24a)-(24c) for the adjoint system (22) satisfy
(26) | |||
(27) | |||
(28) | |||
(29) | |||
(30) | |||
(31) |
Then, by solving the adjoint system with the final condition (23), we obtain the exact gradient and .
Proof.
4 Examples
We consider several classes of PRK methods and show corresponding GPRK methods that are uniquely determined from the conditions in Theorem 2.
Example 1 (Symplectic PRK methods for Hamiltonian systems).
For Hamiltonian systems, the coefficients of most symplectic PRK methods, such as the Störmer–Verlet method and the 3-stage Lobatto IIIA–IIIB pair, satisfy
(44) | |||
(45) |
In this case, the coefficients of the GPRK method satisfying the conditions in Theorem 2 are explicitly given by
(46) |
where . The GPRK method reduces to a PRK method. We note that the GPRK method for the Störmer–Verlet method is consistent with the one which was presented in the context of inverse problem for ODEs [13], and essentially the same algorithm for a certain vector field can also be found in the context of deep neural networks [8].
Example 2 (Symplectic PRK methods for separable Hamiltonian systems).
For separable Hamiltonian systems, a PRK method is symplectic even if the first condition (44) is violated. We consider the case where . In this case, the GPRK method satisfying the conditions in Theorem 2 does not reduces to a PRK method. However, when the system (20) is separable, i.e. and , we see from (24b) that . Thus the coefficients , , and are no longer needed, and the GPRK method reduces to a PRK method. The remaining coefficients are explicitly given by
(47) |
Example 3 (Spatially partitioned embedded RK methods).
Spatially partitioned embedded RK methods are sometimes applied to a system of ODEs arising from discretizing partial differential equations [12]. The methods belong to a class of PRK methods with and . In this case, the GPRK method satisfying the conditions in Theorem 2 is no longer a PRK method. The coefficients are given by
(48) | |||
(49) |
5 Concluding remarks
In this paper, we have shown that the gradient of a function of numerical solutions to ODEs with respect to the initial condition can be systematically and efficiently computed when the ODE is solved by a partitioned Runge–Kutta method. The key idea is to apply a certain generalization of partitioned Runge–Kutta methods to the corresponding adjoint system. The proposed method is applicable to, for example, estimation of initial condition or underlying system parameters of ODE models and training of deep neural networks.
It is an interesting problem to construct a similar recipe for other types of ODE solvers such as linear multistep methods and exponential integrators. We are now working on this issue.
Acknowledgement
This work was supported in part by JST ACT-I Grant Number JPMJPR18US, and JSPS Grants-in-Aid for Early-Career Scientists Grant Numbers 16K17550 and 19K20220.
References
- Abia and Sanz-Serna [1993] L. Abia, J.M. Sanz-Serna, Partitioned Runge–Kutta methods for separable Hamiltonian problems, Math. Comp. 60 (1993) 617–634.
- Chen et al. [2018a] R.T. Chen, Y. Rubanova, J. Bettencourt, D. Duvenaud, Neural ordinary differential equations, arXiv:1806.07366 (2018a).
- Chen et al. [2018b] R.T.Q. Chen, Y. Rubanova, J. Bettencourt, D.K. Duvenaud, Neural ordinary differential equations, in: Advances in Neural Information Processing Systems 31, 2018b, pp. 6571–6583.
- Dimet and Talagrand [1986] F.X.L. Dimet, O. Talagrand, Variational algorithms for analysis and assimilation of meteorological observations: theoretical aspects, Tellus A 38A (1986) 97–110.
- Fichtner et al. [2006] A. Fichtner, H.P. Bunge, H. Igel, The adjoint method in seismology: I. theory, Phys. Earth Planet. In. 157 (2006) 86–104.
- Giles [2000] N.A. Giles, Michael B.and Pierce, An introduction to the adjoint approach to design, Flow, Turbul. Combust. 65 (2000) 393–415.
- Goodfellow et al. [2016] I. Goodfellow, Y. Bengio, A. Courville, Deep Learning, MIT Press, 2016. http://www.deeplearningbook.org.
- Haber and Ruthotto [2018] E. Haber, L. Ruthotto, Stable architectures for deep neural networks, Inverse Problems 34 (2018) 014004.
- Hairer et al. [2006] E. Hairer, C. Lubich, G. Wanner, Geometric Numerical Integration: Structure-Preserving Algorithms for Ordinary Differential quations, Springer-Verlag, Berlin, second edition, 2006.
- Ito et al. [2019] S. Ito, T. Matsuda, Y. Miyatake, Adjoint-based exact hessian-vector multiplication using symplectic runge–kutta methods, arXiv:1910.06524 (2019).
- Ito et al. [2016] S. Ito, H. Nagao, A. Yamanaka, Y. Tsukada, T. Koyama, M. Kano, J. Inoue, Data assimilation for massive autonomous systems based on a second-order adjoint method, Phys. Rev. E 94 (2016) 043307.
- Ketcheson et al. [2013] D.I. Ketcheson, C.B. MacDonald, S.J. Ruuth, Spatially partitioned embedded Runge-Kutta methods, SIAM J. Numer. Anal. 51 (2013) 2887–2910.
- Matsuda and Miyatake [2019] T. Matsuda, Y. Miyatake, Estimation of ordinary differential equation models with discretization error quantification, arXiv:1907.10565 (2019).
- Sanz-Serna [2016] J.M. Sanz-Serna, Symplectic Runge–Kutta schemes for adjoint equations, automatic differentiation, optimal control, and more, SIAM Rev. 58 (2016) 3–33.
- Sun [1993] G. Sun, Symplectic partitioned Runge–Kutta methods, J. Comput. Math. 11 (1993) 365–372.
- Thacker [1989] W.C. Thacker, The role of the hessian matrix in fitting models to measurements, J. Geophys. Res. Oceans 94 (1989) 6177–6196.
- Wang et al. [1998] Z. Wang, K. Droegemeier, L. White, The adjoint Newton algorithm for large-scale unconstrained optimization in meteorology applications, Comput. Optim. and Appl. 10 (1998) 283–320.
- Wang et al. [1992] Z. Wang, I.M. Navon, F.X.L. Dimet, X. Zou, The second order adjoint analysis: Theory and applications, Meteor. Atmos. Phys. 50 (1992) 3–20.