Hi guys I am trying to writ e a code on python to correct forecast data using Kalman Filter. I am following the equations and recommendations in this link : http://www.swarthmore.edu/NatSci/echeeve1/Ref/Kalman/ScalarKalman.html. At some point, I have written a function which satisfies me since I don't know whatsoever how to use the pykalman module to correct estimations. I am using just one parameter (unidimensional and univariate time series), so my matrices form will be a numerical value. My main problem is what is the transition matrix? In many paper they just use a transition matrix of 1 but I think this is not rigorous since it would mean that: forecast(t) = A * forecast(t-1) We do not have a constant value of forecast so what would be my transition matrix?

Hypothesis 1: Can I just try to see a correlation coefficient between two estimated values then take the mean of those coefficients for my first day of forecast.By the way this transition matrix will be just an initialization and will change for each forecast following


The transition matrix relates state t and state t-1.

If we write the temporal coherence equation like this

$$ x_t = \Psi x_{t-1} + \epsilon_p $$

This is the temporal model. This model tells you what is the tendency of your system. When no measurement is found, the system will follow this tendency. When it is found, there is a trade-off between where the measurement says the track should go and where the temporal model says it should go.

$\Psi$ is the transition matrix then.

You can have different types of transition matrix, for instance, temporal brownian motion, where $\Psi = I $, meaning that the next state is the last one plus some noise.

Another possibility would be constant velocity.

Imagine an easy example in 1d. We are tracking the position of an object and its velocity. It is just the same equation as above, in this particular case.

$$ \begin{bmatrix} x_t\\ vel_t \end{bmatrix} = \begin{bmatrix} 1 & 1\\ 0 & 1 \end{bmatrix} \begin{bmatrix} x_t\\ vel_{t-1} \end{bmatrix} + \epsilon_p $$

Then, if you multiply terms, you get

$$ x_t = x_t + vel_t + \epsilon_{p,x}$$ $$ vel_t = vel_{t-1} + \epsilon_{p,vel}$$

This example would be, as the second equation tells us, a constant velocity model.

If you still have doubts, there is a nice explanation of Kalman Filter here: http://web4.cs.ucl.ac.uk/staff/s.prince/book/book.pdf Chapter 19.


I think you should consult a clearer description. (I like a lot the one from Matlab (which you can easily port).

Especially your formula is wrong it is:

predicted state space $\tilde X(t) = A * $corrected state space $\hat X(t-1)$

the forecast would be $h(X)$.

Most important even though you just observe one dimension your state space can be much bigger. Your idea with correlation coefficient would imply a two dimensional one.

  • $\begingroup$ Thanks can you help me on one of my post here:stackoverflow.com/questions/24736263/… $\endgroup$
    – Kunta
    Jul 14 '14 at 12:26
  • $\begingroup$ Sorry - I'm not a python user. So you will need someone else. $\endgroup$
    – bdecaf
    Jul 14 '14 at 13:29

Your Answer

