c4dynamics.filters.kalman.kalman.store

Contents

c4dynamics.filters.kalman.kalman.store#

kalman.store(t: int = -1)[source]#

Stores the current state and diagonal elements of the covariance matrix.

The store method captures the current state of the Kalman filter, storing the state vector (X) and the error covariance matrix (P) at the specified time.

Parameters:

t (int, optional) – The current time at which the state is being stored. Defaults to -1.

Notes

  1. The stored data can be accessed via data or other methods for post-analysis or visualization.

  2. The elements on the main diagonal of the covariance matrix are named according to their position, starting with ‘P’ followed by their row and column indices. For example, the first element is named ‘P00’, and so on.

  3. See also store and data for more details.

Examples

For more detailed usage, see the examples in the introduction to the filters module and the kalman class.

Import required packages:

>>> from c4dynamics.filters import kalman
>>> kf = kalman({'x': 0}, P0 = 0.5**2, F = 1, H = 1, Q = 0.05, R = 200)
>>> # store initial conditions
>>> kf.store()
>>> kf.predict()
>>> # store X after prediction
>>> kf.store()
>>> kf.update(z = 100)    
[[0.00149...]]
>>> # store X after correct
>>> kf.store()

Access stored data:

>>> kf.data('x')[1]  
[0  0  0.15])
>>> kf.data('P00')[1]  
[0.25  0.3  0.299])