diff --git a/previews/PR269/.documenter-siteinfo.json b/previews/PR269/.documenter-siteinfo.json index 056dc9cbe..d1a27c9a9 100644 --- a/previews/PR269/.documenter-siteinfo.json +++ b/previews/PR269/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-11-09T22:46:24","documenter_version":"1.1.2"}} \ No newline at end of file +{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-11-10T10:37:36","documenter_version":"1.1.2"}} \ No newline at end of file diff --git a/previews/PR269/benchmarks/hodgkinhuxley/index.html b/previews/PR269/benchmarks/hodgkinhuxley/index.html index 4e58eac0c..038367c8f 100644 --- a/previews/PR269/benchmarks/hodgkinhuxley/index.html +++ b/previews/PR269/benchmarks/hodgkinhuxley/index.html @@ -609,4 +609,4 @@ [3f19e933] p7zip_jll v17.4.0+0 Info Packages marked with ⌅ have new versions available but compatibility c onstraints restrict them from upgrading. To see why use `status --outdated --m` +-m` diff --git a/previews/PR269/benchmarks/lotkavolterra/index.html b/previews/PR269/benchmarks/lotkavolterra/index.html index a03b25ac7..f726ab8c1 100644 --- a/previews/PR269/benchmarks/lotkavolterra/index.html +++ b/previews/PR269/benchmarks/lotkavolterra/index.html @@ -766,4 +766,4 @@ [3f19e933] p7zip_jll v17.4.0+0 Info Packages marked with ⌅ have new versions available but compatibility c onstraints restrict them from upgrading. To see why use `status --outdated --m` +-m` diff --git a/previews/PR269/benchmarks/multi-language-wrappers/index.html b/previews/PR269/benchmarks/multi-language-wrappers/index.html index 2eee17b0e..8f645e00c 100644 --- a/previews/PR269/benchmarks/multi-language-wrappers/index.html +++ b/previews/PR269/benchmarks/multi-language-wrappers/index.html @@ -672,4 +672,4 @@ [3f19e933] p7zip_jll v17.4.0+0 Info Packages marked with ⌅ have new versions available but compatibility c onstraints restrict them from upgrading. To see why use `status --outdated --m` +-m` diff --git a/previews/PR269/benchmarks/pleiades/index.html b/previews/PR269/benchmarks/pleiades/index.html index a3f61fee3..cab2a76a9 100644 --- a/previews/PR269/benchmarks/pleiades/index.html +++ b/previews/PR269/benchmarks/pleiades/index.html @@ -544,4 +544,4 @@ [3f19e933] p7zip_jll v17.4.0+0 Info Packages marked with ⌅ have new versions available but compatibility c onstraints restrict them from upgrading. To see why use `status --outdated --m` +-m` diff --git a/previews/PR269/benchmarks/rober/index.html b/previews/PR269/benchmarks/rober/index.html index 04a54d708..66c4d5c8f 100644 --- a/previews/PR269/benchmarks/rober/index.html +++ b/previews/PR269/benchmarks/rober/index.html @@ -481,4 +481,4 @@ [3f19e933] p7zip_jll v17.4.0+0 Info Packages marked with ⌅ have new versions available but compatibility c onstraints restrict them from upgrading. To see why use `status --outdated --m` +-m` diff --git a/previews/PR269/benchmarks/vanderpol/index.html b/previews/PR269/benchmarks/vanderpol/index.html index 54279e5f0..3b6e37ec8 100644 --- a/previews/PR269/benchmarks/vanderpol/index.html +++ b/previews/PR269/benchmarks/vanderpol/index.html @@ -589,4 +589,4 @@ [3f19e933] p7zip_jll v17.4.0+0 Info Packages marked with ⌅ have new versions available but compatibility c onstraints restrict them from upgrading. To see why use `status --outdated --m` +-m` diff --git a/previews/PR269/diffusions/index.html b/previews/PR269/diffusions/index.html index 641594ded..44459ab6c 100644 --- a/previews/PR269/diffusions/index.html +++ b/previews/PR269/diffusions/index.html @@ -5,4 +5,4 @@ \text{d} Y^{(i)}(t) &= Y^{(i+1)}(t) \ \text{d}t, \qquad i = 0, \dots, q-1, \\ \text{d} Y^{(q)}(t) &= \textcolor{#389826}{A} Y(t) \ \text{d}t + \textcolor{#4063D8}{\Gamma} \ \text{d}W(t), \\ Y(0) &\sim \textcolor{purple}{ \mathcal{N} \left( \mu_0, \Sigma_0 \right) }. -\end{aligned}\]

Then $Y^{(i)}(t)$ models the $i$-th derivative of $y(t)$. In this section, we consider choices relating to the "diffusion" $\textcolor{#4063D8}{\Gamma}$. If you're more interested in the drift matrix $\textcolor{#389826}{A}$ check out the Priors section, and for info on the initial distribution $\textcolor{purple}{ \mathcal{N} \left( \mu_0, \Sigma_0 \right) }$ check out the Initialization section.

Diffusion and calibration

We call $\textcolor{#4063D8}{\Gamma}$ the "diffusion" parameter. Since it is typically not known we need to estimate it; this is called "calibration".

There are a few different choices for how to model and estimate $\textcolor{#4063D8}{\Gamma}$:

Or more compactly:

Isotropic:Diagonal (only for the EK0)
Time-varyingDynamicDiffusionDynamicMVDiffusion
Time-fixedFixedDiffusionFixedMVDiffusion

For more details on diffusions and calibration, check out this paper [8].

API

ProbNumDiffEq.DynamicDiffusionType
DynamicDiffusion()

Time-varying, isotropic diffusion, which is quasi-maximum-likelihood-estimated at each step.

This is the recommended diffusion when using adaptive step-size selection, and in particular also when solving stiff systems.

source
ProbNumDiffEq.FixedDiffusionType
FixedDiffusion(; initial_diffusion=1.0, calibrate=true)

Time-fixed, isotropic diffusion, which is (optionally) quasi-maximum-likelihood-estimated.

This is the recommended diffusion when using fixed steps.

By default with calibrate=true, all covariances are re-scaled at the end of the solve with the MLE diffusion. Set calibrate=false to skip this step, e.g. when setting the initial_diffusion and then estimating the diffusion outside of the solver (e.g. with Fenrir.jl).

source
ProbNumDiffEq.DynamicMVDiffusionType
DynamicMVDiffusion()

Time-varying, diagonal diffusion, which is quasi-maximum-likelihood-estimated at each step.

Only works with the EK0!

A multi-variate version of DynamicDiffusion, where instead of an isotropic matrix, a diagonal matrix is estimated. This can be helpful to get more expressive posterior covariances when using the EK0, since the individual dimensions can be adjusted separately.

References

  • [8] Bosch et al, "Calibrated Adaptive Probabilistic ODE Solvers", AISTATS (2021)
source
ProbNumDiffEq.FixedMVDiffusionType
FixedMVDiffusion(; initial_diffusion=1.0, calibrate=true)

Time-fixed, diagonal diffusion, which is quasi-maximum-likelihood-estimated at each step.

Only works with the EK0!

A multi-variate version of FixedDiffusion, where instead of an isotropic matrix, a diagonal matrix is estimated. This can be helpful to get more expressive posterior covariances when using the EK0, since the individual dimensions can be adjusted separately.

References

  • [8] Bosch et al, "Calibrated Adaptive Probabilistic ODE Solvers", AISTATS (2021)
source

References

[8]
N. Bosch, P. Hennig and F. Tronarp. Calibrated Adaptive Probabilistic ODE Solvers. In: Proceedings of The 24th International Conference on Artificial Intelligence and Statistics, Vol. 130 of Proceedings of Machine Learning Research, edited by A. Banerjee and K. Fukumizu (PMLR, 13–15 Apr 2021); pp. 3466–3474.
+\end{aligned}\]

Then $Y^{(i)}(t)$ models the $i$-th derivative of $y(t)$. In this section, we consider choices relating to the "diffusion" $\textcolor{#4063D8}{\Gamma}$. If you're more interested in the drift matrix $\textcolor{#389826}{A}$ check out the Priors section, and for info on the initial distribution $\textcolor{purple}{ \mathcal{N} \left( \mu_0, \Sigma_0 \right) }$ check out the Initialization section.

Diffusion and calibration

We call $\textcolor{#4063D8}{\Gamma}$ the "diffusion" parameter. Since it is typically not known we need to estimate it; this is called "calibration".

There are a few different choices for how to model and estimate $\textcolor{#4063D8}{\Gamma}$:

Or more compactly:

Isotropic:Diagonal (only for the EK0)
Time-varyingDynamicDiffusionDynamicMVDiffusion
Time-fixedFixedDiffusionFixedMVDiffusion

For more details on diffusions and calibration, check out this paper [8].

API

ProbNumDiffEq.DynamicDiffusionType
DynamicDiffusion()

Time-varying, isotropic diffusion, which is quasi-maximum-likelihood-estimated at each step.

This is the recommended diffusion when using adaptive step-size selection, and in particular also when solving stiff systems.

source
ProbNumDiffEq.FixedDiffusionType
FixedDiffusion(; initial_diffusion=1.0, calibrate=true)

Time-fixed, isotropic diffusion, which is (optionally) quasi-maximum-likelihood-estimated.

This is the recommended diffusion when using fixed steps.

By default with calibrate=true, all covariances are re-scaled at the end of the solve with the MLE diffusion. Set calibrate=false to skip this step, e.g. when setting the initial_diffusion and then estimating the diffusion outside of the solver (e.g. with Fenrir.jl).

source
ProbNumDiffEq.DynamicMVDiffusionType
DynamicMVDiffusion()

Time-varying, diagonal diffusion, which is quasi-maximum-likelihood-estimated at each step.

Only works with the EK0!

A multi-variate version of DynamicDiffusion, where instead of an isotropic matrix, a diagonal matrix is estimated. This can be helpful to get more expressive posterior covariances when using the EK0, since the individual dimensions can be adjusted separately.

References

  • [8] Bosch et al, "Calibrated Adaptive Probabilistic ODE Solvers", AISTATS (2021)
source
ProbNumDiffEq.FixedMVDiffusionType
FixedMVDiffusion(; initial_diffusion=1.0, calibrate=true)

Time-fixed, diagonal diffusion, which is quasi-maximum-likelihood-estimated at each step.

Only works with the EK0!

A multi-variate version of FixedDiffusion, where instead of an isotropic matrix, a diagonal matrix is estimated. This can be helpful to get more expressive posterior covariances when using the EK0, since the individual dimensions can be adjusted separately.

References

  • [8] Bosch et al, "Calibrated Adaptive Probabilistic ODE Solvers", AISTATS (2021)
source

References

[8]
N. Bosch, P. Hennig and F. Tronarp. Calibrated Adaptive Probabilistic ODE Solvers. In: Proceedings of The 24th International Conference on Artificial Intelligence and Statistics, Vol. 130 of Proceedings of Machine Learning Research, edited by A. Banerjee and K. Fukumizu (PMLR, 13–15 Apr 2021); pp. 3466–3474.
diff --git a/previews/PR269/filtering/index.html b/previews/PR269/filtering/index.html index a37216042..2429ee682 100644 --- a/previews/PR269/filtering/index.html +++ b/previews/PR269/filtering/index.html @@ -1,26 +1,26 @@ -Filtering and Smoothing · ProbNumDiffEq.jl

Gaussian Filtering and Smoothing

Predict

ProbNumDiffEq.predictFunction
predict(x::Gaussian, A::AbstractMatrix, Q::AbstractMatrix)

Prediction step in Kalman filtering for linear dynamics models.

Given a Gaussian $x = \mathcal{N}(μ, Σ)$, compute and return $\mathcal{N}(A μ, A Σ A^T + Q)$.

See also the non-allocating square-root version predict!.

source
ProbNumDiffEq.predict!Function
predict!(x_out, x_curr, Ah, Qh, cachemat)

In-place and square-root implementation of predict which saves the result into x_out.

Only works with PSDMatrices.PSDMatrix types as Ah, Qh, and in the covariances of x_curr and x_out (both of type Gaussian). To prevent allocations, a cache matrix cachemat of size $D \times 2D$ (where $D \times D$ is the size of Ah and Qh) needs to be passed.

See also: predict.

source

Update

ProbNumDiffEq.updateFunction
update(x, measurement, H)

Update step in Kalman filtering for linear dynamics models.

Given a Gaussian $x = \mathcal{N}(μ, Σ)$ and a measurement $z = \mathcal{N}(\hat{z}, S)$, with $S = H Σ H^T$, compute

\[\begin{aligned} +Filtering and Smoothing · ProbNumDiffEq.jl

Gaussian Filtering and Smoothing

Predict

ProbNumDiffEq.predictFunction
predict(x::Gaussian, A::AbstractMatrix, Q::AbstractMatrix)

Prediction step in Kalman filtering for linear dynamics models.

Given a Gaussian $x = \mathcal{N}(μ, Σ)$, compute and return $\mathcal{N}(A μ, A Σ A^T + Q)$.

See also the non-allocating square-root version predict!.

source
ProbNumDiffEq.predict!Function
predict!(x_out, x_curr, Ah, Qh, cachemat)

In-place and square-root implementation of predict which saves the result into x_out.

Only works with PSDMatrices.PSDMatrix types as Ah, Qh, and in the covariances of x_curr and x_out (both of type Gaussian). To prevent allocations, a cache matrix cachemat of size $D \times 2D$ (where $D \times D$ is the size of Ah and Qh) needs to be passed.

See also: predict.

source

Update

ProbNumDiffEq.updateFunction
update(x, measurement, H)

Update step in Kalman filtering for linear dynamics models.

Given a Gaussian $x = \mathcal{N}(μ, Σ)$ and a measurement $z = \mathcal{N}(\hat{z}, S)$, with $S = H Σ H^T$, compute

\[\begin{aligned} K &= Σ^P H^T S^{-1}, \\ μ^F &= μ + K (0 - \hat{z}), \\ Σ^F &= Σ - K S K^T, -\end{aligned}\]

and return an updated state \mathcal{N}(μ^F, Σ^F). Note that this assumes zero-measurements. When called with ProbNumDiffEq.SquarerootMatrix type arguments it performs the update in Joseph / square-root form.

For better performance, we recommend to use the non-allocating update!.

source
ProbNumDiffEq.update!Function
update!(x_out, x_pred, measurement, H, K_cache, M_cache, S_cache)

In-place and square-root implementation of update which saves the result into x_out.

Implemented in Joseph Form to retain the PSDMatrix covariances:

\[\begin{aligned} +\end{aligned}\]

and return an updated state \mathcal{N}(μ^F, Σ^F). Note that this assumes zero-measurements. When called with ProbNumDiffEq.SquarerootMatrix type arguments it performs the update in Joseph / square-root form.

For better performance, we recommend to use the non-allocating update!.

source
ProbNumDiffEq.update!Function
update!(x_out, x_pred, measurement, H, K_cache, M_cache, S_cache)

In-place and square-root implementation of update which saves the result into x_out.

Implemented in Joseph Form to retain the PSDMatrix covariances:

\[\begin{aligned} K &= Σ^P H^T S^{-1}, \\ μ^F &= μ + K (0 - \hat{z}), \\ \sqrt{Σ}^F &= (I - KH) \sqrt(Σ), -\end{aligned}\]

where $\sqrt{M}$ denotes the left square-root of a matrix M, i.e. $M = \sqrt{M} \sqrt{M}^T$.

To prevent allocations, write into caches K_cache and M_cache, both of size D × D, and S_cache of same type as measurement.Σ.

See also: update.

source

Smooth

ProbNumDiffEq.smoothFunction
smooth(x_curr, x_next_smoothed, A, Q)

Update step of the Kalman smoother, aka. Rauch-Tung-Striebel smoother, for linear dynamics models.

Given Gaussians $x_n = \mathcal{N}(μ_{n}, Σ_{n})$ and $x_{n+1} = \mathcal{N}(μ_{n+1}^S, Σ_{n+1}^S)$, compute

\[\begin{aligned} +\end{aligned}\]

where $\sqrt{M}$ denotes the left square-root of a matrix M, i.e. $M = \sqrt{M} \sqrt{M}^T$.

To prevent allocations, write into caches K_cache and M_cache, both of size D × D, and S_cache of same type as measurement.Σ.

See also: update.

source

Smooth

ProbNumDiffEq.smoothFunction
smooth(x_curr, x_next_smoothed, A, Q)

Update step of the Kalman smoother, aka. Rauch-Tung-Striebel smoother, for linear dynamics models.

Given Gaussians $x_n = \mathcal{N}(μ_{n}, Σ_{n})$ and $x_{n+1} = \mathcal{N}(μ_{n+1}^S, Σ_{n+1}^S)$, compute

\[\begin{aligned} μ_{n+1}^P &= A μ_n^F, \\ P_{n+1}^P &= A Σ_n^F A + Q, \\ G &= Σ_n^S A^T (Σ_{n+1}^P)^{-1}, \\ μ_n^S &= μ_n^F + G (μ_{n+1}^S - μ_{n+1}^P), \\ Σ_n^S &= (I - G A) Σ_n^F (I - G A)^T + G Q G^T + G Σ_{n+1}^S G^T, -\end{aligned}\]

and return a smoothed state \mathcal{N}(μ_n^S, Σ_n^S). When called with ProbNumDiffEq.SquarerootMatrix type arguments it performs the update in Joseph / square-root form.

source

Markov Kernels

ProbNumDiffEq.AffineNormalKernelType
AffineNormalKernel(A[, b], C)

Structure to represent affine Normal Markov kernels, i.e. conditional distributions of the form

\[\begin{aligned} +\end{aligned}\]

and return a smoothed state \mathcal{N}(μ_n^S, Σ_n^S). When called with ProbNumDiffEq.SquarerootMatrix type arguments it performs the update in Joseph / square-root form.

source

Markov Kernels

ProbNumDiffEq.AffineNormalKernelType
AffineNormalKernel(A[, b], C)

Structure to represent affine Normal Markov kernels, i.e. conditional distributions of the form

\[\begin{aligned} y \mid x \sim \mathcal{N} \left( y; A x + b, C \right). -\end{aligned}\]

At the point of writing, AffineNormalKernels are only used to precompute and store the backward representation of the posterior (via compute_backward_kernel!) and for smoothing (via marginalize!).

source
ProbNumDiffEq.marginalize!Function
marginalize!(
     xout::Gaussian{Vector{T},PSDMatrix{T,S}}
     x::Gaussian{Vector{T},PSDMatrix{T,S}},
     K::AffineNormalKernel{<:AbstractMatrix,Union{<:Number,<:AbstractVector,Missing},<:PSDMatrix};
     C_DxD, C_3DxD
-)

Basically the same as predict!), but in kernel language and with support for affine transitions. At the time of writing, this is only used to smooth the posterior using it's backward representation, where the kernels are precomputed with compute_backward_kernel!.

Note that this function assumes certain shapes:

  • size(x.μ) == (D, D)
  • size(x.Σ) == (D, D)
  • size(K.A) == (D, D)
  • size(K.b) == (D,), or missing
  • size(K.C) == (D, D), _but with a tall square-root size(K.C.R) == (3D, D)

xout is assumes to have the same shapes as x.

source
ProbNumDiffEq.compute_backward_kernel!Function
compute_backward_kernel!(Kout, xpred, x, K; C_DxD[, diffusion=1])

Compute the backward representation of the posterior, i.e. the conditional distribution of the current state given the next state and the transition kernel.

More precisely, given a distribution (x)

\[\begin{aligned} +)

Basically the same as predict!), but in kernel language and with support for affine transitions. At the time of writing, this is only used to smooth the posterior using it's backward representation, where the kernels are precomputed with compute_backward_kernel!.

Note that this function assumes certain shapes:

  • size(x.μ) == (D, D)
  • size(x.Σ) == (D, D)
  • size(K.A) == (D, D)
  • size(K.b) == (D,), or missing
  • size(K.C) == (D, D), _but with a tall square-root size(K.C.R) == (3D, D)

xout is assumes to have the same shapes as x.

source
ProbNumDiffEq.compute_backward_kernel!Function
compute_backward_kernel!(Kout, xpred, x, K; C_DxD[, diffusion=1])

Compute the backward representation of the posterior, i.e. the conditional distribution of the current state given the next state and the transition kernel.

More precisely, given a distribution (x)

\[\begin{aligned} x \sim \mathcal{N} \left( x; μ, Σ \right), \end{aligned}\]

a kernel (K)

\[\begin{aligned} y \mid x \sim \mathcal{N} \left( y; A x + b, C \right), @@ -34,4 +34,4 @@ G &= Σ A^\top (Σ^P)^{-1}, \\ d &= μ - G μ^P, \\ Λ &= Σ - G Σ^P G^\top. -\end{aligned}\]

Everything is computed in square-root form and with minimal allocations (thus the cache C_DxD), so the actual formulas implemented here differ a bit.

The resulting backward kernels are used to smooth the posterior, via marginalize!.

source
+\end{aligned}\]

Everything is computed in square-root form and with minimal allocations (thus the cache C_DxD), so the actual formulas implemented here differ a bit.

The resulting backward kernels are used to smooth the posterior, via marginalize!.

source
diff --git a/previews/PR269/implementation/index.html b/previews/PR269/implementation/index.html index 604b5b8f0..e7776ba48 100644 --- a/previews/PR269/implementation/index.html +++ b/previews/PR269/implementation/index.html @@ -1,2 +1,2 @@ -Implementation via OrdinaryDiffEq.jl · ProbNumDiffEq.jl

Solver Implementation via OrdinaryDiffEq.jl

ProbNumDiffEq.jl builds directly on OrdinaryDiffEq.jl to benefit from its iterator interface, flexible step-size control, and efficient Jacobian calculations. But, this requires extending non-public APIs. This page is meant to provide an overview on which parts exactly ProbNumDiffEq.jl builds on.

For more discussion on the pros and cons of building on OrdinaryDiffEq.jl, see this thread on discourse.

Building on OrdinaryDiffEq.jl

ProbNumDiffEq.jl shares most of OrdinaryDiffEq.jl's implementation. In particular:

  1. OrdinaryDiffEq.__init builds the cache and the integrator, and calls OrdinaryDiffEq.initialize!
  2. OrdinaryDiffEq.solve! implements the actual iterator structure, with
    • OrdinaryDiffEq.loopheader!
    • OrdinaryDiffEq.perform_step!
    • OrdinaryDiffEq.loopfooter!
    • OrdinaryDiffEq.postamble!

ProbNumDiffEq.jl builds around this structure and overloads some of the parts:

  • Algorithms: EK0/EK1 <: AbstractEK <: OrdinaryDiffEq.OrdinaryDiffEqAdaptiveAlgorithm
    • ./src/algorithms.jl provides the algorithms themselves
    • ./src/alg_utils.jl implements many traits (e.g. relating to autodiff, implicitness, step-size control)
  • Cache: EKCache <: AbstractODEFilterCache <: OrdinaryDiffEq.OrdinaryDiffEqCache
    • ./src/caches.jl implements the cache and its main constructor: OrdinaryDiffEq.alg_cache
  • Initialization and perform_step!: via OrdinaryDiffEq.initialize! and OrdinaryDiffEq.perform_step!. Implemented in ./src/perform_step.jl.
  • Custom postamble by overloading OrdinaryDiffEq.postamble! (which should always call OrdinaryDiffEq._postamble!). This is where we do the "smoothing" of the solution. Implemented in ./src/integrator_utils.jl.
  • Custom saving by overloading OrdinaryDiffEq.savevalues! (which should always call OrdinaryDiffEq._savevalues!). Implemented in ./src/integrator_utils.jl.

Building on DiffEqBase.jl

  • DiffEqBase.__init is currently overloaded to transform OOP problems into IIP problems (in ./src/solve.jl).
  • The solution object: ProbODESolution <: AbstractProbODESolution <: DiffEqBase.AbstractODESolution
    • ./src/solution.jl implements the main parts. Note that the main constructor DiffEqBase.build_solution is called by OrdinaryDiffEq.__init - so OrdinaryDiffEq.jl has control over its inputs.
    • There is also MeanProbODESolution <: DiffEqBase.AbstractODESolution: It allows handling the mean of a probabilistic ODE solution the same way one would handle any "standard" ODE solution - e.g. it is compatible with DiffEqDevTools.appxtrue.
    • AbstractODEFilterPosterior <: DiffEqBase.AbstractDiffEqInterpolation is the current interpolant, but it does not actually fully handle the interpolation right now. This part might be subject to change soon.
    • Plot recipe in ./src/solution_plotting.jl
    • Sampling in ./src/solution_sampling.jl
  • DiffEqBase.prepare_alg(::EK1{0}); closely follows a similar function implemented in OrdinaryDiffEq.jl ./src/alg_utils.jl
    • this also required DiffEqBase.remake(::EK1)

Other packages

  • DiffEqDevTools.appxtrue is overloaded to work with ProbODESolution (by just doing mean(sol)). This also enables DiffEqDevTools.WorkPrecision to work out of th box.
+Implementation via OrdinaryDiffEq.jl · ProbNumDiffEq.jl

Solver Implementation via OrdinaryDiffEq.jl

ProbNumDiffEq.jl builds directly on OrdinaryDiffEq.jl to benefit from its iterator interface, flexible step-size control, and efficient Jacobian calculations. But, this requires extending non-public APIs. This page is meant to provide an overview on which parts exactly ProbNumDiffEq.jl builds on.

For more discussion on the pros and cons of building on OrdinaryDiffEq.jl, see this thread on discourse.

Building on OrdinaryDiffEq.jl

ProbNumDiffEq.jl shares most of OrdinaryDiffEq.jl's implementation. In particular:

  1. OrdinaryDiffEq.__init builds the cache and the integrator, and calls OrdinaryDiffEq.initialize!
  2. OrdinaryDiffEq.solve! implements the actual iterator structure, with
    • OrdinaryDiffEq.loopheader!
    • OrdinaryDiffEq.perform_step!
    • OrdinaryDiffEq.loopfooter!
    • OrdinaryDiffEq.postamble!

ProbNumDiffEq.jl builds around this structure and overloads some of the parts:

  • Algorithms: EK0/EK1 <: AbstractEK <: OrdinaryDiffEq.OrdinaryDiffEqAdaptiveAlgorithm
    • ./src/algorithms.jl provides the algorithms themselves
    • ./src/alg_utils.jl implements many traits (e.g. relating to autodiff, implicitness, step-size control)
  • Cache: EKCache <: AbstractODEFilterCache <: OrdinaryDiffEq.OrdinaryDiffEqCache
    • ./src/caches.jl implements the cache and its main constructor: OrdinaryDiffEq.alg_cache
  • Initialization and perform_step!: via OrdinaryDiffEq.initialize! and OrdinaryDiffEq.perform_step!. Implemented in ./src/perform_step.jl.
  • Custom postamble by overloading OrdinaryDiffEq.postamble! (which should always call OrdinaryDiffEq._postamble!). This is where we do the "smoothing" of the solution. Implemented in ./src/integrator_utils.jl.
  • Custom saving by overloading OrdinaryDiffEq.savevalues! (which should always call OrdinaryDiffEq._savevalues!). Implemented in ./src/integrator_utils.jl.

Building on DiffEqBase.jl

  • DiffEqBase.__init is currently overloaded to transform OOP problems into IIP problems (in ./src/solve.jl).
  • The solution object: ProbODESolution <: AbstractProbODESolution <: DiffEqBase.AbstractODESolution
    • ./src/solution.jl implements the main parts. Note that the main constructor DiffEqBase.build_solution is called by OrdinaryDiffEq.__init - so OrdinaryDiffEq.jl has control over its inputs.
    • There is also MeanProbODESolution <: DiffEqBase.AbstractODESolution: It allows handling the mean of a probabilistic ODE solution the same way one would handle any "standard" ODE solution - e.g. it is compatible with DiffEqDevTools.appxtrue.
    • AbstractODEFilterPosterior <: DiffEqBase.AbstractDiffEqInterpolation is the current interpolant, but it does not actually fully handle the interpolation right now. This part might be subject to change soon.
    • Plot recipe in ./src/solution_plotting.jl
    • Sampling in ./src/solution_sampling.jl
  • DiffEqBase.prepare_alg(::EK1{0}); closely follows a similar function implemented in OrdinaryDiffEq.jl ./src/alg_utils.jl
    • this also required DiffEqBase.remake(::EK1)

Other packages

  • DiffEqDevTools.appxtrue is overloaded to work with ProbODESolution (by just doing mean(sol)). This also enables DiffEqDevTools.WorkPrecision to work out of th box.
diff --git a/previews/PR269/index.html b/previews/PR269/index.html index 026e6caa1..7faedb5a8 100644 --- a/previews/PR269/index.html +++ b/previews/PR269/index.html @@ -1,3 +1,3 @@ Home · ProbNumDiffEq.jl

Probabilistic Numerical Differential Equation Solvers

Banner

ProbNumDiffEq.jl provides probabilistic numerical solvers to the DifferentialEquations.jl ecosystem. The implemented ODE filters solve differential equations via Bayesian filtering and smoothing and compute not just a single point estimate of the true solution, but a posterior distribution that contains an estimate of its numerical approximation error.

For a short intro video, check out our poster presentation at JuliaCon2021.

Installation

Run Julia, enter ] to bring up Julia's package manager, and add the ProbNumDiffEq.jl package:

julia> ]
-(v1.9) pkg> add ProbNumDiffEq

Getting Started

For a quick introduction check out the "Solving ODEs with Probabilistic Numerics" tutorial.

Features

  • probdiffeq: Fast and feature-rich filtering-based probabilistic ODE solvers in JAX.
  • ProbNum: Probabilistic numerics in Python. It has not only probabilistic ODE solvers, but also probabilistic linear solvers, Bayesian quadrature, and many filtering and smoothing implementations.
  • Fenrir.jl: Parameter-inference in ODEs with probabilistic ODE solvers. This package builds on ProbNumDiffEq.jl to provide a negative marginal log-likelihood function, which can then be used with an optimizer or with MCMC for parameter inference.
+(v1.9) pkg> add ProbNumDiffEq

Getting Started

For a quick introduction check out the "Solving ODEs with Probabilistic Numerics" tutorial.

Features

diff --git a/previews/PR269/initialization/index.html b/previews/PR269/initialization/index.html index 41b85e946..3f8569daa 100644 --- a/previews/PR269/initialization/index.html +++ b/previews/PR269/initialization/index.html @@ -11,4 +11,4 @@ \end{aligned}\]

It is clear that this contains quite some information for $Y(0)$: The initial value $y_0$ and the vector field $f$ imply

\[\begin{aligned} Y^{(0)}(0) &= y_0, \\ Y^{(1)}(0) &= f(y_0, 0). -\end{aligned}\]

It turns out that we can also compute higher-order derivatives of $y$ with the chain rule, and then use these to better initialize $Y^{(i)}(0)$. This, done efficiently with Taylor-mode autodiff by using TaylorIntegration.jl, is what TaylorModeInit does. See also [1].

In the vast majority of cases, just stick to the exact Taylor-mode initialization TaylorModeInit!

API

ProbNumDiffEq.TaylorModeInitType
TaylorModeInit(order)

Exact initialization via Taylor-mode automatic differentiation up to order order.

This is the recommended initialization method!

It uses TaylorIntegration.jl to efficiently compute the higher-order derivatives of the solution at the initial value, via Taylor-mode automatic differentiation.

In some special cases it can happen that TaylorIntegration.jl is incompatible with the given problem (typically because the problem definition does not allow for elements of type Taylor). If this happens, try one of SimpleInit, ForwardDiffInit (for low enough orders), ClassicSolverInit.

References

  • [6] Krämer et al, "Stable Implementation of Probabilistic ODE Solvers" (2020)
source
ProbNumDiffEq.ForwardDiffInitType
ForwardDiffInit(order)

Exact initialization via ForwardDiff.jl up to order order.

Warning: This does not scale well to high orders! For orders > 3, TaylorModeInit most likely performs better.

source
ProbNumDiffEq.SimpleInitType
SimpleInit()

Simple initialization, only with the given initial value and derivative.

The remaining derivatives are set to zero with unit covariance (unless specified otherwise by setting a custom FixedDiffusion).

source
ProbNumDiffEq.ClassicSolverInitType
ClassicSolverInit(; alg=OrdinaryDiffEq.Tsit5(), init_on_ddu=false)

Initialization via regression on a few steps of a classic ODE solver.

In a nutshell, instead of specifying $\mu_0$ exactly and setting $\Sigma_0=0$ (which is what TaylorModeInit does), use a classic ODE solver to compute a few steps of the solution, and then regress on the computed values (by running a smoother) to compute $\mu_0$ and $\Sigma_0$ as the mean and covariance of the smoothing posterior at time 0. See also [2].

The initial value and derivative are set directly from the given initial value problem; optionally the second derivative can also be set via automatic differentiation by setting init_on_ddu=true.

Arguments

  • alg: The solver to be used. Can be any solver from OrdinaryDiffEq.jl.
  • init_on_ddu: If true, the second derivative is also initialized exactly via automatic differentiation with ForwardDiff.jl.

References

  • [6] Krämer et al, "Stable Implementation of Probabilistic ODE Solvers" (2020)
  • [7] Schober et al, "A probabilistic model for the numerical solution of initial value problems", Statistics and Computing (2019)
source

References

[6]
N. Krämer and P. Hennig. Stable Implementation of Probabilistic ODE Solvers. CoRR (2020), arXiv:2012.10106 [stat.ML].
[7]
M. Schober, S. Särkkä and P. Hennig. A probabilistic model for the numerical solution of initial value problems. Statistics and Computing 29, 99–122 (2019).
+\end{aligned}\]

