]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/covariance.cpp
1 // (C) Copyright 2005 Daniel Egloff, Eric Niebler
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
8 #include <boost/test/unit_test.hpp>
9 #include <boost/test/floating_point_comparison.hpp>
10 #include <boost/accumulators/accumulators.hpp>
11 #include <boost/accumulators/statistics/variates/covariate.hpp>
12 #include <boost/accumulators/statistics/stats.hpp>
13 #include <boost/accumulators/statistics/covariance.hpp>
15 using namespace boost
;
16 using namespace unit_test
;
17 using namespace accumulators
;
19 ///////////////////////////////////////////////////////////////////////////////
24 std::vector
<double> dummy
;
28 accumulator_set
<double, stats
<tag::covariance
<double, tag::covariate1
> > > acc
;
29 accumulator_set
<std::vector
<double>, stats
<tag::covariance
<double, tag::covariate1
> > > acc2(sample
= dummy
);
30 accumulator_set
<double, stats
<tag::covariance
<std::vector
<double>, tag::covariate1
> > > acc3(covariate1
= dummy
);
31 accumulator_set
<std::vector
<double>, stats
<tag::covariance
<std::vector
<double>, tag::covariate1
> > > acc4(sample
= dummy
, covariate1
= dummy
);
33 std::vector
<double> a
;
36 std::vector
<double> b
;
39 std::vector
<double> c
;
42 std::vector
<double> d
;
48 acc(1., covariate1
= 2.);
49 acc(1., covariate1
= 4.);
50 acc(2., covariate1
= 3.);
51 acc(6., covariate1
= 1.);
56 acc2(a
, covariate1
= 1.);
57 acc2(b
, covariate1
= 1.);
58 acc2(c
, covariate1
= 2.);
59 acc2(d
, covariate1
= 6.);
64 acc3(1., covariate1
= a
);
65 acc3(1., covariate1
= b
);
66 acc3(2., covariate1
= c
);
67 acc3(6., covariate1
= d
);
72 acc4(a
, covariate1
= b
);
73 acc4(b
, covariate1
= c
);
74 acc4(a
, covariate1
= c
);
75 acc4(d
, covariate1
= b
);
78 double epsilon
= 1e-6;
80 BOOST_CHECK_CLOSE((covariance(acc
)), -1.75, epsilon
);
81 BOOST_CHECK_CLOSE((covariance(acc2
))[0], 1.75, epsilon
);
82 BOOST_CHECK_CLOSE((covariance(acc2
))[1], -1.125, epsilon
);
83 BOOST_CHECK_CLOSE((covariance(acc3
))[0], 1.75, epsilon
);
84 BOOST_CHECK_CLOSE((covariance(acc3
))[1], -1.125, epsilon
);
85 BOOST_CHECK_CLOSE((covariance(acc4
))(0,0), 0.125, epsilon
);
86 BOOST_CHECK_CLOSE((covariance(acc4
))(0,1), -0.25, epsilon
);
87 BOOST_CHECK_CLOSE((covariance(acc4
))(1,0), -0.125, epsilon
);
88 BOOST_CHECK_CLOSE((covariance(acc4
))(1,1), 0.25, epsilon
);
91 ///////////////////////////////////////////////////////////////////////////////
92 // init_unit_test_suite
94 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
96 test_suite
*test
= BOOST_TEST_SUITE("covariance test");
98 test
->add(BOOST_TEST_CASE(&test_stat
));