LDS¶
- class LDS(emission_coeff: torch.Tensor, transition_coeff: torch.Tensor, innovation_coeff: torch.Tensor, noise_std: torch.Tensor, prior_mean: torch.Tensor, prior_cov: torch.Tensor, offset: torch.Tensor, seq_length: int, latent_dim: int)[source]¶
Bases:
etna.core.mixins.BaseMixin
Class which implements Linear Dynamical System (LDS) as a distribution.
Create instance of LDS.
- Parameters
emission_coeff (torch.Tensor) – Emission coefficient matrix with shape (batch_size, seq_length, latent_dim).
transition_coeff (torch.Tensor) – Transition coefficient matrix with shape (latent_dim, latent_dim).
innovation_coeff (torch.Tensor) – Innovation coefficient matrix with shape (batch_size, seq_length, latent_dim).
noise_std (torch.Tensor) – Noise standard deviation for targets with shape (batch_size, seq_length, 1).
prior_mean (torch.Tensor) – Prior mean for latent state with shape (batch_size, latent_dim)
prior_cov (torch.Tensor) – Prior covariance matrix for latent state with shape (batch_size, latent_dim, latent_dim)
offset (torch.Tensor) – Offset for the target with shape (batch_size, seq_length, 1)
seq_length (int) – Length of the sequence.
latent_dim (int) – Dimension of the latent space.
- Inherited-members
Methods
kalman_filter
(targets)Perform Kalman filtering of given observations.
kalman_filter_step
(target, noise_std, ...)One step of the Kalman filter.
log_likelihood
(targets)Compute the log-likelihood of the target.
sample
(n_samples)Sample the trajectories of targets from the current LDS.
set_params
(**params)Return new object instance with modified parameters.
to_dict
()Collect all information about etna object in dict.
- kalman_filter(targets: torch.Tensor) Tuple[torch.Tensor, torch.Tensor, torch.Tensor] [source]¶
Perform Kalman filtering of given observations.
- Parameters
targets (torch.Tensor) – Tensor with observations with shape (batch_size, seq_length, 1)
- Returns
Log probabilities with shape shape (batch_size, seq_length)
Mean of p(l_T | l_{T-1}), where T is seq_length, with shape (batch_size, latent_dim)
Covariance of p(l_T | l_{T-1}), where T is seq_length, with shape (batch_size, latent_dim, latent_dim)
- Return type
Tuple[torch.Tensor, torch.Tensor, torch.Tensor]
- kalman_filter_step(target: torch.Tensor, noise_std: torch.Tensor, prior_mean: torch.Tensor, prior_cov: torch.Tensor, emission_coeff: torch.Tensor, offset: torch.Tensor)[source]¶
One step of the Kalman filter.
This function computes the filtered state (mean and covariance) given the LDS coefficients in the prior state (mean and variance) and observations.
- Parameters
target (torch.Tensor) – Observations of the system with shape (batch_size, 1)
noise_std (torch.Tensor) – Standard deviation of the observations noise with shape (batch_size, 1)
prior_mean (torch.Tensor) – Prior mean of the latent state with shape (batch_size, latent_dim)
prior_cov (torch.Tensor) – Prior covariance of the latent state with shape (batch_size, latent_dim, latent_dim)
emission_coeff (torch.Tensor) – Emission coefficient with shape (batch_size, latent_dim)
offset (torch.Tensor) – Offset for the observations with shape (batch_size, 1)
- Returns
Log probability with shape (batch_size, 1)
Filtered_mean with shape (batch_size, latent_dim, 1)
Filtered_covariance with shape (batch_size, latent_dim, latent_dim)
- log_likelihood(targets: torch.Tensor) torch.Tensor [source]¶
Compute the log-likelihood of the target.
- Parameters
targets (torch.Tensor) – Tensor with targets of shape (batch_size, seq_length, 1)
- Returns
Tensor with log-likelihoods of target of shape (batch_size, seq_length)
- Return type
- sample(n_samples: int) torch.Tensor [source]¶
Sample the trajectories of targets from the current LDS.
- Parameters
n_samples (int) – Number of trajectories to sample.
- Returns
Tensor with trajectories with shape (n_samples, batch_size, seq_length, 1).
- Return type
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.