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
REF/Design hessian_factor in multi-parameter models, tuple or array #7827
We need a consistent convention for how we return score_factor and hessian_factors for multiple parameters
Tuple would be better, because then we don't have to pack and unpack the array each time. If the array is fortran ordered, then we could just use a view on the array and don't need memory copies.
Usage will mostly require that we multiply individual factors by the corresponding exog.
betareg.BetaModel uses array, symmetric 2 by 2
draft version for GPP and NBP in #7825 also use arrays
somewhere (?) I use tuples
For generic models, score_factor and hessian_factor will be a combination of distribution derivatives and (inverse) link derivatives (chain rule).
problem is because hessian_factor was converted from oim and eim factors without changing sign dbae402
pretty old 2014
The original GLM.score_test in that PR changes the sign of hessian_factor to compute hessian.
The newer generic version assumes that hessian_factor directly corresponds to 2nd derivative.
BetaModel is using both
score factor is column_stacked
score_hessian_factor stacks score_factor and tuples hessian_factor np.column_stack((sf1, sf2)), (-jbb, -jbg, -jgg)
score and score_obs use column indexing
hessian uses tuple unpacking
I think I switch to tuples everywhere including discrete models like NBP and GPP
I want to extend score_test to NBP, and need a consistent design for this.
score factor is easy to handle either way.
hessian factor needs block "matrix" as used in BetaModel.hessian. np.bmat has now an alternative np.block that avoids producing np.matrix.
A bit messy for block. For some cases of multi-link model we need 3 or more components.
The tuple of hessian factor will be based on triu or tril indices. We need to build a symmetric block matrix (array) from the triu or tril list.
If we add exog_extra only to one link, then we could reuse the hessian for some of the other blocks. But I guess that makes it more complicated without a large gain.
(e.g. heteroscedasticity score test could reuse mean parameter block, we still need off-diagonal blocks in addition to main added variable block)
Another implementation problem:
We have two types of additional paramters, multilink with additional exog (even if they can be just constant/ones), and extra params that are scalar like scale and dispersion parameters (e.g. NB, NBP, GPP)
In the second case, the hessian block is just the component of the hessian_factor. In the first case, we need products with different exog.
That's too much code to inline in the score_test function/method.
If hessian methods like the one in BetaModel take a list of exog, then we could just reuse the existing hessian_factor to hessian conversion.
and another painful case: OrderedModel has the extra threshold parameters. That's a set of extra scalar params.
Currently I rely on numdiff for score and hessian in OrdereModel.
Aside: for score_test it would be simpler just to create the full model and expand params with zeros. We don't need to estimate the full model, just use it to create score and hessian. (Currently the reverse is implemented user needs to provide the full model and the constrained params.)
Activity
josef-pkt commentedon Oct 28, 2021
edit this comment might be in the wrong issue
problem is because hessian_factor was converted from oim and eim factors without changing sign
dbae402
pretty old 2014
The original GLM.score_test in that PR changes the sign of hessian_factor to compute hessian.
The newer generic version assumes that hessian_factor directly corresponds to 2nd derivative.
josef-pkt commentedon Oct 29, 2021
BetaModel is using both
score factor is column_stacked
score_hessian_factor stacks score_factor and tuples hessian_factor np.column_stack((sf1, sf2)), (-jbb, -jbg, -jgg)
score and score_obs use column indexing
hessian uses tuple unpacking
I think I switch to tuples everywhere including discrete models like NBP and GPP
josef-pkt commentedon Oct 29, 2021
asides
josef-pkt commentedon Nov 21, 2021
I will refactor to use tuple.
I want to extend
score_testto NBP, and need a consistent design for this.score factor is easy to handle either way.
hessian factor needs block "matrix" as used in BetaModel.hessian.
np.bmathas now an alternativenp.blockthat avoids producing np.matrix.A bit messy for
block. For some cases of multi-link model we need 3 or more components.The tuple of hessian factor will be based on triu or tril indices. We need to build a symmetric block matrix (array) from the triu or tril list.
If we add exog_extra only to one link, then we could reuse the hessian for some of the other blocks. But I guess that makes it more complicated without a large gain.
(e.g. heteroscedasticity score test could reuse mean parameter block, we still need off-diagonal blocks in addition to main added variable block)
Another implementation problem:
We have two types of additional paramters, multilink with additional exog (even if they can be just constant/ones), and extra params that are scalar like scale and dispersion parameters (e.g. NB, NBP, GPP)
In the second case, the hessian block is just the component of the hessian_factor. In the first case, we need products with different exog.
That's too much code to inline in the score_test function/method.
If hessian methods like the one in BetaModel take a list of exog, then we could just reuse the existing hessian_factor to hessian conversion.
and another painful case: OrderedModel has the extra threshold parameters. That's a set of extra scalar params.
Currently I rely on numdiff for score and hessian in OrdereModel.
Aside: for score_test it would be simpler just to create the full model and expand params with zeros. We don't need to estimate the full model, just use it to create score and hessian. (Currently the reverse is implemented user needs to provide the full model and the constrained params.)
josef-pkt commentedon Nov 25, 2021
internal naming, general issue for multi-exog
Do we use 0-based or 1-based names in list of names?
e.g.
sf1, sf2 = self.score_factor(params)
[exog, exog2, exog3] or [exog, exog1, exog2]