Skip to content

fix: compute FisherSnedecor pdf in log space for large freedoms - #448

Open
teddytennant wants to merge 1 commit into
statrs-dev:mainfrom
teddytennant:wrangle-fisher-c
Open

fix: compute FisherSnedecor pdf in log space for large freedoms#448
teddytennant wants to merge 1 commit into
statrs-dev:mainfrom
teddytennant:wrangle-fisher-c

Conversation

@teddytennant

Copy link
Copy Markdown
Contributor

FisherSnedecor::pdf evaluates ((d1 x)^d1 * d2^d2) / (d1 x + d2)^(d1+d2) with powf. At ordinary in-range parameters those powers overflow independently, so pdf comes back 0 or NaN and ln_pdf (which is just pdf(x).ln()) cannot recover.

FisherSnedecor::new(80.0, 80.0).unwrap().pdf(1.0) // was 0.0
FisherSnedecor::new(100.0, 100.0).unwrap().pdf(1.0) // was NaN

F(80, 80) at the mode x = 1 is a textbook density of about 1.78, not a tail.

Compute ln_pdf from the log of the documented formula (ln_beta already exists) and take pdf = ln_pdf.exp(). Same class of fix as the Hypergeometric / Multinomial pmfs.

A few existing small-dof fixtures differ by about 1 ULP from the old product-then-sqrt path, so those tolerances moved one digit (for example 1e-16 to 1e-15). That is not how the overflow cases are tested; those have their own expected values.

cargo test --lib is green (792 passed).

@codecov

codecovBot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.07%. Comparing base (92819b6) to head (0a84d2b).

Additional details and impacted files
@@ Coverage Diff @@## main #448 +/- ##
=======================================
Coverage 95.07% 95.07% =======================================
Files 62 62 Lines 14191 14203 +12 =======================================
+ Hits 13492 13504 +12 
Misses 699 699 

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for freeto 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.

1 participant

@teddytennant