Skip to content

Commit

Permalink
Update kolmogorov quantile newton ub to 1 (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanelandt authored Jul 31, 2023
1 parent fb0af63 commit c62682b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/boost/math/distributions/kolmogorov_smirnov.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ inline RealType quantile(const kolmogorov_smirnov_distribution<RealType, Policy>
std::uintmax_t m = policies::get_max_root_iterations<Policy>(); // and max iterations.

return tools::newton_raphson_iterate(detail::kolmogorov_smirnov_quantile_functor<RealType, Policy>(dist, p),
k, RealType(0), boost::math::tools::max_value<RealType>(), get_digits, m);
k, RealType(0), RealType(1), get_digits, m);
} // quantile

template <class RealType, class Policy>
Expand All @@ -407,7 +407,7 @@ inline RealType quantile(const complemented2_type<kolmogorov_smirnov_distributio

return tools::newton_raphson_iterate(
detail::kolmogorov_smirnov_complementary_quantile_functor<RealType, Policy>(dist, p),
k, RealType(0), boost::math::tools::max_value<RealType>(), get_digits, m);
k, RealType(0), RealType(1), get_digits, m);
} // quantile (complemented)

template <class RealType, class Policy>
Expand Down
4 changes: 2 additions & 2 deletions include/boost/math/distributions/skew_normal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ namespace boost{ namespace math{

// refine the result by numerically searching the root of (p-cdf)

const RealType search_min = range(dist).first;
const RealType search_max = range(dist).second;
const RealType search_min = support(dist).first;
const RealType search_max = support(dist).second;

const int get_digits = policies::digits<RealType, Policy>();// get digits from policy,
std::uintmax_t m = policies::get_max_root_iterations<Policy>(); // and max iterations.
Expand Down
9 changes: 1 addition & 8 deletions include/boost/math/tools/roots.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,7 @@ T newton_raphson_iterate(F f, T guess, T min, T max, int digits, std::uintmax_t&
if (fabs(delta * 2) > fabs(delta2))
{
// Last two steps haven't converged.
T shift = (delta > 0) ? (result - min) / 2 : (result - max) / 2;
if ((result != 0) && (fabs(shift) > fabs(result)))
{
delta = sign(delta) * fabs(result) * 1.1f; // Protect against huge jumps!
//delta = sign(delta) * result; // Protect against huge jumps! Failed for negative result. https://github.com/boostorg/math/issues/216
}
else
delta = shift;
delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2;
// reset delta1/2 so we don't take this branch next time round:
delta1 = 3 * delta;
delta2 = 3 * delta;
Expand Down
4 changes: 4 additions & 0 deletions test/test_roots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ BOOST_AUTO_TEST_CASE( test_main )

test_beta(0.1, "double");

// bug reports:
boost::math::skew_normal_distribution<> dist(2.0, 1.0, -2.5);
BOOST_CHECK(boost::math::isfinite(quantile(dist, 0.075)));

#if !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !defined(BOOST_NO_CXX11_LAMBDAS)
test_complex_newton<std::complex<float>>();
test_complex_newton<std::complex<double>>();
Expand Down

0 comments on commit c62682b

Please sign in to comment.