It turns out that we can also compute higher-order derivatives of $y$ with the chain rule, and then use these to better initialize $Y^{(i)}(0)$. This, done efficiently with Taylor-mode autodiff by using TaylorIntegration.jl, is what TaylorModeInit does. See also [1].

In the vast majority of cases, just stick to the exact Taylor-mode initialization TaylorModeInit!

API

ProbNumDiffEq.TaylorModeInitType
TaylorModeInit(order)

Exact initialization via Taylor-mode automatic differentiation up to order order.

This is the recommended initialization method!

It uses TaylorIntegration.jl to efficiently compute the higher-order derivatives of the solution at the initial value, via Taylor-mode automatic differentiation.

In some special cases it can happen that TaylorIntegration.jl is incompatible with the given problem (typically because the problem definition does not allow for elements of type Taylor). If this happens, try one of SimpleInit, ForwardDiffInit (for low enough orders), ClassicSolverInit.

References

  • [6] Krämer et al, "Stable Implementation of Probabilistic ODE Solvers" (2020)
source
ProbNumDiffEq.ForwardDiffInitType
ForwardDiffInit(order)

Exact initialization via ForwardDiff.jl up to order order.

Warning: This does not scale well to high orders! For orders > 3, TaylorModeInit most likely performs better.

source
ProbNumDiffEq.SimpleInitType
SimpleInit()

