-
Notifications
You must be signed in to change notification settings - Fork 226
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
Change skew normal quantile to use bracket_and_solve_root. #1123
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db90dfd
Change skew normal quantile to use bracket_and_solve_root.
jzmaddock 991700d
Correct <random> usage.
jzmaddock a194dc5
Clean up skew normal quantile with one Newton step.
jzmaddock 4f6963a
clang need a higher tolerance.
jzmaddock c728d05
Up clang error rates again.
jzmaddock e287517
Update max iterations.
jzmaddock fc2ebf5
Merge branch 'develop' into issue1120
jzmaddock c61c4af
Merge branch 'develop' into issue1120
jzmaddock 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 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 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 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright John Maddock 2024. | ||
// Use, modification and distribution are subject to the | ||
// Boost Software License, Version 1.0. (See accompanying file | ||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
// | ||
// The purpose of this test case is to probe the skew normal quantiles | ||
// for extreme values of skewness and ensure that our root finders don't | ||
// blow up, see https://github.com/boostorg/math/issues/1120 for original | ||
// test case. We test both the maximum number of iterations taken, and the | ||
// overall total (ie average). Any changes to the skew normal should | ||
// ideally NOT cause this test to fail, as this indicates that our root | ||
// finding has been made worse by the change!! | ||
// | ||
// Note that defining BOOST_MATH_INSTRUMENT_SKEW_NORMAL_ITERATIONS | ||
// causes the skew normal quantile to save the number of iterations | ||
// to a global variable "global_iter_count". | ||
// | ||
|
||
#define BOOST_MATH_INSTRUMENT_SKEW_NORMAL_ITERATIONS | ||
|
||
#include <random> | ||
#include <boost/math/distributions/skew_normal.hpp> | ||
#include "math_unit_test.hpp" | ||
|
||
std::uintmax_t global_iter_count; | ||
std::uintmax_t total_iter_count = 0; | ||
|
||
int main() | ||
{ | ||
using scipy_policy = boost::math::policies::policy<boost::math::policies::promote_double<false>>; | ||
|
||
std::mt19937 gen; | ||
std::uniform_real<> location(-3, 3); | ||
std::uniform_real<> scale(0.001, 3); | ||
|
||
for (unsigned skew = 50; skew < 2000; skew += 43) | ||
{ | ||
constexpr double pn[] = { 0.0001, 0.001, 0.01, 0.1, 0.2, 0.3, 0.4 }; | ||
boost::math::skew_normal_distribution<double, scipy_policy> dist(location(gen), scale(gen), skew); | ||
for (unsigned i = 0; i < 7; ++i) | ||
{ | ||
global_iter_count = 0; | ||
double x = quantile(dist, pn[i]); | ||
total_iter_count += global_iter_count; | ||
CHECK_LE(global_iter_count, static_cast<std::uintmax_t>(55)); | ||
double p = cdf(dist, x); | ||
CHECK_ULP_CLOSE(p, pn[i], 45000); | ||
|
||
global_iter_count = 0; | ||
x = quantile(complement(dist, pn[i])); | ||
total_iter_count += global_iter_count; | ||
CHECK_LE(global_iter_count, static_cast<std::uintmax_t>(55)); | ||
p = cdf(complement(dist, x)); | ||
CHECK_ULP_CLOSE(p, pn[i], 45000); | ||
} | ||
} | ||
CHECK_LE(total_iter_count, static_cast<std::uintmax_t>(10000)); | ||
return boost::math::test::report_errors(); | ||
} |
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.
Given that we know that derivative of the CDF, I wonder if we could make this a bit more simple using the condition number of rootfinding, e.g.,