Skip to content

fix: NormalDist.log_pdf weight application (#457)#516

Open
dkstlzk wants to merge 1 commit intodswah:mainfrom
dkstlzk:issue/457-log-pdf-weights
Open

fix: NormalDist.log_pdf weight application (#457)#516
dkstlzk wants to merge 1 commit intodswah:mainfrom
dkstlzk:issue/457-log-pdf-weights

Conversation

@dkstlzk
Copy link

@dkstlzk dkstlzk commented Mar 10, 2026

Description

Fixes #457.

This PR corrects the mathematical application of sample weights in NormalDist.log_pdf. In GLM conventions, weights $w$ should divide the variance ($\text{Var} = \sigma^2 / w$), which implies the standard deviation used in the PDF should be adjusted by the square root of the weight ($\text{SD} = \sigma / \sqrt{w}$).

Changes

  • Distributions: Updated NormalDist.log_pdf to divide the scale by np.sqrt(weights) to ensure statistical consistency with the rest of the library's PIRLS implementation.
  • Infrastructure: Configured the matplotlib non-interactive Agg backend in conftest.py and test_gen_imgs.py to resolve the _tkinter.TclError (missing init.tcl) that causes failures on headless Windows CI runners.
  • Tests: Added a regression test test_normal_dist_log_pdf_weights to test_GAMs.py that validates log_pdf output against scipy.stats.norm.logpdf.

Testing Performed

  • Verified fix with a standalone reproduction script (matches scipy.stats).
  • Confirmed that the new regression test passes locally with pytest.
  • Verified all 164 existing tests pass across platforms, resolving the Windows-specific failure.
  • Verified code style compliance with ruff format.

@dkstlzk dkstlzk changed the title feat: fix NormalDist.log_pdf weight application (#457) fix: NormalDist.log_pdf weight application (#457) Mar 10, 2026
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