mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
[distributions] Hyper-Exponential: added test for special cases (i.e., the one discussed under the 'Related distributions' section of the doc).
This commit is contained in:
@@ -338,3 +338,34 @@ BOOST_AUTO_TEST_CASE(construct)
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(special_cases, RealT, test_types)
|
||||
{
|
||||
const RealT tol = make_tolerance<RealT>();
|
||||
|
||||
// When the number of phases is 1, the hyperexponential distribution is an exponential distribution
|
||||
const RealT rates1[] = { static_cast<RealT>(0.5L) };
|
||||
boost::math::hyperexponential_distribution<RealT> hexp1(rates1);
|
||||
boost::math::exponential_distribution<RealT> exp1(rates1[0]);
|
||||
BOOST_CHECK_CLOSE(boost::math::pdf(hexp1, static_cast<RealT>(1L)), boost::math::pdf(exp1, static_cast<RealT>(1L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::cdf(hexp1, static_cast<RealT>(1L)), boost::math::cdf(exp1, static_cast<RealT>(1L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::mean(hexp1), boost::math::mean(exp1), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::variance(hexp1), boost::math::variance(exp1), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::quantile(hexp1, static_cast<RealT>(0.25L)), boost::math::quantile(exp1, static_cast<RealT>(0.25L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::median(hexp1), boost::math::median(exp1), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::quantile(hexp1, static_cast<RealT>(0.75L)), boost::math::quantile(exp1, static_cast<RealT>(0.75L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::mode(hexp1), boost::math::mode(exp1), tol);
|
||||
|
||||
// When a k-phase hyperexponential distribution has all rates equal to r, the distribution is an exponential distribution with rate r
|
||||
const RealT rate2 = static_cast<RealT>(0.5L);
|
||||
const RealT rates2[] = { rate2, rate2, rate2 };
|
||||
boost::math::hyperexponential_distribution<RealT> hexp2(rates2);
|
||||
boost::math::exponential_distribution<RealT> exp2(rate2);
|
||||
BOOST_CHECK_CLOSE(boost::math::pdf(hexp2, static_cast<RealT>(1L)), boost::math::pdf(exp2, static_cast<RealT>(1L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::cdf(hexp2, static_cast<RealT>(1L)), boost::math::cdf(exp2, static_cast<RealT>(1L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::mean(hexp2), boost::math::mean(exp2), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::variance(hexp2), boost::math::variance(exp2), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::quantile(hexp2, static_cast<RealT>(0.25L)), boost::math::quantile(exp2, static_cast<RealT>(0.25L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::median(hexp2), boost::math::median(exp2), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::quantile(hexp2, static_cast<RealT>(0.75L)), boost::math::quantile(exp2, static_cast<RealT>(0.75L)), tol);
|
||||
BOOST_CHECK_CLOSE(boost::math::mode(hexp2), boost::math::mode(exp2), tol);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user