c4dynamics.filters.kalman.kalman.predict#
- kalman.predict(u: ndarray | None = None, Q: ndarray | None = None)[source]#
Predicts the filter’s next state and covariance matrix based on the current state and the process model.
- Parameters:
u (numpy.ndarray, optional) – Control input. Defaults to None.
Q (numpy.ndarray, optional) – Process noise covariance matrix. Defaults to None.
- Raises:
ValueError – If Q is not missing (neither provided during construction nor passed to predict).
ValueError – If a control input is provided, but the number of elements in u does not match the number of columns of the input matrix G.
Examples
For more detailed usage, see the examples in the introduction to the
filtersmodule and thekalmanclass.Import required packages:
>>> from c4dynamics.filters import kalman
Plain predict step (predict in steady-state mode where the process variance matrix remains constant and is provided once to initialize the filter):
>>> kf = kalman({'x': 0}, P0 = 0.5**2, F = 1, H = 1, Q = 0.05, R = 200, steadystate = True) >>> print(kf) [ x ] >>> kf.X [0] >>> kf.P [[3.187...]] >>> kf.predict() >>> kf.X [0] >>> kf.P [[3.187...]]
Predict with control input:
>>> kf = kalman({'x': 0}, P0 = 0.5**2, F = 1, G = 150, H = 1, R = 200, Q = 0.05) >>> kf.X [0] >>> kf.P [[0.25...]] >>> kf.predict(u = 1) >>> kf.X [150] >>> kf.P [[0.3]]
Predict with updated process noise covariance matrix:
>>> kf = kalman({'x': 0}, P0 = 0.5**2, F = 1, G = 150, H = 1, R = 200, Q = 0.05) >>> kf.X [0] >>> kf.P [[0.25]] >>> kf.predict(u = 1, Q = 0.01) >>> kf.X [150] >>> kf.P [[0.26]]