Simple initialization, only with the given initial value and derivative.

The remaining derivatives are set to zero with unit covariance (unless specified otherwise by setting a custom FixedDiffusion).

source
ProbNumDiffEq.ClassicSolverInitType
ClassicSolverInit(; alg=OrdinaryDiffEq.Tsit5(), init_on_ddu=false)

Initialization via regression on a few steps of a classic ODE solver.

In a nutshell, instead of specifying $\mu_0$ exactly and setting $\Sigma_0=0$ (which is what TaylorModeInit does), use a classic ODE solver to compute a few steps of the solution, and then regress on the computed values (by running a smoother) to compute $\mu_0$ and $\Sigma_0$ as the mean and covariance of the smoothing posterior at time 0. See also [2].

The initial value and derivative are set directly from the given initial value problem; optionally the second derivative can also be set via automatic differentiation by setting init_on_ddu=true.

Arguments

  • alg: The solver to be used. Can be any solver from OrdinaryDiffEq.jl.
  • init_on_ddu: If true, the second derivative is also initialized exactly via automatic differentiation with ForwardDiff.jl.

References

  • [6] Krämer et al, "Stable Implementation of Probabilistic ODE Solvers" (2020)
  • [7] Schober et al, "A probabilistic model for the numerical solution of initial value problems", Statistics and Computing (2019)
source

References

[6]
N. Krämer and P. Hennig. Stable Implementation of Probabilistic ODE Solvers. CoRR (2020), arXiv:2012.10106 [stat.ML].
[7]
M. Schober, S. Särkkä and P. Hennig. A probabilistic model for the numerical solution of initial value problems. Statistics and Computing 29, 99–122 (2019).
diff --git a/previews/PR269/priors/index.html b/previews/PR269/priors/index.html index 2ca522e4b..93ba0c366 100644 --- a/previews/PR269/priors/index.html +++ b/previews/PR269/priors/index.html @@ -8,12 +8,12 @@ \end{aligned}\]

Then $Y^{(i)}(t)$ models the $i$-th derivative of $y(t)$. In this section, we consider choices relating to the drift matrix $\textcolor{#389826}{A}$. If you're more interested in the diffusion $\textcolor{#4063D8}{\Gamma}$ check out the Diffusion models and calibration section, and for info on the initial distribution $\textcolor{purple}{ \mathcal{N} \left( \mu_0, \Sigma_0 \right) }$ check out the Initialization section.

If you're unsure which prior to use, just stick to the integrated Wiener process prior IWP! This is also the default choice for all solvers. The other priors are rather experimental / niche at the time of writing.

API

ProbNumDiffEq.IWPType
IWP([wiener_process_dimension::Integer,] num_derivatives::Integer)

Integrated Wiener process.

This is the recommended prior! It is the most well-tested prior, both in this package and in the probabilistic numerics literature in general (see the references). It is also the prior that has the most efficient implementation.

The IWP can be created without specifying the dimension of the Wiener process, in which case it will be inferred from the dimension of the ODE during the solve. This is typically the preferred usage.

In math

\[\begin{aligned} \text{d} Y^{(i)}(t) &= Y^{(i+1)}(t) \ \text{d}t, \qquad i = 0, \dots, q-1 \\ \text{d} Y^{(q)}(t) &= \Gamma \ \text{d}W(t). -\end{aligned}\]

Examples

julia> solve(prob, EK1(prior=IWP(2)))
source
ProbNumDiffEq.IOUPType
IOUP([wiener_process_dimension::Integer,]
+\end{aligned}\]

Examples

julia> solve(prob, EK1(prior=IWP(2)))
source
ProbNumDiffEq.IOUPType
IOUP([wiener_process_dimension::Integer,]
      num_derivatives::Integer,
      rate_parameter::Union{Number,AbstractVector,AbstractMatrix})

Integrated Ornstein–Uhlenbeck process.

As with the IWP, the IOUP can be created without specifying its dimension, in which case it will be inferred from the dimension of the ODE during the solve. This is typically the preferred usage. The rate parameter however always needs to be specified.

In math

\[\begin{aligned} \text{d} Y^{(i)}(t) &= Y^{(i+1)}(t) \ \text{d}t, \qquad i = 0, \dots, q-1 \\ \text{d} Y^{(q)}(t) &= L Y^{(q)}(t) \ \text{d}t + \Gamma \ \text{d}W(t), -\end{aligned}\]

where $L$ is the rate_parameter.

Examples

julia> solve(prob, EK1(prior=IOUP(2, -1)))
source
ProbNumDiffEq.MaternType
Matern([wiener_process_dimension::Integer,]
+\end{aligned}\]

where $L$ is the rate_parameter.

Examples

julia> solve(prob, EK1(prior=IOUP(2, -1)))
source
ProbNumDiffEq.MaternType
Matern([wiener_process_dimension::Integer,]
        num_derivatives::Integer,
        lengthscale::Number)

Matern process.

As with the IWP, the Matern can be created without specifying its dimension, in which case it will be inferred from the dimension of the ODE during the solve. This is typically the preferred usage. The lengthscale parameter however always needs to be specified.

In math

\[\begin{aligned} \text{d} Y^{(i)}(t) &= Y^{(i+1)}(t) \ \text{d}t, \qquad i = 0, \dots, q-1 \\ @@ -21,4 +21,4 @@ \begin{pmatrix} q+1 \\ j \end{pmatrix} \left( \frac{\sqrt{2q - 1}}{l} \right)^{q-j} Y^{(j)}(t) \right) \ \text{d}t + \Gamma \ \text{d}W(t). -\end{aligned}\]

where $l$ is the lengthscale.

Examples

julia> solve(prob, EK1(prior=Matern(2, 1)))
source
+\end{aligned}\]

where $l$ is the lengthscale.

Examples

julia> solve(prob, EK1(prior=Matern(2, 1)))
source diff --git a/previews/PR269/references/index.html b/previews/PR269/references/index.html index 3c454db56..171267f27 100644 --- a/previews/PR269/references/index.html +++ b/previews/PR269/references/index.html @@ -1,2 +1,2 @@ -References · ProbNumDiffEq.jl

References

[1]
N. Bosch, F. Tronarp and P. Hennig. Pick-and-Mix Information Operators for Probabilistic ODE Solvers. In: Proceedings of The 25th International Conference on Artificial Intelligence and Statistics, Vol. 151 of Proceedings of Machine Learning Research, edited by G. Camps-Valls, F. J. Ruiz and I. Valera (PMLR, 28–30 Mar 2022); pp. 10015–10027.
[2]
N. Bosch, P. Hennig and F. Tronarp. Probabilistic Exponential Integrators. In: Thirty-seventh Conference on Neural Information Processing Systems (2023).
[3]
F. Tronarp, N. Bosch and P. Hennig. Fenrir: Physics-Enhanced Regression for Initial Value Problems. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 21776–21794.
[4]
[5]
N. Krämer, N. Bosch, J. Schmidt and P. Hennig. Probabilistic ODE Solutions in Millions of Dimensions. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 11634–11649.
[6]
[7]
[8]
N. Bosch, P. Hennig and F. Tronarp. Calibrated Adaptive Probabilistic ODE Solvers. In: Proceedings of The 24th International Conference on Artificial Intelligence and Statistics, Vol. 130 of Proceedings of Machine Learning Research, edited by A. Banerjee and K. Fukumizu (PMLR, 13–15 Apr 2021); pp. 3466–3474.
[9]
P. Hennig, M. A. Osborne and H. P. Kersting. Probabilistic Numerics: Computation as Machine Learning (Cambridge University Press, 2022).
[10]
H. Kersting and P. Hennig. Active Uncertainty Calibration in Bayesian ODE Solvers. In: Proceedings of the Thirty-Second Conference on Uncertainty in Artificial Intelligence, UAI'16 (AUAI Press, 2016); pp. 309–318.
[11]
H. Kersting, T. J. Sullivan and P. Hennig. Convergence rates of Gaussian ODE filters. Statistics and Computing 30, 1791–1816 (2020).
[12]
+References · ProbNumDiffEq.jl

References

[1]
N. Bosch, F. Tronarp and P. Hennig. Pick-and-Mix Information Operators for Probabilistic ODE Solvers. In: Proceedings of The 25th International Conference on Artificial Intelligence and Statistics, Vol. 151 of Proceedings of Machine Learning Research, edited by G. Camps-Valls, F. J. Ruiz and I. Valera (PMLR, 28–30 Mar 2022); pp. 10015–10027.
[2]
N. Bosch, P. Hennig and F. Tronarp. Probabilistic Exponential Integrators. In: Thirty-seventh Conference on Neural Information Processing Systems (2023).
[3]
F. Tronarp, N. Bosch and P. Hennig. Fenrir: Physics-Enhanced Regression for Initial Value Problems. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 21776–21794.
[4]
[5]
N. Krämer, N. Bosch, J. Schmidt and P. Hennig. Probabilistic ODE Solutions in Millions of Dimensions. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 11634–11649.
[6]
[7]
[8]
N. Bosch, P. Hennig and F. Tronarp. Calibrated Adaptive Probabilistic ODE Solvers. In: Proceedings of The 24th International Conference on Artificial Intelligence and Statistics, Vol. 130 of Proceedings of Machine Learning Research, edited by A. Banerjee and K. Fukumizu (PMLR, 13–15 Apr 2021); pp. 3466–3474.
[9]
P. Hennig, M. A. Osborne and H. P. Kersting. Probabilistic Numerics: Computation as Machine Learning (Cambridge University Press, 2022).
[10]
H. Kersting and P. Hennig. Active Uncertainty Calibration in Bayesian ODE Solvers. In: Proceedings of the Thirty-Second Conference on Uncertainty in Artificial Intelligence, UAI'16 (AUAI Press, 2016); pp. 309–318.
[11]
H. Kersting, T. J. Sullivan and P. Hennig. Convergence rates of Gaussian ODE filters. Statistics and Computing 30, 1791–1816 (2020).
[12]
diff --git a/previews/PR269/solvers/index.html b/previews/PR269/solvers/index.html index e6963c098..c0cf18c6b 100644 --- a/previews/PR269/solvers/index.html +++ b/previews/PR269/solvers/index.html @@ -4,10 +4,10 @@ prior=IWP(order), diffusionmodel=DynamicDiffusion(), initialization=TaylorModeInit(prior.num_derivatives), - kwargs...)

Gaussian ODE filter with first-order vector field linearization.

This is a semi-implicit, L-stable ODE solver so it can handle stiffness quite well [4], and it generally produces more expressive posterior covariances than the EK0. However, as typical implicit ODE solvers it scales cubically with the ODE dimension [5], so if you're solving a high-dimensional non-stiff problem you might want to give the EK0 a try.

Arguments

Some additional kwargs relating to implicit solvers are supported; check out DifferentialEquations.jl's Extra Options page. Right now, we support autodiff, chunk_size, and diff_type. In particular, autodiff=false can come in handy to use finite differences instead of ForwardDiff.jl to compute Jacobians.

Examples

julia> solve(prob, EK1())

References

source
ProbNumDiffEq.EK0Type
EK0(; order=3,
+      kwargs...)

Gaussian ODE filter with first-order vector field linearization.

This is a semi-implicit, L-stable ODE solver so it can handle stiffness quite well [4], and it generally produces more expressive posterior covariances than the EK0. However, as typical implicit ODE solvers it scales cubically with the ODE dimension [5], so if you're solving a high-dimensional non-stiff problem you might want to give the EK0 a try.

Arguments

  • order::Integer: Order of the integrated Wiener process (IWP) prior.
  • smooth::Bool: Turn smoothing on/off; smoothing is required for dense output.
  • prior::AbstractODEFilterPrior: Prior to be used by the ODE filter. By default, uses a 3-times integrated Wiener process prior IWP(3). See also: Priors.
  • diffusionmodel::ProbNumDiffEq.AbstractDiffusion: See Diffusion models and calibration.
  • initialization::ProbNumDiffEq.InitializationScheme: See Initialization.

Some additional kwargs relating to implicit solvers are supported; check out DifferentialEquations.jl's Extra Options page. Right now, we support autodiff, chunk_size, and diff_type. In particular, autodiff=false can come in handy to use finite differences instead of ForwardDiff.jl to compute Jacobians.

Examples

julia> solve(prob, EK1())

References

source
ProbNumDiffEq.EK0Type
EK0(; order=3,
       smooth=true,
       prior=IWP(order),
       diffusionmodel=DynamicDiffusion(),
-      initialization=TaylorModeInit(prior.num_derivatives))

Gaussian ODE filter with zeroth-order vector field linearization.

This is an explicit ODE solver. It is fast and scales well to high-dimensional problems [5], but it is not L-stable [4]. So for stiff problems, use the EK1.

Whenever possible this solver will use a Kronecker-factored implementation to achieve its linear scaling and to get the best runtimes. This can currently be done only with an IWP prior (default), with a scalar diffusion model (either DynamicDiffusion or FixedDiffusion). For other configurations the solver falls back to a dense implementation which scales cubically with the problem size.

Arguments

  • order::Integer: Order of the integrated Wiener process (IWP) prior.
  • smooth::Bool: Turn smoothing on/off; smoothing is required for dense output.
  • prior::AbstractODEFilterPrior: Prior to be used by the ODE filter. By default, uses a 3-times integrated Wiener process prior IWP(3). See also: Priors.
  • diffusionmodel::ProbNumDiffEq.AbstractDiffusion: See Diffusion models and calibration.
  • initialization::ProbNumDiffEq.InitializationScheme: See Initialization.

Examples

julia> solve(prob, EK0())

References

source

Probabilistic Exponential Integrators

ProbNumDiffEq.ExpEKFunction
ExpEK(; L, order=3, kwargs...)

Probabilistic exponential integrator

Probabilistic exponential integrators are a class of integrators for semi-linear stiff ODEs that provide improved stability by essentially solving the linear part of the ODE exactly. In probabilistic numerics, this amounts to including the linear part into the prior model of the solver.

ExpEK is therefore just a short-hand for EK0 with IOUP prior:

ExpEK(; order=3, L, kwargs...) = EK0(; prior=IOUP(order, L), kwargs...)

See also RosenbrockExpEK, EK0, EK1.

Arguments

See EK0 for available keyword arguments.

Examples

julia> prob = ODEProblem((du, u, p, t) -> (@. du = - u + sin(u)), [1.0], (0.0, 10.0))
-julia> solve(prob, ExpEK(L=-1))

Reference

  • [2] Bosch et al, "Probabilistic Exponential Integrators", arXiv (2021)
source
ProbNumDiffEq.RosenbrockExpEKFunction
RosenbrockExpEK(; order=3, kwargs...)

Probabilistic Rosenbrock-type exponential integrator

A probabilistic exponential integrator similar to ExpEK, but with automatic linearization along the mean numerical solution. This brings the advantage that the linearity does not need to be specified manually, and the more accurate local linearization can sometimes also improve stability; but since the "prior" is adjusted at each step the probabilistic interpretation becomes more complicated.

RosenbrockExpEK is just a short-hand for EK1 with locally-updated IOUP prior:

RosenbrockExpEK(; order=3, kwargs...) = EK1(; prior=IOUP(order, update_rate_parameter=true), kwargs...)

See also ExpEK, EK0, EK1.

Arguments

See EK1 for available keyword arguments.

Examples

julia> prob = ODEProblem((du, u, p, t) -> (@. du = - u + sin(u)), [1.0], (0.0, 10.0))
-julia> solve(prob, RosenbrockExpEK())

Reference

  • [2] Bosch et al, "Probabilistic Exponential Integrators", arXiv (2021)
source

References

[4]
F. Tronarp, H. Kersting, S. Särkkä and P. Hennig. Probabilistic solutions to ordinary differential equations as nonlinear Bayesian filtering: a new perspective. Statistics and Computing 29, 1297–1315 (2019).
[5]
N. Krämer, N. Bosch, J. Schmidt and P. Hennig. Probabilistic ODE Solutions in Millions of Dimensions. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 11634–11649.
[2]
N. Bosch, P. Hennig and F. Tronarp. Probabilistic Exponential Integrators. In: Thirty-seventh Conference on Neural Information Processing Systems (2023).
+ initialization=TaylorModeInit(prior.num_derivatives))

Gaussian ODE filter with zeroth-order vector field linearization.

This is an explicit ODE solver. It is fast and scales well to high-dimensional problems [5], but it is not L-stable [4]. So for stiff problems, use the EK1.

Whenever possible this solver will use a Kronecker-factored implementation to achieve its linear scaling and to get the best runtimes. This can currently be done only with an IWP prior (default), with a scalar diffusion model (either DynamicDiffusion or FixedDiffusion). For other configurations the solver falls back to a dense implementation which scales cubically with the problem size.

Arguments

Examples

julia> solve(prob, EK0())

References

source

Probabilistic Exponential Integrators

ProbNumDiffEq.ExpEKFunction
ExpEK(; L, order=3, kwargs...)

Probabilistic exponential integrator

