- Notifications
You must be signed in to change notification settings - Fork3.3k
Comments
ENH: Optimize GLM Hessian calculation for canonical links#9753
Open
rikardo21-2bleA wants to merge 1 commit intostatsmodels:mainfrom
Open
ENH: Optimize GLM Hessian calculation for canonical links#9753rikardo21-2bleA wants to merge 1 commit intostatsmodels:mainfrom
rikardo21-2bleA wants to merge 1 commit intostatsmodels:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR implements an optimization for the GLM Hessian calculation (Observed Information Matrix).$(y - \mu)$ vanishes. This PR detects canonical links and skips this unnecessary computation.
When a canonical link is used, the Observed Information Matrix (OIM) coincides with the Expected Information Matrix (EIM) / Fisher Information.
Mathematically, the curvature term involving
Closes#4269
Changes
is_canonical_linkproperty toFamilyclass and_canonical_link_classto subclasses (Binomial, Poisson, Gaussian, etc.).type(link) is ...instead ofisinstanceintentionally to strictly match the canonical link implementation and avoid inheritance issues.hessian_factoringeneralized_linear_model.py. Ifis_canonical_linkis True, it setsobserved=False, forcing the use of the EIM formula (hessian_factor.statsmodels/genmod/tests/test_glm_canonical.pywith 11 tests covering all major families to ensure numerical equivalence between the optimized path and the original path.Verification
pytest statsmodels/genmod/tests/test_glm_canonical.py(11 passed).