annotate DEPENDENCIES/generic/include/boost/accumulators/statistics/rolling_moment.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 ///////////////////////////////////////////////////////////////////////////////
Chris@102 2 // rolling_moment.hpp
Chris@102 3 // Copyright 2005 Eric Niebler.
Chris@102 4 // Copyright (C) 2014 Pieter Bastiaan Ober (Integricom).
Chris@102 5 // Distributed under the Boost Software License, Version 1.0.
Chris@102 6 // (See accompanying file LICENSE_1_0.txt or copy at
Chris@102 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@102 8
Chris@102 9 #ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
Chris@102 10 #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
Chris@102 11
Chris@102 12 #include <boost/config/no_tr1/cmath.hpp>
Chris@102 13 #include <boost/mpl/int.hpp>
Chris@102 14 #include <boost/mpl/assert.hpp>
Chris@102 15 #include <boost/mpl/placeholders.hpp>
Chris@102 16 #include <boost/accumulators/framework/accumulator_base.hpp>
Chris@102 17 #include <boost/accumulators/framework/extractor.hpp>
Chris@102 18 #include <boost/accumulators/numeric/functional.hpp>
Chris@102 19 #include <boost/accumulators/framework/parameters/sample.hpp>
Chris@102 20 #include <boost/accumulators/framework/depends_on.hpp>
Chris@102 21 #include <boost/accumulators/statistics_fwd.hpp>
Chris@102 22 #include <boost/accumulators/statistics/moment.hpp>
Chris@102 23 #include <boost/accumulators/statistics/rolling_count.hpp>
Chris@102 24
Chris@102 25 namespace boost { namespace accumulators
Chris@102 26 {
Chris@102 27 namespace impl
Chris@102 28 {
Chris@102 29 ///////////////////////////////////////////////////////////////////////////////
Chris@102 30 // rolling_moment_impl
Chris@102 31 template<typename N, typename Sample>
Chris@102 32 struct rolling_moment_impl
Chris@102 33 : accumulator_base
Chris@102 34 {
Chris@102 35 BOOST_MPL_ASSERT_RELATION(N::value, >, 0);
Chris@102 36 // for boost::result_of
Chris@102 37 typedef typename numeric::functional::fdiv<Sample, std::size_t,void,void>::result_type result_type;
Chris@102 38
Chris@102 39 template<typename Args>
Chris@102 40 rolling_moment_impl(Args const &args)
Chris@102 41 : sum_(args[sample | Sample()])
Chris@102 42 {
Chris@102 43 }
Chris@102 44
Chris@102 45 template<typename Args>
Chris@102 46 void operator ()(Args const &args)
Chris@102 47 {
Chris@102 48 if(is_rolling_window_plus1_full(args))
Chris@102 49 {
Chris@102 50 this->sum_ -= numeric::pow(rolling_window_plus1(args).front(), N());
Chris@102 51 }
Chris@102 52 this->sum_ += numeric::pow(args[sample], N());
Chris@102 53 }
Chris@102 54
Chris@102 55 template<typename Args>
Chris@102 56 result_type result(Args const &args) const
Chris@102 57 {
Chris@102 58 return numeric::fdiv(this->sum_, rolling_count(args));
Chris@102 59 }
Chris@102 60
Chris@102 61 private:
Chris@102 62 result_type sum_;
Chris@102 63 };
Chris@102 64 } // namespace impl
Chris@102 65
Chris@102 66 ///////////////////////////////////////////////////////////////////////////////
Chris@102 67 // tag::rolling_moment
Chris@102 68 //
Chris@102 69 namespace tag
Chris@102 70 {
Chris@102 71 template<int N>
Chris@102 72 struct rolling_moment
Chris@102 73 : depends_on< rolling_window_plus1, rolling_count>
Chris@102 74 {
Chris@102 75 /// INTERNAL ONLY
Chris@102 76 ///
Chris@102 77 typedef accumulators::impl::rolling_moment_impl<mpl::int_<N>, mpl::_1> impl;
Chris@102 78
Chris@102 79 #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
Chris@102 80 /// tag::rolling_window::window_size named parameter
Chris@102 81 static boost::parameter::keyword<tag::rolling_window_size> const window_size;
Chris@102 82 #endif
Chris@102 83 };
Chris@102 84 }
Chris@102 85
Chris@102 86 ///////////////////////////////////////////////////////////////////////////////
Chris@102 87 // extract::rolling_moment
Chris@102 88 //
Chris@102 89 namespace extract
Chris@102 90 {
Chris@102 91 BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, rolling_moment, (int))
Chris@102 92 }
Chris@102 93
Chris@102 94 using extract::rolling_moment;
Chris@102 95
Chris@102 96 // There is no weighted_rolling_moment (yet)...
Chris@102 97 //
Chris@102 98 //// So that rolling_moment<N> can be automatically substituted with
Chris@102 99 //// weighted_rolling_moment<N> when the weight parameter is non-void
Chris@102 100 //template<int N>
Chris@102 101 //struct as_weighted_feature<tag::rolling_moment<N> >
Chris@102 102 //{
Chris@102 103 // typedef tag::weighted_rolling_moment<N> type;
Chris@102 104 //};
Chris@102 105 //
Chris@102 106 //template<int N>
Chris@102 107 //struct feature_of<tag::weighted_rolling_moment<N> >
Chris@102 108 // : feature_of<tag::rolling_moment<N> >
Chris@102 109 //{
Chris@102 110 //};
Chris@102 111 }} // namespace boost::accumulators
Chris@102 112
Chris@102 113 #endif