Chris@102: /////////////////////////////////////////////////////////////////////////////// Chris@102: // rolling_moment.hpp Chris@102: // Copyright 2005 Eric Niebler. Chris@102: // Copyright (C) 2014 Pieter Bastiaan Ober (Integricom). Chris@102: // Distributed under the Boost Software License, Version 1.0. Chris@102: // (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: #ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005 Chris@102: #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005 Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: namespace boost { namespace accumulators Chris@102: { Chris@102: namespace impl Chris@102: { Chris@102: /////////////////////////////////////////////////////////////////////////////// Chris@102: // rolling_moment_impl Chris@102: template Chris@102: struct rolling_moment_impl Chris@102: : accumulator_base Chris@102: { Chris@102: BOOST_MPL_ASSERT_RELATION(N::value, >, 0); Chris@102: // for boost::result_of Chris@102: typedef typename numeric::functional::fdiv::result_type result_type; Chris@102: Chris@102: template Chris@102: rolling_moment_impl(Args const &args) Chris@102: : sum_(args[sample | Sample()]) Chris@102: { Chris@102: } Chris@102: Chris@102: template Chris@102: void operator ()(Args const &args) Chris@102: { Chris@102: if(is_rolling_window_plus1_full(args)) Chris@102: { Chris@102: this->sum_ -= numeric::pow(rolling_window_plus1(args).front(), N()); Chris@102: } Chris@102: this->sum_ += numeric::pow(args[sample], N()); Chris@102: } Chris@102: Chris@102: template Chris@102: result_type result(Args const &args) const Chris@102: { Chris@102: return numeric::fdiv(this->sum_, rolling_count(args)); Chris@102: } Chris@102: Chris@102: private: Chris@102: result_type sum_; Chris@102: }; Chris@102: } // namespace impl Chris@102: Chris@102: /////////////////////////////////////////////////////////////////////////////// Chris@102: // tag::rolling_moment Chris@102: // Chris@102: namespace tag Chris@102: { Chris@102: template Chris@102: struct rolling_moment Chris@102: : depends_on< rolling_window_plus1, rolling_count> Chris@102: { Chris@102: /// INTERNAL ONLY Chris@102: /// Chris@102: typedef accumulators::impl::rolling_moment_impl, mpl::_1> impl; Chris@102: Chris@102: #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED Chris@102: /// tag::rolling_window::window_size named parameter Chris@102: static boost::parameter::keyword const window_size; Chris@102: #endif Chris@102: }; Chris@102: } Chris@102: Chris@102: /////////////////////////////////////////////////////////////////////////////// Chris@102: // extract::rolling_moment Chris@102: // Chris@102: namespace extract Chris@102: { Chris@102: BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, rolling_moment, (int)) Chris@102: } Chris@102: Chris@102: using extract::rolling_moment; Chris@102: Chris@102: // There is no weighted_rolling_moment (yet)... Chris@102: // Chris@102: //// So that rolling_moment can be automatically substituted with Chris@102: //// weighted_rolling_moment when the weight parameter is non-void Chris@102: //template Chris@102: //struct as_weighted_feature > Chris@102: //{ Chris@102: // typedef tag::weighted_rolling_moment type; Chris@102: //}; Chris@102: // Chris@102: //template Chris@102: //struct feature_of > Chris@102: // : feature_of > Chris@102: //{ Chris@102: //}; Chris@102: }} // namespace boost::accumulators Chris@102: Chris@102: #endif