Skip to content
Open
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
9 changes: 5 additions & 4 deletions include/boost/math/distributions/arcsine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ namespace boost
// Special cases:
if (p == 0)
{
return 0;
return x_min;
}
if (p == 1)
{
return 1;
return x_max;
}
using boost::math::constants::half_pi;
RealType sin2hpip = sin(half_pi<RealType>() * p);
Expand All @@ -247,11 +247,11 @@ namespace boost
// Special cases:
if (q == 1)
{
return 0;
return x_min;
}
if (q == 0)
{
return 1;
return x_max;
}
// Naive RealType p = 1 - q; result = sin(half_pi<RealType>() * p); loses accuracy, so use a cos alternative instead.
//result = cos(half_pi<RealType>() * q); // for arcsine(0,1)
Expand Down Expand Up @@ -281,6 +281,7 @@ namespace boost
m_x_max,
&result, Policy());
} // arcsine_distribution constructor.
BOOST_MATH_GPU_ENABLED arcsine_distribution(std::vector<RealType> params) : arcsine_distribution(params[0], params[1]) {}
// Accessor functions:
BOOST_MATH_GPU_ENABLED RealType x_min() const
{
Expand Down
95 changes: 13 additions & 82 deletions test/test_arcsine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ using boost::math::constants::one_div_root_two;
#include <cmath>

#include "test_out_of_range.hpp"
#include "test_dist_helpers.hpp"

#include <iostream>
using std::cout;
Expand Down Expand Up @@ -65,21 +66,6 @@ void test_ignore_policy(RealType)
RealType nan = std::numeric_limits<RealType>::quiet_NaN();

using boost::math::policies::policy;
// Types of error whose action can be altered by policies:.
//using boost::math::policies::evaluation_error;
//using boost::math::policies::domain_error;
//using boost::math::policies::overflow_error;
//using boost::math::policies::underflow_error;
//using boost::math::policies::domain_error;
//using boost::math::policies::pole_error;

//// Actions on error (in enum error_policy_type):
//using boost::math::policies::errno_on_error;
//using boost::math::policies::ignore_error;
//using boost::math::policies::throw_on_error;
//using boost::math::policies::denorm_error;
//using boost::math::policies::pole_error;
//using boost::math::policies::user_error;

typedef policy<
boost::math::policies::domain_error<boost::math::policies::ignore_error>,
Expand All @@ -105,39 +91,6 @@ void test_ignore_policy(RealType)
//std::cout << "pdf(ignore_error_arcsine(-1, +1), std::numeric_limits<RealType>::infinity()) = " << pdf(ignore_error_arcsine(-1, +1), std::numeric_limits<RealType>::infinity()) << std::endl;
// Outputs: pdf(ignore_error_arcsine(-1, +1), std::numeric_limits<RealType>::infinity()) = 1.#QNAN
}
// PDF
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_arcsine(0, 1), std::numeric_limits<RealType>::infinity()))); // x == infinity
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_arcsine(-1, 1), std::numeric_limits<RealType>::infinity()))); // x == infinity
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_arcsine(0, 1), static_cast <RealType>(-2)))); // x < xmin
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_arcsine(-1, 1), static_cast <RealType>(-2)))); // x < xmin
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_arcsine(0, 1), static_cast <RealType>(+2)))); // x > x_max
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_arcsine(-1, 1), static_cast <RealType>(+2)))); // x > x_max

// Logpdf
BOOST_CHECK((boost::math::isnan)(logpdf(ignore_error_arcsine(0, 1), std::numeric_limits<RealType>::infinity()))); // x == infinity
BOOST_CHECK((boost::math::isnan)(logpdf(ignore_error_arcsine(-1, 1), std::numeric_limits<RealType>::infinity()))); // x == infinity
BOOST_CHECK((boost::math::isnan)(logpdf(ignore_error_arcsine(0, 1), static_cast <RealType>(-2)))); // x < xmin
BOOST_CHECK((boost::math::isnan)(logpdf(ignore_error_arcsine(-1, 1), static_cast <RealType>(-2)))); // x < xmin
BOOST_CHECK((boost::math::isnan)(logpdf(ignore_error_arcsine(0, 1), static_cast <RealType>(+2)))); // x > x_max
BOOST_CHECK((boost::math::isnan)(logpdf(ignore_error_arcsine(-1, 1), static_cast <RealType>(+2)))); // x > x_max

