mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
C++11 Stats (#498)
* Configure tests and jamfile to verify C++11 compat * Remove language standard guards
This commit is contained in:
@@ -979,10 +979,10 @@ test-suite misc :
|
||||
[ run signal_statistics_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run anderson_darling_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run ljung_box_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run test_t_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run test_z_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run bivariate_statistics_test.cpp : : : [ requires cxx11_hdr_forward_list cxx11_hdr_tuple cxx11_sfinae_expr ] ]
|
||||
[ run linear_regression_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run test_t_test.cpp : : : [ requires cxx11_hdr_forward_list cxx11_hdr_atomic cxx11_hdr_thread cxx11_hdr_tuple cxx11_hdr_future cxx11_sfinae_expr ] ]
|
||||
[ run test_z_test.cpp : : : [ requires cxx11_hdr_forward_list cxx11_hdr_atomic cxx11_hdr_thread cxx11_hdr_tuple cxx11_hdr_future cxx11_sfinae_expr ] ]
|
||||
[ run bivariate_statistics_test.cpp : : : [ requires cxx11_hdr_forward_list cxx11_hdr_atomic cxx11_hdr_thread cxx11_hdr_tuple cxx11_hdr_future cxx11_sfinae_expr ] ]
|
||||
[ run linear_regression_test.cpp : : : [ requires cxx11_hdr_forward_list cxx11_hdr_atomic cxx11_hdr_thread cxx11_hdr_tuple cxx11_hdr_future cxx11_sfinae_expr ] ]
|
||||
[ run test_runs_test.cpp : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run lanczos_smoothing_test.cpp ../../test/build//boost_unit_test_framework : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
[ run condition_number_test.cpp ../../test/build//boost_unit_test_framework : : : [ requires cxx17_if_constexpr cxx17_std_apply ] ]
|
||||
|
||||
@@ -21,11 +21,7 @@
|
||||
#include <boost/math/statistics/bivariate_statistics.hpp>
|
||||
#include <boost/multiprecision/cpp_bin_float.hpp>
|
||||
#include <boost/multiprecision/cpp_complex.hpp>
|
||||
|
||||
#if __cplusplus > 201700L || _MSVC_LANG > 201700L
|
||||
#include <boost/math/statistics/univariate_statistics.hpp>
|
||||
#define CPP17TESTS
|
||||
#endif
|
||||
|
||||
using boost::multiprecision::cpp_bin_float_50;
|
||||
using boost::multiprecision::cpp_complex_50;
|
||||
@@ -110,7 +106,6 @@ void test_covariance()
|
||||
v[i] = (Real) dis(gen);
|
||||
}
|
||||
|
||||
#ifdef CPP17TESTS
|
||||
Real mu_u = boost::math::statistics::mean(u);
|
||||
Real mu_v = boost::math::statistics::mean(v);
|
||||
Real sigma_u_sq = boost::math::statistics::variance(u);
|
||||
@@ -131,7 +126,6 @@ void test_covariance()
|
||||
BOOST_TEST(abs(cov_uu - sigma_u_sq) < tol);
|
||||
Real cov_vv = covariance(v, v);
|
||||
BOOST_TEST(abs(cov_vv - sigma_v_sq) < tol);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class Z>
|
||||
@@ -202,7 +196,6 @@ void test_integer_covariance()
|
||||
v[i] = (Z) dis(gen);
|
||||
}
|
||||
|
||||
#ifdef CPP17TESTS
|
||||
double mu_u = boost::math::statistics::mean(u);
|
||||
double mu_v = boost::math::statistics::mean(v);
|
||||
double sigma_u_sq = boost::math::statistics::variance(u);
|
||||
@@ -223,7 +216,6 @@ void test_integer_covariance()
|
||||
BOOST_TEST(abs(cov_uu - sigma_u_sq) < tol);
|
||||
double cov_vv = covariance(v, v);
|
||||
BOOST_TEST(abs(cov_vv - sigma_v_sq) < tol);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class Real>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "math_unit_test.hpp"
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <utility>
|
||||
#include <boost/math/statistics/univariate_statistics.hpp>
|
||||
#include <boost/math/statistics/t_test.hpp>
|
||||
#include <boost/multiprecision/cpp_bin_float.hpp>
|
||||
@@ -31,7 +32,9 @@ void test_exact_mean()
|
||||
|
||||
Real mu = boost::math::statistics::mean(v);
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::one_sample_t_test(v, mu);
|
||||
std::pair<Real, Real> temp = boost::math::statistics::one_sample_t_test(v, mu);
|
||||
Real computed_statistic = std::get<0>(temp);
|
||||
Real computed_pvalue = std::get<1>(temp);
|
||||
|
||||
CHECK_MOLLIFIED_CLOSE(Real(0), computed_statistic, 10*std::numeric_limits<Real>::epsilon());
|
||||
CHECK_ULP_CLOSE(Real(1), computed_pvalue, 9);
|
||||
@@ -49,7 +52,9 @@ void test_multiprecision_exact_mean()
|
||||
|
||||
Real mu = boost::math::statistics::mean(v);
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::one_sample_t_test(v, mu);
|
||||
std::pair<Real, Real> temp = boost::math::statistics::one_sample_t_test(v, mu);
|
||||
Real computed_statistic = std::get<0>(temp);
|
||||
Real computed_pvalue = std::get<1>(temp);
|
||||
|
||||
CHECK_MOLLIFIED_CLOSE(Real(0), computed_statistic, 15*std::numeric_limits<Real>::epsilon());
|
||||
CHECK_ULP_CLOSE(Real(1), computed_pvalue, 25);
|
||||
@@ -59,7 +64,9 @@ template<typename Z>
|
||||
void test_integer()
|
||||
{
|
||||
// https://www.wolframalpha.com/input/?i=t+test
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::one_sample_t_test(Z(12), Z(5*5), Z(25), Z(10));
|
||||
std::pair<double, double> temp = boost::math::statistics::one_sample_t_test(Z(12), Z(5*5), Z(25), Z(10));
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
double computed_pvalue = std::get<1>(temp);
|
||||
CHECK_MOLLIFIED_CLOSE(2.0, computed_statistic, 10*std::numeric_limits<double>::epsilon());
|
||||
CHECK_MOLLIFIED_CLOSE(0.02847*2, computed_pvalue, 0.00001);
|
||||
}
|
||||
@@ -98,7 +105,9 @@ void test_agreement_with_mathematica()
|
||||
double expected_statistic = 0.4587075249160456;
|
||||
double expected_pvalue = 0.6472282548266728;
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::one_sample_t_test(v, 0.0);
|
||||
std::pair<double, double> temp = boost::math::statistics::one_sample_t_test(v, 0.0);
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
double computed_pvalue = std::get<1>(temp);
|
||||
|
||||
CHECK_ULP_CLOSE(expected_statistic, computed_statistic, 8);
|
||||
CHECK_ULP_CLOSE(expected_pvalue, computed_pvalue, 90);
|
||||
@@ -110,7 +119,9 @@ void test_agreement_with_mathematica()
|
||||
expected_statistic = 2.103013485037935;
|
||||
expected_pvalue = 0.1701790440880712;
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::one_sample_t_test(v, 0.0);
|
||||
std::pair<double, double> temp = boost::math::statistics::one_sample_t_test(v, 0.0);
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
double computed_pvalue = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(expected_statistic, computed_statistic, 2);
|
||||
CHECK_ULP_CLOSE(expected_pvalue, computed_pvalue, 7);
|
||||
}
|
||||
@@ -119,15 +130,18 @@ void test_agreement_with_mathematica()
|
||||
template<typename Real>
|
||||
void test_two_sample_t()
|
||||
{
|
||||
auto [computed_statistic, computed_pvalue] =
|
||||
std::pair<Real, Real> temp =
|
||||
boost::math::statistics::detail::two_sample_t_test_impl<std::pair<Real, Real>>(Real(10.0), Real(1.0), Real(20), Real(5.0), Real(0.25), Real(20));
|
||||
|
||||
Real computed_statistic = std::get<0>(temp);
|
||||
Real computed_pvalue = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(Real(20), computed_statistic, 5);
|
||||
CHECK_MOLLIFIED_CLOSE(Real(0), computed_pvalue, 1e-21);
|
||||
|
||||
std::vector<Real> set_1 {301, 298, 295, 297, 304, 305, 309, 298, 291, 299, 293, 304};
|
||||
|
||||
auto [computed_statistic_2, computed_pvalue_2] = boost::math::statistics::two_sample_t_test(set_1, set_1);
|
||||
temp = boost::math::statistics::two_sample_t_test(set_1, set_1);
|
||||
Real computed_statistic_2 = std::get<0>(temp);
|
||||
Real computed_pvalue_2 = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(Real(0), computed_statistic_2, 5);
|
||||
CHECK_ULP_CLOSE(Real(1), computed_pvalue_2, 5);
|
||||
}
|
||||
@@ -135,14 +149,16 @@ void test_two_sample_t()
|
||||
template<typename Z>
|
||||
void test_integer_two_sample_t()
|
||||
{
|
||||
auto [computed_statistic, computed_pvalue] =
|
||||
std::pair<double, double> temp =
|
||||
boost::math::statistics::detail::two_sample_t_test_impl<std::pair<double, double>>(Z(10), Z(4), Z(20), Z(5), Z(1), Z(20));
|
||||
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
CHECK_ULP_CLOSE(10.0, computed_statistic, 5);
|
||||
|
||||
std::vector<Z> set_1 {301, 298, 295, 297, 304, 305, 309, 298, 291, 299, 293, 304};
|
||||
|
||||
auto [computed_statistic_2, computed_pvalue_2] = boost::math::statistics::two_sample_t_test(set_1, set_1);
|
||||
temp = boost::math::statistics::two_sample_t_test(set_1, set_1);
|
||||
double computed_statistic_2 = std::get<0>(temp);
|
||||
double computed_pvalue_2 = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(0.0, computed_statistic_2, 5);
|
||||
CHECK_ULP_CLOSE(1.0, computed_pvalue_2, 5);
|
||||
}
|
||||
@@ -152,15 +168,16 @@ void test_welch()
|
||||
{
|
||||
using std::sqrt;
|
||||
|
||||
auto [computed_statistic, computed_pvalue] =
|
||||
std::pair<Real, Real> temp =
|
||||
boost::math::statistics::detail::welchs_t_test_impl<std::pair<Real, Real>>(Real(10.0), Real(1.0), Real(20), Real(5.0), Real(0.25), Real(20));
|
||||
|
||||
Real computed_statistic = std::get<0>(temp);
|
||||
Real computed_pvalue = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(Real(20), computed_statistic, 5);
|
||||
CHECK_MOLLIFIED_CLOSE(Real(0), computed_pvalue, 5e-18);
|
||||
|
||||
auto [computed_statistic_2, computed_pvalue_2] =
|
||||
boost::math::statistics::detail::welchs_t_test_impl<std::pair<Real, Real>>(Real(10.0), Real(0.5), Real(20), Real(10.0), Real(0.5), Real(20));
|
||||
|
||||
temp = boost::math::statistics::detail::welchs_t_test_impl<std::pair<Real, Real>>(Real(10.0), Real(0.5), Real(20), Real(10.0), Real(0.5), Real(20));
|
||||
Real computed_statistic_2 = std::get<0>(temp);
|
||||
Real computed_pvalue_2 = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(Real(0), computed_statistic_2, 5);
|
||||
CHECK_ULP_CLOSE(Real(1), computed_pvalue_2, 5);
|
||||
}
|
||||
@@ -168,13 +185,14 @@ void test_welch()
|
||||
template<typename Z>
|
||||
void test_integer_welch()
|
||||
{
|
||||
auto [computed_statistic, computed_pvalue] =
|
||||
std::pair<double, double> temp =
|
||||
boost::math::statistics::detail::welchs_t_test_impl<std::pair<double, double>>(10.0, 4.0, 20.0, 5.0, 1.0, 20.0);
|
||||
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
CHECK_ULP_CLOSE(10.0, computed_statistic, 5);
|
||||
|
||||
auto [computed_statistic_2, computed_pvalue_2] =
|
||||
boost::math::statistics::detail::welchs_t_test_impl<std::pair<double, double>>(10.0, 0.5, 20.0, 10.0, 0.5, 20.0);
|
||||
temp = boost::math::statistics::detail::welchs_t_test_impl<std::pair<double, double>>(10.0, 0.5, 20.0, 10.0, 0.5, 20.0);
|
||||
double computed_statistic_2 = std::get<0>(temp);
|
||||
double computed_pvalue_2 = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(0.0, computed_statistic_2, 5);
|
||||
CHECK_ULP_CLOSE(1.0, computed_pvalue_2, 5);
|
||||
}
|
||||
@@ -185,8 +203,8 @@ void test_paired_samples()
|
||||
std::vector<Real> set_1 {2,4};
|
||||
std::vector<Real> set_2 {1,2};
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::paired_samples_t_test(set_1, set_2);
|
||||
|
||||
std::pair<Real, Real> temp = boost::math::statistics::paired_samples_t_test(set_1, set_2);
|
||||
Real computed_statistic = std::get<0>(temp);
|
||||
CHECK_ULP_CLOSE(Real(3), computed_statistic, 5);
|
||||
}
|
||||
|
||||
@@ -196,8 +214,8 @@ void test_integer_paired_samples()
|
||||
std::vector<Z> set_1 {2,4};
|
||||
std::vector<Z> set_2 {1,2};
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::paired_samples_t_test(set_1, set_2);
|
||||
|
||||
std::pair<double, double> temp = boost::math::statistics::paired_samples_t_test(set_1, set_2);
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
CHECK_ULP_CLOSE(3.0, computed_statistic, 5);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,31 +10,39 @@
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <utility>
|
||||
|
||||
using quad = boost::multiprecision::cpp_bin_float_quad;
|
||||
|
||||
template<typename Real>
|
||||
void test_one_sample_z()
|
||||
{
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::one_sample_z_test(Real(10), Real(2), Real(100), Real(10));
|
||||
std::pair<Real, Real> temp = boost::math::statistics::one_sample_z_test(Real(10), Real(2), Real(100), Real(10));
|
||||
Real computed_statistic = std::get<0>(temp);
|
||||
Real computed_pvalue = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(Real(0), computed_statistic, 5);
|
||||
CHECK_MOLLIFIED_CLOSE(Real(0), computed_pvalue, 5*std::numeric_limits<Real>::epsilon());
|
||||
|
||||
auto [computed_statistic_2, computed_pvalue_2] = boost::math::statistics::one_sample_z_test(Real(10), Real(2), Real(100), Real(5));
|
||||
temp = boost::math::statistics::one_sample_z_test(Real(10), Real(2), Real(100), Real(5));
|
||||
Real computed_statistic_2 = std::get<0>(temp);
|
||||
CHECK_ULP_CLOSE(Real(25), computed_statistic_2, 5);
|
||||
|
||||
auto [computed_statistic_3, computed_pvalue_3] = boost::math::statistics::one_sample_z_test(Real(1)/2, Real(10), Real(100), Real(1)/3);
|
||||
temp = boost::math::statistics::one_sample_z_test(Real(1)/2, Real(10), Real(100), Real(1)/3);
|
||||
Real computed_statistic_3 = std::get<0>(temp);
|
||||
CHECK_ULP_CLOSE(Real(1)/6, computed_statistic_3, 5);
|
||||
}
|
||||
|
||||
template<typename Z>
|
||||
void test_integer_one_sample_z()
|
||||
{
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::one_sample_z_test(Z(10), Z(2), Z(100), Z(10));
|
||||
std::pair<double, double> temp = boost::math::statistics::one_sample_z_test(Z(10), Z(2), Z(100), Z(10));
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
double computed_pvalue = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(0.0, computed_statistic, 5);
|
||||
CHECK_MOLLIFIED_CLOSE(0.0, computed_pvalue, 5*std::numeric_limits<double>::epsilon());
|
||||
|
||||
auto [computed_statistic_2, computed_pvalue_2] = boost::math::statistics::one_sample_z_test(Z(10), Z(2), Z(100), Z(5));
|
||||
temp = boost::math::statistics::one_sample_z_test(Z(10), Z(2), Z(100), Z(5));
|
||||
double computed_statistic_2 = std::get<0>(temp);
|
||||
CHECK_ULP_CLOSE(25.0, computed_statistic_2, 5);
|
||||
}
|
||||
|
||||
@@ -44,7 +52,9 @@ void test_two_sample_z()
|
||||
std::vector<Real> set_1 {1,2,3,4,5};
|
||||
std::vector<Real> set_2 {2,3,4,5,6};
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::two_sample_z_test(set_2, set_1);
|
||||
std::pair<Real, Real> temp = boost::math::statistics::two_sample_z_test(set_2, set_1);
|
||||
Real computed_statistic = std::get<0>(temp);
|
||||
Real computed_pvalue = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(Real(1), computed_statistic, 5);
|
||||
CHECK_MOLLIFIED_CLOSE(Real(0), computed_pvalue, 5*std::numeric_limits<Real>::epsilon());
|
||||
}
|
||||
@@ -55,7 +65,9 @@ void test_integer_two_sample_z()
|
||||
std::vector<Z> set_1 {1,2,3,4,5};
|
||||
std::vector<Z> set_2 {2,3,4,5,6};
|
||||
|
||||
auto [computed_statistic, computed_pvalue] = boost::math::statistics::two_sample_z_test(set_2, set_1);
|
||||
std::pair<double, double> temp = boost::math::statistics::two_sample_z_test(set_2, set_1);
|
||||
double computed_statistic = std::get<0>(temp);
|
||||
double computed_pvalue = std::get<1>(temp);
|
||||
CHECK_ULP_CLOSE(1.0, computed_statistic, 5);
|
||||
CHECK_MOLLIFIED_CLOSE(0.0, computed_pvalue, 5*std::numeric_limits<double>::epsilon());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user