mirror of
https://github.com/boostorg/math.git
synced 2026-02-24 04:02:18 +00:00
Updated code to match non_central_chi_squared syntax
This commit is contained in:
@@ -44,23 +44,23 @@ namespace boost
|
||||
};
|
||||
|
||||
template <class RealType, class Policy>
|
||||
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<RealType>(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<RealType>::quiet_NaN()), Policy()); // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
|
||||
non_centrality_finder_f<RealType, Policy> 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<Policy>();
|
||||
tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>());
|
||||
|
||||
std::pair<RealType, RealType> result_bracket = tools::bracket_and_solve_root(
|
||||
detail::non_centrality_finder_f<RealType, Policy>(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<Policy>()) {
|
||||
@@ -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<RealType, Policy>::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<eval_type>(x),
|
||||
static_cast<eval_type>(dfn),
|
||||
static_cast<eval_type>(dfd),
|
||||
static_cast<eval_type>(p),
|
||||
static_cast<eval_type>(x),
|
||||
static_cast<eval_type>(1-p),
|
||||
forwarding_policy());
|
||||
return policies::checked_narrowing_cast<RealType, forwarding_policy>(
|
||||
result,
|
||||
@@ -143,6 +144,7 @@ namespace boost
|
||||
static_cast<eval_type>(c.param1),
|
||||
static_cast<eval_type>(c.param2),
|
||||
static_cast<eval_type>(c.param3),
|
||||
static_cast<eval_type>(1-c.param3),
|
||||
forwarding_policy());
|
||||
return policies::checked_narrowing_cast<RealType, forwarding_policy>(
|
||||
result,
|
||||
|
||||
@@ -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<RealType>() > 50)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user