error_of_mean.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
  8. #define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
  9. #include <boost/mpl/placeholders.hpp>
  10. #include <boost/accumulators/framework/accumulator_base.hpp>
  11. #include <boost/accumulators/framework/extractor.hpp>
  12. #include <boost/accumulators/framework/depends_on.hpp>
  13. #include <boost/accumulators/statistics_fwd.hpp>
  14. #include <boost/accumulators/statistics/error_of.hpp>
  15. #include <boost/accumulators/statistics/variance.hpp>
  16. #include <boost/accumulators/statistics/count.hpp>
  17. namespace boost { namespace accumulators
  18. {
  19. namespace impl
  20. {
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // error_of_mean_impl
  23. template<typename Sample, typename Variance>
  24. struct error_of_mean_impl
  25. : accumulator_base
  26. {
  27. // for boost::result_of
  28. typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type;
  29. error_of_mean_impl(dont_care) {}
  30. template<typename Args>
  31. result_type result(Args const &args) const
  32. {
  33. using namespace std;
  34. extractor<Variance> const variance = {};
  35. return sqrt(numeric::fdiv(variance(args), count(args) - 1));
  36. }
  37. };
  38. } // namespace impl
  39. ///////////////////////////////////////////////////////////////////////////////
  40. // tag::error_of
  41. //
  42. namespace tag
  43. {
  44. template<>
  45. struct error_of<mean>
  46. : depends_on<lazy_variance, count>
  47. {
  48. /// INTERNAL ONLY
  49. ///
  50. typedef accumulators::impl::error_of_mean_impl<mpl::_1, lazy_variance> impl;
  51. };
  52. template<>
  53. struct error_of<immediate_mean>
  54. : depends_on<variance, count>
  55. {
  56. /// INTERNAL ONLY
  57. ///
  58. typedef accumulators::impl::error_of_mean_impl<mpl::_1, variance> impl;
  59. };
  60. }
  61. }} // namespace boost::accumulators
  62. #endif