summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/accumulators/test/kurtosis.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/accumulators/test/kurtosis.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/accumulators/test/kurtosis.cpp')
-rw-r--r--src/boost/libs/accumulators/test/kurtosis.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/boost/libs/accumulators/test/kurtosis.cpp b/src/boost/libs/accumulators/test/kurtosis.cpp
new file mode 100644
index 00000000..92c5cfe9
--- /dev/null
+++ b/src/boost/libs/accumulators/test/kurtosis.cpp
@@ -0,0 +1,102 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// Test case for kurtosis.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/kurtosis.hpp>
+#include <sstream>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ // double epsilon = 1;
+
+ accumulator_set<double, stats<tag::kurtosis > > acc1;
+ accumulator_set<int, stats<tag::kurtosis > > acc2;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ acc1(normal());
+ }
+
+ // This check fails because epsilon is relative and not absolute
+ // BOOST_CHECK_CLOSE( kurtosis(acc1), 0., epsilon );
+
+ acc2(2);
+ acc2(7);
+ acc2(4);
+ acc2(9);
+ acc2(3);
+
+ BOOST_CHECK_EQUAL( mean(acc2), 5 );
+ BOOST_CHECK_EQUAL( accumulators::moment<2>(acc2), 159./5. );
+ BOOST_CHECK_EQUAL( accumulators::moment<3>(acc2), 1171./5. );
+ BOOST_CHECK_EQUAL( accumulators::moment<4>(acc2), 1863 );
+ BOOST_CHECK_CLOSE( kurtosis(acc2), -1.39965397924, 1e-6 );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_persistency
+//
+void test_persistency()
+{
+ // "persistent" storage
+ std::stringstream ss;
+ // tolerance
+ double epsilon = 1e-6;
+ double kurtosis_value = -1.39965397924;
+ {
+ accumulator_set<int, stats<tag::kurtosis > > acc;
+ acc(2);
+ acc(7);
+ acc(4);
+ acc(9);
+ acc(3);
+ BOOST_CHECK_CLOSE( kurtosis(acc), kurtosis_value, epsilon);
+ boost::archive::text_oarchive oa(ss);
+ acc.serialize(oa, 0);
+ }
+
+ accumulator_set<double, stats<tag::kurtosis > > acc;
+ boost::archive::text_iarchive ia(ss);
+ acc.serialize(ia, 0);
+ BOOST_CHECK_CLOSE( kurtosis(acc), kurtosis_value, epsilon);
+
+}
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("kurtosis test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+ test->add(BOOST_TEST_CASE(&test_persistency));
+
+ return test;
+}
+