-
Notifications
You must be signed in to change notification settings - Fork 257
Find degrees of freedom for non_central_f distribution
#1368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JacobHass8
wants to merge
8
commits into
boostorg:develop
Choose a base branch
from
JacobHass8:nc-f-find-v1
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+236
−5
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44cbb53
Initial implementation/test of find_v1
JacobHass8 3eb7561
Added v2 finder
JacobHass8 4801654
Included edge cases for code coverage [ci skip]
JacobHass8 04eace4
Added checks for multiple degrees of freedom
JacobHass8 d43d08c
Improved test coverage
JacobHass8 ceb66f5
Merge branch 'boostorg:develop' into nc-f-find-v1
JacobHass8 bdce34d
Added chi squared approximation
JacobHass8 a0bd79c
Changed to non-central chi-squared dist
JacobHass8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,13 +138,13 @@ void test_spot( | |
| BOOST_CHECK_CLOSE( | ||
| cdf(complement(dist, x)), Q, tol); | ||
| BOOST_CHECK_CLOSE( | ||
| quantile(dist, P), x, tol * 10); | ||
| quantile(dist, P), x, tol * 10); | ||
| BOOST_CHECK_CLOSE( | ||
| quantile(complement(dist, Q)), x, tol * 10); | ||
| quantile(complement(dist, Q)), x, tol * 10); | ||
| BOOST_CHECK_CLOSE( | ||
| dist.find_non_centrality(x, a, b, P), ncp, tol * 10); | ||
| dist.find_non_centrality(x, a, b, P), ncp, tol * 10); | ||
| BOOST_CHECK_CLOSE( | ||
| dist.find_non_centrality(boost::math::complement(x, a, b, Q)), ncp, tol * 10); | ||
| dist.find_non_centrality(boost::math::complement(x, a, b, Q)), ncp, tol * 10); | ||
| } | ||
| if(boost::math::tools::digits<RealType>() > 50) | ||
| { | ||
|
|
@@ -369,6 +369,48 @@ void test_spots(RealType, const char* name = nullptr) | |
| } | ||
| } | ||
| } | ||
|
|
||
| // Quick spot check for finding degrees of freedom. When checking for two degrees | ||
| // of freedom for real_concept types, the cdf at large/small v2 can be greater than 1 | ||
| // or less than 0. | ||
| if (!std::is_same<RealType, boost::math::concepts::real_concept>::value){ | ||
| RealType v1 = 10; | ||
| RealType v2 = 5; | ||
| nc = 1; | ||
| x = 6; | ||
| boost::math::non_central_f_distribution<RealType> ref(v1, v2, nc); | ||
| RealType P = cdf(ref, x); | ||
| BOOST_CHECK_CLOSE(ref.find_v2(x, v1, nc, P), v2, tolerance); | ||
| BOOST_CHECK_CLOSE(ref.find_v2(boost::math::complement(x, v1, nc, 1-P)), v2, tolerance); | ||
| BOOST_CHECK_CLOSE(ref.find_v1(x, v2, nc, P), v1, tolerance); | ||
| BOOST_CHECK_CLOSE(ref.find_v1(boost::math::complement(x, v2, nc, 1-P)), v1, tolerance); | ||
| } | ||
|
|
||
| // Check case where two degrees of freedom solve the inversion problem | ||
| BOOST_MATH_CHECK_THROW(dist.find_v1(RealType(1.5), RealType(2.0), RealType(1.0), RealType(0.49845842011686358665786775091245664L)), boost::math::evaluation_error); | ||
| BOOST_MATH_CHECK_THROW(dist.find_v1(RealType(3.51), RealType(5), RealType(0), RealType(0.85802971653663762108266155337333L)), boost::math::evaluation_error); | ||
|
|
||
| // Check find_v1/v2 edge cases | ||
| // Case when P=1 or P=0 | ||
| nc = 2; | ||
| BOOST_MATH_CHECK_THROW(dist.find_v1(x, b, nc, 1), std::domain_error); | ||
| BOOST_MATH_CHECK_THROW(dist.find_v1(x, b, nc, 0), std::domain_error); | ||
| // Case when Q=1 or Q=0 | ||
| BOOST_MATH_CHECK_THROW(dist.find_v1(boost::math::complement(x, b, nc, 1)), std::domain_error); | ||
| BOOST_MATH_CHECK_THROW(dist.find_v1(boost::math::complement(x, b, nc, 0)), std::domain_error); | ||
| // Check very small values of x an evaluation error is thrown | ||
| x = boost::math::tools::epsilon<long double>() / 10; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use of |
||
| BOOST_MATH_CHECK_THROW(dist.find_v1(boost::math::complement(x, b, nc, 0.5)), boost::math::evaluation_error); | ||
| BOOST_MATH_CHECK_THROW(dist.find_v1(x, b, nc, 0.5), boost::math::evaluation_error); | ||
|
|
||
| BOOST_MATH_CHECK_THROW(dist.find_v2(x, b, nc, 1), std::domain_error); | ||
| BOOST_MATH_CHECK_THROW(dist.find_v2(x, b, nc, 0), std::domain_error); | ||
| // Case when Q=1 or Q=0 | ||
| BOOST_MATH_CHECK_THROW(dist.find_v2(boost::math::complement(x, b, nc, 1)), std::domain_error); | ||
| BOOST_MATH_CHECK_THROW(dist.find_v2(boost::math::complement(x, b, nc, 0)), std::domain_error); | ||
| // Check very small values of x an evaluation error is thrown | ||
| BOOST_MATH_CHECK_THROW(dist.find_v2(boost::math::complement(x, b, nc, 0.5)), boost::math::evaluation_error); | ||
| BOOST_MATH_CHECK_THROW(dist.find_v2(x, b, nc, 0.5), boost::math::evaluation_error); | ||
| } // template <class RealType>void test_spots(RealType) | ||
|
|
||
| BOOST_AUTO_TEST_CASE( test_main ) | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using an asymptotic expression for
v1but not forv2?It might be easier to split this over two PRs instead of one to make review easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we're only using the asymptotic expression when solving for
v1. This is because I can't find an expression for the distribution asv1-> infinity.We could split it up, but the asymptotic approximation is the only place where these functions differ. Otherwise, you just need to swap the order of
v1andv2.