Skip to content

KalmanFilterTransformerFP

KalmanFilterTransformerFP

class KalmanFilterTransformerFP(state_dim, state_transition=None, control_transition=None, process_noise=None, measurement_noise=None, measurement_function=None, initial_state=None, initial_state_covariance=None, estimate_matrices=None, denoising=False)[source]

Kalman Filter is used for denoising or inferring the hidden state of given data.

The Kalman Filter is an unsupervised algorithm, consisting of several mathematical equations which are used to create an estimate of the state of a process.

This class is the adapter for the FilterPy package into sktime. KalmanFilterTransformerFP implements hidden inferred states and denoising, depending on the boolean input parameter denoising. In addition, KalmanFilterTransformerFP provides parameter optimization via Expectation-Maximization (EM) algorithm.

Parameters:
state_dimint

System state feature dimension.

state_transitionnp.ndarray, optional (default=None)

of shape (state_dim, state_dim) or (time_steps, state_dim, state_dim). State transition matrix, also referred to as F, is a matrix which describes the way the underlying series moves through successive time periods.

control_transitionnp.ndarray, optional (default=None)

of shape (state_dim, control_variable_dim) or (time_steps, state_dim, control_variable_dim). Control transition matrix, also referred to as G. control_variable_dim is the dimension of control variable, also referred to as u. control variable is an optional parameter for fit and transform functions.

process_noisenp.ndarray, optional (default=None)

of shape (state_dim, state_dim) or (time_steps, state_dim, state_dim). Process noise matrix, also referred to as Q, the uncertainty of the dynamic model.

measurement_noisenp.ndarray, optional (default=None)

of shape (measurement_dim, measurement_dim) or (time_steps, measurement_dim, measurement_dim). Measurement noise matrix, also referred to as R, represents the uncertainty of the measurements.

measurement_functionnp.ndarray, optional (default=None)

of shape (measurement_dim, state_dim) or (time_steps, measurement_dim, state_dim). Measurement equation matrix, also referred to as H, adjusts dimensions of measurements to match dimensions of state.

initial_statenp.ndarray, optional (default=None)

of shape (state_dim,). Initial estimated system state, also referred to as X0.

initial_state_covariancenp.ndarray, optional (default=None)

of shape (state_dim, state_dim). Initial estimated system state covariance, also referred to as P0.

estimate_matricesstr or list of str, optional (default=None).

Subset of [state_transition, measurement_function, process_noise, measurement_noise, initial_state, initial_state_covariance] or - all. If estimate_matrices is an iterable of strings, only matrices in estimate_matrices will be estimated using EM algorithm. If estimate_matrices is all, then all matrices will be estimated using EM algorithm.

Note -
  • parameters estimated by EM algorithm assumed to be constant.

  • control_transition matrix cannot be estimated.

denoisingbool, optional (default=False).

This parameter affects transform. If False, then transform will be inferring hidden state. If True, uses FilterPy rts_smoother for denoising.

Attributes:
is_fitted

Whether fit has been called.

See also

KalmanFilterTransformerPK

Kalman Filter transformer, adapter for the pykalman package into sktime.

Notes

FilterPy KalmanFilter documentation :

https://filterpy.readthedocs.io/en/latest/kalman/KalmanFilter.html

References

[1]

Greg Welch and Gary Bishop, “An Introduction to the Kalman Filter”, 2006 https://www.cs.unc.edu/~welch/media/pdf/kalman_intro.pdf

[2]

R.H.Shumway and D.S.Stoffer “An Approach to time Series Smoothing and Forecasting Using the EM Algorithm”, 1982 https://www.stat.pitt.edu/stoffer/dss_files/em.pdf

>>> import numpy as np
>>> import sktime.transformations.kalman_filter as kf
>>> time_steps, state_dim, measurement_dim = 10, 2, 3
>>>
>>> X = np.random.rand(time_steps, measurement_dim) * 10
>>> transformer = kf.KalmanFilterTransformerFP(state_dim=state_dim)
>>> Xt = transformer.fit_transform(X=X)

Example of - denoising, matrix estimation, missing values and transform with y:

>>> import numpy as np
>>> import sktime.transformations.kalman_filter as kf
>>> time_steps, state_dim, measurement_dim = 10, 3, 3
>>> control_variable_dim = 2
>>>
>>> X = np.random.rand(time_steps, measurement_dim)
>>> # missing value
>>> X[0][0] = np.nan
>>>
>>> # y
>>> control_variable = np.random.rand(time_steps, control_variable_dim)
>>>
>>> # If matrices estimation is required, elements of ``estimate_matrices``
>>> # are assumed to be constants.
>>> transformer = kf.KalmanFilterTransformerFP(
...     state_dim=state_dim,
...     measurement_noise=np.eye(measurement_dim),
...     denoising=True,
...     estimate_matrices='measurement_noise'
...     )
>>> Xt = transformer.fit_transform(X=X, y=control_variable)

Example of - dynamic inputs (matrix per time-step), missing values:

>>> import numpy as np
>>> import sktime.transformations.kalman_filter as kf
>>> time_steps, state_dim, measurement_dim = 10, 4, 4
>>> control_variable_dim = 4
>>>
>>> X = np.random.rand(time_steps, measurement_dim)
>>> # missing values
>>> X[0] = [np.nan for i in range(measurement_dim)]
>>>
>>> # y
>>> control_variable = np.random.rand(control_variable_dim)
>>>
>>> # Dynamic input -
>>> # ``state_transition`` provide different matrix for each time step.
>>> transformer = kf.KalmanFilterTransformerFP(
...     state_dim=state_dim,
...     state_transition=np.random.rand(time_steps, state_dim, state_dim),
...     estimate_matrices=['initial_state', 'initial_state_covariance']
...     )
>>> Xt = transformer.fit_transform(X=X, y=control_variable)

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(X[, y])

Fit transformer to X, optionally to y.

fit_transform(X[, y])

Fit to data, then transform it.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

inverse_transform(X[, y])

Inverse transform X and return an inverse transformed version.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.

transform(X[, y])

Transform X and return a transformed version.

update(X[, y, update_params])

Update transformer with X, optionally y.