Skip to content

parameter restrictions where to define df_model, xnames, ...  #921

Open

Description

@josef-pkt

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.

Activity

  1. josef-pkt commented on Jun 28, 2013

    @josef-pkt
    MemberAuthor

    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:

    if fixone:
        mod_par.fixed_params = fixdf
        mod_par.fixed_paramsmask = np.isnan(fixdf)
        mod_par.start_params = mod_par.start_params[mod_par.fixed_paramsmask]
        mod_par.df_model = 2
        mod_par.df_resid = mod_par.endog.shape[0] - mod_par.df_model
        mod_par.data.xnames = ['shape', 'scale']
    else:
        mod_par.fixed_params = None
        mod_par.fixed_paramsmask = None
        mod_par.df_model = 3
        mod_par.df_resid = mod_par.endog.shape[0] - mod_par.df_model
        mod_par.data.xnames = ['shape', 'loc', 'scale']
    

    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

  2. josef-pkt commented on Jun 28, 2013

    @josef-pkt
    MemberAuthor

    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".

  3. josef-pkt commented on Jun 28, 2013

    @josef-pkt
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions