Skip to content

Fix InvCDF crash on tail quantiles outside the fixed root-finding bracket - #1158

Open
gaoflow wants to merge 1 commit into
mathnet:masterfrom
gaoflow:fix-invcdf-bracket-tail-crash
Open

Fix InvCDF crash on tail quantiles outside the fixed root-finding bracket#1158
gaoflow wants to merge 1 commit into
mathnet:masterfrom
gaoflow:fix-invcdf-bracket-tail-crash

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 31, 2026

Copy link
Copy Markdown

FisherSnedecor.InvCDF and StudentT.InvCDF solve CDF(x) = p with Brent.FindRoot over a hard-coded finite bracket ([0, 1000] / [-800, 800]). Both distributions have unbounded heavy tails, so any quantile outside the bracket throws NonConvergenceException on a perfectly valid probability — including routine calls like:

FisherSnedecor.InvCDF(1, 1, 0.99);   // true quantile 4052.18 -> throws
FisherSnedecor.InvCDF(2, 1, 0.999);  // true quantile 499999.5 -> throws
StudentT.InvCDF(0, 1, 1, 0.9999);    // t(1) is Cauchy; true ~3183.1 -> throws
StudentT.InvCDF(1000, 1, 5, 0.99);   // true 1003.36 -> throws (location outside the absolute bracket)

The fix uses the library's own Brent.FindRootExpand (expands the bracket until it straddles the root, then runs the same Brent.FindRoot with the same 1e-12 accuracy), centers the StudentT bracket on the location/scale parametrization so any offset parametrization is reachable, and returns the support endpoints at p == 0 / p == 1 like the Cauchy/Exponential/LogNormal implementations instead of letting the expander run at the boundary. Values inside the old bracket are unchanged (same solver, same bounds).

Verified against an mpmath oracle (dps 30 and 35 in agreement) across a grid of 189 F and 42 StudentT cases — every formerly-throwing tail quantile now matches the true value and satisfies CDF(InvCDF(p)) == p within the solver's 1e-12 accuracy. Full test suite: 20951 passed, 0 failed.

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.

1 participant