The predict function performs the Kalman filter prediction step for one or more states simultaneously. To leverage SIMD-like performance, you can stack multiple states, transition matrices, and process noise into single arrays.
When stacking:
- States (
mean): Should be stacked into a shape of (N, dim, 1), where N is the number of states and dim is the state dimension. - Transition Matrices (
state_transition): Should be stacked into a shape of (N, dim, dim). - Covariance (
covariance): Can be a single matrix of shape (dim, dim) applied to all states, or a stacked array of shape (N, dim, dim). - Process Noise (
process_noise): Can be a single matrix of shape (dim, dim) applied to all states, or a stacked array of shape (N, dim, dim).
from simdkalman.primitives import predict
import numpy
# different states (3 states of dimension 2)
m1, m2, m3 = [numpy.array([[0],[i]]) for i in range(3)]
# with the same covariance (initially)
P = numpy.eye(2)
# different transition matrices
A1, A2, A3 = [numpy.eye(2)*i for i in range(3)]
# same process noise
Q = numpy.eye(2)*0.01
# stack correctly
m = numpy.vstack([
m1[numpy.newaxis, ...],
m2[numpy.newaxis, ...],
m3[numpy.newaxis, ...]
])
A = numpy.vstack([
A1[numpy.newaxis, ...],
A2[numpy.newaxis, ...],
A3[numpy.newaxis, ...]
])
# predict
m, P = predict(m, P, A, Q)
print(m.shape) # Expected: (3, 2, 1)
print(P.shape) # Expected: (3, 2, 2)