Source-linked AI summary

DiffEqFlux.jl - A Julia Library for Neural Differential Equations

Chris Rackauckas, Mike Innes, Yingbo Ma, Jesse Bettencourt, Lyndon White, Vaibhav Dixit

arXiv:1902.02376v1cs.LGstat.ML

TL;DR

When a nonlinear input-output relation is unknown, machine learning can fit it, while differential equations can encode structural assumptions. DiffEqFlux.jl combines differential-equation solves with neural networks; its examples show learned ODE dynamics that extrapolate to different starting conditions and handle unevenly spaced times. The paper also notes limits of particular solver and adjoint approaches, including assumptions that exclude some ODEs.

  • Problem

    When the exact nonlinear relation between inputs and outputs is unknown, the section asks how to model it.

    Source: §1 · p. 2
  • Method

    DiffEqFlux.jl places differentiable differential-equation solves in neural-network computations, including neural ODE and stochastic differential equation models.

    Source: §4 · p. 7, §8 · p. 15
  • Results

    The neural ODE example learns a compact representation of time-series dynamics that can extrapolate to different starting conditions and accommodate unevenly spaced times.

    Source: §8 · p. 15
  • Takeaways & Limitations

    The Julia ecosystem combines machine learning and differential equations as complementary ways to describe nonlinear systems.

    Source: §10 · p. 17

    The backward adjoint approach assumes reversible integration, is not guaranteed to work for ODEs, and excludes equations with discontinuities or events.

    Source: §9 · p. 16

Abstract

from arXiv · show

DiffEqFlux.jl is a library for fusing neural networks and differential equations. In this work we describe differential equations from the viewpoint of data science and discuss the complementary nature between machine learning models and differential equations. We demonstrate the ability to incorporate DifferentialEquations.jl-defined differential equation problems into a Flux-defined neural network, and vice versa. The advantages of being able to use the entire DifferentialEquations.jl suite for this purpose is demonstrated by counter examples where simple integration strategies fail, but the sophisticated integration strategies provided by the DifferentialEquations.jl library succeed. This is followed by a demonstration of delay differential equations and stochastic differential equations inside of neural networks. We show high-level functionality for defining neural ordinary differential equations (neural networks embedded into the differential equation) and describe the extra models in the Flux model zoo which includes neural stochastic differential equations. We conclude by discussing the various adjoint methods used for backpropogation of the differential equation solvers. DiffEqFlux.jl is an important contribution to the area, as it allows the full weight of the differential equation solvers developed from decades of research in the scientific computing field to be readily applied to the challenges posed by machine learning and data science.

1 What do differential equations have to do with machine learning?

Machine learning can model unknown nonlinear transformations, while differential equations encode known structural assumptions about them. The two approaches are complementary: equations provide learnable but constrained models that incorporate prior domain knowledge.

1 What do differential equations have to do with machine learning?

  • Differential equations encode prior structural assumptions about nonlinear transformations, while machine learning adapts its transformation to data.The paper frames them as complementary modeling tools.Source: §1 · pp. 2–3
  • When the exact input-output relation is unknown, directly specifying its nonlinear function is not possible, motivating alternative modeling approaches.The section asks how to model a nonlinearity that is not known a priori.Source: §1 · p. 2
  • Machine learning fits nonlinear transformations by adjusting parameters so predictions match outputs, and sufficiently large networks can approximate nonlinear functions under common constraints.The example uses a three-layer network with learnable weight matrices.Source: §1 · p. 2
  • A data-only model must learn the transformation directly, whereas a differential equation can encode known relations, such as rabbit birth rate depending on population.The equation specifies the assumed structure without requiring its solution to be known in advance.Source: §1 · pp. 2–3

2 What is the Neural Ordinary Differential Equation (ODE)?

A neural ODE places a machine-learning model on the derivative and solves the resulting ODE. Euler integration produces a residual-network-like computation, while purpose-built solvers can use adaptive steps and higher-order approximations.

2 What is the Neural Ordinary Differential Equation (ODE)?

  • A neural ODE learns a derivative function, y′(x) = ML(x), and obtains the transformation by solving the ODE rather than learning the transformation directly.The paper presents this as learning the structure of a nonlinear transformation.Source: §2 · p. 3
  • Euler integration of a neural ODE is equivalent to a residual neural network, while modern ODE solvers can adapt step sizes and use higher-order approximations.The Neural ODE paper interprets increasingly deep ResNet-like models as approximating an infinitely deep model as each layer tends to zero.Source: §2 · pp. 3–4

