torchfilter.base._dynamics_model
Private module; avoid importing from directly.
Module Contents
Classes
Base class for a generic differentiable dynamics model, with additive white |
- class torchfilter.base._dynamics_model.DynamicsModel(*, state_dim: int)[source]
Bases:
torch.nn.Module
,abc.ABC
Base class for a generic differentiable dynamics model, with additive white Gaussian noise.
Subclasses should override either
forward
orforward_loop
for computing dynamics estimates.- state_dim
Dimensionality of our state.
- Type:
int
- forward(self, *, initial_states: types.StatesTorch, controls: types.ControlsTorch) Tuple[types.StatesTorch, types.ScaleTrilTorch] [source]
Dynamics model forward pass, single timestep.
Computes both predicted states and uncertainties. Note that uncertainties correspond to the (Cholesky decompositions of the) “Q” matrices in a standard linear dynamical system w/ additive white Gaussian noise. In other words, they should be lower triangular and not accumulate – the uncertainty at at time
t
should be computed as if the estimate at timet - 1
is a ground-truth input.By default, this is implemented by bootstrapping the
forward_loop()
method.- Parameters:
initial_states (torch.Tensor) – Initial states of our system. Shape should be
(N, state_dim)
.controls (dict or torch.Tensor) – Control inputs. Should be either a dict of tensors or tensor of size
(N, ...)
.
- Returns:
Tuple[torch.Tensor, torch.Tensor] – Predicted states & uncertainties. States should have shape
(N, state_dim)
, and uncertainties should be lower triangular with shape(N, state_dim, state_dim).
- forward_loop(self, *, initial_states: types.StatesTorch, controls: types.ControlsTorch) Tuple[types.StatesTorch, torch.Tensor] [source]
Dynamics model forward pass, over sequence length
T
and batch sizeN
. By default, this is implemented by iteratively callingforward()
.Computes both predicted states and uncertainties. Note that uncertainties correspond to the (Cholesky decompositions of the) “Q” matrices in a standard linear dynamical system w/ additive white Gaussian noise. In other words, they should be lower triangular and not accumulate – the uncertainty at at time
t
should be computed as if the estimate at timet - 1
is a ground-truth input.To inject code between timesteps (for example, to inspect hidden state), use
register_forward_hook()
.- Parameters:
initial_states (torch.Tensor) – Initial states to pass to our dynamics model. Shape should be
(N, state_dim)
.controls (dict or torch.Tensor) – Control inputs. Should be either a dict of tensors or tensor of size
(T, N, ...)
.
- Returns:
Tuple[torch.Tensor, torch.Tensor] – Predicted states & uncertainties. States should have shape
(T, N, state_dim)
, and uncertainties should be lower triangular with shape(T, N, state_dim, state_dim).
- jacobian(self, initial_states: types.StatesTorch, controls: types.ControlsTorch) torch.Tensor [source]
Returns Jacobian of the dynamics model.
- Parameters:
states (torch.Tensor) – Current state, size
(N, state_dim)
.controls (dict or torch.Tensor) – Control inputs. Should be either a dict of tensors or tensor of size
(N, ...)
.
- Returns:
torch.Tensor – Jacobian, size
(N, state_dim, state_dim)