Fix InvCDF crash on tail quantiles outside the fixed root-finding bracket - #1158
Open
gaoflow wants to merge 1 commit into
Open
Fix InvCDF crash on tail quantiles outside the fixed root-finding bracket#1158gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
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.
FisherSnedecor.InvCDFandStudentT.InvCDFsolveCDF(x) = pwithBrent.FindRootover a hard-coded finite bracket ([0, 1000]/[-800, 800]). Both distributions have unbounded heavy tails, so any quantile outside the bracket throwsNonConvergenceExceptionon a perfectly valid probability — including routine calls like:The fix uses the library's own
Brent.FindRootExpand(expands the bracket until it straddles the root, then runs the sameBrent.FindRootwith the same1e-12accuracy), centers the StudentT bracket on the location/scale parametrization so any offset parametrization is reachable, and returns the support endpoints atp == 0/p == 1like 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)) == pwithin the solver's1e-12accuracy. Full test suite: 20951 passed, 0 failed.