ENH: add parameter finder for degrees or freedom for students_t distribution#1385
Open
dschmitz89 wants to merge 3 commits intoboostorg:developfrom
Open
ENH: add parameter finder for degrees or freedom for students_t distribution#1385dschmitz89 wants to merge 3 commits intoboostorg:developfrom
dschmitz89 wants to merge 3 commits intoboostorg:developfrom
Conversation
8 tasks
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.
Towards #1305
This adds a parameter finder for the student t distribution with respect to the degrees or freedom.
Disclaimer: this PR is heavily LLM supported as C++ is not (yet?) my forte.
I verified the math with a simple Python program before. I also ran a simple sanity script to see that the function actually executes. I am not so confident about the tests though as I cannot really decipher the output of
b2.Approach: We use$df > 10$ but useless for low degrees of freedom as it returns
bracket_and_solve_rootwith an initial guess from a second order Edgeworth expansion of the CDF. The initial guess is very good forNaN. In this case or if it gives a relative error of the CDF worse than 10%, we fall back to an initial guess of 0.01.Detailed approach for finding the initial guess
Given a quantile$x$ and a CDF value $p = P(T \leq x)$ , we want to recover the degrees of freedom $\nu$ .
Step 1 — Edgeworth warm start.
We use the 2nd-order Edgeworth expansion of the$t$ CDF in powers of $1/\nu$ :
where
Setting
where
The physically meaningful root (smallest positive$u$ , i.e. largest $\nu$ ) gives a closed-form starting estimate $\hat\nu = 1/u$ .
Step 2 — Validation.
We plug$\hat\nu$ into the exact $t$ CDF. If the relative residual $|F(x;\hat\nu) - p|/|p|$ exceeds 10%, we fall back to a safe low starting value $\nu_0 = 10^{-2}$ .