c4dynamics.filters.ekf.ekf.update

Contents

c4dynamics.filters.ekf.ekf.update#

ekf.update(z: ndarray, H: ndarray | None = None, hx: ndarray | None = None, R: ndarray | None = None)[source]#

Updates the state estimate based on the latest measurement, using an optional nonlinear measurement function.

Parameters:
  • z (np.ndarray) – Measurement vector, representing observed values from the system.

  • H (np.ndarray, optional) – Measurement Jacobian matrix. If provided, it overrides the previously set H matrix for this update step.

  • hx (np.ndarray, optional) – Nonlinear measurement function output. If provided, it is used as the current estimate of the state based on measurement data.

  • R (np.ndarray, optional) – Measurement noise covariance matrix, representing the uncertainty in the measurements.

Examples

The examples in this section are intended to demonstrate the usage of the ekf class and specifically the update method. However, they are not limited to nonlinear dynamics. For detailed usage that highlights the properties of nonlinear dynamics, refer to the filters module introduction.

Import required packages:

>>> from c4dynamics.filters import ekf

Plain update step:

>>> _ekf = ekf({'x': 0}, P0 = 0.5**2, F = 1, H = 1, Q = 0.05, R = 200)
>>> print(_ekf)
[ x ]
>>> _ekf.X   
[0]
>>> _ekf.P                
[[0.25]]
>>> _ekf.update(z = 100)  # returns Kalman gain   
[[0.001...]]
>>> _ekf.X                
[0.124...]
>>> _ekf.P                
[[0.249...]]

Update with modified measurement noise covariance matrix:

>>> _ekf = ekf({'x': 0}, P0 = 0.5**2, F = 1, G = 150, H = 1, R = 200, Q = 0.05)
>>> _ekf.X   
[0]
>>> _ekf.P  
[[0.25]]
>>> K = _ekf.update(z = 150, R = 0)
>>> K   
[[1]]
>>> _ekf.X  
[150]
>>> _ekf.P  
[[0]]