I am trying to use pykalman to apply KalmanFilter
on a data. When I wrote the code for KalmanFilter on my own, it was working fine but I wanted to use the pykalman
library.
The code is as follows:
Initializing code:
self.Ve=1e-3
self.delta=1e-4
self.Vw=self.delta/(1-self.delta)*np.eye(2)
self.means=np.zeros((1,2))
self.cov=np.zeros((2,2))
self.kf = pykalman.KalmanFilter(
n_dim_obs=1,
n_dim_state=2,
transition_covariance=self.Vw,
observation_matrices = np.matrix([0,1]),
observation_covariance=self.Ve,
initial_state_mean=self.means,
initial_state_covariance=self.cov,
)
The code to update these values:
self.means,self.cov=self.kf.filter_update(filtered_state_mean=self.means,
filtered_state_covariance=self.cov,
observation_matrix=self.x,
observation=self.y[0])
The results that I got are as follows:
Initial values of the shapes of matrices:
observation - predicted_obs_mean.shape (1, 1)
R.shape (2, 2)
Kalman Gain.shape (2, 1)
observation_matrix.shape (1, 2)
filtered_state_mean.shape (2, 1)
filtered_state_cov.shape (2, 2)
predicted_observation_covariance.shape (1, 1)
Predicted Observation Mean.shape (1, 1)
Values after one state update:
observation - predicted_obs_mean.shape (1, 2)
R.shape (2, 2)
Kalman Gain.shape (2, 1)
observation_matrix.shape (1, 2)
filtered_state_mean.shape (2, 2)
filtered_state_cov.shape (2, 2)
predicted_observation_covariance.shape (1, 1)
Predicted Observation Mean.shape (1, 2)
The state mean is changing its shape. I can't figure out why. Any help would be appreciated.
question from:
https://stackoverflow.com/questions/65934550/pykalman-dimensions-after-filter-update-are-not-matching-up