Repository navigation
Description
What should be our long term pattern for hyper parameter selection?
examples: lag selection in tsa models, penalty in penalized models.
tradeoff: clean, more "fool-proof" design versus computational efficiency
Our old pattern was to add those hyper parameters to fit, e.g. some tsa models still have lag selection "ic" in fit. This can potentially take advantage of computationally efficient search without creating new models each time.
Our newer pattern is to put hyper parameters in the model.__init__ to avoid incorrect state, attributes in models. This requires that a new model is created for each set of values for the hyper parameters. This adds additional overhead and cannot take advantage of unchanging intermediate results.
lag selection:
There are some open issues for lag selection in tsa which still needs refactoring, e.g. #4536 for VAR
example penalization:
In penalized or regularized regression, the underlying data, endog and exog, does not change.
In #4576 I avoided the issue of a proper API so far, and make penalization weights as a model attribute, but I change the attribute before running fit. It is essentially a __init__ keyword that can be manipulated as a fit keyword. but will cause incorrect stale state if several results instances refer to the same model.
TheilGLS, and current fit_regularized model methods specify penalization parameters in a fit method. However, in those cases there should not be any penalization attributes attached to the model instance.
However, this requires that there are separate methods that are used by fit_regularized, so un-regularized methods do not need to check model attributes about the penalization.
This does not work if, for example, loglike is used for penalized and unpenalized estimation.
In #4576, I added a keyword for the penalization to loglike and similar, but it is not used because the currently standard results class (not specialized for penalized fit) does not know about those extra keywords.
So if we want to avoid model attributes that change during hyper parameter search, we would have to attach them to the model, and use them as arguments in any model calls.
AFAIR, we do this now (0.9) for scale in GLM to avoid needing scale as model attribute.
fit_constrained:
There might be a similar problem in fit_constrained, when constraints are considered as hyper parameters. I don't remember the details right now, or never looked at it specifically in terms of location for attaching attributes.
The current fit_constrained is somewhat different because it works by creating a new auxiliary model.
An alternative that we don't widely use yet is to add constrained optimization. Example is imposing stationarity in ARMA variants, or in miscmodels TModel that uses the generic reparameterization for imposing constraints.
However, constraints on parameters during optimization are simpler issue, because once we have the params, then we don't need to consider the constraints anymore, i.e. transform_params is internal to fit and an attribute that changes only temporarily.
For imposed binding constraints, the constraints need to be taken into account in the model and results.
Activity
josef-pkt commentedon May 4, 2018
related cross validation cost or loss criteria #2572
e.g. in Poisson with leave-k-out cross validation we should use loglike or something that is consistent with the estimation objective function.
e.g. family loglike as function of mu, or more general loglike as function of resid or other parameter that is independent of the hyper parameter like number of variables or size of penalization and can easily be evaluated out of sample.
(There is a related issue for count models, which for some cases manipulate internal model.endog and model.exog. I don't find it right now.)
jbrockmendel commentedon May 4, 2018
Unreliable/unintentional state is an easy way to screw up, so the newer pattern makes a lot of sense.
It sounds like you're thinking of a pre-Model class that instantiates/spawns/holds(?) multiple models (and maybe results?). Am I reading you correctly here?
josef-pkt commentedon May 4, 2018
From the outside it would be extra functions that select hyper parameters, e.g. like a function that does a cross validation loop.
However, computationally it would be easier and faster to change the hyper parameter on an existing model, which however runs into the unreliable state problem if also the user has access to the attribute, or if we keep the same model for different runs of the cross-validation loop.
Within a loop there is no real problem with stale/incorrect state because the results are only temporarily used.
The problem is with the final results instance where the user is allowed to compute many things lazily and those will be incorrect if the underlying state has changed.
josef-pkt commentedon Jan 25, 2019
example GAM PR #5370
I added two methods,
select_penweightandselect_penweight_kfoldto the model classselect_penweight_fit_pirlsto avoid recreating a model, but manipulates model attributeselect_penweight_kfoldside question
How do we unit/integration test that a method like
select_penweight_kfoldworks correctly given that it hides everything and returns only limited results information?