fix(distributions): correct NormalDist weight handling and UBRE calculation#532
Open
Karman580 wants to merge 2 commits into
Open
fix(distributions): correct NormalDist weight handling and UBRE calculation#532Karman580 wants to merge 2 commits into
Karman580 wants to merge 2 commits into
Conversation
added 2 commits
March 14, 2026 22:20
…lation - Fix NormalDist.log_pdf: change scale = self.scale / weights to scale = self.scale / np.sqrt(weights) to match the GLM convention Var = sigma^2 / w (previously implied Var = sigma^2 / w^2) - Fix UBRE boolean bug: replace ~add_scale (bitwise NOT, yields -2) with float(not add_scale) (logical negation, yields 0.0 or 1.0) - Fix ValueError formatting: format(gamma) was passed as a second argument to ValueError instead of being interpolated into the string - Add 5 regression tests verifying weighted log-pdf against scipy.stats.norm.logpdf Fixes dswah#457
- Remove unused 'pytest' import from test_distributions.py
- Add matplotlib.use('Agg') to gen_imgs.py for headless CI environments
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 free
to 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.
This PR fixes statistical correctness issues in the weighted log-likelihood computation for NormalDist and related UBRE calculations. Previously, weights were applied as scale = self.scale / weights, which implied a variance of σ²/w². Following the GLM convention used in PyGAM (Var = σ²/w), the correct standard deviation for weighted observations is σ/√w; therefore, the implementation has been updated to self.scale / np.sqrt(weights). Additionally, this PR corrects a boolean inversion bug in the UBRE computation (~add_scale → float(not add_scale)) and fixes a formatting issue in the gamma scaling ValueError message. Regression tests were added to validate weighted log-likelihood behavior against scipy.stats.norm.logpdf. All tests pass successfully. Fixes #457.