// CDF
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_arcsine(0, 1), std::numeric_limits<RealType>::infinity()))); // x == infinity
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_arcsine(-1, 1), std::numeric_limits<RealType>::infinity()))); // x == infinity
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_arcsine(0, 1), static_cast <RealType>(-2)))); // x < xmin
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_arcsine(-1, 1), static_cast <RealType>(-2)))); // x < xmin
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_arcsine(0, 1), static_cast <RealType>(+2)))); // x > x_max
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_arcsine(-1, 1), static_cast <RealType>(+2)))); // x > x_max
BOOST_CHECK((boost::math::isnan)(cdf(complement(ignore_error_arcsine(0, 1), std::numeric_limits<RealType>::infinity())))); // x == infinity
BOOST_CHECK((boost::math::isnan)(cdf(complement(ignore_error_arcsine(0, 1), static_cast <RealType>(-2))))); // x < xmin

// Quantile
BOOST_CHECK((boost::math::isnan)(quantile(ignore_error_arcsine(0, 1), std::numeric_limits<RealType>::infinity()))); // p == infinity
BOOST_CHECK((boost::math::isnan)(quantile(ignore_error_arcsine(0, 1), static_cast<RealType>(-1)))); // p < 0
BOOST_CHECK((boost::math::isnan)(quantile(ignore_error_arcsine(0, 1), static_cast<RealType>(2)))); // p > 1
BOOST_CHECK((boost::math::isnan)(quantile(complement(ignore_error_arcsine(0, 1), std::numeric_limits<RealType>::infinity())))); // q == infinity
BOOST_CHECK((boost::math::isnan)(quantile(complement(ignore_error_arcsine(0, 1), static_cast<RealType>(-1))))); // q < 0
BOOST_CHECK((boost::math::isnan)(quantile(complement(ignore_error_arcsine(0, 1), static_cast<RealType>(2))))); // q > 1

// Mean
BOOST_CHECK((boost::math::isnan)(mean(ignore_error_arcsine(-nan, 0))));
Expand Down Expand Up @@ -201,6 +154,7 @@ void test_ignore_policy(RealType)
BOOST_CHECK(boost::math::isfinite(mean(ignore_error_arcsine(0, std::numeric_limits<RealType>::epsilon()))));

check_support<arcsine_distribution<RealType> >(arcsine_distribution<RealType>(0, 1));
test_invalid_support<arcsine_distribution, RealType>();
} // ordinary floats.
} // template <class RealType> void test_ignore_policy(RealType)

Expand Down Expand Up @@ -363,7 +317,6 @@ void test_spots(RealType)
BOOST_CHECK_CLOSE_FRACTION(cdf(complement(arcsine_01, 0.95)), static_cast<RealType>(0.14356629312870627075094188477505571882161519989741L), 8 * tolerance); // 2 for asin
BOOST_CHECK_CLOSE_FRACTION(cdf(complement(arcsine_01, 0.999999)), static_cast<RealType>(1 - 0.99936338012152907551581622632042615133907872213939L), 1000000 * tolerance); // 10000 for asin, 1000000 for acos.

// Quantile.

// Check 1st, 2nd and 3rd quartiles.
BOOST_CHECK_CLOSE_FRACTION(quantile(arcsine_01, static_cast<RealType>(0.25L)), static_cast<RealType>(0.14644660940672624L), tolerance);
Expand Down Expand Up @@ -471,10 +424,6 @@ void test_spots(RealType)
BOOST_CHECK_CLOSE_FRACTION(quantile(as_m2m1, static_cast<RealType>(0.85643370687129372924905811522494428117838480010259L)), -static_cast<RealType>(1.05L), 2 * tolerance); //
BOOST_CHECK_CLOSE_FRACTION(quantile(as_m2m1, static_cast<RealType>(0.5L)), -static_cast<RealType>(1.5L), 2 * tolerance); //
BOOST_CHECK_CLOSE_FRACTION(quantile(as_m2m1, static_cast<RealType>(0.14356629312870627075094188477505571882161519989741L)), -static_cast<RealType>(1.95L), 4 * tolerance); //
BOOST_CHECK_EQUAL(quantile(as_m2m1, 1), 1);
BOOST_CHECK_EQUAL(quantile(as_m2m1, 0), 0);
BOOST_CHECK_EQUAL(quantile(complement(as_m2m1, 1)), 0);
BOOST_CHECK_EQUAL(quantile(complement(as_m2m1, 0)), 1);

