From b330dd7e0cfa2f661373346cc599c3d25200df12 Mon Sep 17 00:00:00 2001 From: Jacob Hass Date: Fri, 2 Jan 2026 11:09:54 -0800 Subject: [PATCH] Updated code to match non_central_chi_squared syntax --- .../boost/math/distributions/non_central_f.hpp | 16 +++++++++------- test/test_nc_f.cpp | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/boost/math/distributions/non_central_f.hpp b/include/boost/math/distributions/non_central_f.hpp index 63736a2b5..8bad55c45 100644 --- a/include/boost/math/distributions/non_central_f.hpp +++ b/include/boost/math/distributions/non_central_f.hpp @@ -44,23 +44,23 @@ namespace boost }; template - inline RealType find_non_centrality_f(const RealType dfn, const RealType dfd, const RealType p, const RealType x, const Policy& pol) + inline RealType find_non_centrality_f(RealType x, const RealType dfn, const RealType dfd, const RealType p, const RealType q, const Policy& pol) { constexpr auto function = "non_central_f<%1%>::find_non_centrality"; - if ( p <= 0 || p >= 1) { + if ( p == 0 || q == 0) { return policies::raise_domain_error(function, "Can't find non centrality parameter when the probability is <=0 or >=1, only possible answer is %1%", // LCOV_EXCL_LINE RealType(boost::math::numeric_limits::quiet_NaN()), Policy()); // LCOV_EXCL_LINE } - + + non_centrality_finder_f f(x, dfn, dfd, p < q ? p : q, p < q ? false : true); RealType guess = RealType(10); // Starting guess. RealType factor = 1; // How big steps to take when searching. boost::math::uintmax_t max_iter = policies::get_max_root_iterations(); tools::eps_tolerance tol(policies::digits()); std::pair result_bracket = tools::bracket_and_solve_root( - detail::non_centrality_finder_f(x, dfn, dfd, p, false), guess, factor, - false, tol, max_iter, pol); + f, guess, factor, false, tol, max_iter, pol); RealType result = result_bracket.first + (result_bracket.second - result_bracket.first)/2; if (max_iter >= policies::get_max_root_iterations()) { @@ -107,7 +107,7 @@ namespace boost { // Private data getter function. return ncp; } - static RealType find_non_centrality(const RealType dfn, const RealType dfd, const RealType p, const RealType x) + static RealType find_non_centrality(const RealType x, const RealType dfn, const RealType dfd, const RealType p) { constexpr auto function = "non_central_f_distribution<%1%>::find_non_centrality"; typedef typename policies::evaluation::type eval_type; @@ -118,10 +118,11 @@ namespace boost policies::discrete_quantile<>, policies::assert_undefined<> >::type forwarding_policy; eval_type result = detail::find_non_centrality_f( + static_cast(x), static_cast(dfn), static_cast(dfd), static_cast(p), - static_cast(x), + static_cast(1-p), forwarding_policy()); return policies::checked_narrowing_cast( result, @@ -143,6 +144,7 @@ namespace boost static_cast(c.param1), static_cast(c.param2), static_cast(c.param3), + static_cast(1-c.param3), forwarding_policy()); return policies::checked_narrowing_cast( result, diff --git a/test/test_nc_f.cpp b/test/test_nc_f.cpp index 064e9eb88..6000a051c 100644 --- a/test/test_nc_f.cpp +++ b/test/test_nc_f.cpp @@ -142,9 +142,9 @@ void test_spot( BOOST_CHECK_CLOSE( quantile(complement(dist, Q)), x, tol * 10); BOOST_CHECK_CLOSE( - dist.find_non_centrality(a, b, P, x), ncp, tol * 10); + dist.find_non_centrality(x, a, b, P), ncp, tol * 10); BOOST_CHECK_CLOSE( - dist.find_non_centrality(boost::math::complement(a, b, P, x)), ncp, tol * 10); + dist.find_non_centrality(boost::math::complement(x, a, b, P)), ncp, tol * 10); } if(boost::math::tools::digits() > 50) {