Problem and Goals
- Models for learning unknown dynamics in dynamical systems: dtdy(t)=f(y(t),t)
- Adapt the Neural ODE model with the adjoint method.
- To enforce the stability of the dynamics via Lypanunov constraints on the forward and adjoint equations.
The forward and backwards (adjoint equations) for a Neural ODE are dtdz(t)=fθ(z(t),t) dtda(t)=−a(t)T∂z(t)∂f(z(t),t)
The Lyapunov stability constraints for the two equation are: dtdV(z(t))<−αV(z(t)) dtdW(a(t))<−βW(a(t)). dtdW(a(t))=∇W(a(t))Ta′(t)=−∇W(a(t))Ta(t)T∂z(t)∂f(z(t),t) =−∇W(a(t))T∂z(t)∂LT∂z(t)∂f(z(t),t)=−∇W(a(t))T∂z(t)∂LT∂z(t)∂dtdz(t)
Neural ODEs
A neural ODE is a machine learning model where the output is a solution to an ordinary differential equation (ODE) governed by a learned dynamics function, which is a neural network. z(0)=g1(x)(wherexistheinput) dtdz(t)=fθ(z(t),t),0≤t≤T Output:y=g2(z(T))
Neural ODEs are in some way inspired by the similarity of residual neural networks and the Euler discretization of an ODE:zn+1=zn+fθn(zn)(residualnetwork) zn+1=zn+Δtfθ(zn,tn)(Eulerdiscretization)
by using neural ODEs, more advanced ODE solvers such as Runge-Kutta solvers and adaptive solvers like DOPRI.
Neural ODE adjoints
In order to train the Neural ODE, the gradient of the loss with respect to the parameter, ∂θ∂L, must be computed. The typical method of backpropagation used in neural networks can have high computation/memory cost when using ODE solvers. An alternative method for neural ODE is using the adjoint ODE. The adjoint ODE is solved backwards in time for the gradients. The adjoint state is defined by a(t)=∂z(t)∂L, and it solves the adjoint ODE, dtda(t)=−a(t)T∂z(t)∂fθ(z(t),t),T≥t≥0.
From the adjoint, the loss gradient can be computed by ∂θ∂L=−∫0Ta(t)T∂θ∂fθ(z(t),t).
Stability Criteria
Lyapunov Stability
An ODE is Lyapunov stable if ∀ϵ>0∃δ>0:∥z(0)∥<δ⇒∀t>0∥z(t)∥<ϵ.
Asymptotic Stability
An ODE is asymptoticly stable if limz→∞z(t)=0foranyinitialconditionz(0).
Exponential Stability
An ODE is exponentially stable with equilibrium ze if ∥z(t)∥≤Ce−αt∥z(0)∥forsomeC,α>0
Lyapunov Functions
A Lyapunov function is a function V:Rd→R such that V(z)>0 for z=0 and V(0)=0.
An ODE is asymptoticaly stable if there exists a Lyapunov function V such that dtdV(z(t))=∇V(z(t))Tz′(t)=∇V(z(t))Tf(z(t),t)<0.
An ODE is exponentially stable if there exists a Lyapunov function V such that dtdV(z(t))=∇V(z(t))Tz′(t)≤−αV(z(t)), V(z(t))dtdV(z(t))≤−α dtdlog(V(z(t)))≤−α log(V(z(t)))−log(V(z(0)))≤−αt log(V(z(t))≤−αt+log(V(z(0))) V(z(t))≤e−αtV(z(0))
To show that exponential stability implies the above Lyapunov condition:
Assume that ∥z(t)∥≤Ce−αt∥z(0)∥.
Related Work on Stablizing Neural ODEs
Learning Stable Deep Dynamics Models
This paper describes a method to learn the dynamics function and guarentee that it is stable. In order to guarentee it is stable, in addition to learning the dynamics function and Lyapunov function is also learned. The dynamics function is projected onto the half-space that satisfying the Lyapunov stability condition, so that the projected dynamics function is guaranteed to be stable. The projection is given by: f(z)=f^(z)−∇V(z)∥∇V(z)∥2RELU(∇V(z)Tf^(z)+αV(z))
It is stable since dtdV(z(t))=∇V(z)Tf(z)=∇V(z)T∇f^(z) −∇V(x)T∇V(z)∥∇V(z)∥2RELU(∇V(z)Tf^(z)+αV(z)) =∇V(z)T∇f^(z)−RELU(∇V(z)Tf^(z)+αV(z))
If ∇V(z)Tf^(z)+αV(z)≤0, then dtdV(z(t))=∇V(z)T∇f^(z)≤−αV(z).
If ∇V(z)Tf^(z)+αV(z)>0, then dtdV(z(t))=∇V(z)T∇f^(z)−(∇V(z)Tf^(z)+αV(z))=−αV(z).
So for either case, it is exponentially stable.
Adjoint equation with Lyapunov projection
Let us consider the adjoint equation,
dtda(t)=−a(t)T∂z(t)∂f^θ,ϕ(z(t),t)=−a(t)T∂z(t)∂(fθ(z(t))−∇Vϕ(z(t))∣∇Vϕ(z(t))∣2ReLU(∇Vϕ(z(t))Tfθ(z(t))+αVϕ(z(t)))=−a(t)T∂z(t)∂fθ(z(t))+a(t)T∂z(t)∂(∇Vϕ(z(t))∣∇Vϕ(z(t))∣2ReLU(∇Vϕ(z(t))Tfθ(z(t))+αVϕ(z(t)))
The projection for the adjoint would be:
−a(t)T∂z(t)∂fθ(z(t))−∇V(a(t))∣∇V(a)∣2ReLU(−∇V(a)Ta(t)T∂z(t)∂fθ(z(t))+αV(a(t)))
LyaNet
LyaNet is a Neural ODE with a modified loss function so that zero loss guarantees the exponential stability of the forward ODE.
Consider the Neural ODE taking input x to output y: z(0)=gθ(x) dtdz(t)=fθ(z(t),t),0<t≤1 y=hθ(z(1))
Let the standard loss function be ℓ(y,y^).
The Lyapunov function is taken to be V(z(t))=ℓ(hθ(z(t)),y^).
The new loss function is V(θ)=∫01RELU(dtdV(z(t))+αV(z(t)))dt.
Suppose there exists optimal parameters θ∗ such that V(θ∗)=0.
Then dtdV(z(t))+αV(z(t))≤0,
so it is exponentially stable, and also: V(z(t))≤e−αtV(z(0)) ℓ(hθ(z(t)),y^)≤e−αtℓ(hθ(z(0)),y^).
The Lyapunov loss function is an integral that must be approximated. There are two proposed methods for approximating it. One is to use a Monte Carlo method of sampling time points ti and states zi and averaging the value at different samples. The other is path integration. The ODE is numerically integrated for an approximate solution at a number of time steps. Then discrete approximations of the derivative and integral in the Lyapunov loss function are used.
Possible approach for adjoint
Consider using two regularizations, one for the forward and one for the adjoint: LLyap=∫01ReLU(dtdV(z(t))+αV(z(t)))dt
For adjoint: Ladj=∫01ReLU(dtdW(a(t))+αW(a(t)))dt
The problem will be determining how
Dueling Neural ODE Inner and Outer Loop
The inner loop contains the forward and adjoint ODE solves with stability constraints.
The outer loop focuses on the filtering of gradients, i.e. selection of gradients with highest impact on training.
- To enforce stability in the gradient calculations used for updating in the training process.
Some Results
Comparison of standard NODE, LyaNet, and PINN for solving spring equation (NYU data) over a domain of initial conditions

Note: PINN is trained for 200000 epochs and the final test loss is shown for reference.
Results of training LyaNet to solve spring equation (NYU data). Two types of loss are computed, MSE and Lyapunov, for each the training and testing datasets (top figure). The differences between the training and testing loss (a measure of generalization) is plotted in the bottom figure.

Results of previous model but with controller that removes some gradients

References
- Ricky T. Q. Chen, Yulia Rubanova, Jesse Bettencourt, David Duvenaud. Neural Ordinary Differential Equations. 2019. https://arxiv.org/abs/1806.07366
- Gaurav Manek and J. Zico Kolter. Learning stable deep dynamics models. Neural information processing systems. 2019. https://arxiv.org/pdf/2001.06116 https://github.com/locuslab/stable_dynamics
- Ivan Dario Jimenez Rodriguez, Aaron D. Ames, Yisong Yue. LyaNet: A Lyapunov dramework for training neural ODEs. 2022. https://arxiv.org/abs/2202.02526
- Sanchez-Lengeling and Aspuru-Guzik. Inverse molecular design using machine learning: generative models for matter engineering. Science. 2018.
- Advanced Generative Adversarial Autoencoder Model for de Novo Generation of New Molecules with Desired Molecular Properties in Silico. Mol. Pharmaceutics. 2017.
- Bajaj, et al. An Efficient Higher-Order Fast Multipole Boundary Element Solution for Poisson–Boltzmann-Based Molecular Electrostatics. SIAM J Sci Comput. 2011.
- Lelièvre and Stoltz. Partial differential equations and stochastic methods in molecular dynamics. Actua Numerica. 2016.
- J.T. Oden, Ludovic Chamoin, Serge Prudhomme. A stochastic coupling method for atomic-to-continuum Monte-Carlo simulations. Comput. Methods Appl. Mech. Engrg. 2008.