How to run the Pikalman Kalman filter with one observation? (Python)

I can run the simple Pilkalman Kalman filter example given in the pykalman documentation :

import pykalman
import numpy as np
kf = pykalman.KalmanFilter(transition_matrices = [[1, 1], [0, 1]], observation_matrices = [[0.1, 0.5], [-0.3, 0.0]])
measurements = np.asarray([[1,0], [0,0], [0,1]])  # 3 observations
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
print filtered_state_means

      

This correctly returns the status scores (one for each observation):

[[ 0.07285974  0.39708561]
 [ 0.30309693  0.2328318 ]
 [-0.5533711  -0.0415223 ]]

      

However, if I only provide one observation, the code fails:

import pykalman
import numpy as np
kf = pykalman.KalmanFilter(transition_matrices = [[1, 1], [0, 1]], observation_matrices = [[0.1, 0.5], [-0.3, 0.0]])
measurements = np.asarray([[1,0]])  # 1 observation
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
print filtered_state_means

      

with the following error:

ValueError: could not broadcast input array from shape (2,2) into shape (2,1)

      

How can I use pykalman to update baseline and baseline covariance using just one observation?

+3


source to share


2 answers


From the documentation at: http://pykalman.github.io/#kalmanfilter

filter_update(filtered_state_mean, filtered_state_covariance, observation=None, transition_matrix=None, transition_offset=None, transition_covariance=None, observation_matrix=None, observation_offset=None, observation_covariance=None)

      



This takes the value of filter_state_mean and filter_state_covariance at time t and observation at t + 1 and returns the state and state covariance at t + 1 (which will be used for the next update)

+2


source


If I understand the Kalman filter algorithm correctly, you can predict the state using only one observation. But the payoff and covariance would be out of the way, and the prediction would nowhere come close to the actual state. You should give Kalman a few observations as the training kit reaches steady state.



+1


source







All Articles