You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Design: Coupling of statespace classes with downstream models #2265
Currently the design suggests that estimated state space models be descendants of the Representation and KalmanFilter classes, where the inheritance is through MLEModel and Model.
For example, the SARIMAX class has the following inheritance structure:
The entire purpose of the Model class is to join the inheritance trees of statespace and statsmodels. However, there is no particular reason for the relatively strict coupling via inheritance, particularly since most users will not care about the state space representation (e.g. the design matrix with the MLE parameters, etc.).
There are several issues with the current approach:
The inheritance structure enforces that the self.endog for Representation is the same array as the self.endog for SARIMAX. This is problematic when simple_differencing=True, which means that the self.endog used by Representation has to be the differenced time series, whereas the self.endog for SARIMAX should probably be the endog array that was passed in (and similar for `exog).
The inheritance structure requires the SARIMAX model to hold state.
There are many attributes in the SARIMAX class that are somewhat unrelated to the model per se (e.g. state space matrices, filtering options, etc.).
One way to refactor the model is via delegation. In that case, the Model class would likely be eliminated, and the inheritance structure for SARIMAX could be:
TimeSeriesModel - MLEModel - SARIMAX
Then MLEModel could delegate all filtering and likelihood computation to a KalmanFilter instance (e.g. self.ssm or self.statespace or similar). MLEResults could delegate the base predict method to FilterResults.
Any fix of the problem via delegation still needs to take into account copying versus references of endog and exog arrays.
another possible issue circular references (just found them in #2288)
If delegation requires circular references between Model, Representation and KalmanFilter, then it might also not be the right choice. (Based on previous cases of circular references, it can create problems with garbage collection and blow up the memory requirements when we create models in a loop for example for bootstrapping. It needs explicit gc.collect)
Main question is which class needs to hold on and change which attributes, and whether it's possible to work at least partially in a functional way instead of working mainly through side-effects (changing attributes).
One possibility is to start with increasing separation within the current class structure (triple inheritance), to have more incremental refactoring (e.g. to make it easier to add the wrapper class) instead of one big refactor.
Activity
josef-pkt commentedon Feb 22, 2015
another possible issue circular references (just found them in #2288)
If delegation requires circular references between Model, Representation and KalmanFilter, then it might also not be the right choice. (Based on previous cases of circular references, it can create problems with garbage collection and blow up the memory requirements when we create models in a loop for example for bootstrapping. It needs explicit gc.collect)
Main question is which class needs to hold on and change which attributes, and whether it's possible to work at least partially in a functional way instead of working mainly through side-effects (changing attributes).
josef-pkt commentedon Feb 22, 2015
One possibility is to start with increasing separation within the current class structure (triple inheritance), to have more incremental refactoring (e.g. to make it easier to add the wrapper class) instead of one big refactor.
ChadFulton commentedon Feb 12, 2016
The decoupling was completed in #2473.