Skip to content

Commit e959929

Browse files
committed
Moved Advanced SDE example into examples, streamlined notation, improved how_to_choose_a_solver
1 parent 0433920 commit e959929

File tree

6 files changed

+653
-737
lines changed

6 files changed

+653
-737
lines changed

docs/api/solvers/sde_solvers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SDE solvers
22

33
See also [How to choose a solver](../../usage/how-to-choose-a-solver.md#stochastic-differential-equations)
4-
and [SDE example](../../devdocs/sde_example.ipynb/#table-of-available-srk-methods-in-diffrax) which contains a table of SDE solvers and their properties.
4+
and [SDE example](../../../examples/sde_example.ipynb/#table-of-available-srk-methods-in-diffrax) which contains a table of SDE solvers and their properties.
55

66
!!! info "Term structure"
77

docs/devdocs/SDE_solver_table.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SDE solver table
2+
3+
For an explanation of the terms in the table, see [how to choose a solver](../usage/how-to-choose-a-solver.md#stochastic-differential-equations).
4+
5+
```
6+
+----------------+-------+------------+------------------------------------+-------------------+----------------+------------------------------------------+
7+
| | SDE | Lévy | Strong/weak order (per noise type) | VF evaluations | Embedded error | Recommended for |
8+
| | type | area +----------+--------------+----------+-------+-----------+ estimation | (and other notes) |
9+
| | | | General | Commutative | Additive | Drift | Diffusion | | |
10+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
11+
| Euler | Itô | BM only | 0.5/1.0 | 0.5/1.0 | 1.0/1.0 | 1 | 1 | No | Itô SDEs when a cheap solver is needed. |
12+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
13+
| Heun | Strat | BM only | 0.5/1.0 | 1.0/1.0 | 1.0/1.0 | 2 | 2 | Yes | Standard solver for Stratonovich SDEs. |
14+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
15+
| EulerHeun | Strat | BM only | 0.5/1.0 | 0.5/1.0 | 1.0/1.0 | 1 | 2 | No | Stratonovich SDEs with expensive drift. |
16+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
17+
| ItoMilstein | Itô | BM only | 0.5/1.0 | 1.0/1.0 | 1.0/1.0 | 1 | 1 | No | Better than Euler for Itô SDEs, but |
18+
| | | | | | | | | | comuptes the derivative of diffusion VF. |
19+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
20+
| Stratonovich | Strat | BM only | 0.5/1.0 | 1.0/1.0 | 1.0/1.0 | 1 | 1 | No | For commutative Stratonovich SDEs when |
21+
| Milstein | | | | | | | | | space-time Lévy area is not available. |
22+
| | | | | | | | | | Computes derivative of diffusion VF. |
23+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
24+
| ReversibleHeun | Strat | BM only | 0.5/1.0 | 1.0/1.0 | 1.0/1.0 | 2 | 2 | Yes | When a reversible solver is needed. |
25+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
26+
| Midpoint | Strat | BM only | 0.5/1.0 | 1.0/1.0 | 1.0/1.0 | 2 | 2 | Yes | Usually Heun should be preferred. |
27+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
28+
| Ralston | Strat | BM only | 0.5/1.0 | 1.0/1.0 | 1.0/1.0 | 2 | 2 | Yes | Usually Heun should be preferred. |
29+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
30+
| ShARK | Strat | space-time | / | / | 1.5/2.0 | 2 | 2 | Yes | Additive noise SDEs. |
31+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
32+
| SRA1 | Strat | space-time | / | / | 1.5/2.0 | 2 | 2 | Yes | Only slightly worse than ShARK. |
33+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
34+
| SEA | Strat | space-time | / | / | 1.0/1.0 | 1 | 1 | No | Cheap solver for additive noise SDEs. |
35+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
36+
| SPaRK | Strat | space-time | 0.5/1.0 | 1.0/1.0 | 1.5/2.0 | 3 | 3 | Yes | General SDEs when embedded error |
37+
| | | | | | | | | | estimation is needed. |
38+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
39+
| GeneralShARK | Strat | space-time | 0.5/1.0 | 1.0/1.0 | 1.5/2.0 | 2 | 3 | No | General SDEs when embedded error |
40+
| | | | | | | | | | estimaiton is not needed. |
41+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
42+
| SlowRK | Strat | space-time | 0.5/1.0 | 1.5/2.0 | 1.5/2.0 | 2 | 5 | No | Commutative noise SDEs. |
43+
+----------------+-------+------------+----------+--------------+----------+-------+-----------+----------------+------------------------------------------+
44+
```

docs/devdocs/sde_example.ipynb

Lines changed: 0 additions & 709 deletions
This file was deleted.

docs/usage/how-to-choose-a-solver.md

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,54 +42,51 @@ For "split stiffness" problems, with one term that is stiff and another term tha
4242

4343
## Stochastic differential equations
4444

45-
SDE solvers are relatively specialised depending on the type of problem. Each solver will converge to either the Itô solution or the Stratonovich solution. In addition some solvers require "commutative noise".
45+
SDE solvers are relatively specialised depending on the type of problem. Each solver will converge to either the Itô solution or the Stratonovich solution of the SDE. The Itô and Stratonovich solutions coincide iff the SDE has additive noise (as defined below). In addition some solvers require the SDE to have "commutative noise" or "additive noise". All of these terms are defined below.
4646

47-
!!! info "Commutative noise"
47+
### General (noncommutative) noise
48+
This includes any SDE of the form $dy(t) = f(y(t), t) dt + g(y(t), t) dw(t),$ where $t \in [0, T]$, $y(t) \in \mathbb{R}^e$, and $w$ is a standard Brownian motion on $\mathbb{R}^d$. We refer to $f: \mathbb{R}^e \times [0, T] \to \mathbb{R}^e$ as the drift vector field (VF) and $g: \mathbb{R}^e \times [0, T] \to \mathbb{R}^{e \times d}$ is the diffusion matrix field with columns $g_i$ for $i = 1, \ldots, d$.
4849

49-
Consider the SDE
5050

51-
$\mathrm{d}y(t) = μ(t, y(t))\mathrm{d}t + σ(t, y(t))\mathrm{d}w(t)$
51+
### Commutative noise
52+
The diffusion matrix $σ$ is said to satisfy the commutativity condition if
5253

53-
then the diffusion matrix $σ$ is said to satisfy the commutativity condition if
54+
$\sum_{i=1}^d g_{i, j} \frac{\partial g_{k, l}}{\partial y_i} = \sum_{i=1}^d g_{i, l} \frac{\partial g_{k, j}}{\partial y_i}$
5455

55-
$\sum_{i=1}^d σ_{i, j} \frac{\partial σ_{k, l}}{\partial y_i} = \sum_{i=1}^d σ_{i, l} \frac{\partial σ_{k, j}}{\partial y_i}$
56+
For example, this holds:
5657

57-
Some common special cases in which this condition is satisfied are:
58+
- when $g$ is a diagonal operator (i.e. $g(y,t)$ is a diagonal matrix for all $y, t$ and the i-th diagonal entry depends only on $y_i$),
59+
- when the dimension of BM is $d=1$, or
60+
- when the noise is additive (see below).
5861

59-
- the diffusion is additive ($σ$ is independent of $y$);
60-
- the noise is scalar ($w$ is scalar-valued);
61-
- the diffusion is diagonal ($σ$ is a diagonal matrix and such that the i-th
62-
diagonal entry depends only on $y_i$; *not* to be confused with the simpler
63-
but insufficient condition that $σ$ is only a diagonal matrix)
62+
- The solver with the highest order of convergence for commutative noise SDEs is [`diffrax.SlowRK`][]. [`diffrax.ItoMilstein`][] and [`diffrax.StratonovichMilstein`][] are alternatives which evaluate the vector field fewer times per step, but also compute its derivative.
63+
64+
65+
### Additive noise
66+
We say that the diffusion is additive when $g$ does not depend on $y(t)$ and the SDE can be written as $dy(t) = f(y(t), t) dt + g(t) dw(t)$.
67+
68+
Additive noise is a special case of commutative noise. For additive noise SDEs, the Itô and Stratonovich solutions conicide. Some solvers are specifically designed for additive noise SDEs, of these [`diffrax.SEA`][] is the cheapest, [`diffrax.ShARK`][] is the most accurate and [`diffrax.SRA1`][] is another alternative.
6469

6570
### Itô
6671

6772
For Itô SDEs:
6873

74+
- For general noise [`diffrax.Euler`][] is a typical choice.
6975
- If the noise is commutative then [`diffrax.ItoMilstein`][] is a typical choice;
70-
- If the noise is noncommutative then [`diffrax.Euler`][] is a typical choice.
7176

7277
### Stratonovich
7378

7479
For Stratonovich SDEs:
7580

7681
- If cheap low-accuracy solves are desired then [`diffrax.EulerHeun`][] is a typical choice.
77-
- Otherwise, and if the noise is commutative, then [`diffrax.SlowRK`][] has the best order of convergence, but is expensive per step. [`diffrax.StratonovichMilstein`][] is a good cheap alternative.
78-
- If the noise is noncommutative, [`diffrax.GeneralShARK`][] is the most efficient choice, while [`diffrax.Heun`][] is a good cheap alternative.
79-
- If the noise is noncommutative and an embedded method for adaptive step size control is desired, then [`diffrax.SPaRK`][] is the recommended choice.
80-
81-
### Additive noise
82-
83-
Consider the SDE
84-
85-
$\mathrm{d}y(t) = μ(t, y(t))\mathrm{d}t + σ(t, y(t))\mathrm{d}w(t)$
86-
87-
Then the diffusion matrix $σ$ is said to be additive if $σ(t, y) = σ(t)$. That is to say if the diffusion is independent of $y$.
82+
- For general noise, [`diffrax.GeneralShARK`][] is the most efficient choice, while [`diffrax.Heun`][] is a good cheap alternative.
83+
- If an embedded method for adaptive step size control is desired and the noise is noncommutative then [`diffrax.SPaRK`][] is the recommended choice.
84+
- If the noise is commutative, then [`diffrax.SlowRK`][] has the best order of convergence, but is expensive per step. [`diffrax.StratonovichMilstein`][] is a good cheaper alternative.
8885

89-
In this case the Itô solution and the Stratonovich solution coincide, and mathematically speaking the choice of Itô vs Stratonovich is unimportant. Special solvers for additive-noise SDEs tend to do particularly well as compared to the general Itô or Stratonovich solvers discussed above.
86+
### More information about SDE solvers
9087

91-
- The cheapest (but least accurate) solver is [`diffrax.SEA`][].
92-
- Otherwise [`diffrax.ShARK`][] or [`diffrax.SRA1`][] are good choices.
88+
A detailed example of how to simulate SDEs can be found in the [SDE example](../examples/sde_example.ipynb).
89+
A table of all SDE solvers and their properties can be found in [SDE solver table](../devdocs/SDE_solver_table.md).
9390

9491
---
9592

examples/sde_example.ipynb

Lines changed: 582 additions & 0 deletions
Large diffs are not rendered by default.

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ nav:
112112
- Kalman filter: 'examples/kalman_filter.ipynb'
113113
- Second-order sensitivities: 'examples/hessian.ipynb'
114114
- Nonlinear heat PDE: 'examples/nonlinear_heat_pde.ipynb'
115+
- Advanced SDE simulation example: 'examples/sde_example.ipynb'
115116
- Basic API:
116117
- 'api/diffeqsolve.md'
117118
- Solvers:
@@ -139,3 +140,4 @@ nav:
139140
- 'devdocs/predictor_dirk.md'
140141
- 'devdocs/adjoint_commutative_noise.md'
141142
- Stochastic Runge-Kutta methods: 'devdocs/srk_example.ipynb'
143+
- Table of SDE solvers: 'devdocs/SDE_solver_table.md'

0 commit comments

Comments
 (0)