BOOST_CHECK_CLOSE_FRACTION(quantile(complement(as_m2m1, static_cast<RealType>(0.14356629312870627075094188477505571882161519989741L))), -static_cast<RealType>(1.05L), 2 * tolerance); //
BOOST_CHECK_CLOSE_FRACTION(quantile(as_m2m1, static_cast<RealType>(0.5L)), -static_cast<RealType>(1.5L), 2 * tolerance); //
Expand Down Expand Up @@ -505,11 +454,6 @@ void test_spots(RealType)
arcsine_distribution<RealType>(static_cast<RealType>(1), static_cast<RealType>(1)), // equal constructor parameters.
static_cast<RealType>(-1)), std::domain_error);

BOOST_CHECK_THROW(
pdf(
arcsine_distribution<RealType>(static_cast<RealType>(0), static_cast<RealType>(1)), // bad x > 1.
static_cast<RealType>(999)), std::domain_error);

BOOST_CHECK_THROW( // For various bad arguments.
logpdf(
arcsine_distribution<RealType>(static_cast<RealType>(+1), static_cast<RealType>(-1)), // min_x > max_x
Expand All @@ -534,30 +478,10 @@ void test_spots(RealType)
logpdf(
arcsine_distribution<RealType>(static_cast<RealType>(0), static_cast<RealType>(1)), // bad x > 1.
static_cast<RealType>(999)), std::domain_error);

// Checks on things that are errors.

// Construction with 'bad' parameters.
BOOST_CHECK_THROW(arcsine_distribution<RealType>(+1, -1), std::domain_error); // max < min.
BOOST_CHECK_THROW(arcsine_distribution<RealType>(+1, 0), std::domain_error); // max < min.

arcsine_distribution<> dist;
BOOST_CHECK_THROW(pdf(dist, -1), std::domain_error);
BOOST_CHECK_THROW(logpdf(dist, -1), std::domain_error);
BOOST_CHECK_THROW(cdf(dist, -1), std::domain_error);
BOOST_CHECK_THROW(cdf(complement(dist, -1)), std::domain_error);
BOOST_CHECK_THROW(quantile(dist, -1), std::domain_error);
BOOST_CHECK_THROW(quantile(complement(dist, -1)), std::domain_error);
BOOST_CHECK_THROW(quantile(dist, -1), std::domain_error);
BOOST_CHECK_THROW(quantile(complement(dist, -1)), std::domain_error);

// Various combinations of bad constructor and member function parameters.
BOOST_CHECK_THROW(pdf(boost::math::arcsine_distribution<RealType>(0, 1), -1), std::domain_error);
BOOST_CHECK_THROW(pdf(boost::math::arcsine_distribution<RealType>(-1, 1), +2), std::domain_error);
BOOST_CHECK_THROW(logpdf(boost::math::arcsine_distribution<RealType>(0, 1), -1), std::domain_error);
BOOST_CHECK_THROW(logpdf(boost::math::arcsine_distribution<RealType>(-1, 1), +2), std::domain_error);
BOOST_CHECK_THROW(quantile(boost::math::arcsine_distribution<RealType>(1, 1), -1), std::domain_error);
BOOST_CHECK_THROW(quantile(boost::math::arcsine_distribution<RealType>(1, 1), 2), std::domain_error);

// std::vector<std::vector<RealType> > invalid_params = {{1, 0}, // x_min > x_max
// {1, -1}};
// test_invalid_parameters<arcsine_distribution, RealType>(invalid_params);

// No longer allow any parameter to be NaN or inf, so all these tests should throw.
if (std::numeric_limits<RealType>::has_quiet_NaN)
Expand Down Expand Up @@ -612,6 +536,13 @@ void test_spots(RealType)
BOOST_CHECK_THROW(quantile(complement(w, +inf)), std::domain_error); // p = + inf
} // has_infinity

