torchfilter.base._dynamics_model

Private module; avoid importing from directly.

Module Contents

Classes

DynamicsModel

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

Inheritance diagram of torchfilter.base._dynamics_model.DynamicsModel

Base class for a generic differentiable dynamics model, with additive white Gaussian noise.

Subclasses should override either forward or forward_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 time t - 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 size N. By default, this is implemented by iteratively calling forward().

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 time t - 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)