diff --git a/test/test_cauchy.cpp b/test/test_cauchy.cpp index 38bf168ca..43498cc5b 100644 --- a/test/test_cauchy.cpp +++ b/test/test_cauchy.cpp @@ -640,16 +640,19 @@ void test_spots(RealType T) static_cast(-3), // probability. tolerance); // % - // - // Things that are errors: - // - cauchy_distribution dist; - BOOST_CHECK_THROW( - mean(dist), - std::domain_error); + cauchy_distribution dist; // default (0, 1) BOOST_CHECK_EQUAL( mode(dist), static_cast(0)); + BOOST_CHECK_EQUAL( + median(dist), + static_cast(0)); + // + // Things that are errors: + // + BOOST_CHECK_THROW( + mean(dist), + std::domain_error); BOOST_CHECK_THROW( variance(dist), std::domain_error); diff --git a/test/test_chi_squared.cpp b/test/test_chi_squared.cpp index 651d8e696..5d96ea927 100644 --- a/test/test_chi_squared.cpp +++ b/test/test_chi_squared.cpp @@ -404,6 +404,12 @@ void test_spots(RealType) BOOST_CHECK_CLOSE( mode(dist) , static_cast(6), tol2); + + BOOST_CHECK_CLOSE( + median(dist), + quantile( + chi_squared_distribution(static_cast(8)), + static_cast(0.5)), static_cast(1)); // 1% - approximate. // skewness: BOOST_CHECK_CLOSE( skewness(dist) diff --git a/test/test_exponential_dist.cpp b/test/test_exponential_dist.cpp index d232aa9e9..1062d54be 100644 --- a/test/test_exponential_dist.cpp +++ b/test/test_exponential_dist.cpp @@ -208,6 +208,13 @@ void test_spots(RealType T) exponential_distribution(2)), static_cast(0), tolerance); // % + + BOOST_CHECK_CLOSE( + ::boost::math::median( + exponential_distribution(4)), + static_cast(0.693147180559945309417232121458176568075500134360255254) / 4, + tolerance); // % + BOOST_CHECK_CLOSE( ::boost::math::skewness( exponential_distribution(2)), diff --git a/test/test_extreme_value.cpp b/test/test_extreme_value.cpp index 748684801..d91a5aac0 100644 --- a/test/test_extreme_value.cpp +++ b/test/test_extreme_value.cpp @@ -5,7 +5,7 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -// test_students_t.cpp +// test_extreme_value.cpp #define BOOST_MATH_THROW_ON_DOMAIN_ERROR #define BOOST_MATH_THROW_ON_OVERFLOW_ERROR @@ -27,7 +27,6 @@ #include // Boost.Test #include - #include using std::cout; using std::endl; @@ -146,6 +145,12 @@ void test_spots(RealType T) extreme_value_distribution(2, 3)), static_cast(2), tolerance); // % + BOOST_CHECK_CLOSE( + ::boost::math::median( + extreme_value_distribution(0, 1)), + static_cast(+0.36651292058166432701243915823266946945426344783710526305367771367056), + tolerance); // % + BOOST_CHECK_CLOSE( ::boost::math::skewness( extreme_value_distribution(2, 3)), diff --git a/test/test_fisher_f.cpp b/test/test_fisher_f.cpp index 67330fcb6..172232598 100644 --- a/test/test_fisher_f.cpp +++ b/test/test_fisher_f.cpp @@ -204,7 +204,6 @@ void test_spots(RealType) // pretty useless, but it is an excellent sanity check. RealType tolerance = 0.002f * 100; - cout << "Tolerance = " << tolerance << "%." << endl; using boost::math::fisher_f_distribution; @@ -370,8 +369,7 @@ void test_spots(RealType) // These might allow some further cross checks? - - RealType tol2 = boost::math::tools::epsilon() * 5 * 100; // 5eps as a percent + RealType tol2 = boost::math::tools::epsilon() * 5 * 100; // 5 eps as a percent cout << "Tolerance = " << tol2 << "%." << endl; fisher_f_distribution dist(static_cast(8), static_cast(6)); RealType x = 7; @@ -510,6 +508,10 @@ void test_spots(RealType) fisher_f_distribution(8, 8), static_cast(1.1))), std::domain_error ); + // median NOT implemented. + BOOST_CHECK_THROW( + median(fisher_f_distribution(8, 8)), std::domain_error); + } // template void test_spots(RealType) int test_main(int, char* []) diff --git a/test/test_gamma_dist.cpp b/test/test_gamma_dist.cpp index 8f7267f8c..7ef82529d 100644 --- a/test/test_gamma_dist.cpp +++ b/test/test_gamma_dist.cpp @@ -221,6 +221,10 @@ void test_spots(RealType T) kurtosis_excess(dist) , 6 / static_cast(8), tol2); + BOOST_CHECK_CLOSE( + median(dist), static_cast(23.007748327502412), tol2); + // Rely on default definition in derived accessors. + } // template void test_spots(RealType) int test_main(int, char* []) @@ -245,3 +249,20 @@ int test_main(int, char* []) } // int test_main(int, char* []) +/* + +Output: + +Running 1 test case... +Tolerance for type float is 0.000238419 % +Tolerance for type float is 0.001 % +Tolerance for type double is 5e-012 % +Tolerance for type double is 0.001 % +Tolerance for type long double is 5e-012 % +Tolerance for type long double is 0.001 % +Tolerance for type class boost::math::concepts::real_concept is 5e-012 % +Tolerance for type class boost::math::concepts::real_concept is 0.001 % +*** No errors detected + + +*/ \ No newline at end of file diff --git a/test/test_lognormal.cpp b/test/test_lognormal.cpp index 5392577ff..96f675f50 100644 --- a/test/test_lognormal.cpp +++ b/test/test_lognormal.cpp @@ -220,6 +220,15 @@ void test_spots(RealType T) BOOST_CHECK_CLOSE( mode(dist) , static_cast(0.36787944117144232159552377016146L), tolerance); + + BOOST_CHECK_CLOSE( + median(dist) + , static_cast(exp(dist.location())), tolerance); + + BOOST_CHECK_CLOSE( + median(dist), + quantile(dist, static_cast(0.5)), tolerance); + // skewness: BOOST_CHECK_CLOSE( skewness(dist) diff --git a/test/test_negative_binomial.cpp b/test/test_negative_binomial.cpp index a673131c4..369b5ba74 100644 --- a/test/test_negative_binomial.cpp +++ b/test/test_negative_binomial.cpp @@ -716,6 +716,12 @@ if(std::numeric_limits::is_specialized) static_cast(0)), std::domain_error ); // End of check throwing 'duff' out-of-domain values. + + BOOST_CHECK_THROW( + median( // NOT implemented. + negative_binomial_distribution(static_cast(8), static_cast(1.25))), + std::domain_error); + return; } // template void test_spots(RealType) // Any floating-point type RealType. @@ -734,14 +740,14 @@ int test_main(int, char* []) #endif #ifdef BOOST_MATH_THROW_ON_OVERFLOW_ERROR - cout << "BOOST_MATH_THROW_ON_OVERFLOW_ERROR" << " is defined to throw on domain error." << endl; + cout << "BOOST_MATH_THROW_ON_OVERFLOW_ERROR" << " is defined to throw on overflow error." << endl; #else - cout << "BOOST_MATH_THROW_ON_OVERFLOW_ERROR" << " is NOT defined, so NO throw on domain error." << endl; + cout << "BOOST_MATH_THROW_ON_OVERFLOW_ERROR" << " is NOT defined, so NO throw on overflow error." << endl; #endif #ifdef BOOST_MATH_THROW_ON_UNDERFLOW_ERROR - cout << "BOOST_MATH_THROW_ON_UNDERFLOW_ERROR" << " is defined to throw on domain error." << endl; + cout << "BOOST_MATH_THROW_ON_UNDERFLOW_ERROR" << " is defined to throw on underflow error." << endl; #else - cout << "BOOST_MATH_THROW_ON_UNDERFLOW_ERROR" << " is NOT defined, so NO throw on domain error." << endl; + cout << "BOOST_MATH_THROW_ON_UNDERFLOW_ERROR" << " is NOT defined, so NO throw on underflow error." << endl; #endif // Test some simple double only examples. negative_binomial_distribution my8dist(8., 0.25); @@ -765,15 +771,14 @@ int test_main(int, char* []) /* ------- Build started: Project: test_negative_binomial, Configuration: Debug Win32 ------ Compiling... test_negative_binomial.cpp Linking... Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_negative_binomial.exe" Running 1 test case... BOOST_MATH_THROW_ON_DOMAIN_ERROR is defined to throw on domain error. -BOOST_MATH_THROW_ON_OVERFLOW_ERROR is NOT defined, so NO throw on domain error. -BOOST_MATH_THROW_ON_UNDERFLOW_ERROR is NOT defined, so NO throw on domain error. +BOOST_MATH_THROW_ON_OVERFLOW_ERROR is NOT defined, so NO throw on overflow error. +BOOST_MATH_THROW_ON_UNDERFLOW_ERROR is NOT defined, so NO throw on underflow error. Tolerance = 0.0119209%. Tolerance 5 eps = 5.96046e-007%. Tolerance = 2.22045e-011%. @@ -783,8 +788,5 @@ Tolerance 5 eps = 1.11022e-015%. Tolerance = 2.22045e-011%. Tolerance 5 eps = 1.11022e-015%. *** No errors detected -Build Time 0:08 -Build log was saved at "file://i:\boost-06-05-03-1300\libs\math\test\Math_test\test_negative_binomial\Debug\BuildLog.htm" -test_negative_binomial - 0 error(s), 0 warning(s) */ diff --git a/test/test_normal.cpp b/test/test_normal.cpp index 8c81b058b..ce124f2bd 100644 --- a/test/test_normal.cpp +++ b/test/test_normal.cpp @@ -223,6 +223,11 @@ void test_spots(RealType T) BOOST_CHECK_CLOSE( mode(dist) , static_cast(8), tol2); + + BOOST_CHECK_CLOSE( + median(dist) + , static_cast(8), tol2); + // skewness: BOOST_CHECK_CLOSE( skewness(dist) diff --git a/test/test_poisson.cpp b/test/test_poisson.cpp index 41ce9f294..c1edd1a7e 100644 --- a/test/test_poisson.cpp +++ b/test/test_poisson.cpp @@ -143,6 +143,23 @@ void test_spots(RealType) std::domain_error); // Check some test values. + + BOOST_CHECK_CLOSE( // mode + mode(poisson_distribution(static_cast(4))), // mode = mean = 4. + static_cast(4), // mode. + tolerance); + + //BOOST_CHECK_CLOSE( // mode + // median(poisson_distribution(static_cast(4))), // mode = mean = 4. + // static_cast(4), // mode. + // tolerance); + poisson_distribution dist4(static_cast(40)); + + BOOST_CHECK_CLOSE( // median + median(dist4), // mode = mean = 4. median = 40.328333333333333 + quantile(dist4, static_cast(0.5)), // 39.332839138842637 + tolerance); + // PDF BOOST_CHECK_CLOSE( pdf(poisson_distribution(static_cast(4)), // mean 4. @@ -319,7 +336,7 @@ void test_spots(RealType) tolerance/5); // // EQUAL is too optimistic - fails [5.0000000000000124 != 5] - //BOOST_CHECK_EQUAL(boost::math::quantile( // + // BOOST_CHECK_EQUAL(boost::math::quantile( // // poisson_distribution(5.), // mean. // static_cast(0.615960654833065)), // probability. // static_cast(5.)); // Expect k = 5 events. @@ -330,6 +347,55 @@ void test_spots(RealType) static_cast(5.), // Expect k = 5 events. tolerance/5); + // Check on quantile of other examples of inverse of cdf. + BOOST_CHECK_CLOSE( + cdf(poisson_distribution(static_cast(10.)), // mean + static_cast(10)), // k events. + static_cast(0.5830397501929856), // probability. + tolerance); + + BOOST_CHECK_CLOSE(boost::math::quantile( // inverse of cdf above. + poisson_distribution(10.), // mean. + static_cast(0.5830397501929856)), // probability. + static_cast(10.), // Expect k = 10 events. + tolerance/5); + + + BOOST_CHECK_CLOSE( + cdf(poisson_distribution(static_cast(4.)), // mean + static_cast(5)), // k events. + static_cast(0.785130387030406), // probability. + tolerance); + + BOOST_CHECK_CLOSE(boost::math::quantile( // inverse of cdf above. + poisson_distribution(4.), // mean. + static_cast(0.785130387030406)), // probability. + static_cast(5.), // Expect k = 10 events. + tolerance/5); + + + + //BOOST_CHECK_CLOSE(boost::math::quantile( + // poisson_distribution(5), // mean. + // static_cast(0.785130387030406)), // probability. + // // 6.1882832344329559 result but MathCAD givest smallest integer ppois(k, mean) >= prob + // static_cast(6.), // Expect k = 6 events. + // tolerance/5); + + //BOOST_CHECK_CLOSE(boost::math::quantile( + // poisson_distribution(5), // mean. + // static_cast(0.77)), // probability. + // // 6.1882832344329559 result but MathCAD givest smallest integer ppois(k, mean) >= prob + // static_cast(7.), // Expect k = 6 events. + // tolerance/5); + + //BOOST_CHECK_CLOSE(boost::math::quantile( + // poisson_distribution(5), // mean. + // static_cast(0.75)), // probability. + // // 6.1882832344329559 result but MathCAD givest smallest integer ppois(k, mean) >= prob + // static_cast(6.), // Expect k = 6 events. + // tolerance/5); + BOOST_CHECK_CLOSE( boost::math::quantile( complement( @@ -441,11 +507,21 @@ int test_main(int, char* []) cout << endl; } + cout << cdf(poisson_distribution(5), static_cast(0)) << ' ' << endl; // 0.006737946999085467 cout << cdf(poisson_distribution(5), static_cast(1)) << ' ' << endl; // 0.040427681994512805 cout << cdf(poisson_distribution(2), static_cast(3)) << ' ' << endl; // 0.85712346049854715 #endif + { + for (int i = 1; i < 100; i++) + { + poisson_distribution distn(static_cast(i)); + cout << i << ' ' << median(distn) << ' ' << quantile(distn, 0.5) << ' ' + << median(distn) - quantile(distn, 0.5) << endl; + } + } + // (Parameter value, arbitrarily zero, only communicates the floating-point type). test_spots(0.0F); // Test float. test_spots(0.0); // Test double. diff --git a/test/test_triangular.cpp b/test/test_triangular.cpp index dfd21417f..5362b3e20 100644 --- a/test/test_triangular.cpp +++ b/test/test_triangular.cpp @@ -458,6 +458,8 @@ void test_spots(RealType T) BOOST_CHECK_CLOSE_FRACTION( mode(distu01), static_cast(0), tolerance); // skewness: + BOOST_CHECK_CLOSE_FRACTION( + median(trim12), static_cast(-0.13397459621556151), tolerance); BOOST_CHECK_EQUAL( skewness(distu01), static_cast(0)); // kertosis: @@ -528,6 +530,8 @@ int test_main(int, char* []) BOOST_CHECK_EQUAL(tristd.mode(), 0); BOOST_CHECK_EQUAL(tristd.upper(), 1); + cout << median(tristd) << endl; + triangular_distribution<> tri011(0, 1, 1); // Using default RealType double. // mode is upper BOOST_CHECK_EQUAL(tri011.lower(), 0); // Check defaults again. @@ -611,6 +615,7 @@ int test_main(int, char* []) BOOST_CHECK_EQUAL(quantile(complement(*dists[i], 1.)), quantile(*dists[i], 0.)); BOOST_CHECK_CLOSE_FRACTION(quantile(*dists[i], 0.5), quantile(complement(*dist, 0.5)), tol5eps); // OK BOOST_CHECK_CLOSE_FRACTION(quantile(*dists[i], 0.98), quantile(complement(*dist, 1. - 0.98)),tol5eps); + // cout << setprecision(17) << median(*dist) << endl; } cout << showpos << setprecision(2) << endl; @@ -635,10 +640,6 @@ int test_main(int, char* []) BOOST_CHECK_CLOSE_FRACTION(quantile(trim12, dx), quantile(complement(trim12, 1 - dx)), tol500eps); } cout << endl; - - - - // Basic sanity-check spot values. // (Parameter value, arbitrarily zero, only communicates the floating point type). test_spots(0.0F); // Test float. OK at decdigits = 0 tolerance = 0.0001 % @@ -662,26 +663,27 @@ int test_main(int, char* []) Output: ------- Build started: Project: test_triangular, Configuration: Debug Win32 ------ Compiling... test_triangular.cpp Linking... Autorun "i:\boost-06-05-03-1300\libs\math\test\Math_test\debug\test_triangular.exe" Running 1 test case... +0 Distribution 0 +0 Distribution 1 +1 Distribution 2 +0.35355339059327373 Distribution 3 +0.5 Distribution 4 +-0.13397459621556151 Tolerance for type float is 5.96046e-007. Tolerance for type double is 1.11022e-015. Tolerance for type long double is 1.11022e-015. Tolerance for type class boost::math::concepts::real_concept is 1.11022e-015. *** No errors detected -Build Time 0:05 -Build log was saved at "file://i:\boost-06-05-03-1300\libs\math\test\Math_test\test_triangular\Debug\BuildLog.htm" -test_triangular - 0 error(s), 0 warning(s) -========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== diff --git a/test/test_uniform.cpp b/test/test_uniform.cpp index 159123035..ab1d942b2 100644 --- a/test/test_uniform.cpp +++ b/test/test_uniform.cpp @@ -320,6 +320,8 @@ void test_spots(RealType T) // mode: BOOST_CHECK_CLOSE_FRACTION( mode(distu01), static_cast(0), tolerance); + BOOST_CHECK_CLOSE_FRACTION( + median(distu01), static_cast(0.5), tolerance); // skewness: BOOST_CHECK_EQUAL( skewness(distu01), static_cast(0)); diff --git a/test/test_weibull.cpp b/test/test_weibull.cpp index 2618f4ab1..b34ea0d56 100644 --- a/test/test_weibull.cpp +++ b/test/test_weibull.cpp @@ -296,6 +296,10 @@ void test_spots(RealType T) BOOST_CHECK_CLOSE( mode(dist) , dist.scale() * pow((dist.shape() - 1) / dist.shape(), 1/dist.shape()), tolerance); + // median: + BOOST_CHECK_CLOSE( + median(dist) + , dist.scale() * pow(log(static_cast(2)), 1 / dist.shape()), tolerance); // skewness: BOOST_CHECK_CLOSE( skewness(dist),