]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/anderson_darling_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / math / test / anderson_darling_test.cpp
1 /*
2 * Copyright Nick Thompson, 2019
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 */
7
8 #include "math_unit_test.hpp"
9 #include <numeric>
10 #include <utility>
11 #include <random>
12 #include <boost/core/demangle.hpp>
13 #include <boost/math/statistics/anderson_darling.hpp>
14 #ifdef BOOST_HAS_FLOAT128
15 #include <boost/multiprecision/float128.hpp>
16 using boost::multiprecision::float128;
17 #endif
18
19
20 using boost::math::statistics::anderson_darling_normality_statistic;
21
22 void test_ad_normal_agreement_w_mathematica()
23 {
24 // To reproduce:
25 // data = RandomVariate[NormalDistribution[0.0, 1], 32];
26 // AndersonDarlingTest[data, NormalDistribution[0.0, 1.0], "TestStatistic"]
27 std::vector<double> v = {0.6018671202167422, 0.34935310534248165, -0.2975464874480147, 0.19075371678288966, 0.7871329594028097, 1.153968559452821,
28 -0.22255484635945819, 0.08509539017654276, -1.3495873906132927, 0.5579622886226612, -0.8781637835839865, 1.144016010880056,
29 0.3117638373078617, 1.2774825413798292, 0.24847416220730323, -0.5002468827503855, -0.23124277830160153, 0.1880980838556693,
30 -1.2249409521605903, 2.583585311795, -1.4237305768919715, -0.7613985266437971, -1.089096700141564, -1.2595396780059587,
31 -0.735507006841229, -0.6957024998691735, 0.24671590370045435, 0.24620128485023313, -2.4445908627621833, 0.1882647961008893,
32 1.8527432579288248, -0.1908629038857823, -1.6542624501251562, 1.414542907065601, 0.8188282235404601, -0.5040501225935047,
33 -1.634617885381599, -0.43608956281596023, -1.7347258501594351, 0.8387606547880405, 0.3554282034994122, -0.27872688042721255,
34 -1.6445047421517192, 1.0262620986278987, -0.14517030192098415, -0.15386932114942647, -0.13364750619758223, 0.27194802295714676,
35 -0.6396907621289796, 0.3390884293844603, -0.08298748318375798, -0.7165572035514544, -0.2580817977433051, -1.9250094572058072,
36 -0.07995578394716944, -1.146629910012214, -2.0053073148074665, -1.6745995591714353, 0.2973860474005926, -0.4981763213542575,
37 0.22190763958244972, 0.699111028057888, -1.1872952966557475, 0.6151420566782272};
38
39 double expected = 1.542329830419774;
40 std::sort(v.begin(), v.end());
41 double ADtest = anderson_darling_normality_statistic(v, 0.0, 1.0);
42
43 CHECK_ULP_CLOSE(expected, ADtest, 250);
44
45 double sigma = 2;
46 for (auto & x : v) {
47 x *= sigma;
48 }
49 ADtest = anderson_darling_normality_statistic(v, 0.0, sigma);
50 CHECK_ULP_CLOSE(expected, ADtest, 250);
51
52 double mu = 10;
53 for (auto & x : v) {
54 x += mu;
55 }
56 ADtest = anderson_darling_normality_statistic(v, mu, sigma);
57 CHECK_ULP_CLOSE(expected, ADtest, 250);
58 }
59
60 int main()
61 {
62 test_ad_normal_agreement_w_mathematica();
63 return boost::math::test::report_errors();
64 }