3 How do you solve an ODE?

An ODE problem specifies a derivative function, initial condition, time span, and parameters, then calls a solver to obtain a solution. The section illustrates this workflow with Lotka–Volterra dynamics and parameter-dependent initial conditions and time spans.

3 How do you solve an ODE?

  • An ODE problem is specified by a derivative equation u’=f(u,p,t), initial condition u0, time span tspan, and parameters p.The solution is obtained by calling a solver on the problem.Source: §3 · p. 4
  • The Lotka–Volterra example encodes rabbit and wolf population dynamics in a function of the state and parameters.The passage introduces the equations and gives their Julia encoding.Source: §3 · p. 4
  • The initial condition and time span can be functions of the parameter vector, making the entire problem depend on those parameters.The example defines u0_f(p,t0) and tspan_f(p).Source: §3 · p. 5
  • DifferentialEquations.jl exposes options for solver methods, accuracy, tolerances, and event handling.The section points readers to the documentation for more advanced options.Source: §3 · p. 5

4 Let’s Put an ODE Into a Neural Net Framework!

A differential-equation solve can serve as a differentiable layer inside a Flux network, allowing standard optimization to train parameters through the solver. The examples show an ODE-based forward pass, neural-network compositions, and a fitted population trajectory.

4 Let’s Put an ODE Into a Neural Net Framework!

  • A differential-equation solve maps parameters to a solution and is differentiable, so it can be placed in a larger program optimized with methods such as ADAM.The section introduces solving an equation before gradients and describes the solve as a neural-network layer.Source: §4 · p. 5
  • The diffeq_rd layer passes parameters into the differential equation and solves it with the chosen solver and arguments.The example uses Tsit5 and saves the solution at specified times.Source: §4 · p. 6
  • The solve reports retcode: Success with first-order linear interpolation and a 101-element time array, and returns solution values beginning [1.0, 1.0] and [1.06108, 0.821084].Source: §4 · pp. 6–7
  • Flux can train the ODE-containing network by minimizing a loss over its predictions.The section describes defining a parameter vector, loss function, and training loop.Source: §4 · p. 7
  • By minimizing a cost that penalizes rabbit counts far from 1, the ODE-solving forward-pass network found parameters yielding rabbit and wolf populations both constant at 1.Source: §4 · p. 8
  • An ODE layer can be inserted into multilayer perceptrons or convolutional networks, with earlier layers supplying its parameters or initial condition.The text frames any parameterized differentiable forward pass as optimizable.Source: §4 · pp. 8–9

5 Why is a full ODE solver suite necessary for doing this well?

The ROBER example shows why solver choice matters: methods that stall on a stiff equation can be replaced by a solver that handles it quickly. DiffEqFlux.jl uses DifferentialEquations.jl’s full solver suite rather than building a separate ML-specific suite.

5 Why is a full ODE solver suite necessary for doing this well?

  • On the stiff ROBER ODE, CVODE’s Adams method and dopri stall or fail, while Rodas5() solves it in a blink.The example uses the CVODE integrator from SUNDIALS for the Adams method.Source: §5 · p. 9
  • Robust solver construction involves details such as stabilizing explicit methods, predicting implicit-solver steps, and choosing symplectic or IMEX methods for particular problems.Symplectic integrators address physical problems where drift matters; IMEX methods are used for ODEs from partial differential equations.Source: §5 · p. 10
  • Julia uses the same production solver suite for machine learning and scientific computing, while torchdiffeq implements a more limited set of solver methods directly in PyTorch.The passage describes torchdiffeq’s approach as effective for certain models but limited by the absence of a full solver suite.Source: §5 · pp. 9–10

6 What kinds of differential equations are there?

Differential equation layers can represent delayed or random dynamics as well as ordinary differential equations. The examples show how these models fit into Flux and point to additional equation types in the model zoo.