// Quantile should return x_min and x_max
arcsine_distribution<RealType> dist(0, 1);
BOOST_CHECK_EQUAL(quantile(dist, static_cast<RealType>(1)), static_cast<RealType>(1)); // p = 1
BOOST_CHECK_EQUAL(quantile(dist, static_cast<RealType>(0)), static_cast<RealType>(0)); // p = 0
BOOST_CHECK_EQUAL(quantile(complement(dist, static_cast<RealType>(1))), static_cast<RealType>(0)); // q = 1
BOOST_CHECK_EQUAL(quantile(complement(dist, static_cast<RealType>(0))), static_cast<RealType>(1)); // q = 0

// Error handling checks:
check_out_of_range<boost::math::arcsine_distribution<RealType> >(-1, +1); // (All) valid constructor parameter values.
// and range and non-finite.
Expand Down
49 changes: 8 additions & 41 deletions test/test_bernoulli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using boost::math::bernoulli_distribution;
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp> // for test_main
#include <boost/test/tools/floating_point_comparison.hpp> // for BOOST_CHECK_CLOSE_FRACTION, BOOST_CHECK_EQUAL...
#include "test_dist_helpers.hpp"

#include <iostream>
using std::cout;
Expand Down Expand Up @@ -278,52 +279,18 @@ void test_spots(RealType)
#else
BOOST_MATH_CHECK_THROW(bernoulli_distribution<RealType>(inf), std::domain_error);
#endif
BOOST_MATH_CHECK_THROW(pdf(w, +inf), std::domain_error); // x = inf
BOOST_MATH_CHECK_THROW(cdf(w, +inf), std::domain_error); // x = inf
BOOST_MATH_CHECK_THROW(cdf(complement(w, +inf)), std::domain_error); // x = + inf
BOOST_MATH_CHECK_THROW(quantile(w, +inf), std::domain_error); // p = + inf
BOOST_MATH_CHECK_THROW(quantile(complement(w, +inf)), std::domain_error); // p = + inf
} // has_infinity
#endif

using boost::math::policies::policy;
typedef policy<
boost::math::policies::domain_error<boost::math::policies::ignore_error>,
boost::math::policies::overflow_error<boost::math::policies::ignore_error>,
boost::math::policies::underflow_error<boost::math::policies::ignore_error>,
boost::math::policies::denorm_error<boost::math::policies::ignore_error>,
boost::math::policies::pole_error<boost::math::policies::ignore_error>,
boost::math::policies::evaluation_error<boost::math::policies::ignore_error>
> ignore_all_policy;

typedef bernoulli_distribution<RealType, ignore_all_policy> ignore_error_bernoulli;

bernoulli_distribution<RealType> fair_dist(0.5);
BOOST_CHECK_EQUAL(quantile(fair_dist, static_cast<RealType>(1)), static_cast<RealType>(1)); // p = 1
BOOST_CHECK_EQUAL(quantile(fair_dist, static_cast<RealType>(0)), static_cast<RealType>(0)); // p = 0
BOOST_CHECK_EQUAL(quantile(complement(fair_dist, static_cast<RealType>(1))), static_cast<RealType>(0)); // q = 1
BOOST_CHECK_EQUAL(quantile(complement(fair_dist, static_cast<RealType>(0))), static_cast<RealType>(1)); // q = 0

if (std::numeric_limits<RealType>::has_quiet_NaN)
{
// PDF
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_bernoulli(0.5), std::numeric_limits<RealType>::infinity()))); // k == infinity
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_bernoulli(0.5), 2))); // k > 1
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_bernoulli(0.5), static_cast<RealType>(0.5)))); // k != 0, 1
BOOST_CHECK((boost::math::isnan)(pdf(ignore_error_bernoulli(0.5), static_cast<RealType>(-0.5)))); // k != 0, 1

