TME in SymPy
Taylor moment expansion (TME) in SymPy.
TME applies on stochastic differential equations (SDEs) of the form
\[d X(t) = a(X(t))dt + b(X(t)) dW(t),\]where \(X \colon \mathbb{T} \to \mathbb{R}^d\), and \(W\colon \mathbb{T} \to \mathrm{R}^w\) is a Wiener process having the unit spectral density. Functions \(a \colon \mathbb{R}^d \to \mathbb{R}^d\) and \(b \colon \mathbb{R}^d \to \mathbb{R}^{d \times w}\) stand for the drift and dispersion coefficients, respectively. \(\mathbb{T} = [t_0, \infty)\) stands for a temporal domain.
For more detailed explanations of TME, see, Zhao (2021) or Zhao et al. (2020). Notations used in this doc-site follows from Zhao (2021).
Functions
mean_and_cov()
TME approximation for mean and covariance. In case you just want to compute the mean, use function
expectation()
with argumentphi
fed by an identity function.expectation()
TME approximation for any expectation of the form \(\mathbb{E}[\phi(X(t + \Delta t)) \mid X(t)]\).
generator()
Infinitesimal generator.
generator_vec()
Infinitesimal generator extended for vector-valued target function.
generator_mat()
Infinitesimal generator extended for matrix-valued target function.
generator_power()
Iterations/power of infinitesimal generators.
References
Zheng Zhao. State-space deep Gaussian processes. PhD thesis, Aalto University. 2021.
Zheng Zhao, Toni Karvonen, Roland Hostettler, and Simo Särkkä. Taylor Moment Expansion for Continuous-Discrete Gaussian Filtering. IEEE Transactions on Automatic Control, 66(9):4460-4467, 2021.
Didier Dacunha-Castelle and Danielle Florens-Zmirou. Estimation of the coefficients of a diffusion from discrete observations. Stochastics, 19(4):263–284, 1986.
Danielle Florens-Zmirou. Approximate discrete-time schemes for statistics of diffusion processes. Statistics, 20(4):547–557, 1989.
Notes
Currently, this symbolc implementation has a problem as the SymPy simplification function
sympy.simplify
is not working well. See details in the docstring of function mean_and_cov()
.
- tme.base_sympy.expectation(phi, x, drift, dispersion, dt=None, order=3, simp=True)[source]
TME approximation of expectation on target function \(\phi\).
Formally, this function approximates
\[\mathbb{E}[\phi(X(t+\Delta t)) \mid X(t)],\]where \(\phi \colon \mathbb{R}^d \to \mathbb{R}^{m\times n}\) is any smooth enough function of interest.
- Parameters
- phiMatrix
Target function.
- xMatrixSymbol
Symbolic state vector.
- driftMatrix
Symbolic drift coefficient.
- dispersionMatrix
Symbolic dispersion coefficient.
- dtSymbol, optional
Symbolic time interval. If this is not specified by the user, then the function will create one.
- orderint, default=3
Order of TME.
- simpbool or Callable, default=True
Set True to simplify the results by calling the default
sympy.simplify
method. You can also give your own simplification method as a callable function input.
- Returns
- Matrix
TME approximation of \(\mathbb{E}[\phi(X(t + \Delta t)) \mid X(t)]\).
- Return type
Matrix
- tme.base_sympy.generator(phi, x, drift, dispersion)[source]
Infinitesimal generator for diffusion processes in Ito’s SDE constructions.
\[(\mathcal{A}\phi)(x) = \sum^d_{i=1} a_i(x)\,\frac{\partial \phi}{\partial x_i}(x) + \frac{1}{2}\, \sum^d_{i,j=1} \Gamma_{ij}(x) \, \frac{\partial^2 \phi}{\partial x_i \, \partial x_j}(x),\]where \(\phi\colon \mathbb{R}^d \to \mathbb{R}\) must be sufficiently smooth function depending on the expansion order, and \(\Gamma(x) = b(x) \, b(x)^\top\).
- Parameters
- phiExpr
Scalar-valued target function.
- xMatrixSymbol
Symbolic state vector.
- driftMatrix
Symbolic drift coefficient.
- dispersionMatrix
Symbolic dispersion coefficient.
- Returns
- Expr
Symbolic \((\mathcal{A}\phi)(x)\).
- Return type
Expr
- tme.base_sympy.generator_mat(phi_mat, x, drift, dispersion)[source]
Infinitesimal generator for matrix-valued \(\phi\colon \mathbb{R}^d\to\mathbb{R}^{m\times n}\).
This function exactly corresponds to the operator \(\overline{\mathcal{A}}\) in Zhao (2021).
- Parameters
- phi_matMatrix
Matrix-valued target function.
- xMatrixSymbol
Symbolic state vector.
- driftMatrix
Symbolic drift coefficient.
- dispersionMatrix
Symbolic dispersion coefficient.
- Returns
- Matrix
Symbolic \((\mathcal{A}\phi)(x)\).
- Return type
Matrix
- tme.base_sympy.generator_power(phi, x, drift, dispersion, p)[source]
Iterations/power of infinitesimal generator for scalar/vector/matrix-valued \(\phi\).
\[(\mathcal{A}^p\phi)(x),\]where \(p\) is the number of iterations.
- Parameters
- phiMatrix
Scalar/vector/Matrix-valued target function.
- xMatrixSymbol
Symbolic state vector.
- driftMatrix
Symbolic drift coefficient.
- dispersionMatrix
Symbolic dispersion coefficient.
- pint
Power/number of iterations.
- Returns
- List[Matrix]
A list of iterated generators \([(\mathcal{A}^0\phi)(x), (\mathcal{A}\phi)(x), \ldots, (\mathcal{A}^p\phi)(x)]\).
- Return type
List
[Matrix
]
- tme.base_sympy.generator_vec(phi_vec, x, drift, dispersion)[source]
Infinitesimal generator for vector-valued \(\phi\colon \mathbb{R}^d\to\mathbb{R}^{m}\).
- Parameters
- phi_vecMatrix
Vector-valued target function.
- xMatrixSymbol
Symbolic state vector.
- driftMatrix
Symbolic drift coefficient.
- dispersionMatrix
Symbolic dispersion coefficient.
- Returns
- Matrix
Symbolic \((\mathcal{A}\phi)(x)\).
Notes
Since we are using
sympy.Matrix
, the functiongenerator_mat()
can exactly replace this function.- Return type
Matrix
- tme.base_sympy.mean_and_cov(x, drift, dispersion, dt, order=3, simp=True)[source]
TME approximation for mean and covariance.
Formally, this function approximates
\[ \begin{align}\begin{aligned}\mathbb{E}[X(t + \Delta t) \mid X(t)],\\\mathrm{Cov}[X(t + \Delta t) \mid X(t)].\end{aligned}\end{align} \]See, Zhao (2021, Lemma 3.4) for details.
- Parameters
- xMatrixSymbol
Symbolic state vector.
- driftMatrix
Symbolic drift coefficient.
- dispersionMatrix
Symbolic dispersion coefficient.
- dtSymbol
Symbolic time interval. You can create one, for example, by
dt=sympy.Symbol('dt', positive=True)
.- orderint, default=3
Order of TME.
- simpbool or Callable, default=True
Set
True
to simplify the results by calling the defaultsympy.simplify
method. You can also use your own simplification method by feeding it a callable function.Warning
The method
sympy.simplify
can be unnecessarily slow when the system is complicated, see this page for details.
- Returns
- mMatrix
TME approximation of mean \(\mathbb{E}[X(t + \Delta t) \mid X(t)]\).
- covMatrix
TME approximation of covariance \(\mathrm{Cov}[X(t + \Delta t) \mid X(t)]\).
- Return type
Tuple
[Matrix
,Matrix
]