/////////////////////////////////////////////////////////////////////////////// // rolling_mean.hpp // Copyright (C) 2005 Eric Niebler // Copyright (C) 2011 Pieter Bastiaan Ober (Integricom). Distributed under 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) #ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_mean_HPP_EAN_15_11_2011 #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_mean_HPP_EAN_15_11_2011 #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace accumulators { namespace impl { /////////////////////////////////////////////////////////////////////////////// // rolling_mean_impl // template struct rolling_mean_impl : accumulator_base { typedef Sample result_type; template rolling_mean_impl(Args const &args) : mean_(0.0) {} template void operator()(Args const &args) { if(is_rolling_window_plus1_full(args)) { mean_ += (args[sample]-rolling_window_plus1(args).front())/rolling_count(args); } else { Sample prev_mean = mean_; mean_ += (args[sample]-prev_mean)/rolling_count(args); } } template result_type result(Args const &args) const { return mean_; } private: Sample mean_; }; } // namespace impl /////////////////////////////////////////////////////////////////////////////// // tag:: rolling_mean // namespace tag { struct rolling_mean : depends_on< rolling_window_plus1, rolling_count> { /// INTERNAL ONLY /// typedef accumulators::impl::rolling_mean_impl< mpl::_1 > impl; #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED /// tag::rolling_window::window_size named parameter static boost::parameter::keyword const window_size; #endif }; } // namespace tag /////////////////////////////////////////////////////////////////////////////// // extract::rolling_mean // namespace extract { extractor const rolling_mean = {}; BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_mean) } using extract::rolling_mean; }} // namespace boost::accumulators #endif