// CDF
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_bernoulli(0.5), std::numeric_limits<RealType>::infinity()))); // k == infinity
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_bernoulli(0.5), 2))); // k > 1
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_bernoulli(0.5), static_cast<RealType>(0.5)))); // k != 0, 1
BOOST_CHECK((boost::math::isnan)(cdf(ignore_error_bernoulli(0.5), static_cast<RealType>(-0.5)))); // k != 0, 1
BOOST_CHECK((boost::math::isnan)(cdf(complement(ignore_error_bernoulli(0.5), std::numeric_limits<RealType>::infinity())))); // k == infinity
BOOST_CHECK((boost::math::isnan)(cdf(complement(ignore_error_bernoulli(0.5), 2)))); // k > 1
BOOST_CHECK((boost::math::isnan)(cdf(complement(ignore_error_bernoulli(0.5), static_cast<RealType>(0.5))))); // k != 0, 1
BOOST_CHECK((boost::math::isnan)(cdf(complement(ignore_error_bernoulli(0.5), static_cast<RealType>(-0.5))))); // k != 0, 1

// // Quantile
BOOST_CHECK((boost::math::isnan)(quantile(ignore_error_bernoulli(0.5), std::numeric_limits<RealType>::infinity()))); // p == infinity
BOOST_CHECK((boost::math::isnan)(quantile(ignore_error_bernoulli(0.5), static_cast<RealType>(-1)))); // p < 0
BOOST_CHECK((boost::math::isnan)(quantile(ignore_error_bernoulli(0.5), static_cast<RealType>(2)))); // p > 1
BOOST_CHECK((boost::math::isnan)(quantile(complement(ignore_error_bernoulli(0.5), std::numeric_limits<RealType>::infinity())))); // q == infinity
BOOST_CHECK((boost::math::isnan)(quantile(complement(ignore_error_bernoulli(0.5), static_cast<RealType>(-1))))); // q < 0
BOOST_CHECK((boost::math::isnan)(quantile(complement(ignore_error_bernoulli(0.5), static_cast<RealType>(2))))); // q > 1

test_invalid_support<bernoulli_distribution, RealType>();
} // has_quiet_NaN
} // template <class RealType>void test_spots(RealType)

Expand Down
15 changes: 15 additions & 0 deletions test/test_cauchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,26 @@
// To compile even if Cauchy mean is used.
#include <boost/math/concepts/real_concept.hpp> // for real_concept
#include <boost/math/distributions/cauchy.hpp>
#include <boost/math/distributions/arcsine.hpp>
using boost::math::cauchy_distribution;

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp> // Boost.Test
#include <boost/test/tools/floating_point_comparison.hpp>

#include "test_out_of_range.hpp"
#include "test_dist_helpers.hpp"

#if defined(BOOST_CHECK_THROW) && defined(BOOST_MATH_NO_EXCEPTIONS)
# undef BOOST_CHECK_THROW
# define BOOST_CHECK_THROW(x, y)
#endif

#include <iostream>
using std::cout;
using std::endl;
#include <limits>
using std::numeric_limits;

template <class RealType>
void test_spots(RealType T)
Expand Down Expand Up @@ -798,6 +807,12 @@ void test_spots(RealType T)
BOOST_CHECK((boost::math::isnan)(boost::math::quantile(ignore_error_cauchy(static_cast<RealType>(0), static_cast<RealType>(-1)), static_cast<RealType>(0.25))));
BOOST_CHECK((boost::math::isnan)(boost::math::quantile(ignore_error_cauchy(std::numeric_limits<RealType>::infinity(), static_cast<RealType>(1)), static_cast<RealType>(0.25))));
BOOST_CHECK((boost::math::isnan)(boost::math::quantile(ignore_error_cauchy(static_cast<RealType>(0), static_cast<RealType>(1)), static_cast<RealType>(-0.25))));

if (std::numeric_limits<RealType>::has_quiet_NaN)
{
test_invalid_support<boost::math::cauchy_distribution, RealType>();
}

}

} // template <class RealType>void test_spots(RealType)
Expand Down
Loading
Loading