Skip to content

fix(distributions): correct NormalDist weight handling and UBRE calculation#532

Open
Karman580 wants to merge 2 commits into
dswah:mainfrom
Karman580:fix-normaldist-weight-handling
Open

fix(distributions): correct NormalDist weight handling and UBRE calculation#532
Karman580 wants to merge 2 commits into
dswah:mainfrom
Karman580:fix-normaldist-weight-handling

Conversation

@Karman580
Copy link
Copy Markdown

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.

KARMAN SINGH TALWAR 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - NormalDist.log_pdf applies weights to standard deviation instead of variance

1 participant