Repository navigation
Description
just an idea for reusable components.
We have several cases where we want to look at changes of the likelihood function if we vary an additional parameter.
This can be a hyper parameter like penalization weight in GAM, penalized models (my current use case) or the dispersion parameter in GLM-NegativeBinomial.
Or this can be a parameter that is assumed to be fixed as in profile confidence interval or score confidence interval computation, issue #2722, PR #1791
dual usage
Kerby mentioned in the context of profile confidence interval that it would be useful to evaluate the profile likelihood on a grid instead of just looking for the conf_int bounds.
Similarly, I was looking at values for the penalization parameters in GAM on a grid and use it for optimization.
Currently I am using internal nested functions for the optimization or rootfinding. Instead the idea is to make this generally available, i.e. add a method get_loglike_function that returns the loglikelihood function or lambda function that is just a function of one, or a list of parameters. The function will have the state, internal attributes, for the things that remain fixed during optimization.
We can add keywords like start_params for additional options that depend on the parameter values.
(e.g. for warm start when evaluating on a grid.)
This would allow arbitrary usage, the function can be evaluated on a grid, inside optimization or rootfinding routines. And would allow basic numerical computation like numerical derivatives.
The main advantage is that users have access to the model and parameter specific computational shortcuts. At the moment users need to create new models each time they want to change a fixed model.__init__ parameter.
see comments in #2722
Note: We need to make sure that we don't change the model itself, i.e. leave or keep model attributes unchanged. This is not a problem when we have to create an auxiliary model for the profile likelihood, but could happen if we change a "hyperparameter" directly.
In the worst case we might need a cleanup stage after usage, which would require a context manager or yield to reset attributes when the user/caller is finished. (I'm not sure how this would work.) Or a flag to do cleanup if fit is called and the state is "dirty". This sounds fragile in either case.
Activity
josef-pkt commentedon Nov 15, 2018
see comment in https://github.com/statsmodels/statsmodels/pull/1791/files#r146047881
The idea is not new, but we can use it more widely than I thought before.
e.g. GAM penalization case, e.g. providing public backdoors to improve computational efficiency for specific use cases.
link to score_test PR #4716 (open) and #2096 (merged, but no public methods)