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
parameter restrictions where to define df_model, xnames, ... #921
I'm reviewing the GenericLikelihoodModel, and try to fix so it works again out of the box.
One problem I run into is when I set a parameter restriction in the fit method. During initialization I don't know yet how many parameters will be estimated. fit can fix some parameters at predefined values, and as a consequence the actual number of params can change.
Since now the initialization code for xnames, df_model, df_resid, and so on, is in the __init__ and initialize which is called by __init__, the default code paths don't work correctly.
I get exceptions at various places, when df_model, xnames, ... are not defined or not defined correctly.
One option is to force that the restrictions are in __init__, so that the correct number of parameters is already known.
The other option is a fall back that fixes up the missing or incorrect meta attributes during fit.
I don't really like the first option, since it makes it more difficult to write fit methods with different constraints. However, the problem is a bit similar to the one we had when we moved order from fit to __init__ in ARMA.
The parameters in my cases are extra parameters that are not associated with an exog. The two cases I'm looking at are fixing the location in distribution estimation (like floc in scipy.stats) and fixing extra shape parameters such as the degrees of freedom in a maximum likelihood estimation with the t distribution.
The same problem will show up when we get non-linear least squares with or without restrictions.
another possibility is to add a method to the model to change the number of parameter, for example in this case something like change_restriction.
This will be more convenient for users and we can decide internally whether to return a new instance (if restrictions have to be in __init__), or to adjust the necessary attributes.
this works currently with summary() and with t_test (no patsy exception in this case)
Note: model.exog_names is a cached attribute and we can append if it's mutable, but we cannot assign directly model.data.xnames is the original that model.exog_names references
.data.xnames
same argument as before in favor in putting restrictions in __init__
I run fit with an initial model, then I change the parameter restrictions, and run fit a second time based on different restrictions. Now, I have two result instances that both reference the same model instance, one results instance has the model with the wrong "state".
One other possibility how to handle restriction, would be to work with the cov_params for the full model, and nan the rows and columns that are fixed. Similar if we have (linear) restriction, we have the question whether to report for the transformed, reduced parameter space or the full, original parameter space.
Activity
josef-pkt commentedon Jun 28, 2013
another possibility is to add a method to the model to change the number of parameter, for example in this case something like
change_restriction.This will be more convenient for users and we can decide internally whether to return a new instance (if restrictions have to be in
__init__), or to adjust the necessary attributes.For the latter case, I have as example:
this works currently with summary() and with t_test (no patsy exception in this case)
Note:
model.exog_namesis a cached attribute and we can append if it's mutable, but we cannot assign directlymodel.data.xnamesis the original thatmodel.exog_namesreferences.data.xnames
josef-pkt commentedon Jun 28, 2013
same argument as before in favor in putting restrictions in
__init__I run fit with an initial model, then I change the parameter restrictions, and run fit a second time based on different restrictions. Now, I have two result instances that both reference the same model instance, one results instance has the model with the wrong "state".
josef-pkt commentedon Jun 28, 2013
One other possibility how to handle restriction, would be to work with the cov_params for the full model, and nan the rows and columns that are fixed. Similar if we have (linear) restriction, we have the question whether to report for the transformed, reduced parameter space or the full, original parameter space.