Probabilistic exponential integrators are a class of integrators for semi-linear stiff ODEs that provide improved stability by essentially solving the linear part of the ODE exactly. In probabilistic numerics, this amounts to including the linear part into the prior model of the solver.

ExpEK is therefore just a short-hand for EK0 with IOUP prior:

ExpEK(; order=3, L, kwargs...) = EK0(; prior=IOUP(order, L), kwargs...)

See also RosenbrockExpEK, EK0, EK1.

Arguments

See EK0 for available keyword arguments.

Examples

julia> prob = ODEProblem((du, u, p, t) -> (@. du = - u + sin(u)), [1.0], (0.0, 10.0))
+julia> solve(prob, ExpEK(L=-1))

Reference

  • [2] Bosch et al, "Probabilistic Exponential Integrators", arXiv (2021)
source
ProbNumDiffEq.RosenbrockExpEKFunction
RosenbrockExpEK(; order=3, kwargs...)

Probabilistic Rosenbrock-type exponential integrator

A probabilistic exponential integrator similar to ExpEK, but with automatic linearization along the mean numerical solution. This brings the advantage that the linearity does not need to be specified manually, and the more accurate local linearization can sometimes also improve stability; but since the "prior" is adjusted at each step the probabilistic interpretation becomes more complicated.

RosenbrockExpEK is just a short-hand for EK1 with locally-updated IOUP prior:

RosenbrockExpEK(; order=3, kwargs...) = EK1(; prior=IOUP(order, update_rate_parameter=true), kwargs...)

See also ExpEK, EK0, EK1.

Arguments

See EK1 for available keyword arguments.

Examples

julia> prob = ODEProblem((du, u, p, t) -> (@. du = - u + sin(u)), [1.0], (0.0, 10.0))
+julia> solve(prob, RosenbrockExpEK())

Reference

  • [2] Bosch et al, "Probabilistic Exponential Integrators", arXiv (2021)
source

References

[4]
F. Tronarp, H. Kersting, S. Särkkä and P. Hennig. Probabilistic solutions to ordinary differential equations as nonlinear Bayesian filtering: a new perspective. Statistics and Computing 29, 1297–1315 (2019).
[5]
N. Krämer, N. Bosch, J. Schmidt and P. Hennig. Probabilistic ODE Solutions in Millions of Dimensions. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 11634–11649.
[2]
N. Bosch, P. Hennig and F. Tronarp. Probabilistic Exponential Integrators. In: Thirty-seventh Conference on Neural Information Processing Systems (2023).
diff --git a/previews/PR269/tutorials/dae/02838a3c.svg b/previews/PR269/tutorials/dae/02838a3c.svg new file mode 100644 index 000000000..bb824e986 --- /dev/null +++ b/previews/PR269/tutorials/dae/02838a3c.svg @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/dae/686c34f4.svg b/previews/PR269/tutorials/dae/686c34f4.svg deleted file mode 100644 index 9d7cdf3a8..000000000 --- a/previews/PR269/tutorials/dae/686c34f4.svg +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/previews/PR269/tutorials/dae/67fa0595.svg b/previews/PR269/tutorials/dae/c154e788.svg similarity index 65% rename from previews/PR269/tutorials/dae/67fa0595.svg rename to previews/PR269/tutorials/dae/c154e788.svg index bf3aafbb1..fbbfbcd57 100644 --- a/previews/PR269/tutorials/dae/67fa0595.svg +++ b/previews/PR269/tutorials/dae/c154e788.svg @@ -1,59 +1,59 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/dae/index.html b/previews/PR269/tutorials/dae/index.html index 3157831bb..abab36068 100644 --- a/previews/PR269/tutorials/dae/index.html +++ b/previews/PR269/tutorials/dae/index.html @@ -28,7 +28,7 @@ ylabel=["u₁(t)" "u₂(t)" "u₃(t)"], xlabel=["" "" "t"], denseplot=false, -)Example block output

Looks good!

Solving an Index-3 DAE directly

The following is based on the "Automatic Index Reduction of DAEs" tutorial by ModelingToolkit.jl, which demonstrates how the classic Rodas4 solver fails to solve a DAE due to the fact that it is of index 3; which is why ModelingToolkit's automatic index reduction is so useful.

It turns out that our probabilistic numerical solvers can directly solve the index-3 DAE!

First, define the pendulum problem as in the tutorial:

function pendulum!(du, u, p, t)
+)
Example block output

Looks good!

Solving an Index-3 DAE directly

The following is based on the "Automatic Index Reduction of DAEs" tutorial by ModelingToolkit.jl, which demonstrates how the classic Rodas4 solver fails to solve a DAE due to the fact that it is of index 3; which is why ModelingToolkit's automatic index reduction is so useful.

It turns out that our probabilistic numerical solvers can directly solve the index-3 DAE!

First, define the pendulum problem as in the tutorial:

function pendulum!(du, u, p, t)
     x, dx, y, dy, T = u
     g, L = p
     du[1] = dx
@@ -59,9 +59,9 @@
 u: 5-element Vector{Vector{Float64}}:
  [1.0, 0.0, 0.0, 0.0, 0.0]
  [1.0, 0.0, -4.8999999999999965e-12, -9.799999999999993e-6, 0.0]
- [1.0, -5.282199999999992e-16, -5.928999999999995e-10, -0.00010779999999999991, -9.04785641150889e-11]
- [1.0, -2.211945263568203e-13, -7.101167872169468e-9, -0.00037307223200678104, -2.651533816040319e-8]
- [1.0, -3.16619714623608e-12, -1.0142856375187924e-8, -0.00044586991931917005, -2.959672249087358e-6]

It does not work! This is because of the index of the DAE; see e.g. this explenation from the tutorial.

Does this also hold for the EK1 solver? Let's find out:

sol = solve(pendulum_prob, EK1())
retcode: Success
+ [1.0, -5.282199999999992e-16, -5.928999999999995e-10, -0.00010779999999999991, -9.047856411508895e-11]
+ [1.0, -2.2119452635682026e-13, -7.101167872169468e-9, -0.00037307223200678104, -2.6515338160403223e-8]
+ [1.0, -3.1661971462360842e-12, -1.0142856375187924e-8, -0.00044586991931917005, -2.9596722490873632e-6]

It does not work! This is because of the index of the DAE; see e.g. this explenation from the tutorial.

Does this also hold for the EK1 solver? Let's find out:

sol = solve(pendulum_prob, EK1())
retcode: Success
 Interpolation: ODE Filter Posterior
 t: 650-element Vector{Float64}:
  0.0
@@ -73,38 +73,38 @@
  0.0010432618632924343
  0.0023836933769503994
  0.00376397894518298
- 0.00519132985680733
+ 0.0051913299545603515
  ⋮
- 4.90762357257373
- 4.9249233452052845
- 4.94156648581745
- 4.957218738682317
- 4.971355170249541
- 4.982608288374372
- 4.991694323386008
- 4.999056608191708
+ 4.9075170789627265
+ 4.924817713693013
+ 4.941465957324324
+ 4.957126949171166
+ 4.971273780619228
+ 4.982539464941735
+ 4.991636376370394
+ 4.99900754138034
  5.0
 u: 650-element Vector{Vector{Float64}}:
  [1.0, 0.0, 0.0, 0.0, 0.0]
- [1.0, -2.431486347058932e-18, -4.899999999937332e-12, -9.800000000000003e-6, -3.870090816200658e-16]
- [1.0, 1.7789146062622286e-14, -5.929000004468115e-10, -0.00010780000000000093, -3.017617467891285e-12]
- [0.9999999999999998, -3.70439374569034e-12, -1.940772692127772e-8, -0.0006167588252348038, -1.3035790712252288e-9]
- [0.9999999999999896, 1.2314211594323908e-11, -1.446191174462324e-7, -0.001683607644419325, -3.157756137849315e-8]
- [0.9999999999996368, -9.146450475261067e-11, -8.52071296369091e-7, -0.004086636443002533, -4.845251072100237e-7]
- [0.9999999999857788, -1.891363005747165e-9, -5.333137047544634e-6, -0.01022396626026856, -7.83019593285614e-6]
- [0.9999999996124179, -5.727074844387708e-8, -2.7841771139449655e-5, -0.023360195092905718, -9.453725376044754e-5]
- [0.9999999975903671, -3.47565511825995e-7, -6.942093370365592e-5, -0.03688699364700588, -0.00037351475462522237]
- [0.9999999912808007, -1.274813798477067e-6, -0.0001320545364564287, -0.05087503248488846, -0.0009815791969192166]
+ [1.0, -2.4314862436613554e-18, -4.899999999937332e-12, -9.800000000000003e-6, -3.8700908657424404e-16]
+ [1.0, 1.7789145294998677e-14, -5.929000004468103e-10, -0.00010780000000000091, -3.017617506782065e-12]
+ [0.9999999999999998, -3.7043936982564946e-12, -1.9407726921277853e-8, -0.0006167588252348037, -1.3035790882853504e-9]
+ [0.9999999999999896, 1.2314211580771381e-11, -1.44619117446232e-7, -0.001683607644419324, -3.157756179550416e-8]
+ [0.9999999999996368, -9.14645049694511e-11, -8.520712963690922e-7, -0.0040866364430025325, -4.845251136462963e-7]
+ [0.9999999999857788, -1.891363036782452e-9, -5.333137047544626e-6, -0.010223966260268558, -7.830196037185059e-6]
+ [0.9999999996124179, -5.727074911250456e-8, -2.7841771139449754e-5, -0.023360195092905718, -9.453725502159396e-5]
+ [0.9999999975903671, -3.475655166455989e-7, -6.942093370365463e-5, -0.03688699364700587, -0.0003735147596097568]
+ [0.9999999912808, -1.2748139121346314e-6, -0.0001320545414296173, -0.050875033442868076, -0.0009815792655509948]
  ⋮
- [0.9901515983094562, -0.23196902176174244, -0.13999933176674903, -1.6410837906157405, -4.117701928160619]
- [0.985485923574849, -0.30971129638217454, -0.1697571656603886, -1.7984136618947304, -4.994077776833265]
- [0.9796090113312815, -0.398800977543536, -0.20091338119171973, -1.9446914200669492, -5.913934139779012]
- [0.9726222728427493, -0.4962033190633123, -0.23239173633629934, -2.07644496292479, -6.846657390063813]
- [0.964917713366661, -0.5960601567138191, -0.2625525038826454, -2.1894567194126324, -7.74446764211966]
- [0.9577276499036896, -0.6838774862987164, -0.28767648800680296, -2.2745959491885257, -8.496131042340755]
- [0.9511778571574013, -0.7602782053875152, -0.30864332405019274, -2.33976685635828, -9.126586023494314]
- [0.9453481754881106, -0.8258220430542568, -0.3260626415701132, -2.389978687873951, -9.652657051845301]
- [0.9445663499404606, -0.8344575788264914, -0.3283205911593655, -2.3962338652159065, -9.72104344598]

Nope! The EK1 is able to solve the index-3 DAE directly. Pretty cool!

plot(sol)
Example block output

Is index-reduction still worth it?

The point of the "Automatic Index Reduction of DAEs" tutorial is to demonstrate ModelingToolkit's utility for automatic index reduction, which enables the classic implicit Runge-Kutta solvers such as Rodas5 to solve this DAE. Let's see if that still helps in this context here.

First, modelingtoolkitize the problem:

traced_sys = modelingtoolkitize(pendulum_prob)