6 What kinds of differential equations are there?

  • A delay differential equation (DDE) uses a lagged past state in its derivative, and DifferentialEquations.jl’s shared interface lets DDEs serve as Flux layers.The example’s lag term represents a birth rate that depends on the past population.Source: §6 · p. 10
  • An SDE adds randomness to differential-equation dynamics, modeling random events such as extra births or deaths, and can likewise be handled as a Flux layer.The passage describes handling SDEs as layers similarly to the other differential-equation models.Source: §6 · p. 11
  • The model zoo includes a neural SDE example, while the same framework also covers piecewise-constant and jump-diffusion equations.The passage says the solvers map into the Flux framework through DiffEqFlux.jl, which uses around 100 lines of code for this functionality.Source: §6 · p. 12

7 Implementing the Neural ODE layer in Julia

The Neural ODE layer uses a neural network to define the derivative function, then solves the ODE over a supplied timespan. The section also describes how to run the solver on a GPU.

7 Implementing the Neural ODE layer in Julia

  • A neural ODE defines the derivative function with a neural network, then solves that ODE over the layer’s supplied timespan.The section introduces a multilayer perceptron with one hidden layer and a tanh activation as the derivative network.Source: §7 · p. 12
  • Putting both the initial condition and neural network on the GPU lets the solver’s internal operations run there without extra data transfers during integration.Source: §7 · p. 12

8 Understanding the Neural ODE layer behavior by example

In the example, a neural network inside a Neural ODE learns the dynamics that generate a time series rather than directly learning its solution. The resulting representation is compact, can extrapolate to different initial conditions, and accommodates uneven observation times through the solver.

8 Understanding the Neural ODE layer behavior by example

  • The neural network learns the small ODE system that generates the time series, rather than learning the ODE solution directly.The example compares a neural ODE prediction with data generated from a test equation.Source: §8 · pp. 13, 15
  • The learned representation is compact and can extrapolate to different starting conditions.Source: §8 · p. 15
  • Passing uneven observation times through saveat lets the ODE solver handle those sampling times.Source: §8 · p. 15
  • The section also points to neural SDEs as an additional model-zoo option in DiffEqFlux.jl.Source: §8 · p. 15

9 The core technical challenge: backpropagation through differential equation solvers

Embedding an ODE solver in a neural-network layer requires gradients to pass through the solver. The paper compares gradient approaches and highlights the limits of backward-solving adjoint methods.

9 The core technical challenge: backpropagation through differential equation solvers

  • Adjoint sensitivity analysis solves a secondary ODE for gradients, but can require multiple forward ODE solutions; checkpointing trades extra memory for shorter forward recomputations.The neural ODE paper's backward solve assumes the ODE integrator is reversible, which the passage says is not guaranteed for first-order ODEs.Source: §9 · pp. 15–16
  • >1700% final-point error is reported for backward Adams integration despite solver tolerances of 1e-12.The example reports a final residual of [-17.5445, -14.7706, 39.7985] relative to the initial state.Source: §9 · p. 16
  • The backward-solve adjoint method applies only to ODEs and excludes ODEs with discontinuities such as events.The authors state that one gradient method is not enough because this method does not apply to all ODEs.Source: §9 · p. 16
  • Forward-mode automatic differentiation is fastest below 100 parameters, while adjoint sensitivity analysis is most efficient above 100 parameters.The authors also believe Zygote.jl source-to-source reverse-mode AD may outperform adjoint implementations for large parameter counts.Source: §9 · p. 16
  • DiffEqFlux.jl lets users switch gradient methods without changing the rest of their code, and the native Julia solvers can benefit from AD advances.The passage describes three similarly structured functions for reverse-mode AD, forward-mode AD, and adjoint sensitivity analysis.Source: §9 · pp. 16–17

10 Conclusion

The conclusion presents machine learning and differential equations as complementary ways to describe nonlinear systems. It points to access to a broad solver suite as a basis for future applications.

10 Conclusion

  • The authors describe machine learning and differential equations as complementary approaches and note that their Julia packages can be developed independently yet used together.They say the possibilities opened by the software are only beginning to be understood.Source: §10 · p. 17
  • The authors identify embedding the PuMaS.jl pharmacometric simulation engine into deep learning as one possible application, alongside access to solvers for ODEs, SDEs, DAEs, DDEs, PDEs, and discrete stochastic equations.They express interest in what researchers will build with this solver range.Source: §10 · p. 17
Loading 1902.02376v1…