1

I have a simple Kalman model:

y_1_t = (1 + phi) * alpha_t + e_1_t 

y_2_t = (1 - phi) * alpha_t + e_2_t 

alpha_t+1 = alpha_t + s_t

Now I know the variances over time for e_1_t and e_2_t - they are not constant. Is there a python package that I could use to estimate this model?

The parameter phi is unknown. It would be great if the model could estimate if. If not it also could be provided since approximate estimations exists.

Thanks a lot for any hint.

PS: I also checked the liabrary pykalman. https://pykalman.github.io/#mathematical-formulation. It seems that here the variance is assumed to be constant over time.

denniz
  • 13
  • 4
  • Do you want to change both measurement and system noise covariance or only the measurement covariance? I have some problems interpreting your expressions. – Anton Jun 16 '19 at 12:17
  • @Anton Hi there. I would like to modify the covariance of the measurment expression. So based on equations in https://en.wikipedia.org/wiki/Kalman_filter it would be R_k. The reason is that I have another "measurement" outside of the system that tells me how accurate the observation is. – denniz Jun 16 '19 at 18:04

1 Answers1

1

If you need to change either the transition covariance (matrix Q) or the measurement covariance (matrix R) during the estimation you can still use the pykalman library you've mentioned in your question.

Have a look at the function filter_update(). It is useful if you want to change some filter parameters (especially the covariance matrices) from one call to another.

The function call looks like this:

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)

to modify the covariance matrices you just need to put the customized values into transition_covariance and observation_covariance

Have a look at my post here: Kalman filter with varying timesteps

In this example I modified the observation covariance on the fly depending on the sensor the measurement came from:

    if Sensor[t] == 0:
        obs = None
        obs_cov = None
    else:
        obs = [X[t], Y[t]]

        if Sensor[t] == 1:
            obs_cov = np.asarray(R_1)
        else:
            obs_cov = np.asarray(R_2)

    filtered_state_means[t], filtered_state_covariances[t] = (
    kf.filter_update(
        filtered_state_means[t-1],
        filtered_state_covariances[t-1],
        observation = obs,
        observation_covariance = obs_cov)
    )

For some reason one has to cast the observation covariance to np.asarray, otherwise the library does not work.

Anton
  • 4,544
  • 2
  • 25
  • 31
  • Thanks a lot. I will try that out. Quite funny actually I already saw your post and though it might go in that direcation! When observations are missing, my idea to place a dummy observation and give it high variance (I think it should work if the observations are not correlated, but that is just a special case). – denniz Jun 16 '19 at 19:32