\[ \begin{align} + [0.9901762759660948, -0.23153527591044915, -0.13982468680458193, -1.640101658366291, -4.112574152777] + [0.9855186074470814, -0.30919223345740243, -0.16956731768246527, -1.7974680534518155, -4.9885089317327855] + [0.9796490622634825, -0.39822009128183117, -0.20071800271956705, -1.9438255578695307, -5.908213354069727] + [0.9726677674452103, -0.4955947555822665, -0.23220124652881585, -2.0756910626846037, -6.841100611544916] + [0.9649661547451862, -0.5954563486023015, -0.26237440996324674, -2.1888237301825506, -7.739309093847773] + [0.9577746394881572, -0.6833238755307015, -0.28752000462841704, -2.2740882543003975, -8.491657268979921] + [0.9512218014609886, -0.759783699618783, -0.3085078634659908, -2.339360099921525, -9.122785446176398] + [0.9453886341259372, -0.8253850822607255, -0.3259453168467175, -2.3896494063406686, -9.649455463447856] + [0.9445663666993634, -0.8344686220854718, -0.3283205429487118, -2.3962309474349133, -9.721401965804043]

Nope! The EK1 is able to solve the index-3 DAE directly. Pretty cool!

plot(sol)
Example block output

Is index-reduction still worth it?

The point of the "Automatic Index Reduction of DAEs" tutorial is to demonstrate ModelingToolkit's utility for automatic index reduction, which enables the classic implicit Runge-Kutta solvers such as Rodas5 to solve this DAE. Let's see if that still helps in this context here.

First, modelingtoolkitize the problem:

traced_sys = modelingtoolkitize(pendulum_prob)

\[ \begin{align} \frac{\mathrm{d} x_1\left( t \right)}{\mathrm{d}t} =& x_2\left( t \right) \\ \frac{\mathrm{d} x_2\left( t \right)}{\mathrm{d}t} =& x_1\left( t \right) x_5\left( t \right) \\ \frac{\mathrm{d} x_3\left( t \right)}{\mathrm{d}t} =& x_4\left( t \right) \\ @@ -131,7 +131,7 @@ sol3_final_error = norm(sol3.u[end] - truesol.u[end]) sol3_f_evals = sol3.stats.nf @info "Results" sol1_final_error sol1_f_evals sol3_final_error sol3_f_evals

┌ Info: Results
-│   sol1_final_error = 0.011009099106911627
+│   sol1_final_error = 0.01094743764363371
 │   sol1_f_evals = 1085
-│   sol3_final_error = 0.059628113793166855
-└   sol3_f_evals = 1409

The error for the index-1 DAE solve is much lower. So it seems that, even if the index-3 DAE could also be solved directly, index lowering might still be beneficial when solving DAEs with the EK1!

References

[1]
N. Bosch, F. Tronarp and P. Hennig. Pick-and-Mix Information Operators for Probabilistic ODE Solvers. In: Proceedings of The 25th International Conference on Artificial Intelligence and Statistics, Vol. 151 of Proceedings of Machine Learning Research, edited by G. Camps-Valls, F. J. Ruiz and I. Valera (PMLR, 28–30 Mar 2022); pp. 10015–10027.
+│ sol3_final_error = 0.059986712035684786 +└ sol3_f_evals = 1409

The error for the index-1 DAE solve is much lower. So it seems that, even if the index-3 DAE could also be solved directly, index lowering might still be beneficial when solving DAEs with the EK1!

References

[1]
N. Bosch, F. Tronarp and P. Hennig. Pick-and-Mix Information Operators for Probabilistic ODE Solvers. In: Proceedings of The 25th International Conference on Artificial Intelligence and Statistics, Vol. 151 of Proceedings of Machine Learning Research, edited by G. Camps-Valls, F. J. Ruiz and I. Valera (PMLR, 28–30 Mar 2022); pp. 10015–10027.
diff --git a/previews/PR269/tutorials/dynamical_odes/27b496d0.svg b/previews/PR269/tutorials/dynamical_odes/4087074d.svg similarity index 88% rename from previews/PR269/tutorials/dynamical_odes/27b496d0.svg rename to previews/PR269/tutorials/dynamical_odes/4087074d.svg index 8bc8d149c..ca89790d1 100644 --- a/previews/PR269/tutorials/dynamical_odes/27b496d0.svg +++ b/previews/PR269/tutorials/dynamical_odes/4087074d.svg @@ -1,46 +1,46 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/dynamical_odes/9c2daa49.svg b/previews/PR269/tutorials/dynamical_odes/9c2daa49.svg new file mode 100644 index 000000000..d3106ae91 --- /dev/null +++ b/previews/PR269/tutorials/dynamical_odes/9c2daa49.svg @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/dynamical_odes/961d3b04.svg b/previews/PR269/tutorials/dynamical_odes/ae304336.svg similarity index 88% rename from previews/PR269/tutorials/dynamical_odes/961d3b04.svg rename to previews/PR269/tutorials/dynamical_odes/ae304336.svg index c9dd1a90e..f3276bb5a 100644 --- a/previews/PR269/tutorials/dynamical_odes/961d3b04.svg +++ b/previews/PR269/tutorials/dynamical_odes/ae304336.svg @@ -1,46 +1,46 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/dynamical_odes/ba106ab3.svg b/previews/PR269/tutorials/dynamical_odes/ba106ab3.svg deleted file mode 100644 index b0c016e7e..000000000 --- a/previews/PR269/tutorials/dynamical_odes/ba106ab3.svg +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/previews/PR269/tutorials/dynamical_odes/bb2f9685.svg b/previews/PR269/tutorials/dynamical_odes/bb2f9685.svg deleted file mode 100644 index d20268efb..000000000 --- a/previews/PR269/tutorials/dynamical_odes/bb2f9685.svg +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/previews/PR269/tutorials/dynamical_odes/f97293c8.svg b/previews/PR269/tutorials/dynamical_odes/f97293c8.svg new file mode 100644 index 000000000..a263dec65 --- /dev/null +++ b/previews/PR269/tutorials/dynamical_odes/f97293c8.svg @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/dynamical_odes/index.html b/previews/PR269/tutorials/dynamical_odes/index.html index 0c18182c3..51a47f92d 100644 --- a/previews/PR269/tutorials/dynamical_odes/index.html +++ b/previews/PR269/tutorials/dynamical_odes/index.html @@ -19,13 +19,13 @@ tspan = (0.0, 100.0) prob = ODEProblem(Hénon_Heiles, [du0; u0], tspan) sol = solve(prob, EK1()); -plot(sol, idxs=(3, 4)) # where `idxs=(3,4)` is used to plot x agains yExample block output

Solving the second-order ODE directly

Instead of first transforming the problem, we can also solve it directly as a second-order ODE, by defining it as a SecondOrderODEProblem.

Note

The SecondOrderODEProblem type is not defined in ProbNumDiffEq.jl but is provided by SciMLBase.jl. For more information, check out the DifferentialEquations.jl documentation on Dynamical, Hamiltonian and 2nd Order ODE Problems.

function Hénon_Heiles2(ddu, du, u, p, t)
+plot(sol, idxs=(3, 4)) # where `idxs=(3,4)` is used to plot x agains y
Example block output

Solving the second-order ODE directly

Instead of first transforming the problem, we can also solve it directly as a second-order ODE, by defining it as a SecondOrderODEProblem.

Note

The SecondOrderODEProblem type is not defined in ProbNumDiffEq.jl but is provided by SciMLBase.jl. For more information, check out the DifferentialEquations.jl documentation on Dynamical, Hamiltonian and 2nd Order ODE Problems.

function Hénon_Heiles2(ddu, du, u, p, t)
     ddu[1] = -u[1] - 2 * u[1] * u[2]
     ddu[2] = u[2]^2 - u[2] - u[1]^2
 end
 prob2 = SecondOrderODEProblem(Hénon_Heiles2, du0, u0, tspan)
 sol2 = solve(prob2, EK1());
-plot(sol2, idxs=(3, 4))
Example block output

Benchmark: Solving second order ODEs is faster

Solving second-order ODEs is not just a matter of convenience - in fact, SciMLBase's SecondOrderODEProblem is neatly designed in such a way that all the classic solvers from OrdinaryDiffEq.jl can handle it by solving the corresponding first-order ODE. But, transforming the ODE to first order increases the dimensionality of the problem, and comes therefore at increased computational cost; this also motivates classic specialized solvers for second-order ODEs.

The probabilistic numerical solvers from ProbNumDiffEq.jl have the same internal state representation for first and second order ODEs; all that changes is the measurement model [1]. As a result, we can use the EK1 both for first and second order ODEs, but it automatically specializes on the latter to provide a 2x performance boost:

julia> @btime solve(prob, EK1(order=3), adaptive=false, dt=1e-2);
+plot(sol2, idxs=(3, 4))
Example block output

Benchmark: Solving second order ODEs is faster

Solving second-order ODEs is not just a matter of convenience - in fact, SciMLBase's SecondOrderODEProblem is neatly designed in such a way that all the classic solvers from OrdinaryDiffEq.jl can handle it by solving the corresponding first-order ODE. But, transforming the ODE to first order increases the dimensionality of the problem, and comes therefore at increased computational cost; this also motivates classic specialized solvers for second-order ODEs.

The probabilistic numerical solvers from ProbNumDiffEq.jl have the same internal state representation for first and second order ODEs; all that changes is the measurement model [1]. As a result, we can use the EK1 both for first and second order ODEs, but it automatically specializes on the latter to provide a 2x performance boost:

julia> @btime solve(prob, EK1(order=3), adaptive=false, dt=1e-2);
   766.312 ms (400362 allocations: 173.38 MiB)
 
 julia> @btime solve(prob2, EK1(order=4), adaptive=false, dt=1e-2);
@@ -37,7 +37,7 @@
 E(dx, dy, x, y) = PotentialEnergy(x, y) + KineticEnergy(dx, dy)
 E(u) = E(u...); # convenient shorthand
E (generic function with 2 methods)

So, let's have a look at how the total energy changes over time when we numerically simulate the Hénon-Heiles model over a long period of time: Standard solve

longprob = remake(prob2, tspan=(0.0, 1e3))
 longsol = solve(longprob, EK1(smooth=false), dense=false)
-plot(longsol.t, E.(longsol.u))
Example block output

It visibly loses energy over time, from an initial 0.12967 to a final 0.12899. Let's fix this to get a physically more meaningful solution.

Energy preservation with the ManifoldUpdate callback

In the language of ODE filters, preserving energy over time amounts to just another measurement model [1]. The most convenient way of updating on this additional zero measurement with ProbNumDiffEq.jl is with the ManifoldUpdate callback.

Note

The ManifoldUpdate callback can be thought of a probabilistic counterpart to the ManifoldProjection callback provided by DiffEqCallbacks.jl.

To do so, first define a (vector-valued) residual function, here chosen to be the difference between the current energy and the initial energy, and build a ManifoldUpdate callback

residual(u) = [E(u) - E(du0..., u0...)]
+plot(longsol.t, E.(longsol.u))
Example block output

It visibly loses energy over time, from an initial 0.12967 to a final 0.12899. Let's fix this to get a physically more meaningful solution.

Energy preservation with the ManifoldUpdate callback

In the language of ODE filters, preserving energy over time amounts to just another measurement model [1]. The most convenient way of updating on this additional zero measurement with ProbNumDiffEq.jl is with the ManifoldUpdate callback.

Note

The ManifoldUpdate callback can be thought of a probabilistic counterpart to the ManifoldProjection callback provided by DiffEqCallbacks.jl.

To do so, first define a (vector-valued) residual function, here chosen to be the difference between the current energy and the initial energy, and build a ManifoldUpdate callback

residual(u) = [E(u) - E(du0..., u0...)]
 cb = ManifoldUpdate(residual)
DiscreteCallback{ProbNumDiffEq.var"#condition#55", ProbNumDiffEq.var"#affect!#56"{Int64, Float64, Float64, typeof(Main.residual)}, typeof(SciMLBase.INITIALIZE_DEFAULT), typeof(SciMLBase.FINALIZE_DEFAULT)}(ProbNumDiffEq.var"#condition#55"(), ProbNumDiffEq.var"#affect!#56"{Int64, Float64, Float64, typeof(Main.residual)}(100, 1.0e-25, 1.0e-15, Main.residual), SciMLBase.INITIALIZE_DEFAULT, SciMLBase.FINALIZE_DEFAULT, Bool[1, 1])

Then, solve the ODE with this callback

longsol_preserving = solve(longprob, EK1(smooth=false), dense=false, callback=cb)
 plot(longsol.t, E.(longsol.u))
-plot!(longsol_preserving.t, E.(longsol_preserving.u))
Example block output

Voilà! With the ManifoldUpdate callback we could preserve the energy over time and obtain a more truthful probabilistic numerical long-term simulation of the Hénon-Heiles model.

References

[1]
N. Bosch, F. Tronarp and P. Hennig. Pick-and-Mix Information Operators for Probabilistic ODE Solvers. In: Proceedings of The 25th International Conference on Artificial Intelligence and Statistics, Vol. 151 of Proceedings of Machine Learning Research, edited by G. Camps-Valls, F. J. Ruiz and I. Valera (PMLR, 28–30 Mar 2022); pp. 10015–10027.
+plot!(longsol_preserving.t, E.(longsol_preserving.u))Example block output

Voilà! With the ManifoldUpdate callback we could preserve the energy over time and obtain a more truthful probabilistic numerical long-term simulation of the Hénon-Heiles model.

References

[1]
N. Bosch, F. Tronarp and P. Hennig. Pick-and-Mix Information Operators for Probabilistic ODE Solvers. In: Proceedings of The 25th International Conference on Artificial Intelligence and Statistics, Vol. 151 of Proceedings of Machine Learning Research, edited by G. Camps-Valls, F. J. Ruiz and I. Valera (PMLR, 28–30 Mar 2022); pp. 10015–10027.
diff --git a/previews/PR269/tutorials/exponential_integrators/ff1d4d7c.svg b/previews/PR269/tutorials/exponential_integrators/25b9b1e8.svg similarity index 93% rename from previews/PR269/tutorials/exponential_integrators/ff1d4d7c.svg rename to previews/PR269/tutorials/exponential_integrators/25b9b1e8.svg index e7aef8aea..b1019df47 100644 --- a/previews/PR269/tutorials/exponential_integrators/ff1d4d7c.svg +++ b/previews/PR269/tutorials/exponential_integrators/25b9b1e8.svg @@ -1,63 +1,63 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/exponential_integrators/5d81ea50.svg b/previews/PR269/tutorials/exponential_integrators/290cb01f.svg similarity index 93% rename from previews/PR269/tutorials/exponential_integrators/5d81ea50.svg rename to previews/PR269/tutorials/exponential_integrators/290cb01f.svg index 7e35e1e4b..9eadc0dea 100644 --- a/previews/PR269/tutorials/exponential_integrators/5d81ea50.svg +++ b/previews/PR269/tutorials/exponential_integrators/290cb01f.svg @@ -1,55 +1,55 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/exponential_integrators/a3687327.svg b/previews/PR269/tutorials/exponential_integrators/7d04d0ad.svg similarity index 92% rename from previews/PR269/tutorials/exponential_integrators/a3687327.svg rename to previews/PR269/tutorials/exponential_integrators/7d04d0ad.svg index 9b04f79cf..5265c3190 100644 --- a/previews/PR269/tutorials/exponential_integrators/a3687327.svg +++ b/previews/PR269/tutorials/exponential_integrators/7d04d0ad.svg @@ -1,65 +1,65 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/exponential_integrators/9e2f6528.svg b/previews/PR269/tutorials/exponential_integrators/abf67c7b.svg similarity index 93% rename from previews/PR269/tutorials/exponential_integrators/9e2f6528.svg rename to previews/PR269/tutorials/exponential_integrators/abf67c7b.svg index 16bf8a13a..ee80a7103 100644 --- a/previews/PR269/tutorials/exponential_integrators/9e2f6528.svg +++ b/previews/PR269/tutorials/exponential_integrators/abf67c7b.svg @@ -1,51 +1,51 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/exponential_integrators/index.html b/previews/PR269/tutorials/exponential_integrators/index.html index d1af025b6..e639fbb7e 100644 --- a/previews/PR269/tutorials/exponential_integrators/index.html +++ b/previews/PR269/tutorials/exponential_integrators/index.html @@ -12,7 +12,7 @@ prob = ODEProblem(f, u0, tspan) ref = solve(prob, EK1(), abstol=1e-10, reltol=1e-10) -plot(ref, color=:black, linestyle=:dash, label="Reference")Example block output

But for fixed (large) step sizes this ODE is more challenging: The explicit EK0 method oscillates and diverges due to the stiffness of the ODE, and the semi-implicit EK1 method is stable but the solution is not very accurate.

STEPSIZE = 4
+plot(ref, color=:black, linestyle=:dash, label="Reference")
Example block output

But for fixed (large) step sizes this ODE is more challenging: The explicit EK0 method oscillates and diverges due to the stiffness of the ODE, and the semi-implicit EK1 method is stable but the solution is not very accurate.

STEPSIZE = 4
 DM = FixedDiffusion() # recommended for fixed steps
 
 # we don't smooth the EK0 here to show the oscillations more clearly
@@ -22,14 +22,14 @@
 plot(ylims=(0.3, 1.05))
 plot!(ref, color=:black, linestyle=:dash, label="Reference")
 plot!(sol0, denseplot=false, marker=:o, markersize=2, label="EK0", color=1)
-plot!(sol1, denseplot=false, marker=:o, markersize=2, label="EK1", color=2)
Example block output

Probabilistic exponential integrators leverage the semi-linearity of the ODE to compute more accurate solutions for the same fixed step size. You can use either the ExpEK method and provide the linear part (with the keyword argument L), or the RosenbrockExpEK to automatically linearize along the mean of the numerical solution:

sol_exp = solve(prob, ExpEK(L=-1, diffusionmodel=DM), adaptive=false, dt=STEPSIZE)
+plot!(sol1, denseplot=false, marker=:o, markersize=2, label="EK1", color=2)
Example block output

Probabilistic exponential integrators leverage the semi-linearity of the ODE to compute more accurate solutions for the same fixed step size. You can use either the ExpEK method and provide the linear part (with the keyword argument L), or the RosenbrockExpEK to automatically linearize along the mean of the numerical solution:

sol_exp = solve(prob, ExpEK(L=-1, diffusionmodel=DM), adaptive=false, dt=STEPSIZE)
 sol_ros = solve(prob, RosenbrockExpEK(diffusionmodel=DM), adaptive=false, dt=STEPSIZE)
 
 plot(ylims=(0.3, 1.05))
 plot!(ref, color=:black, linestyle=:dash, label="Reference")
 plot!(sol_exp, denseplot=false, marker=:o, markersize=2, label="ExpEK", color=3)
-plot!(sol_ros, denseplot=false, marker=:o, markersize=2, label="RosenbrockExpEK", color=4)
Example block output

The solutions are indeed much more accurate than those of the standard EK1, for the same fixed step size!

Background: Integrated Ornstein-Uhlenbeck priors

Probabilistic exponential integrators "solve the linear part exactly" by including it into the prior model of the solver. Namely, the solver chooses a (q-times) integrated Ornstein-Uhlenbeck prior with rate parameter equal to the linearity. The ExpEK solver is just a short-hand for an EK0 with appropriate prior:

julia> ExpEK(order=3, L=-1) == EK0(prior=IOUP(3, -1))true

Similarly, the RosenbrockExpEK solver is also just a short-hand:

julia> RosenbrockExpEK(order=3) == EK1(prior=IOUP(3, update_rate_parameter=true))true

This means that you can also construct other probabilistic exponential integrators by hand! In this example the EK1 with IOUP prior with rate parameter -1 performs extremely well:

sol_expek1 = solve(prob, EK1(prior=IOUP(3, -1), diffusionmodel=DM), adaptive=false, dt=STEPSIZE)
+plot!(sol_ros, denseplot=false, marker=:o, markersize=2, label="RosenbrockExpEK", color=4)
Example block output

The solutions are indeed much more accurate than those of the standard EK1, for the same fixed step size!

Background: Integrated Ornstein-Uhlenbeck priors

Probabilistic exponential integrators "solve the linear part exactly" by including it into the prior model of the solver. Namely, the solver chooses a (q-times) integrated Ornstein-Uhlenbeck prior with rate parameter equal to the linearity. The ExpEK solver is just a short-hand for an EK0 with appropriate prior:

julia> ExpEK(order=3, L=-1) == EK0(prior=IOUP(3, -1))true

Similarly, the RosenbrockExpEK solver is also just a short-hand:

julia> RosenbrockExpEK(order=3) == EK1(prior=IOUP(3, update_rate_parameter=true))true

This means that you can also construct other probabilistic exponential integrators by hand! In this example the EK1 with IOUP prior with rate parameter -1 performs extremely well:

sol_expek1 = solve(prob, EK1(prior=IOUP(3, -1), diffusionmodel=DM), adaptive=false, dt=STEPSIZE)
 
 plot(ylims=(0.3, 1.05))
 plot!(ref, color=:black, linestyle=:dash, label="Reference")
-plot!(sol_expek1, denseplot=false, marker=:o, markersize=2, label="EK1 + IOUP")
Example block output

References

[2]
N. Bosch, P. Hennig and F. Tronarp. Probabilistic Exponential Integrators. In: Thirty-seventh Conference on Neural Information Processing Systems (2023).
+plot!(sol_expek1, denseplot=false, marker=:o, markersize=2, label="EK1 + IOUP")Example block output

References

[2]
N. Bosch, P. Hennig and F. Tronarp. Probabilistic Exponential Integrators. In: Thirty-seventh Conference on Neural Information Processing Systems (2023).
diff --git a/previews/PR269/tutorials/fenrir/40c73a6b.svg b/previews/PR269/tutorials/fenrir/40c73a6b.svg deleted file mode 100644 index 43638f474..000000000 --- a/previews/PR269/tutorials/fenrir/40c73a6b.svg +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/previews/PR269/tutorials/fenrir/4f632863.svg b/previews/PR269/tutorials/fenrir/4f632863.svg new file mode 100644 index 000000000..bc496eaa0 --- /dev/null +++ b/previews/PR269/tutorials/fenrir/4f632863.svg @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/fenrir/93abdb27.svg b/previews/PR269/tutorials/fenrir/93abdb27.svg new file mode 100644 index 000000000..64f347a2c --- /dev/null +++ b/previews/PR269/tutorials/fenrir/93abdb27.svg @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/fenrir/a54fc809.svg b/previews/PR269/tutorials/fenrir/a54fc809.svg deleted file mode 100644 index b7e7411ad..000000000 --- a/previews/PR269/tutorials/fenrir/a54fc809.svg +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/previews/PR269/tutorials/fenrir/index.html b/previews/PR269/tutorials/fenrir/index.html index c9eafcbf1..8e9fa11eb 100644 --- a/previews/PR269/tutorials/fenrir/index.html +++ b/previews/PR269/tutorials/fenrir/index.html @@ -26,12 +26,12 @@ odedata = [true_sol(t) .+ sqrt(observation_noise_var) * randn(length(u0)) for t in times] plot(true_sol, color=:black, linestyle=:dash, label=["True Solution" ""]) -scatter!(times, stack(odedata), markersize=2, markerstrokewidth=0.1, color=1, label=["Noisy Data" ""])Example block output

Our goal is then to recover the true parameter p (and thus also the true trajectoy plotted above) the noisy data.

Computing the negative log-likelihood

To do parameter inference - be it maximum-likelihod, maximum a posteriori, or full Bayesian inference with MCMC - we need to evaluate the likelihood of given a parameter estimate $\theta_\text{est}$. This is exactly what Fenrir.jl's fenrir_nll provides:

p_est = (0.1, 0.1, 2.0)
+scatter!(times, stack(odedata), markersize=2, markerstrokewidth=0.1, color=1, label=["Noisy Data" ""])
Example block output

Our goal is then to recover the true parameter p (and thus also the true trajectoy plotted above) the noisy data.

Computing the negative log-likelihood

To do parameter inference - be it maximum-likelihod, maximum a posteriori, or full Bayesian inference with MCMC - we need to evaluate the likelihood of given a parameter estimate $\theta_\text{est}$. This is exactly what Fenrir.jl's fenrir_nll provides:

p_est = (0.1, 0.1, 2.0)
 prob = remake(true_prob, p=p_est)
 data = (t=times, u=odedata)
 κ² = 1e10
 nll, _, _ = fenrir_nll(prob, data, observation_noise_var, κ²; dt=1e-1)
-nll
261.76460703697694

This is the negative marginal log-likelihood of the parameter p_est. You can use it as any other NLL: Optimize it to compute maximum-likelihood estimates or MAPs, or plug it into MCMC to sample from the posterior. In our paper [3] we compute MLEs by pairing Fenrir with Optimization.jl and ForwardDiff.jl. Let's quickly explore how to do this next.

Maximum-likelihood parameter inference

To compute a maximum-likelihood estimate (MLE), we just need to maximize $\theta \to p(\mathcal{D} \mid \theta)$ - that is, minimize the nll from above. We use Optimization.jl for this. First, define a loss function and create an OptimizationProblem

function loss(x, _)
+nll
256.79498264674936

This is the negative marginal log-likelihood of the parameter p_est. You can use it as any other NLL: Optimize it to compute maximum-likelihood estimates or MAPs, or plug it into MCMC to sample from the posterior. In our paper [3] we compute MLEs by pairing Fenrir with Optimization.jl and ForwardDiff.jl. Let's quickly explore how to do this next.

Maximum-likelihood parameter inference

To compute a maximum-likelihood estimate (MLE), we just need to maximize $\theta \to p(\mathcal{D} \mid \theta)$ - that is, minimize the nll from above. We use Optimization.jl for this. First, define a loss function and create an OptimizationProblem

function loss(x, _)
     ode_params = x[begin:end-1]
     prob = remake(true_prob, p=ode_params)
     κ² = exp(x[end]) # the diffusion parameter of the EK1
@@ -49,9 +49,9 @@
  2.0
  1.0

Then, just solve it! Here we use LBFGS:

optsol = solve(optprob, LBFGS())
 p_mle = optsol.u[1:3]
3-element Vector{Float64}:
- 0.19363762164699427
- 0.22182545984718458
- 3.0097788306135462

Success! The computed MLE is quite close to the true parameter which we used to generate the data. As a final step, let's plot the true solution, the data, and the result of the MLE:

plot(true_sol, color=:black, linestyle=:dash, label=["True Solution" ""])
+ 0.2298436563107695
+ 9.555497032433517e-11
+ 3.039576794132833

Success! The computed MLE is quite close to the true parameter which we used to generate the data. As a final step, let's plot the true solution, the data, and the result of the MLE:

plot(true_sol, color=:black, linestyle=:dash, label=["True Solution" ""])
 scatter!(times, stack(odedata), markersize=2, markerstrokewidth=0.1, color=1, label=["Noisy Data" ""])
 mle_sol = solve(remake(true_prob, p=p_mle), EK1())
-plot!(mle_sol, color=3, label=["MLE-parameter Solution" ""])
Example block output

Looks good!

Reference

[3]
F. Tronarp, N. Bosch and P. Hennig. Fenrir: Physics-Enhanced Regression for Initial Value Problems. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 21776–21794.
+plot!(mle_sol, color=3, label=["MLE-parameter Solution" ""])Example block output

Looks good!

Reference

[3]
F. Tronarp, N. Bosch and P. Hennig. Fenrir: Physics-Enhanced Regression for Initial Value Problems. In: Proceedings of the 39th International Conference on Machine Learning, Vol. 162 of Proceedings of Machine Learning Research, edited by K. Chaudhuri, S. Jegelka, L. Song, C. Szepesvari, G. Niu and S. Sabato (PMLR, 17–23 Jul 2022); pp. 21776–21794.
diff --git a/previews/PR269/tutorials/getting_started/a3f0ff47.svg b/previews/PR269/tutorials/getting_started/3d65dce0.svg similarity index 91% rename from previews/PR269/tutorials/getting_started/a3f0ff47.svg rename to previews/PR269/tutorials/getting_started/3d65dce0.svg index 35693b30c..942991903 100644 --- a/previews/PR269/tutorials/getting_started/a3f0ff47.svg +++ b/previews/PR269/tutorials/getting_started/3d65dce0.svg @@ -1,54 +1,54 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/getting_started/c11458c7.svg b/previews/PR269/tutorials/getting_started/8e5b5ab3.svg similarity index 96% rename from previews/PR269/tutorials/getting_started/c11458c7.svg rename to previews/PR269/tutorials/getting_started/8e5b5ab3.svg index acd985b25..fe05b3a9a 100644 --- a/previews/PR269/tutorials/getting_started/c11458c7.svg +++ b/previews/PR269/tutorials/getting_started/8e5b5ab3.svg @@ -1,50 +1,50 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/getting_started/e74a8c7a.svg b/previews/PR269/tutorials/getting_started/c2705ff0.svg similarity index 96% rename from previews/PR269/tutorials/getting_started/e74a8c7a.svg rename to previews/PR269/tutorials/getting_started/c2705ff0.svg index 0b1b04713..e552c1efd 100644 --- a/previews/PR269/tutorials/getting_started/e74a8c7a.svg +++ b/previews/PR269/tutorials/getting_started/c2705ff0.svg @@ -1,50 +1,50 @@ - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/previews/PR269/tutorials/getting_started/index.html b/previews/PR269/tutorials/getting_started/index.html index 17b30c042..ab394f898 100644 --- a/previews/PR269/tutorials/getting_started/index.html +++ b/previews/PR269/tutorials/getting_started/index.html @@ -15,7 +15,7 @@ prob = ODEProblem(fitz, u0, tspan, p) sol = solve(prob, EK1()) -plot(sol)Example block output

Step 1: Define the problem

First, import ProbNumDiffEq.jl

using ProbNumDiffEq

Then, set up the ODEProblem exactly as you would in DifferentialEquations.jl. Define the vector field

function fitz(du, u, p, t)
+plot(sol)
Example block output

Step 1: Define the problem

First, import ProbNumDiffEq.jl

using ProbNumDiffEq

Then, set up the ODEProblem exactly as you would in DifferentialEquations.jl. Define the vector field

function fitz(du, u, p, t)
     a, b, c = p
     du[1] = c * (u[1] - u[1]^3 / 3 + u[2])
     du[2] = -(1 / c) * (u[1] - a - b * u[2])
@@ -47,50 +47,50 @@
  20.0
 u: 267-element Vector{Vector{Float64}}:
  [-1.0, 1.0]
- [-0.978397898660792, 1.0098599972789335]
- [-0.9424079091803094, 1.0253304289278917]
- [-0.9028542905882085, 1.0410170752594414]
- [-0.8445349615757094, 1.061811723174967]
- [-0.7847703259504633, 1.0804970332988895]
- [-0.7018976697192758, 1.102556299329848]
- [-0.6220689201271806, 1.1201790771323812]
- [-0.5125846235780982, 1.1395948416743378]
- [-0.41230242602460077, 1.1534759756505184]
+ [-0.9783978986607919, 1.0098599972789337]
+ [-0.942407909180309, 1.0253304289278917]
+ [-0.9028542905882084, 1.0410170752594414]
+ [-0.8445349615757093, 1.0618117231749669]
+ [-0.7847703259504631, 1.0804970332988895]
+ [-0.7018976697192763, 1.102556299329848]
+ [-0.6220689201271807, 1.120179077132381]
+ [-0.5125846235780989, 1.139594841674338]
+ [-0.4123024260246011, 1.1534759756505186]
  ⋮
- [2.0826740294562955, 0.9061101524201121]
- [2.0787445607569244, 0.8805858429639267]
- [2.0732021275130466, 0.853936833241537]
- [2.066046263371205, 0.8247002716083782]
- [2.0573291294637484, 0.7924433159689326]
- [2.047122912814466, 0.756988343459779]
- [2.0350861534147553, 0.7169394922556975]
- [2.0210436519484083, 0.6717007174964885]
- [2.010440511866882, 0.6383145073764052]

That's it! we just computed a probabilistic numerical ODE solution!

Step 3: Analyze the solution

Let's plot the result with Plots.jl.

using Plots
-plot(sol)
Example block output

Looks good! Looks like the EK1 managed to solve the Fitzhugh-Nagumo problem quite well.

Tip

To learn more about plotting ODE solutions, check out the plotting tutorial for DifferentialEquations.jl + Plots.jl provided here. Most of that works exactly as expected with ProbNumDiffEq.jl.

Plot the probabilistic error estimates

The plot above looks like a standard ODE solution – but it's not! The numerical errors are just so small that we can't see them in the plot, and the probabilistic error estimates are too. We can visualize them by plotting the errors and error estimates directly:

using OrdinaryDiffEq, Statistics
+ [2.0826740294562907, 0.9061101524201061]
+ [2.07874456075692, 0.8805858429639213]
+ [2.0732021275130426, 0.8539368332415318]
+ [2.066046263371202, 0.8247002716083734]
+ [2.0573291294637452, 0.7924433159689279]
+ [2.047122912814464, 0.7569883434597745]
+ [2.035086153414754, 0.7169394922556932]
+ [2.021043651948407, 0.6717007174964843]
+ [2.010440511866881, 0.6383145073764008]

That's it! we just computed a probabilistic numerical ODE solution!

Step 3: Analyze the solution

Let's plot the result with Plots.jl.

using Plots
+plot(sol)
Example block output

Looks good! Looks like the EK1 managed to solve the Fitzhugh-Nagumo problem quite well.

Tip

To learn more about plotting ODE solutions, check out the plotting tutorial for DifferentialEquations.jl + Plots.jl provided here. Most of that works exactly as expected with ProbNumDiffEq.jl.

Plot the probabilistic error estimates

The plot above looks like a standard ODE solution – but it's not! The numerical errors are just so small that we can't see them in the plot, and the probabilistic error estimates are too. We can visualize them by plotting the errors and error estimates directly:

using OrdinaryDiffEq, Statistics
 reference = solve(prob, Vern9(), abstol=1e-9, reltol=1e-9, saveat=sol.t)
 errors = reduce(hcat, mean.(sol.pu) .- reference.u)'
 error_estimates = reduce(hcat, std.(sol.pu))'
 plot(sol.t, errors, label="error", color=[1 2], xlabel="t", ylabel="err")
 plot!(sol.t, zero(errors), ribbon=3error_estimates, label="error estimate",
-      color=[1 2], alpha=0.2)
Example block output

More about the ProbabilisticODESolution

The solution object returned by ProbNumDiffEq.jl mostly behaves just like any other ODESolution in DifferentialEquations.jl – with some added uncertainties and related functionality on top. So, sol can be indexed

julia> sol[1]2-element Vector{Float64}:
+      color=[1 2], alpha=0.2)
Example block output

More about the ProbabilisticODESolution

The solution object returned by ProbNumDiffEq.jl mostly behaves just like any other ODESolution in DifferentialEquations.jl – with some added uncertainties and related functionality on top. So, sol can be indexed

julia> sol[1]2-element Vector{Float64}:
  -1.0
   1.0
julia> sol[end]2-element Vector{Float64}: - 2.010440511866882 - 0.6383145073764052

and has fields sol.t and sol.u which store the time points and mean estimates:

julia> sol.t[end]20.0
julia> sol.u[end]2-element Vector{Float64}: - 2.010440511866882 - 0.6383145073764052

But since sol is a probabilistic numerical ODE solution, it contains a Gaussian distributions over solution values. The marginals of this posterior are stored in sol.pu:

julia> sol.pu[end]Gaussian{Vector{Float64},PSDMatrix{Float64, Matrix{Float64}}}([2.010440511866882, 0.6383145073764052], 2x2 PSDMatrix{Float64, Matrix{Float64}}; R=[4.819328866917222e-5 0.00015008628164946077; -4.209242496297612e-5 -0.00013099898184966161; 4.6624624650486946e-7 6.695624542009579e-6; -9.340635818918553e-8 5.806477587559574e-8; 1.3698832861282824e-6 4.548663507955255e-6; -1.6958383599790598e-7 -5.775663746220566e-6; 0.0 0.0; 0.0 0.0])

You can compute means, covariances, and standard deviations via Statistics.jl:

julia> using Statistics
julia> mean(sol.pu[5])2-element Vector{Float64}: - -0.8445349615757094 - 1.061811723174967
julia> cov(sol.pu[5])2x2 PSDMatrix{Float64, Matrix{Float64}} + 2.010440511866881 + 0.6383145073764008

and has fields sol.t and sol.u which store the time points and mean estimates:

julia> sol.t[end]20.0
julia> sol.u[end]2-element Vector{Float64}: + 2.010440511866881 + 0.6383145073764008

But since sol is a probabilistic numerical ODE solution, it contains a Gaussian distributions over solution values. The marginals of this posterior are stored in sol.pu:

julia> sol.pu[end]Gaussian{Vector{Float64},PSDMatrix{Float64, Matrix{Float64}}}([2.010440511866881, 0.6383145073764008], 2x2 PSDMatrix{Float64, Matrix{Float64}}; R=[4.81932886699248e-5 0.00015008628165180923; -4.209242496289744e-5 -0.00013099898184941778; 4.662462465125992e-7 6.695624542200969e-6; -9.340635818945464e-8 5.806477582113023e-8; 1.3698832861141067e-6 4.548663507910416e-6; -1.6958383599828098e-7 -5.7756637462341496e-6; 0.0 0.0; 0.0 0.0])

You can compute means, covariances, and standard deviations via Statistics.jl:

julia> using Statistics
julia> mean(sol.pu[5])2-element Vector{Float64}: + -0.8445349615757093 + 1.0618117231749669
julia> cov(sol.pu[5])2x2 PSDMatrix{Float64, Matrix{Float64}} Right square root: R=8×2 Matrix{Float64}: -2.8014e-6 -1.24815e-7 0.0 2.74772e-6 - 0.0 2.38228e-21 - 0.0 6.4851e-22 - 0.0 5.80915e-20 + 0.0 3.70577e-22 + 0.0 2.18376e-22 + 0.0 -7.29422e-20 0.0 0.0 0.0 0.0 0.0 0.0
julia> std(sol.pu[5])2-element Vector{Float64}: - 2.801400360981113e-6 - 2.7505533924666884e-6

Dense output

Probabilistic numerical ODE solvers approximate the posterior distribution

\[p \Big( y(t) ~\big|~ y(0) = y_0, \{ \dot{y}(t_i) = f_\theta(y(t_i), t_i) \} \Big),\]

which describes a posterior not just for the discrete steps but for any $t$ in the continuous space $t \in [0, T]$; in classic ODE solvers, this is also known as "interpolation" or "dense output". The probabilistic solutions returned by our solvers can be interpolated as usual by treating them as functions, but they return Gaussian distributions

julia> sol(0.45)Gaussian{Vector{Float64},PSDMatrix{Float64, Matrix{Float64}}}([-0.2773821283086774, 1.16756594306271], 2x2 PSDMatrix{Float64, Matrix{Float64}}; R=[-3.208354407823204e-5 -4.789969845353979e-6; 0.0 1.9264788456683634e-5; 0.0 1.4605790175636245e-5; 0.0 1.0839739026011068e-6; 0.0 5.606932635209018e-7; 0.0 0.0; 0.0 0.0; 0.0 0.0])
julia> mean(sol(0.45))2-element Vector{Float64}: - -0.2773821283086774 - 1.16756594306271

Next steps

Check out one of the other tutorials:

+ 2.8014003609809455e-6 + 2.7505533924661454e-6

Dense output

Probabilistic numerical ODE solvers approximate the posterior distribution

\[p \Big( y(t) ~\big|~ y(0) = y_0, \{ \dot{y}(t_i) = f_\theta(y(t_i), t_i) \} \Big),\]

which describes a posterior not just for the discrete steps but for any $t$ in the continuous space $t \in [0, T]$; in classic ODE solvers, this is also known as "interpolation" or "dense output". The probabilistic solutions returned by our solvers can be interpolated as usual by treating them as functions, but they return Gaussian distributions

julia> sol(0.45)Gaussian{Vector{Float64},PSDMatrix{Float64, Matrix{Float64}}}([-0.2773821283086784, 1.1675659430627112], 2x2 PSDMatrix{Float64, Matrix{Float64}}; R=[-3.208354407823606e-5 -4.789969845354348e-6; 0.0 1.9264788456689614e-5; 0.0 1.460579017563194e-5; 0.0 1.0839739026010661e-6; 0.0 -5.606932635217177e-7; 0.0 0.0; 0.0 0.0; 0.0 0.0])
julia> mean(sol(0.45))2-element Vector{Float64}: + -0.2773821283086784 + 1.1675659430627112

Next steps

Check out one of the other tutorials: