Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:02:23

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // rolling_moment.hpp
0003 // Copyright 2005 Eric Niebler.
0004 // Copyright (C) 2014 Pieter Bastiaan Ober (Integricom).
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
0010 #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
0011 
0012 #include <boost/config/no_tr1/cmath.hpp>
0013 #include <boost/mpl/int.hpp>
0014 #include <boost/mpl/assert.hpp>
0015 #include <boost/mpl/placeholders.hpp>
0016 #include <boost/accumulators/framework/accumulator_base.hpp>
0017 #include <boost/accumulators/framework/extractor.hpp>
0018 #include <boost/accumulators/numeric/functional.hpp>
0019 #include <boost/accumulators/framework/parameters/sample.hpp>
0020 #include <boost/accumulators/framework/depends_on.hpp>
0021 #include <boost/accumulators/statistics_fwd.hpp>
0022 #include <boost/accumulators/statistics/moment.hpp>
0023 #include <boost/accumulators/statistics/rolling_count.hpp>
0024 
0025 namespace boost { namespace accumulators
0026 {
0027 namespace impl
0028 {
0029     ///////////////////////////////////////////////////////////////////////////////
0030     // rolling_moment_impl
0031     template<typename N, typename Sample>
0032     struct rolling_moment_impl
0033       : accumulator_base
0034     {
0035         BOOST_MPL_ASSERT_RELATION(N::value, >, 0);
0036         // for boost::result_of
0037         typedef typename numeric::functional::fdiv<Sample, std::size_t,void,void>::result_type result_type;
0038 
0039         template<typename Args>
0040         rolling_moment_impl(Args const &args)
0041           : sum_(args[sample | Sample()])
0042         {
0043         }
0044 
0045         template<typename Args>
0046         void operator ()(Args const &args)
0047         {
0048             if(is_rolling_window_plus1_full(args))
0049             {
0050                 this->sum_ -= numeric::pow(rolling_window_plus1(args).front(), N());
0051             }
0052             this->sum_ += numeric::pow(args[sample], N());
0053         }
0054 
0055         template<typename Args>
0056         result_type result(Args const &args) const
0057         {
0058             return numeric::fdiv(this->sum_, rolling_count(args));
0059         }
0060 
0061         // make this accumulator serializeable
0062         template<class Archive>
0063         void serialize(Archive & ar, const unsigned int file_version)
0064         { 
0065             ar & sum_;
0066         }
0067 
0068     private:
0069         result_type sum_;
0070     };
0071 } // namespace impl
0072 
0073 ///////////////////////////////////////////////////////////////////////////////
0074 // tag::rolling_moment
0075 //
0076 namespace tag
0077 {
0078     template<int N>
0079     struct rolling_moment
0080       : depends_on< rolling_window_plus1, rolling_count>
0081     {
0082         /// INTERNAL ONLY
0083         ///
0084         typedef accumulators::impl::rolling_moment_impl<mpl::int_<N>, mpl::_1> impl;
0085 
0086         #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
0087         /// tag::rolling_window::window_size named parameter
0088         static boost::parameter::keyword<tag::rolling_window_size> const window_size;
0089         #endif
0090     };
0091 }
0092 
0093 ///////////////////////////////////////////////////////////////////////////////
0094 // extract::rolling_moment
0095 //
0096 namespace extract
0097 {
0098     BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, rolling_moment, (int))
0099 }
0100 
0101 using extract::rolling_moment;
0102 
0103 // There is no weighted_rolling_moment (yet)...
0104 //
0105 //// So that rolling_moment<N> can be automatically substituted with
0106 //// weighted_rolling_moment<N> when the weight parameter is non-void
0107 //template<int N>
0108 //struct as_weighted_feature<tag::rolling_moment<N> >
0109 //{
0110 //    typedef tag::weighted_rolling_moment<N> type;
0111 //};
0112 //
0113 //template<int N>
0114 //struct feature_of<tag::weighted_rolling_moment<N> >
0115 //  : feature_of<tag::rolling_moment<N> >
0116 //{
0117 //};
0118 }} // namespace boost::accumulators
0119 
0120 #endif