filterpy icon indicating copy to clipboard operation
filterpy copied to clipboard

Possible issue with loglikelihood computation in kalman/kalman_filter.py update function

Open sortega87 opened this issue 3 years ago • 2 comments

The computation of the log-likelihood, on the kalman update function, is currently made after the state vector is updated with the last observation. That is, the log_likelihood is computed in line 1434 using the updated state of line 1420.

I believe the computation should be made with the prior state estimate; moving the log_likelihood computation just after line 1408 should solve the issue.

https://github.com/rlabbe/filterpy/blob/a437893597957764fb6b415bfb5640bb117f5b99/filterpy/kalman/kalman_filter.py#L1329-L1436

sortega87 avatar Dec 16 '21 03:12 sortega87

Have you compared how this affects the filter?

Eheran1 avatar Apr 18 '22 19:04 Eheran1

@Eheran1 I had trouble with the current implementation while using the log likelihood to fit the parameters of a Dynamic Linear Model (DLM, as in here). I had no luck in fitting the model parameters with the current implementation. However, I was able to fit the model, and the resulting parameters were consistent with my data, with the suggested changes.

The log likelihood is computed using the posterior state estimate in the current implementation, I believe the log likelihood should be computed using the prior state estimate.

sortega87 avatar May 30 '22 02:05 sortega87