9451d40f733990fe9595d180266081f99ecc1d7c
[platform/upstream/boost.git] / boost / accumulators / statistics / error_of_mean.hpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // error_of.hpp
3 //
4 //  Copyright 2005 Eric Niebler. Distributed under the Boost
5 //  Software License, Version 1.0. (See accompanying file
6 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8 #ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
9 #define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
10
11 #include <boost/mpl/placeholders.hpp>
12 #include <boost/accumulators/framework/accumulator_base.hpp>
13 #include <boost/accumulators/framework/extractor.hpp>
14 #include <boost/accumulators/framework/depends_on.hpp>
15 #include <boost/accumulators/statistics_fwd.hpp>
16 #include <boost/accumulators/statistics/error_of.hpp>
17 #include <boost/accumulators/statistics/variance.hpp>
18 #include <boost/accumulators/statistics/count.hpp>
19
20 namespace boost { namespace accumulators
21 {
22
23 namespace impl
24 {
25     ///////////////////////////////////////////////////////////////////////////////
26     // error_of_mean_impl
27     template<typename Sample, typename Variance>
28     struct error_of_mean_impl
29       : accumulator_base
30     {
31         // for boost::result_of
32         typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
33
34         error_of_mean_impl(dont_care) {}
35
36         template<typename Args>
37         result_type result(Args const &args) const
38         {
39             using namespace std;
40             extractor<Variance> const variance = {};
41             return sqrt(numeric::average(variance(args), count(args) - 1));
42         }
43     };
44
45 } // namespace impl
46
47 ///////////////////////////////////////////////////////////////////////////////
48 // tag::error_of
49 //
50 namespace tag
51 {
52     template<>
53     struct error_of<mean>
54       : depends_on<lazy_variance, count>
55     {
56         /// INTERNAL ONLY
57         ///
58         typedef accumulators::impl::error_of_mean_impl<mpl::_1, lazy_variance> impl;
59     };
60
61     template<>
62     struct error_of<immediate_mean>
63       : depends_on<variance, count>
64     {
65         /// INTERNAL ONLY
66         ///
67         typedef accumulators::impl::error_of_mean_impl<mpl::_1, variance> impl;
68     };
69 }
70
71 }} // namespace boost::accumulators
72
73 #endif