Discretizers¶
Using continuous state evolutions can be inconvenient as they entail running full SDE solves for all transitions. dynestyx provides a set of Discretizer objects to discretize a continuous time state evolution to a discrete time state evolution.
Bases: ObjectInterpretation, HandlesSelf
Performs discretization of a continuous-time state evolution, converting it to a discrete-time state evolution.
A Discretizer object should be used as a context manager around a call to a model with a dsx.sample(...)
statement to discretize a continuous-time state evolution to a discrete-time state evolution. The Discretizer
should be at a lower (i.e. inner) level in the current context stack than any inference (e.g., Filter or Simulator)
objects.
Using a Euler Maruyama Discretizer
import dynestyx as dsx
from dynestyx.discretizers import Discretizer, euler_maruyama
from dynestyx.inference.filters import Filter, EKFConfig
from dynestyx.models import (
ContinuousTimeStateEvolution,
DiscreteTimeStateEvolution,
DynamicalModel,
)
def model_with_ctse(obs_times=None, obs_values=None):
dynamics = DynamicalModel(
control_dim=0,
initial_condition=dist.MultivariateNormal(
loc=jnp.zeros(state_dim),
covariance_matrix=jnp.eye(state_dim),
),
state_evolution=ContinuousTimeStateEvolution(
drift=lambda x, u, t: x,
diffusion_coefficient=lambda x, u, t: jnp.eye(state_dim, bm_dim),
),
observation_model=lambda x, u, t: dist.MultivariateNormal(
x,
0.1**2 * jnp.eye(observation_dim),
),
)
return dsx.sample("f", dynamics, obs_times=obs_times, obs_values=obs_values)
def discretized_data_conditioned_model():
# We use a discrete-time filter now
with Filter(filter_config=EKFConfig()):
with Discretizer(discretize=euler_maruyama):
return model_with_ctse(obs_times=obs_times, obs_values=obs_values)
Algorithm Reference
For an overview of discretization methods for SDEs, see Chapter 9 of: Särkkä, S., & Solin, A. (2019). Applied Stochastic Differential Equations. Cambridge University Press. Available Online.
Attributes:
| Name | Type | Description |
|---|---|---|
discretize |
A callable that converts a continuous-time state evolution to a discrete-time state evolution. Defaults to euler_maruyama. |
Discretize continuous-time state evolution via Euler-Maruyama.
Euler-Maruyama is a first-order discrete approximation of a continuous-time state evolution. It is popular, as it is simple and effective for simple models. The resulting discrete-time state evolution is linear and Gaussian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cte
|
ContinuousTimeStateEvolution
|
|
required |
Returns: DiscreteTimeStateEvolution: The discretized state evolution.
Note
No dt is passed; it is set to t_next - t_now in the call method.
Algorithm Reference
The Euler Maruyama is a first order discretization. The resulting discret-time state evolution is approximated as
x_{t+1} ~ N(x_t + drift * delta_t, (L@Q@L.T)*delta_t)
where: x_t is the current state drift is the drift function L is the diffusion coefficient Q is the diffusion covariance delta_t is the time step between timepoints (t_next - t_now)
This is the first-order Ito-Taylor approximation.
References: - This is the first-order Ito-Taylor approximation, discussed in Chapter 9.2 of: Särkkä, S., & Solin, A. (2019). Applied Stochastic Differential Equations. Cambridge University Press. Available Online.