File indexing completed on 2024-11-15 09:02:23
0001
0002
0003
0004
0005
0006
0007
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
0031 template<typename N, typename Sample>
0032 struct rolling_moment_impl
0033 : accumulator_base
0034 {
0035 BOOST_MPL_ASSERT_RELATION(N::value, >, 0);
0036
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
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 }
0072
0073
0074
0075
0076 namespace tag
0077 {
0078 template<int N>
0079 struct rolling_moment
0080 : depends_on< rolling_window_plus1, rolling_count>
0081 {
0082
0083
0084 typedef accumulators::impl::rolling_moment_impl<mpl::int_<N>, mpl::_1> impl;
0085
0086 #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
0087
0088 static boost::parameter::keyword<tag::rolling_window_size> const window_size;
0089 #endif
0090 };
0091 }
0092
0093
0094
0095
0096 namespace extract
0097 {
0098 BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, rolling_moment, (int))
0099 }
0100
0101 using extract::rolling_moment;
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 }}
0119
0120 #endif