Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/math/distributions/fisher_f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ BOOST_MATH_NAMESPACE_BEGIN
//
RealType guess = 1;
std::pair<RealType, RealType> ir = tools::bracket_and_solve_root(
f, guess, RealType(2), f(guess) < 0 ? true : false, tol, max_iter, pol);
f, guess, RealType(2), large_difference > 0, tol, max_iter, pol);
RealType result = ir.first + (ir.second - ir.first) / 2;
if(max_iter >= policies::get_max_root_iterations<Policy>())
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/distributions/non_central_f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ BOOST_MATH_NAMESPACE_BEGIN
//
RealType guess = 1;
std::pair<RealType, RealType> ir = tools::bracket_and_solve_root(
f, guess, RealType(2), f(guess) < 0 ? true : false, tol, max_iter, pol);
f, guess, RealType(2), large_difference > 0, tol, max_iter, pol);
RealType result = ir.first + (ir.second - ir.first) / 2;
if(max_iter >= policies::get_max_root_iterations<Policy>())
{
Expand Down
21 changes: 21 additions & 0 deletions test/test_fisher_f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,27 @@ void test_spots(RealType)
BOOST_CHECK_CLOSE(fisher_f_distribution<RealType>::find_v1(boost::math::complement(x, df2, 1-P)), df1, tol2*200);
BOOST_CHECK_CLOSE(fisher_f_distribution<RealType>::find_v2(boost::math::complement(x, df1, 1-P)), df2, tol2*10);
}
// Both roots are below the initial guess of 1.
{
RealType df1 = RealType(0.1);
RealType df2 = 2;
RealType x = 15;
fisher_f_distribution<RealType> ref(df1, df2);
RealType P = cdf(ref, x);
RealType Q = cdf(complement(ref, x));
BOOST_CHECK_CLOSE(ref.find_v1(x, df2, P), df1, tol2*10);
BOOST_CHECK_CLOSE(ref.find_v1(boost::math::complement(x, df2, Q)), df1, tol2*10);
}
{
RealType df1 = 2;
RealType df2 = RealType(0.5);
RealType x = 15;
fisher_f_distribution<RealType> ref(df1, df2);
RealType P = cdf(ref, x);
RealType Q = cdf(complement(ref, x));
BOOST_CHECK_CLOSE(ref.find_v2(x, df1, P), df2, tol2*10);
BOOST_CHECK_CLOSE(ref.find_v2(boost::math::complement(x, df1, Q)), df2, tol2*10);
}
// Test case where two df solve inversion problem
RealType df1 = 5;
RealType df2 = 3.5;
Expand Down
24 changes: 24 additions & 0 deletions test/test_nc_f.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,30 @@ void test_spots(RealType, const char* name = nullptr)
BOOST_CHECK_CLOSE(ref.find_v1(boost::math::complement(x, v2, nc, 1-P)), v1, tolerance);
}

// gh-1669 reported failures for the degrees of freedom finders for small values of v1 and v2.
{
RealType v1 = RealType(0.1);
RealType v2 = 2;
nc = RealType(0.25);
x = 15;
boost::math::non_central_f_distribution<RealType> ref(v1, v2, nc);
RealType P = cdf(ref, x);
RealType Q = cdf(complement(ref, x));
BOOST_CHECK_CLOSE(ref.find_v1(x, v2, nc, P), v1, tolerance);
BOOST_CHECK_CLOSE(ref.find_v1(boost::math::complement(x, v2, nc, Q)), v1, tolerance);
}
{
RealType v1 = 2;
RealType v2 = 1;
nc = RealType(0.25);
x = 15;
boost::math::non_central_f_distribution<RealType> ref(v1, v2, nc);
RealType P = cdf(ref, x);
RealType Q = cdf(complement(ref, x));
BOOST_CHECK_CLOSE(ref.find_v2(x, v1, nc, P), v2, tolerance);
BOOST_CHECK_CLOSE(ref.find_v2(boost::math::complement(x, v1, nc, Q)), v2, tolerance);
}

// https://github.com/boostorg/math/issues/1491: the cdf is monotonic in v2 here, but at huge v2
// it used to come out negative, so find_v2 reported two roots.
{
Expand Down
Loading