Repository navigation
ENH: Statespace: Add Kalman smoother - #2434
Conversation
|
Here's a notebook with a basic example using the smoothed output: |
|
just a quick clarification to the description: "pure python" means it doesn't use the cython extension? |
|
To get the filtered output (or for parameter estimation, etc.), it uses the usual Cython extension. It's just that the smoothing itself is done in pure python (see the |
Whereas MLE estimation only calls the Kalman filter repeatedly, EM and MCMC call both the Kalman filter and smoother repeatedly. So while the Kalman filtering would still be fast, the Kalman smoothing would be slow here. Eventually I'll add a Cython Kalman smoother, but for now I thought something was better than nothing (and since we don't focus on EM or MCMC, the slower python implementation won't be noticeable). |
|
Ok, thanks for clarifying brief look at the notebook looks strange because in python this looks like fit() would be thrown away, the first res_ll will be overwritten. should this be or is there a "state" of the model so it is equivalent to |
|
Right now there is a "state" of the model, so that you're right, it's equivalent to: mod_ll.fit()
res_ll = mod_ll.smooth()I know we'd like to move away from holding state like that. I plan (and I think we discussed before) to do that by separating the Statsmodels component (MLEModel, Model classes) from the Kalman filtering component (KalmanSmoother, KalmanFilter, Representation classes) and using delegation. Then the Statsmodels component won't hold state, but the Kalman filtering component will (it has to, since it holds the state space matrices which by definition hold state). After that's done, I suppose that it will look something like your second example. Either res_ll = mod_ll.fit()
smoothed_ll = mod_ll.smooth(res_ll)or: res_ll = mod_ll.fit()
smoothed_ll = mod_ll.smooth(res_ll.params) |
|
Test failure related to old Numpy version (same function failing as in #2431) |
38b9234 to
af7df49
Compare
|
Rebased so tests pass. |
af7df49 to
f58874b
Compare
|
Rebased after decoupling, etc. PRs. |
f58874b to
b4664c0
Compare
|
Rebased again. |
b4664c0 to
010962b
Compare
010962b to
3f3583a
Compare
|
Rebased. I think this should be good to merge, the interface issues we discussed above have been fixed (I think) since the rebase after decoupling. See e.g. this notebook for the interface to get smoothed results: http://nbviewer.ipython.org/gist/ChadFulton/06557357b2be654b13a1 |
|
similar here looks good from a superficial review, example notebook looks nice. I started to read the Stata documentation for the models related to these PRs, but I would need to read again for a few days to "understand" this. I'm fine with merging it as is. |
3f3583a to
ace42cf
Compare
|
Rebased on master. |
|
travis the first py2.7 timed out, otherwise green merging |
ENH: Statespace: Add Kalman smoother
Adds pure python Kalman state and disturbance smoothers. Probably wouldn't have enough performance for use real use in estimation (e.g. EM or MCMC), but will be useful for people wanting to get smoothed output when parameters are estimated via MLE.
Also does not currently support smoothing in the case of missing data.