Skip to content

ENH: Decouple state space / filter from MLE - #2473

Merged
josef-pkt merged 4 commits into
statsmodels:masterfrom
ChadFulton:ss-decouple
Jul 7, 2015
Merged

josef-pkt merged 4 commits into
statsmodels:masterfrom
ChadFulton:ss-decouple

Conversation

@ChadFulton

Copy link
Copy Markdown
Member

Removes the inheritance relationship between the MLE classes and the Statespace classes, replacing it with delegation instead.

This PR also incorporates all the changes in #2356, but we could probably merge that first so that the changes are kept separate, and then when I rebase I can make sure the merge goes as planned.

@ChadFulton

Copy link
Copy Markdown
Member Author

Also, this PR as it is now would remove the ability to construct ad hoc state space models (see #2330).

@ChadFulton

Copy link
Copy Markdown
Member Author

This PR changes the structure from:

Representation - KalmanFilter
                               \
                                Model - MLEModel - SARIMAX
                               /
              TimeSeriesModel

to

Representation - KalmanFilter

TimeSeriesModel - MLEModel - SARIMAX

where:

  • MLEModel holds a reference to a KalmanFilter instance, called MLEModel.ssm
  • MLEResults holds a reference to a FilterResults instance, called MLEResults.ssm_result

@ChadFulton

Copy link
Copy Markdown
Member Author

This fixes the following issues:

  • Minimize holding of "state" if it's not needed (remove from methods that don't require it) - params is no longer held by anything except the results instance, and the methods in MLEModel (e.g. MLEModel.filter) now requires params as an argument (the KalmanFilter instance still holds state in the sense that when KalmanFilter.filter is called, it simply applies the filter based on whatever state space representation it currently holds, but I don't see this as something we'd want to change).
  • No longer forces the MLEModel.endog (and exog) array to conform to the requirements in KalmanFilter (e.g. Fortran contiguous, and already differenced in SARIMAX if simple_differencing=True).
  • Fixes the results classes to use the Statsmodels wrapper classes

@ChadFulton

Copy link
Copy Markdown
Member Author

Question: right now, this does not expose in MLEModel any of the KalmanFilter attributes, and it does not expose in MLEResults any of the FilterResults attributes. Do we want to expose any of them directly (obviously they can all be achieved by MLEModel.ssm.<attribute> or MLEResults.ssm_result.<attribute>)?

My initial impression is that we may not need to directly expose them, but instead let individual models do that in a more user friendly way. So SARIMAX may not need the filtered_state, etc. variables at all, whereas UnobservedComponents should have them, but with user friendly names (e.g. UnobservedComponentsResults.level and .trend instead of .filtered_state[0] and .filtered_state[1]).

@josef-pkt

Copy link
Copy Markdown
Member

My initial impression is that we may not need to directly expose them ...

I fully agree. We started at some point early on to copy some attributes from models to results, but I also think now that it keeps it cleaner if we only copy what's really necessary and accessed very often by users.

@ChadFulton

Copy link
Copy Markdown
Member Author

Question: right now, the MLEModel and SARIMAX (and other derivative state space models) send **kwargs in initialization to KalmanFilter.__init__ and **kwargs in fit to KalmanFilter.filter. Should we add specific arguments (e.g. filter_kwargs) to each function and only send that dictionary?

@josef-pkt josef-pkt mentioned this pull request Jul 3, 2015
3 of 7 tasks
@josef-pkt

Copy link
Copy Markdown
Member

this looks like it might include some code from the cov_type PR #2356 that has been merged.

This will need a rebase with likely merge conflicts.

@ChadFulton

Copy link
Copy Markdown
Member Author

Rebased following the merge of #2356.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this also needs dates and freq even though they are positional.
We need a check when the recreating of the model is actually used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but it looks like the other tsa models don't do this. Possibly I will postpone this, then?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed right now. It's currently only used by a few new generic features mainly for discrete and glm. One application is to get a new model for testing a restriction, as in llnull.

@josef-pkt

Copy link
Copy Markdown
Member

spot checking (mainly on interface), I only see a few things to comment on.

IMO, this should be merged before the first release of statespace model. There are user relevant changes for accessing the state variables from the results instance.

The scipy conference sprint is next week, in case Skipper prepares the release, and we still have (most likely) a few days next week. I could merge tomorrow or Monday.

@josef-pkt

Copy link
Copy Markdown
Member

Can I just merge this today, or are there still things to look at?

@josef-pkt

Copy link
Copy Markdown
Member

Do we need to update the notebooks in the documentation, so they still work correctly when this is merged?

@ChadFulton

Copy link
Copy Markdown
Member Author

Can I just merge this today, or are there still things to look at?

Do we need to update the notebooks in the documentation, so they still work correctly when this is merged?

Yes, let's plan to merge today (Monday). But you're right, let me go back through the notebooks to make sure everything works as expected before the merge.

Also, in a previous PR I had added release notes and documentation, so I need to go fix those too. But maybe that should be a separate PR so that we can get this one merged?

@ChadFulton

Copy link
Copy Markdown
Member Author

Do we need to update the notebooks in the documentation, so they still work correctly when this is merged?

What notebook versions do we support? Can I upload the IPython v3.0.0 notebooks (which are actually the v4 notebook format) or do I need to continue to upload older notebooks (e.g. v3 notebook format)?

@josef-pkt

@josef-pkt

Copy link
Copy Markdown
Member

V4 should be fine. If I manage to clean up the data loading, then I might ask you to convert to v4 because I stll only have v3 ipyton.

josef-pkt added a commit that referenced this pull request Jul 7, 2015
REF: Decouple state space / filter from MLE
@josef-pkt
josef-pkt merged commit 058c321 into statsmodels:master Jul 7, 2015
@josef-pkt

Copy link
Copy Markdown
Member

@ChadFulton Can you try to get at least the update of the release notes in this week?

@ChadFulton

Copy link
Copy Markdown
Member Author

Yes, I'm sorry about the delay. I just moved and it's been one thing after another, but I should be done this evening and push the PRs later tonight.

@ChadFulton
ChadFulton deleted the ss-decouple branch July 9, 2015 02:09
ChadFulton added a commit to ChadFulton/statsmodels that referenced this pull request Jul 10, 2015
josef-pkt added a commit that referenced this pull request Jul 12, 2015
REF: Fix regressions introduced in #2473.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants