Skip to content

Commit c62682b

Browse files
authored
Update kolmogorov quantile newton ub to 1 (#1002)
1 parent fb0af63 commit c62682b

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

include/boost/math/distributions/kolmogorov_smirnov.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ inline RealType quantile(const kolmogorov_smirnov_distribution<RealType, Policy>
382382
std::uintmax_t m = policies::get_max_root_iterations<Policy>(); // and max iterations.
383383

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

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

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

413413
template <class RealType, class Policy>

include/boost/math/distributions/skew_normal.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ namespace boost{ namespace math{
676676

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

679-
const RealType search_min = range(dist).first;
680-
const RealType search_max = range(dist).second;
679+
const RealType search_min = support(dist).first;
680+
const RealType search_max = support(dist).second;
681681

682682
const int get_digits = policies::digits<RealType, Policy>();// get digits from policy,
683683
std::uintmax_t m = policies::get_max_root_iterations<Policy>(); // and max iterations.

include/boost/math/tools/roots.hpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,7 @@ T newton_raphson_iterate(F f, T guess, T min, T max, int digits, std::uintmax_t&
275275
if (fabs(delta * 2) > fabs(delta2))
276276
{
277277
// Last two steps haven't converged.
278-
T shift = (delta > 0) ? (result - min) / 2 : (result - max) / 2;
279-
if ((result != 0) && (fabs(shift) > fabs(result)))
280-
{
281-
delta = sign(delta) * fabs(result) * 1.1f; // Protect against huge jumps!
282-
//delta = sign(delta) * result; // Protect against huge jumps! Failed for negative result. https://github.com/boostorg/math/issues/216
283-
}
284-
else
285-
delta = shift;
278+
delta = (delta > 0) ? (result - min) / 2 : (result - max) / 2;
286279
// reset delta1/2 so we don't take this branch next time round:
287280
delta1 = 3 * delta;
288281
delta2 = 3 * delta;

test/test_roots.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ BOOST_AUTO_TEST_CASE( test_main )
654654

655655
test_beta(0.1, "double");
656656

657+
// bug reports:
658+
boost::math::skew_normal_distribution<> dist(2.0, 1.0, -2.5);
659+
BOOST_CHECK(boost::math::isfinite(quantile(dist, 0.075)));
660+
657661
#if !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !defined(BOOST_NO_CXX11_LAMBDAS)
658662
test_complex_newton<std::complex<float>>();
659663
test_complex_newton<std::complex<double>>();

0 commit comments

Comments
 (0)