rlabbe / filterpy

Python Kalman filtering and optimal estimation library. Implements Kalman filter, particle filter, Extended Kalman filter, Unscented Kalman filter, g-h (alpha-beta), least squares, H Infinity, smoothers, and more. Has companion book 'Kalman and Bayesian Filters in Python'.
MIT License
3.22k stars 612 forks source link

Add intercepts to measurement and transition equations. Default is z… #257

Closed dcwtx closed 2 years ago

dcwtx commented 2 years ago

…ero unless they are overridden or provided to the procedural form.

I am working on an adaptation of an R code that is used to find the coefficients of a futures price model by minimizing the negative log likelihood of a Kaman filter applied to historical data. The R routine that is used by the author is fkf. In that routine, their equation setup includes intercepts of the measurement and transition equations, whereas in filterpy there are none. I've added c and d functions to be used in the Kaman filter object and procedural modules.

For background on the model see https://www.sciencedirect.com/science/article/pii/S0140988321003121?via%3Dihub#mmc1. The R code can be downloaded from this site and is linked at Appendix B, supplementary data.

I believe this will have no effect if c and d are not specified, but was not able to run test code in the package. I also believe that c and d will have no impact on S or K, but would appreciate a theoretical check on that to be sure. I've looked at the fkf code on GitHub but I don't like C very much and didn't enjoy going through it. Here's the link to it in any event: https://github.com/cran/FKF

dcwtx commented 2 years ago

I realize that I didn't add c's or d's to the batch update, and also found the test suite. I'll update then be sure the test suite is running before submitting the next pull request.