diff options
Diffstat (limited to 'boost/accumulators')
53 files changed, 779 insertions, 216 deletions
diff --git a/boost/accumulators/accumulators_fwd.hpp b/boost/accumulators/accumulators_fwd.hpp index 9986a537b1..4c0370e21e 100644 --- a/boost/accumulators/accumulators_fwd.hpp +++ b/boost/accumulators/accumulators_fwd.hpp @@ -11,6 +11,7 @@ #include <boost/config.hpp> #include <boost/mpl/apply_fwd.hpp> // for mpl::na #include <boost/mpl/limits/vector.hpp> +#include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/arithmetic/inc.hpp> #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp> #include <boost/preprocessor/repetition/enum_trailing_params.hpp> @@ -185,8 +186,18 @@ namespace detail inline void ignore_variable(void const *) {} - #define BOOST_ACCUMULATORS_IGNORE_GLOBAL(X)\ - namespace detail { inline void BOOST_PP_CAT(ignore_, X)() { boost::accumulators::detail::ignore_variable(&X); } } +#define BOOST_ACCUMULATORS_IGNORE_GLOBAL(X) \ + namespace detail \ + { \ + struct BOOST_PP_CAT(ignore_, X) \ + { \ + void ignore() \ + { \ + boost::accumulators::detail::ignore_variable(&X); \ + } \ + }; \ + } \ + /**/ } }} // namespace boost::accumulators diff --git a/boost/accumulators/framework/accumulators/droppable_accumulator.hpp b/boost/accumulators/framework/accumulators/droppable_accumulator.hpp index 1beed664a3..0e882b5c35 100644 --- a/boost/accumulators/framework/accumulators/droppable_accumulator.hpp +++ b/boost/accumulators/framework/accumulators/droppable_accumulator.hpp @@ -215,7 +215,7 @@ namespace boost { namespace accumulators template<typename Args> void on_drop(Args const &args) { - // cache the result at the point this calcuation was dropped + // cache the result at the point this calculation was dropped BOOST_ASSERT(!this->has_result()); this->set(this->Accumulator::result(args)); } diff --git a/boost/accumulators/framework/depends_on.hpp b/boost/accumulators/framework/depends_on.hpp index 76087b091d..c328972946 100644 --- a/boost/accumulators/framework/depends_on.hpp +++ b/boost/accumulators/framework/depends_on.hpp @@ -11,6 +11,8 @@ #include <boost/version.hpp> #include <boost/mpl/end.hpp> #include <boost/mpl/map.hpp> +#include <boost/mpl/set.hpp> +#include <boost/mpl/copy.hpp> #include <boost/mpl/fold.hpp> #include <boost/mpl/size.hpp> #include <boost/mpl/sort.hpp> @@ -26,6 +28,7 @@ #include <boost/mpl/is_sequence.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/mpl/insert_range.hpp> +#include <boost/mpl/back_inserter.hpp> #include <boost/mpl/transform_view.hpp> #include <boost/mpl/inherit_linearly.hpp> #include <boost/type_traits/is_base_and_derived.hpp> @@ -94,15 +97,49 @@ namespace boost { namespace accumulators template<typename A, typename B> struct is_dependent_on : is_base_and_derived< - typename undroppable<B>::type + typename feature_of<typename undroppable<B>::type>::type , typename undroppable<A>::type > {}; + template<typename Feature> + struct dependencies_of + { + typedef typename Feature::dependencies type; + }; + + // Should use mpl::insert_range, but doesn't seem to work with mpl sets + template<typename Set, typename Range> + struct set_insert_range + : mpl::fold< + Range + , Set + , mpl::insert<mpl::_1, mpl::_2> + > + {}; + + template<typename Features> + struct collect_abstract_features + : mpl::fold< + Features + , mpl::set0<> + , set_insert_range< + mpl::insert<mpl::_1, feature_of<mpl::_2> > + , collect_abstract_features<dependencies_of<mpl::_2> > + > + > + {}; + template<typename Features> struct depends_on_base : mpl::inherit_linearly< - typename mpl::sort<Features, is_dependent_on<mpl::_1, mpl::_2> >::type + typename mpl::sort< + typename mpl::copy< + typename collect_abstract_features<Features>::type + , mpl::back_inserter<mpl::vector0<> > + >::type + , is_dependent_on<mpl::_1, mpl::_2> + >::type // Don't inherit multiply from a feature , mpl::if_< is_dependent_on<mpl::_1, mpl::_2> @@ -319,7 +356,7 @@ namespace boost { namespace accumulators type; }; - // BUGBUG work around a MPL bug wrt map insertion + // BUGBUG work around an MPL bug wrt map insertion template<typename FeatureMap, typename Feature> struct insert_feature : mpl::eval_if< diff --git a/boost/accumulators/framework/parameters/accumulator.hpp b/boost/accumulators/framework/parameters/accumulator.hpp index 30e4b0de99..525ebb30ba 100644 --- a/boost/accumulators/framework/parameters/accumulator.hpp +++ b/boost/accumulators/framework/parameters/accumulator.hpp @@ -9,11 +9,13 @@ #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005 #include <boost/parameter/keyword.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> namespace boost { namespace accumulators { BOOST_PARAMETER_KEYWORD(tag, accumulator) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(accumulator) }} // namespace boost::accumulators diff --git a/boost/accumulators/framework/parameters/sample.hpp b/boost/accumulators/framework/parameters/sample.hpp index 9bfb665a57..8b227eb334 100644 --- a/boost/accumulators/framework/parameters/sample.hpp +++ b/boost/accumulators/framework/parameters/sample.hpp @@ -9,11 +9,13 @@ #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005 #include <boost/parameter/keyword.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> namespace boost { namespace accumulators { BOOST_PARAMETER_KEYWORD(tag, sample) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(sample) }} // namespace boost::accumulators diff --git a/boost/accumulators/framework/parameters/weight.hpp b/boost/accumulators/framework/parameters/weight.hpp index 86f133b914..f36016f372 100644 --- a/boost/accumulators/framework/parameters/weight.hpp +++ b/boost/accumulators/framework/parameters/weight.hpp @@ -9,12 +9,14 @@ #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005 #include <boost/parameter/keyword.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> namespace boost { namespace accumulators { // The weight of a single sample BOOST_PARAMETER_KEYWORD(tag, weight) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(weight) }} // namespace boost::accumulators diff --git a/boost/accumulators/framework/parameters/weights.hpp b/boost/accumulators/framework/parameters/weights.hpp index 85b9e2fbd1..6beae61386 100644 --- a/boost/accumulators/framework/parameters/weights.hpp +++ b/boost/accumulators/framework/parameters/weights.hpp @@ -9,12 +9,14 @@ #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005 #include <boost/parameter/keyword.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> namespace boost { namespace accumulators { // The weight accumulator BOOST_PARAMETER_KEYWORD(tag, weights) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(weights) }} // namespace boost::accumulators diff --git a/boost/accumulators/numeric/functional.hpp b/boost/accumulators/numeric/functional.hpp index 34cd91bdc0..d5d79f5c49 100644 --- a/boost/accumulators/numeric/functional.hpp +++ b/boost/accumulators/numeric/functional.hpp @@ -20,6 +20,7 @@ #include <boost/type_traits/is_floating_point.hpp> #include <boost/utility/enable_if.hpp> #include <boost/typeof/typeof.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> #include <boost/accumulators/numeric/functional_fwd.hpp> #include <boost/accumulators/numeric/detail/function1.hpp> #include <boost/accumulators/numeric/detail/function2.hpp> @@ -166,6 +167,7 @@ namespace boost { namespace numeric { \ op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance; \ } \ + BOOST_ACCUMULATORS_IGNORE_GLOBAL(Name) \ /**/ /// INTERNAL ONLY @@ -243,14 +245,14 @@ namespace boost { namespace numeric }; template<typename Left, typename Right, typename EnableIf> - struct average_base + struct fdiv_base : functional::divides<Left, Right> {}; // partial specialization that promotes the arguments to double for // integral division. template<typename Left, typename Right> - struct average_base<Left, Right, typename enable_if<are_integral<Left, Right> >::type> + struct fdiv_base<Left, Right, typename enable_if<are_integral<Left, Right> >::type> : functional::divides<double const, double const> {}; @@ -346,8 +348,15 @@ namespace boost { namespace numeric {}; template<typename Left, typename Right, typename LeftTag, typename RightTag> + struct fdiv + : fdiv_base<Left, Right, void> + {}; + + /// INTERNAL ONLY + /// For back-compat only. Use fdiv. + template<typename Left, typename Right, typename LeftTag, typename RightTag> struct average - : average_base<Left, Right, void> + : fdiv<Left, Right, LeftTag, RightTag> {}; template<typename Arg, typename Tag> @@ -386,8 +395,13 @@ namespace boost { namespace numeric : boost::detail::function2<functional::max_assign<_1, _2, functional::tag<_1>, functional::tag<_2> > > {}; + struct fdiv + : boost::detail::function2<functional::fdiv<_1, _2, functional::tag<_1>, functional::tag<_2> > > + {}; + + /// INTERNAL ONLY struct average - : boost::detail::function2<functional::average<_1, _2, functional::tag<_1>, functional::tag<_2> > > + : boost::detail::function2<functional::fdiv<_1, _2, functional::tag<_1>, functional::tag<_2> > > {}; struct as_min @@ -411,11 +425,21 @@ namespace boost { namespace numeric { op::min_assign const &min_assign = boost::detail::pod_singleton<op::min_assign>::instance; op::max_assign const &max_assign = boost::detail::pod_singleton<op::max_assign>::instance; - op::average const &average = boost::detail::pod_singleton<op::average>::instance; + op::fdiv const &fdiv = boost::detail::pod_singleton<op::fdiv>::instance; + op::fdiv const &average = boost::detail::pod_singleton<op::fdiv>::instance; ///< INTERNAL ONLY op::as_min const &as_min = boost::detail::pod_singleton<op::as_min>::instance; op::as_max const &as_max = boost::detail::pod_singleton<op::as_max>::instance; op::as_zero const &as_zero = boost::detail::pod_singleton<op::as_zero>::instance; op::as_one const &as_one = boost::detail::pod_singleton<op::as_one>::instance; + + BOOST_ACCUMULATORS_IGNORE_GLOBAL(min_assign) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(max_assign) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(fdiv) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(average) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_min) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_max) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_zero) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_one) } /////////////////////////////////////////////////////////////////////////////// diff --git a/boost/accumulators/numeric/functional/valarray.hpp b/boost/accumulators/numeric/functional/valarray.hpp index 41766a0371..c24b45859d 100644 --- a/boost/accumulators/numeric/functional/valarray.hpp +++ b/boost/accumulators/numeric/functional/valarray.hpp @@ -234,9 +234,9 @@ namespace boost { namespace numeric } }; - // partial specialization of numeric::average<> for std::valarray. + // partial specialization of numeric::fdiv<> for std::valarray. template<typename Left, typename Right, typename RightTag> - struct average<Left, Right, std_valarray_tag, RightTag> + struct fdiv<Left, Right, std_valarray_tag, RightTag> : mpl::if_< are_integral<typename Left::value_type, Right> , divides<Left, double const> diff --git a/boost/accumulators/numeric/functional/vector.hpp b/boost/accumulators/numeric/functional/vector.hpp index cdb234278d..8a68a3f303 100644 --- a/boost/accumulators/numeric/functional/vector.hpp +++ b/boost/accumulators/numeric/functional/vector.hpp @@ -231,7 +231,7 @@ namespace boost { namespace numeric // partial specialization for std::vector. template<typename Left, typename Right> - struct average<Left, Right, std_vector_tag, void> + struct fdiv<Left, Right, std_vector_tag, void> : mpl::if_< are_integral<typename Left::value_type, Right> , divides<Left, double const> diff --git a/boost/accumulators/numeric/functional_fwd.hpp b/boost/accumulators/numeric/functional_fwd.hpp index 940d15b839..501f654b29 100644 --- a/boost/accumulators/numeric/functional_fwd.hpp +++ b/boost/accumulators/numeric/functional_fwd.hpp @@ -141,7 +141,7 @@ namespace boost { namespace numeric template<typename Left, typename Right, typename EnableIf = void> struct max_assign_base; template<typename Left, typename Right, typename EnableIf = void> - struct average_base; + struct fdiv_base; template<typename Arg, typename EnableIf = void> struct as_min_base; template<typename Arg, typename EnableIf = void> @@ -158,7 +158,7 @@ namespace boost { namespace numeric template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type> struct max_assign; template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type> - struct average; + struct fdiv; template<typename Arg, typename Tag = typename tag<Arg>::type> struct as_min; template<typename Arg, typename Tag = typename tag<Arg>::type> @@ -175,7 +175,7 @@ namespace boost { namespace numeric struct promote; struct min_assign; struct max_assign; - struct average; + struct fdiv; struct as_min; struct as_max; struct as_zero; @@ -186,7 +186,7 @@ namespace boost { namespace numeric { extern op::min_assign const &min_assign; extern op::max_assign const &max_assign; - extern op::average const &average; + extern op::fdiv const &fdiv; extern op::as_min const &as_min; extern op::as_max const &as_max; extern op::as_zero const &as_zero; diff --git a/boost/accumulators/statistics/covariance.hpp b/boost/accumulators/statistics/covariance.hpp index b34284b046..73c92aebb5 100644 --- a/boost/accumulators/statistics/covariance.hpp +++ b/boost/accumulators/statistics/covariance.hpp @@ -122,8 +122,8 @@ namespace impl struct covariance_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type sample_type; - typedef typename numeric::functional::average<VariateType, std::size_t>::result_type variate_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type sample_type; + typedef typename numeric::functional::fdiv<VariateType, std::size_t>::result_type variate_type; // for boost::result_of typedef typename numeric::functional::outer_product<sample_type, variate_type>::result_type result_type; @@ -131,8 +131,8 @@ namespace impl covariance_impl(Args const &args) : cov_( numeric::outer_product( - numeric::average(args[sample | Sample()], (std::size_t)1) - , numeric::average(args[parameter::keyword<VariateTag>::get() | VariateType()], (std::size_t)1) + numeric::fdiv(args[sample | Sample()], (std::size_t)1) + , numeric::fdiv(args[parameter::keyword<VariateTag>::get() | VariateType()], (std::size_t)1) ) ) { diff --git a/boost/accumulators/statistics/density.hpp b/boost/accumulators/statistics/density.hpp index 8835f47b69..88ca17df79 100644 --- a/boost/accumulators/statistics/density.hpp +++ b/boost/accumulators/statistics/density.hpp @@ -15,6 +15,7 @@ #include <boost/range.hpp> #include <boost/parameter/keyword.hpp> #include <boost/mpl/placeholders.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> #include <boost/accumulators/framework/accumulator_base.hpp> #include <boost/accumulators/framework/extractor.hpp> #include <boost/accumulators/numeric/functional.hpp> @@ -34,6 +35,9 @@ namespace boost { namespace accumulators BOOST_PARAMETER_NESTED_KEYWORD(tag, density_cache_size, cache_size) BOOST_PARAMETER_NESTED_KEYWORD(tag, density_num_bins, num_bins) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(density_cache_size) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(density_num_bins) + namespace impl { /////////////////////////////////////////////////////////////////////////////// @@ -57,7 +61,7 @@ namespace impl struct density_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; typedef std::vector<float_type> array_type; // for boost::result_of @@ -73,8 +77,8 @@ namespace impl , histogram( num_bins + 2 , std::make_pair( - numeric::average(args[sample | Sample()],(std::size_t)1) - , numeric::average(args[sample | Sample()],(std::size_t)1) + numeric::fdiv(args[sample | Sample()],(std::size_t)1) + , numeric::fdiv(args[sample | Sample()],(std::size_t)1) ) ) , is_dirty(true) @@ -95,13 +99,13 @@ namespace impl } // Once cache_size samples have been accumulated, create num_bins bins of same size between - // the minimum and maximum of the cached samples as well as an under- and and an overflow bin. + // the minimum and maximum of the cached samples as well as under and overflow bins. // Store their lower bounds (bin_positions) and fill the bins with the cached samples (samples_in_bin). if (cnt == this->cache_size) { - float_type minimum = numeric::average((min)(args), (std::size_t)1); - float_type maximum = numeric::average((max)(args), (std::size_t)1); - float_type bin_size = numeric::average(maximum - minimum, this->num_bins ); + float_type minimum = numeric::fdiv((min)(args), (std::size_t)1); + float_type maximum = numeric::fdiv((max)(args), (std::size_t)1); + float_type bin_size = numeric::fdiv(maximum - minimum, this->num_bins ); // determine bin positions (their lower bounds) for (std::size_t i = 0; i < this->num_bins + 2; ++i) @@ -173,7 +177,7 @@ namespace impl for (std::size_t i = 0; i < this->num_bins + 2; ++i) { - this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::average(this->samples_in_bin[i], count(args))); + this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::fdiv(this->samples_in_bin[i], count(args))); } } // returns a range of pairs diff --git a/boost/accumulators/statistics/error_of_mean.hpp b/boost/accumulators/statistics/error_of_mean.hpp index 9451d40f73..7cd923d5f4 100644 --- a/boost/accumulators/statistics/error_of_mean.hpp +++ b/boost/accumulators/statistics/error_of_mean.hpp @@ -29,7 +29,7 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; error_of_mean_impl(dont_care) {} @@ -38,7 +38,7 @@ namespace impl { using namespace std; extractor<Variance> const variance = {}; - return sqrt(numeric::average(variance(args), count(args) - 1)); + return sqrt(numeric::fdiv(variance(args), count(args) - 1)); } }; diff --git a/boost/accumulators/statistics/extended_p_square.hpp b/boost/accumulators/statistics/extended_p_square.hpp index e8d4c0456b..e6cc8dc9a1 100644 --- a/boost/accumulators/statistics/extended_p_square.hpp +++ b/boost/accumulators/statistics/extended_p_square.hpp @@ -18,7 +18,7 @@ #include <boost/iterator/permutation_iterator.hpp> #include <boost/parameter/keyword.hpp> #include <boost/mpl/placeholders.hpp> -#include <boost/accumulators/framework/accumulator_base.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> #include <boost/accumulators/framework/extractor.hpp> #include <boost/accumulators/numeric/functional.hpp> #include <boost/accumulators/framework/parameters/sample.hpp> @@ -34,6 +34,8 @@ namespace boost { namespace accumulators // BOOST_PARAMETER_NESTED_KEYWORD(tag, extended_p_square_probabilities, probabilities) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(extended_p_square_probabilities) + namespace impl { /////////////////////////////////////////////////////////////////////////////// @@ -55,9 +57,9 @@ namespace impl K. E. E. Raatikainen, Simultaneous estimation of several quantiles, Simulation, Volume 49, Number 4 (October), 1986, p. 159-164. - The extended \f$ P^2 \f$ algorithm generalizess the \f$ P^2 \f$ algorithm of + The extended \f$ P^2 \f$ algorithm generalizes the \f$ P^2 \f$ algorithm of - R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and + R. Jain and I. Chlamtac, The P^2 algorithm for dynamic calculation of quantiles and histograms without storing observations, Communications of the ACM, Volume 28 (October), Number 10, 1985, p. 1076-1085. @@ -67,7 +69,7 @@ namespace impl struct extended_p_square_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<float_type> array_type; // for boost::result_of typedef iterator_range< @@ -256,7 +258,7 @@ namespace tag typedef accumulators::impl::extended_p_square_impl<mpl::_1> impl; #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED - /// tag::extended_p_square::probabilities named paramter + /// tag::extended_p_square::probabilities named parameter static boost::parameter::keyword<tag::probabilities> const probabilities; #endif }; diff --git a/boost/accumulators/statistics/extended_p_square_quantile.hpp b/boost/accumulators/statistics/extended_p_square_quantile.hpp index 09ffef2963..a17843d774 100644 --- a/boost/accumulators/statistics/extended_p_square_quantile.hpp +++ b/boost/accumulators/statistics/extended_p_square_quantile.hpp @@ -57,7 +57,7 @@ namespace impl struct extended_p_square_quantile_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<float_type> array_type; typedef iterator_range< detail::lvalue_index_iterator< @@ -137,7 +137,7 @@ namespace impl float_type h1 = *iter_heights; float_type h0 = *(iter_heights - 1); - float_type a = numeric::average(h1 - h0, p1 - p0); + float_type a = numeric::fdiv(h1 - h0, p1 - p0); float_type b = h1 - p1 * a; res = a * this->probability + b; @@ -169,12 +169,12 @@ namespace impl h2 = *iter_heights; } - float_type hp21 = numeric::average(h2 - h1, p2 - p1); - float_type hp10 = numeric::average(h1 - h0, p1 - p0); - float_type p21 = numeric::average(p2 * p2 - p1 * p1, p2 - p1); - float_type p10 = numeric::average(p1 * p1 - p0 * p0, p1 - p0); + float_type hp21 = numeric::fdiv(h2 - h1, p2 - p1); + float_type hp10 = numeric::fdiv(h1 - h0, p1 - p0); + float_type p21 = numeric::fdiv(p2 * p2 - p1 * p1, p2 - p1); + float_type p10 = numeric::fdiv(p1 * p1 - p0 * p0, p1 - p0); - float_type a = numeric::average(hp21 - hp10, p21 - p10); + float_type a = numeric::fdiv(hp21 - hp10, p21 - p10); float_type b = hp21 - a * p21; float_type c = h2 - a * p2 * p2 - b * p2; diff --git a/boost/accumulators/statistics/kurtosis.hpp b/boost/accumulators/statistics/kurtosis.hpp index 4c5c23d5d7..76c93d3850 100644 --- a/boost/accumulators/statistics/kurtosis.hpp +++ b/boost/accumulators/statistics/kurtosis.hpp @@ -47,14 +47,14 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, Sample>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type; kurtosis_impl(dont_care) {} template<typename Args> result_type result(Args const &args) const { - return numeric::average( + return numeric::fdiv( accumulators::moment<4>(args) - 4. * accumulators::moment<3>(args) * mean(args) + 6. * accumulators::moment<2>(args) * mean(args) * mean(args) diff --git a/boost/accumulators/statistics/mean.hpp b/boost/accumulators/statistics/mean.hpp index 0b3ba5e7cd..4788837184 100644 --- a/boost/accumulators/statistics/mean.hpp +++ b/boost/accumulators/statistics/mean.hpp @@ -31,7 +31,7 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; mean_impl(dont_care) {} @@ -39,7 +39,7 @@ namespace impl result_type result(Args const &args) const { extractor<SumFeature> sum; - return numeric::average(sum(args), count(args)); + return numeric::fdiv(sum(args), count(args)); } }; @@ -48,11 +48,11 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; template<typename Args> immediate_mean_impl(Args const &args) - : mean(numeric::average(args[sample | Sample()], numeric::one<std::size_t>::value)) + : mean(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value)) { } @@ -60,7 +60,7 @@ namespace impl void operator ()(Args const &args) { std::size_t cnt = count(args); - this->mean = numeric::average( + this->mean = numeric::fdiv( (this->mean * (cnt - 1)) + args[parameter::keyword<Tag>::get()] , cnt ); diff --git a/boost/accumulators/statistics/median.hpp b/boost/accumulators/statistics/median.hpp index 919cf69e4f..d361c6dda4 100644 --- a/boost/accumulators/statistics/median.hpp +++ b/boost/accumulators/statistics/median.hpp @@ -39,7 +39,7 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; median_impl(dont_care) {} @@ -63,7 +63,7 @@ namespace impl struct with_density_median_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; typedef iterator_range<typename histogram_type::iterator> range_type; // for boost::result_of @@ -71,7 +71,7 @@ namespace impl template<typename Args> with_density_median_impl(Args const &args) - : sum(numeric::average(args[sample | Sample()], (std::size_t)1)) + : sum(numeric::fdiv(args[sample | Sample()], (std::size_t)1)) , is_dirty(true) { } @@ -98,7 +98,7 @@ namespace impl ++it; } --it; - float_type over = numeric::average(this->sum - 0.5 * cnt, it->second * cnt); + float_type over = numeric::fdiv(this->sum - 0.5 * cnt, it->second * cnt); this->median = it->first * over + (it + 1)->first * (1. - over); } @@ -125,7 +125,7 @@ namespace impl struct with_p_square_cumulative_distribution_median_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; typedef iterator_range<typename histogram_type::iterator> range_type; // for boost::result_of @@ -154,7 +154,7 @@ namespace impl { ++it; } - float_type over = numeric::average(it->second - 0.5, it->second - (it - 1)->second); + float_type over = numeric::fdiv(it->second - 0.5, it->second - (it - 1)->second); this->median = it->first * over + (it + 1)->first * ( 1. - over ); } diff --git a/boost/accumulators/statistics/moment.hpp b/boost/accumulators/statistics/moment.hpp index 20421730c3..3dabd47ecf 100644 --- a/boost/accumulators/statistics/moment.hpp +++ b/boost/accumulators/statistics/moment.hpp @@ -55,7 +55,7 @@ namespace impl { BOOST_MPL_ASSERT_RELATION(N::value, >, 0); // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; template<typename Args> moment_impl(Args const &args) @@ -72,7 +72,7 @@ namespace impl template<typename Args> result_type result(Args const &args) const { - return numeric::average(this->sum, count(args)); + return numeric::fdiv(this->sum, count(args)); } private: diff --git a/boost/accumulators/statistics/p_square_cumul_dist.hpp b/boost/accumulators/statistics/p_square_cumul_dist.hpp index b9e24f676c..50692838c7 100644 --- a/boost/accumulators/statistics/p_square_cumul_dist.hpp +++ b/boost/accumulators/statistics/p_square_cumul_dist.hpp @@ -13,6 +13,7 @@ #include <boost/parameter/keyword.hpp> #include <boost/range.hpp> #include <boost/mpl/placeholders.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> #include <boost/accumulators/framework/accumulator_base.hpp> #include <boost/accumulators/framework/extractor.hpp> #include <boost/accumulators/numeric/functional.hpp> @@ -27,6 +28,8 @@ namespace boost { namespace accumulators // BOOST_PARAMETER_NESTED_KEYWORD(tag, p_square_cumulative_distribution_num_cells, num_cells) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(p_square_cumulative_distribution_num_cells) + namespace impl { /////////////////////////////////////////////////////////////////////////////// @@ -41,7 +44,7 @@ namespace impl For further details, see - R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and + R. Jain and I. Chlamtac, The P^2 algorithm for dynamic calculation of quantiles and histograms without storing observations, Communications of the ACM, Volume 28 (October), Number 10, 1985, p. 1076-1085. @@ -51,7 +54,7 @@ namespace impl struct p_square_cumulative_distribution_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<float_type> array_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; // for boost::result_of @@ -73,7 +76,7 @@ namespace impl { this->actual_positions[i] = i + 1.; this->desired_positions[i] = i + 1.; - this->positions_increments[i] = numeric::average(i, b); + this->positions_increments[i] = numeric::fdiv(i, b); } } @@ -195,7 +198,7 @@ namespace impl for (std::size_t i = 0; i < this->histogram.size(); ++i) { - this->histogram[i] = std::make_pair(this->heights[i], numeric::average(this->actual_positions[i], cnt)); + this->histogram[i] = std::make_pair(this->heights[i], numeric::fdiv(this->actual_positions[i], cnt)); } } //return histogram; diff --git a/boost/accumulators/statistics/p_square_quantile.hpp b/boost/accumulators/statistics/p_square_quantile.hpp index 844dfa7728..636fea7f23 100644 --- a/boost/accumulators/statistics/p_square_quantile.hpp +++ b/boost/accumulators/statistics/p_square_quantile.hpp @@ -44,7 +44,7 @@ namespace impl For further details, see - R. Jain and I. Chlamtac, The P^2 algorithmus fordynamic calculation of quantiles and + R. Jain and I. Chlamtac, The P^2 algorithm for dynamic calculation of quantiles and histograms without storing observations, Communications of the ACM, Volume 28 (October), Number 10, 1985, p. 1076-1085. @@ -54,7 +54,7 @@ namespace impl struct p_square_quantile_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef array<float_type, 5> array_type; // for boost::result_of typedef float_type result_type; @@ -69,7 +69,7 @@ namespace impl { for(std::size_t i = 0; i < 5; ++i) { - this->actual_positions[i] = i + 1; + this->actual_positions[i] = i + 1.; } this->desired_positions[0] = 1.; @@ -105,7 +105,7 @@ namespace impl { std::size_t sample_cell = 1; // k - // find cell k such that heights[k-1] <= args[sample] < heights[k] and ajust extreme values + // find cell k such that heights[k-1] <= args[sample] < heights[k] and adjust extreme values if (args[sample] < this->heights[0]) { this->heights[0] = args[sample]; diff --git a/boost/accumulators/statistics/parameters/quantile_probability.hpp b/boost/accumulators/statistics/parameters/quantile_probability.hpp index be68f8955e..e8792642ec 100644 --- a/boost/accumulators/statistics/parameters/quantile_probability.hpp +++ b/boost/accumulators/statistics/parameters/quantile_probability.hpp @@ -9,12 +9,15 @@ #define BOOST_ACCUMULATORS_STATISTICS_PARAMETERS_QUANTILE_PROBABILITY_HPP_EAN_03_11_2005 #include <boost/parameter/keyword.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> namespace boost { namespace accumulators { BOOST_PARAMETER_KEYWORD(tag, quantile_probability) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(quantile_probability) + }} // namespace boost::accumulators #endif diff --git a/boost/accumulators/statistics/peaks_over_threshold.hpp b/boost/accumulators/statistics/peaks_over_threshold.hpp index 01f36f91e6..f04f743a0c 100644 --- a/boost/accumulators/statistics/peaks_over_threshold.hpp +++ b/boost/accumulators/statistics/peaks_over_threshold.hpp @@ -22,6 +22,7 @@ #include <boost/mpl/placeholders.hpp> #include <boost/parameter/keyword.hpp> #include <boost/tuple/tuple.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> #include <boost/accumulators/framework/accumulator_base.hpp> #include <boost/accumulators/framework/extractor.hpp> #include <boost/accumulators/numeric/functional.hpp> @@ -46,6 +47,9 @@ namespace boost { namespace accumulators BOOST_PARAMETER_NESTED_KEYWORD(tag, pot_threshold_value, threshold_value) BOOST_PARAMETER_NESTED_KEYWORD(tag, pot_threshold_probability, threshold_probability) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(pot_threshold_value) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(pot_threshold_probability) + namespace impl { /////////////////////////////////////////////////////////////////////////////// @@ -121,7 +125,7 @@ namespace impl struct peaks_over_threshold_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; // for boost::result_of typedef boost::tuple<float_type, float_type, float_type> result_type; // for left tail fitting, mirror the extreme values @@ -130,8 +134,8 @@ namespace impl template<typename Args> peaks_over_threshold_impl(Args const &args) : Nu_(0) - , mu_(sign::value * numeric::average(args[sample | Sample()], (std::size_t)1)) - , sigma2_(numeric::average(args[sample | Sample()], (std::size_t)1)) + , mu_(sign::value * numeric::fdiv(args[sample | Sample()], (std::size_t)1)) + , sigma2_(numeric::fdiv(args[sample | Sample()], (std::size_t)1)) , threshold_(sign::value * args[pot_threshold_value]) , fit_parameters_(boost::make_tuple(0., 0., 0.)) , is_dirty_(true) @@ -160,13 +164,13 @@ namespace impl std::size_t cnt = count(args); - this->mu_ = sign::value * numeric::average(this->mu_, this->Nu_); - this->sigma2_ = numeric::average(this->sigma2_, this->Nu_); + this->mu_ = sign::value * numeric::fdiv(this->mu_, this->Nu_); + this->sigma2_ = numeric::fdiv(this->sigma2_, this->Nu_); this->sigma2_ -= this->mu_ * this->mu_; - float_type threshold_probability = numeric::average(cnt - this->Nu_, cnt); + float_type threshold_probability = numeric::fdiv(cnt - this->Nu_, cnt); - float_type tmp = numeric::average(( this->mu_ - this->threshold_ )*( this->mu_ - this->threshold_ ), this->sigma2_); + float_type tmp = numeric::fdiv(( this->mu_ - this->threshold_ )*( this->mu_ - this->threshold_ ), this->sigma2_); float_type xi_hat = 0.5 * ( 1. - tmp ); float_type beta_hat = 0.5 * ( this->mu_ - this->threshold_ ) * ( 1. + tmp ); float_type beta_bar = beta_hat * std::pow(1. - threshold_probability, xi_hat); @@ -201,7 +205,7 @@ namespace impl struct peaks_over_threshold_prob_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; // for boost::result_of typedef boost::tuple<float_type, float_type, float_type> result_type; // for left tail fitting, mirror the extreme values @@ -209,8 +213,8 @@ namespace impl template<typename Args> peaks_over_threshold_prob_impl(Args const &args) - : mu_(sign::value * numeric::average(args[sample | Sample()], (std::size_t)1)) - , sigma2_(numeric::average(args[sample | Sample()], (std::size_t)1)) + : mu_(sign::value * numeric::fdiv(args[sample | Sample()], (std::size_t)1)) + , sigma2_(numeric::fdiv(args[sample | Sample()], (std::size_t)1)) , threshold_probability_(args[pot_threshold_probability]) , fit_parameters_(boost::make_tuple(0., 0., 0.)) , is_dirty_(true) @@ -268,14 +272,14 @@ namespace impl sigma2_ += *(tail(args).begin() + i) * (*(tail(args).begin() + i)); } - this->mu_ = sign::value * numeric::average(this->mu_, n); - this->sigma2_ = numeric::average(this->sigma2_, n); + this->mu_ = sign::value * numeric::fdiv(this->mu_, n); + this->sigma2_ = numeric::fdiv(this->sigma2_, n); this->sigma2_ -= this->mu_ * this->mu_; if (is_same<LeftRight, left>::value) this->threshold_probability_ = 1. - this->threshold_probability_; - float_type tmp = numeric::average(( this->mu_ - u )*( this->mu_ - u ), this->sigma2_); + float_type tmp = numeric::fdiv(( this->mu_ - u )*( this->mu_ - u ), this->sigma2_); float_type xi_hat = 0.5 * ( 1. - tmp ); float_type beta_hat = 0.5 * ( this->mu_ - u ) * ( 1. + tmp ); float_type beta_bar = beta_hat * std::pow(1. - threshold_probability_, xi_hat); diff --git a/boost/accumulators/statistics/pot_quantile.hpp b/boost/accumulators/statistics/pot_quantile.hpp index aceff8cee5..470bdbace3 100644 --- a/boost/accumulators/statistics/pot_quantile.hpp +++ b/boost/accumulators/statistics/pot_quantile.hpp @@ -49,7 +49,7 @@ namespace impl struct pot_quantile_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; // for boost::result_of typedef float_type result_type; diff --git a/boost/accumulators/statistics/pot_tail_mean.hpp b/boost/accumulators/statistics/pot_tail_mean.hpp index 088ef98093..a78043fce2 100644 --- a/boost/accumulators/statistics/pot_tail_mean.hpp +++ b/boost/accumulators/statistics/pot_tail_mean.hpp @@ -52,7 +52,7 @@ namespace impl struct pot_tail_mean_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; // for boost::result_of typedef float_type result_type; diff --git a/boost/accumulators/statistics/rolling_mean.hpp b/boost/accumulators/statistics/rolling_mean.hpp index ddcbaa39b9..1439da1e2c 100644 --- a/boost/accumulators/statistics/rolling_mean.hpp +++ b/boost/accumulators/statistics/rolling_mean.hpp @@ -1,9 +1,10 @@ /////////////////////////////////////////////////////////////////////////////// // rolling_mean.hpp -// -// Copyright 2008 Eric Niebler. 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) +// Copyright (C) 2008 Eric Niebler. +// Copyright (C) 2012 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_26_12_2008 #define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MEAN_HPP_EAN_26_12_2008 @@ -20,62 +21,159 @@ namespace boost { namespace accumulators { + namespace impl + { + /////////////////////////////////////////////////////////////////////////////// + // lazy_rolling_mean_impl + // returns the mean over the rolling window and is calculated only + // when the result is requested + template<typename Sample> + struct lazy_rolling_mean_impl + : accumulator_base + { + // for boost::result_of + typedef typename numeric::functional::fdiv<Sample, std::size_t, void, void>::result_type result_type; -namespace impl -{ + lazy_rolling_mean_impl(dont_care) + { + } - /////////////////////////////////////////////////////////////////////////////// - // rolling_mean_impl - // returns the unshifted results from the shifted rolling window - template<typename Sample> - struct rolling_mean_impl - : accumulator_base - { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + template<typename Args> + result_type result(Args const &args) const + { + return numeric::fdiv(rolling_sum(args), rolling_count(args)); + } + }; - rolling_mean_impl(dont_care) - {} + /////////////////////////////////////////////////////////////////////////////// + // immediate_rolling_mean_impl + // The non-lazy version computes the rolling mean recursively when a new + // sample is added + template<typename Sample> + struct immediate_rolling_mean_impl + : accumulator_base + { + // for boost::result_of + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; - template<typename Args> - result_type result(Args const &args) const - { - return numeric::average(rolling_sum(args), rolling_count(args)); - } - }; + template<typename Args> + immediate_rolling_mean_impl(Args const &args) + : mean_(numeric::fdiv(args[sample | Sample()],numeric::one<std::size_t>::value)) + { + } -} // namespace impl + template<typename Args> + void operator()(Args const &args) + { + if(is_rolling_window_plus1_full(args)) + { + mean_ += numeric::fdiv(args[sample]-rolling_window_plus1(args).front(),rolling_count(args)); + } + else + { + result_type prev_mean = mean_; + mean_ += numeric::fdiv(args[sample]-prev_mean,rolling_count(args)); + } + } -/////////////////////////////////////////////////////////////////////////////// -// tag::rolling_mean -// -namespace tag -{ - struct rolling_mean - : depends_on< rolling_sum, 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<tag::rolling_window_size> const window_size; - #endif - }; -} // namespace tag + template<typename Args> + result_type result(Args const &) const + { + return mean_; + } -/////////////////////////////////////////////////////////////////////////////// -// extract::rolling_mean -// -namespace extract -{ - extractor<tag::rolling_mean> const rolling_mean = {}; + private: - BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_mean) -} + result_type mean_; + }; + } // namespace impl -using extract::rolling_mean; + /////////////////////////////////////////////////////////////////////////////// + // tag::lazy_rolling_mean + // tag::immediate_rolling_mean + // tag::rolling_mean + // + namespace tag + { + struct lazy_rolling_mean + : depends_on< rolling_sum, rolling_count > + { + /// INTERNAL ONLY + /// + typedef accumulators::impl::lazy_rolling_mean_impl< mpl::_1 > impl; -}} // namespace boost::accumulators +#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED + /// tag::rolling_window::window_size named parameter + static boost::parameter::keyword<tag::rolling_window_size> const window_size; +#endif + }; + struct immediate_rolling_mean + : depends_on< rolling_window_plus1, rolling_count> + { + /// INTERNAL ONLY + /// + typedef accumulators::impl::immediate_rolling_mean_impl< mpl::_1> impl; + +#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED + /// tag::rolling_window::window_size named parameter + static boost::parameter::keyword<tag::rolling_window_size> const window_size; #endif + }; + + // make immediate_rolling_mean the default implementation + struct rolling_mean : immediate_rolling_mean {}; + } // namespace tag + + /////////////////////////////////////////////////////////////////////////////// + // extract::lazy_rolling_mean + // extract::immediate_rolling_mean + // extract::rolling_mean + // + namespace extract + { + extractor<tag::lazy_rolling_mean> const lazy_rolling_mean = {}; + extractor<tag::immediate_rolling_mean> const immediate_rolling_mean = {}; + extractor<tag::rolling_mean> const rolling_mean = {}; + + BOOST_ACCUMULATORS_IGNORE_GLOBAL(lazy_rolling_mean) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(immediate_rolling_mean) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_mean) + } + + using extract::lazy_rolling_mean; + using extract::immediate_rolling_mean; + using extract::rolling_mean; + + // rolling_mean(lazy) -> lazy_rolling_mean + template<> + struct as_feature<tag::rolling_mean(lazy)> + { + typedef tag::lazy_rolling_mean type; + }; + + // rolling_mean(immediate) -> immediate_rolling_mean + template<> + struct as_feature<tag::rolling_mean(immediate)> + { + typedef tag::immediate_rolling_mean type; + }; + + // for the purposes of feature-based dependency resolution, + // immediate_rolling_mean provides the same feature as rolling_mean + template<> + struct feature_of<tag::immediate_rolling_mean> + : feature_of<tag::rolling_mean> + { + }; + + // for the purposes of feature-based dependency resolution, + // lazy_rolling_mean provides the same feature as rolling_mean + template<> + struct feature_of<tag::lazy_rolling_mean> + : feature_of<tag::rolling_mean> + { + }; +}} // namespace boost::accumulators + +#endif
\ No newline at end of file diff --git a/boost/accumulators/statistics/rolling_moment.hpp b/boost/accumulators/statistics/rolling_moment.hpp new file mode 100644 index 0000000000..f172cee34f --- /dev/null +++ b/boost/accumulators/statistics/rolling_moment.hpp @@ -0,0 +1,113 @@ +/////////////////////////////////////////////////////////////////////////////// +// rolling_moment.hpp +// Copyright 2005 Eric Niebler. +// Copyright (C) 2014 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_MOMENT_HPP_EAN_27_11_2005 +#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005 + +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/accumulators/framework/accumulator_base.hpp> +#include <boost/accumulators/framework/extractor.hpp> +#include <boost/accumulators/numeric/functional.hpp> +#include <boost/accumulators/framework/parameters/sample.hpp> +#include <boost/accumulators/framework/depends_on.hpp> +#include <boost/accumulators/statistics_fwd.hpp> +#include <boost/accumulators/statistics/moment.hpp> +#include <boost/accumulators/statistics/rolling_count.hpp> + +namespace boost { namespace accumulators +{ +namespace impl +{ + /////////////////////////////////////////////////////////////////////////////// + // rolling_moment_impl + template<typename N, typename Sample> + struct rolling_moment_impl + : accumulator_base + { + BOOST_MPL_ASSERT_RELATION(N::value, >, 0); + // for boost::result_of + typedef typename numeric::functional::fdiv<Sample, std::size_t,void,void>::result_type result_type; + + template<typename Args> + rolling_moment_impl(Args const &args) + : sum_(args[sample | Sample()]) + { + } + + template<typename Args> + void operator ()(Args const &args) + { + if(is_rolling_window_plus1_full(args)) + { + this->sum_ -= numeric::pow(rolling_window_plus1(args).front(), N()); + } + this->sum_ += numeric::pow(args[sample], N()); + } + + template<typename Args> + result_type result(Args const &args) const + { + return numeric::fdiv(this->sum_, rolling_count(args)); + } + + private: + result_type sum_; + }; +} // namespace impl + +/////////////////////////////////////////////////////////////////////////////// +// tag::rolling_moment +// +namespace tag +{ + template<int N> + struct rolling_moment + : depends_on< rolling_window_plus1, rolling_count> + { + /// INTERNAL ONLY + /// + typedef accumulators::impl::rolling_moment_impl<mpl::int_<N>, mpl::_1> impl; + + #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED + /// tag::rolling_window::window_size named parameter + static boost::parameter::keyword<tag::rolling_window_size> const window_size; + #endif + }; +} + +/////////////////////////////////////////////////////////////////////////////// +// extract::rolling_moment +// +namespace extract +{ + BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, rolling_moment, (int)) +} + +using extract::rolling_moment; + +// There is no weighted_rolling_moment (yet)... +// +//// So that rolling_moment<N> can be automatically substituted with +//// weighted_rolling_moment<N> when the weight parameter is non-void +//template<int N> +//struct as_weighted_feature<tag::rolling_moment<N> > +//{ +// typedef tag::weighted_rolling_moment<N> type; +//}; +// +//template<int N> +//struct feature_of<tag::weighted_rolling_moment<N> > +// : feature_of<tag::rolling_moment<N> > +//{ +//}; +}} // namespace boost::accumulators + +#endif diff --git a/boost/accumulators/statistics/rolling_sum.hpp b/boost/accumulators/statistics/rolling_sum.hpp index b41ab39e33..bbb7a8e9a0 100644 --- a/boost/accumulators/statistics/rolling_sum.hpp +++ b/boost/accumulators/statistics/rolling_sum.hpp @@ -19,7 +19,6 @@ namespace boost { namespace accumulators { - namespace impl { /////////////////////////////////////////////////////////////////////////////// @@ -47,7 +46,7 @@ namespace impl } template<typename Args> - result_type result(Args const &args) const + result_type result(Args const & /*args*/) const { return this->sum_; } @@ -87,7 +86,6 @@ namespace extract } using extract::rolling_sum; - }} // namespace boost::accumulators #endif diff --git a/boost/accumulators/statistics/rolling_variance.hpp b/boost/accumulators/statistics/rolling_variance.hpp new file mode 100644 index 0000000000..33b3922a50 --- /dev/null +++ b/boost/accumulators/statistics/rolling_variance.hpp @@ -0,0 +1,247 @@ +/////////////////////////////////////////////////////////////////////////////// +// rolling_variance.hpp +// Copyright (C) 2005 Eric Niebler +// Copyright (C) 2014 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_VARIANCE_HPP_EAN_15_11_2011 +#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_VARIANCE_HPP_EAN_15_11_2011 + +#include <boost/accumulators/accumulators.hpp> +#include <boost/accumulators/statistics/stats.hpp> + +#include <boost/mpl/placeholders.hpp> +#include <boost/accumulators/framework/accumulator_base.hpp> +#include <boost/accumulators/framework/extractor.hpp> +#include <boost/accumulators/numeric/functional.hpp> +#include <boost/accumulators/framework/parameters/sample.hpp> +#include <boost/accumulators/framework/depends_on.hpp> +#include <boost/accumulators/statistics_fwd.hpp> +#include <boost/accumulators/statistics/rolling_mean.hpp> +#include <boost/accumulators/statistics/rolling_moment.hpp> + +#include <boost/type_traits/is_arithmetic.hpp> +#include <boost/utility/enable_if.hpp> + +namespace boost { namespace accumulators +{ +namespace impl +{ + //! Immediate (lazy) calculation of the rolling variance. + /*! + Calculation of sample variance \f$\sigma_n^2\f$ is done as follows, see also + http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance. + For a rolling window of size \f$N\f$, when \f$n <= N\f$, the variance is computed according to the formula + \f[ + \sigma_n^2 = \frac{1}{n-1} \sum_{i = 1}^n (x_i - \mu_n)^2. + \f] + When \f$n > N\f$, the sample variance over the window becomes: + \f[ + \sigma_n^2 = \frac{1}{N-1} \sum_{i = n-N+1}^n (x_i - \mu_n)^2. + \f] + */ + /////////////////////////////////////////////////////////////////////////////// + // lazy_rolling_variance_impl + // + template<typename Sample> + struct lazy_rolling_variance_impl + : accumulator_base + { + // for boost::result_of + typedef typename numeric::functional::fdiv<Sample, std::size_t,void,void>::result_type result_type; + + lazy_rolling_variance_impl(dont_care) {} + + template<typename Args> + result_type result(Args const &args) const + { + result_type mean = rolling_mean(args); + size_t nr_samples = rolling_count(args); + if (nr_samples < 2) return result_type(); + return nr_samples*(rolling_moment<2>(args) - mean*mean)/(nr_samples-1); + } + }; + + //! Iterative calculation of the rolling variance. + /*! + Iterative calculation of sample variance \f$\sigma_n^2\f$ is done as follows, see also + http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance. + For a rolling window of size \f$N\f$, for the first \f$N\f$ samples, the variance is computed according to the formula + \f[ + \sigma_n^2 = \frac{1}{n-1} \sum_{i = 1}^n (x_i - \mu_n)^2 = \frac{1}{n-1}M_{2,n}, + \f] + where the sum of squares \f$M_{2,n}\f$ can be recursively computed as: + \f[ + M_{2,n} = \sum_{i = 1}^n (x_i - \mu_n)^2 = M_{2,n-1} + (x_n - \mu_n)(x_n - \mu_{n-1}), + \f] + and the estimate of the sample mean as: + \f[ + \mu_n = \frac{1}{n} \sum_{i = 1}^n x_i = \mu_{n-1} + \frac{1}{n}(x_n - \mu_{n-1}). + \f] + For further samples, when the rolling window is fully filled with data, one has to take into account that the oldest + sample \f$x_{n-N}\f$ is dropped from the window. The sample variance over the window now becomes: + \f[ + \sigma_n^2 = \frac{1}{N-1} \sum_{i = n-N+1}^n (x_i - \mu_n)^2 = \frac{1}{n-1}M_{2,n}, + \f] + where the sum of squares \f$M_{2,n}\f$ now equals: + \f[ + M_{2,n} = \sum_{i = n-N+1}^n (x_i - \mu_n)^2 = M_{2,n-1} + (x_n - \mu_n)(x_n - \mu_{n-1}) - (x_{n-N} - \mu_n)(x_{n-N} - \mu_{n-1}), + \f] + and the estimated mean is: + \f[ + \mu_n = \frac{1}{N} \sum_{i = n-N+1}^n x_i = \mu_{n-1} + \frac{1}{n}(x_n - x_{n-N}). + \f] + + Note that the sample variance is not defined for \f$n <= 1\f$. + + */ + /////////////////////////////////////////////////////////////////////////////// + // immediate_rolling_variance_impl + // + template<typename Sample> + struct immediate_rolling_variance_impl + : accumulator_base + { + // for boost::result_of + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; + + template<typename Args> + immediate_rolling_variance_impl(Args const &args) + : previous_mean_(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value)) + , sum_of_squares_(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value)) + { + } + + template<typename Args> + void operator()(Args const &args) + { + Sample added_sample = args[sample]; + + result_type mean = immediate_rolling_mean(args); + sum_of_squares_ += (added_sample-mean)*(added_sample-previous_mean_); + + if(is_rolling_window_plus1_full(args)) + { + Sample removed_sample = rolling_window_plus1(args).front(); + sum_of_squares_ -= (removed_sample-mean)*(removed_sample-previous_mean_); + prevent_underflow(sum_of_squares_); + } + previous_mean_ = mean; + } + + template<typename Args> + result_type result(Args const &args) const + { + size_t nr_samples = rolling_count(args); + if (nr_samples < 2) return result_type(); + return numeric::fdiv(sum_of_squares_,(nr_samples-1)); + } + + private: + + result_type previous_mean_; + result_type sum_of_squares_; + + template<typename T> + void prevent_underflow(T &non_negative_number,typename boost::enable_if<boost::is_arithmetic<T>,T>::type* = 0) + { + if (non_negative_number < T(0)) non_negative_number = T(0); + } + template<typename T> + void prevent_underflow(T &non_arithmetic_quantity,typename boost::disable_if<boost::is_arithmetic<T>,T>::type* = 0) + { + } + }; +} // namespace impl + +/////////////////////////////////////////////////////////////////////////////// +// tag:: lazy_rolling_variance +// tag:: immediate_rolling_variance +// tag:: rolling_variance +// +namespace tag +{ + struct lazy_rolling_variance + : depends_on< rolling_count, rolling_mean, rolling_moment<2> > + { + /// INTERNAL ONLY + /// + typedef accumulators::impl::lazy_rolling_variance_impl< mpl::_1 > impl; + + #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED + /// tag::rolling_window::window_size named parameter + static boost::parameter::keyword<tag::rolling_window_size> const window_size; + #endif + }; + + struct immediate_rolling_variance + : depends_on< rolling_window_plus1, rolling_count, immediate_rolling_mean> + { + /// INTERNAL ONLY + /// + typedef accumulators::impl::immediate_rolling_variance_impl< mpl::_1> impl; + + #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED + /// tag::rolling_window::window_size named parameter + static boost::parameter::keyword<tag::rolling_window_size> const window_size; + #endif + }; + + // make immediate_rolling_variance the default implementation + struct rolling_variance : immediate_rolling_variance {}; +} // namespace tag + +/////////////////////////////////////////////////////////////////////////////// +// extract::lazy_rolling_variance +// extract::immediate_rolling_variance +// extract::rolling_variance +// +namespace extract +{ + extractor<tag::lazy_rolling_variance> const lazy_rolling_variance = {}; + extractor<tag::immediate_rolling_variance> const immediate_rolling_variance = {}; + extractor<tag::rolling_variance> const rolling_variance = {}; + + BOOST_ACCUMULATORS_IGNORE_GLOBAL(lazy_rolling_variance) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(immediate_rolling_variance) + BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_variance) +} + +using extract::lazy_rolling_variance; +using extract::immediate_rolling_variance; +using extract::rolling_variance; + +// rolling_variance(lazy) -> lazy_rolling_variance +template<> +struct as_feature<tag::rolling_variance(lazy)> +{ + typedef tag::lazy_rolling_variance type; +}; + +// rolling_variance(immediate) -> immediate_rolling_variance +template<> +struct as_feature<tag::rolling_variance(immediate)> +{ + typedef tag::immediate_rolling_variance type; +}; + +// for the purposes of feature-based dependency resolution, +// lazy_rolling_variance provides the same feature as rolling_variance +template<> +struct feature_of<tag::lazy_rolling_variance> + : feature_of<tag::rolling_variance> +{ +}; + +// for the purposes of feature-based dependency resolution, +// immediate_rolling_variance provides the same feature as rolling_variance +template<> +struct feature_of<tag::immediate_rolling_variance> + : feature_of<tag::rolling_variance> +{ +}; +}} // namespace boost::accumulators + +#endif diff --git a/boost/accumulators/statistics/rolling_window.hpp b/boost/accumulators/statistics/rolling_window.hpp index d2f4b0dfe1..2e0a33420a 100644 --- a/boost/accumulators/statistics/rolling_window.hpp +++ b/boost/accumulators/statistics/rolling_window.hpp @@ -13,6 +13,7 @@ #include <boost/assert.hpp> #include <boost/circular_buffer.hpp> #include <boost/range/iterator_range.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> #include <boost/accumulators/framework/extractor.hpp> #include <boost/accumulators/framework/depends_on.hpp> #include <boost/accumulators/framework/accumulator_base.hpp> @@ -28,6 +29,8 @@ namespace boost { namespace accumulators // tag::rolling_window::size named parameter BOOST_PARAMETER_NESTED_KEYWORD(tag, rolling_window_size, window_size) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_window_size) + namespace impl { /////////////////////////////////////////////////////////////////////////////// diff --git a/boost/accumulators/statistics/skewness.hpp b/boost/accumulators/statistics/skewness.hpp index 2e29018f5d..c383ec4a6c 100644 --- a/boost/accumulators/statistics/skewness.hpp +++ b/boost/accumulators/statistics/skewness.hpp @@ -31,7 +31,7 @@ namespace impl @brief Skewness estimation The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the \f$ 3/2 \f$-th power - of the 2nd central moment (the variance) of the sampless 3. The skewness can also be expressed by the simple moments: + of the 2nd central moment (the variance) of the samples 3. The skewness can also be expressed by the simple moments: \f[ \hat{g}_1 = @@ -48,7 +48,7 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, Sample>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type; skewness_impl(dont_care) { @@ -57,7 +57,7 @@ namespace impl template<typename Args> result_type result(Args const &args) const { - return numeric::average( + return numeric::fdiv( accumulators::moment<3>(args) - 3. * accumulators::moment<2>(args) * mean(args) + 2. * mean(args) * mean(args) * mean(args) diff --git a/boost/accumulators/statistics/tail.hpp b/boost/accumulators/statistics/tail.hpp index 159a9b67db..cc9267f9d4 100644 --- a/boost/accumulators/statistics/tail.hpp +++ b/boost/accumulators/statistics/tail.hpp @@ -18,6 +18,7 @@ #include <boost/parameter/keyword.hpp> #include <boost/iterator/reverse_iterator.hpp> #include <boost/iterator/permutation_iterator.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> #include <boost/accumulators/framework/accumulator_base.hpp> #include <boost/accumulators/framework/extractor.hpp> #include <boost/accumulators/numeric/functional.hpp> @@ -32,6 +33,9 @@ namespace boost { namespace accumulators BOOST_PARAMETER_NESTED_KEYWORD(tag, right_tail_cache_size, cache_size) BOOST_PARAMETER_NESTED_KEYWORD(tag, left_tail_cache_size, cache_size) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(right_tail_cache_size) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(left_tail_cache_size) + namespace detail { /////////////////////////////////////////////////////////////////////////////// diff --git a/boost/accumulators/statistics/tail_mean.hpp b/boost/accumulators/statistics/tail_mean.hpp index 323eeb0f91..67dae37b50 100644 --- a/boost/accumulators/statistics/tail_mean.hpp +++ b/boost/accumulators/statistics/tail_mean.hpp @@ -62,7 +62,7 @@ namespace impl struct coherent_tail_mean_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; // for boost::result_of typedef float_type result_type; @@ -82,10 +82,10 @@ namespace impl extractor<tag::non_coherent_tail_mean<LeftRight> > const some_non_coherent_tail_mean = {}; return some_non_coherent_tail_mean(args) - + numeric::average(quantile(args), n) + + numeric::fdiv(quantile(args), n) * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] - - numeric::average(n, count(args)) + - numeric::fdiv(n, count(args)) ); } }; @@ -117,7 +117,7 @@ namespace impl struct non_coherent_tail_mean_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; // for boost::result_of typedef float_type result_type; @@ -136,7 +136,7 @@ namespace impl // If n is in a valid range, return result, otherwise return NaN or throw exception if (n <= static_cast<std::size_t>(tail(args).size())) - return numeric::average( + return numeric::fdiv( std::accumulate( tail(args).begin() , tail(args).begin() + n diff --git a/boost/accumulators/statistics/tail_quantile.hpp b/boost/accumulators/statistics/tail_quantile.hpp index d3b96b4968..9ff56b56e5 100644 --- a/boost/accumulators/statistics/tail_quantile.hpp +++ b/boost/accumulators/statistics/tail_quantile.hpp @@ -46,7 +46,7 @@ namespace impl @brief Tail quantile estimation based on order statistics (for both left and right tails) The estimation of a tail quantile \f$\hat{q}\f$ with level \f$\alpha\f$ based on order statistics requires the - chaching of at least the \f$\lceil n\alpha\rceil\f$ smallest or the \f$\lceil n(1-\alpha)\rceil\f$ largest samples, + caching of at least the \f$\lceil n\alpha\rceil\f$ smallest or the \f$\lceil n(1-\alpha)\rceil\f$ largest samples, \f$n\f$ being the total number of samples. The largest of the \f$\lceil n\alpha\rceil\f$ smallest samples or the smallest of the \f$\lceil n(1-\alpha)\rceil\f$ largest samples provides an estimate for the quantile: diff --git a/boost/accumulators/statistics/tail_variate_means.hpp b/boost/accumulators/statistics/tail_variate_means.hpp index 98991e217b..d34d4abcd5 100644 --- a/boost/accumulators/statistics/tail_variate_means.hpp +++ b/boost/accumulators/statistics/tail_variate_means.hpp @@ -79,7 +79,7 @@ namespace impl struct tail_variate_means_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<float_type> array_type; // for boost::result_of typedef iterator_range<typename array_type::iterator> result_type; diff --git a/boost/accumulators/statistics/variance.hpp b/boost/accumulators/statistics/variance.hpp index 81807a2621..baac55696b 100644 --- a/boost/accumulators/statistics/variance.hpp +++ b/boost/accumulators/statistics/variance.hpp @@ -42,7 +42,7 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; lazy_variance_impl(dont_care) {} @@ -85,11 +85,11 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; template<typename Args> variance_impl(Args const &args) - : variance(numeric::average(args[sample | Sample()], numeric::one<std::size_t>::value)) + : variance(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value)) { } @@ -103,8 +103,8 @@ namespace impl extractor<MeanFeature> mean; result_type tmp = args[parameter::keyword<Tag>::get()] - mean(args); this->variance = - numeric::average(this->variance * (cnt - 1), cnt) - + numeric::average(tmp * tmp, cnt - 1); + numeric::fdiv(this->variance * (cnt - 1), cnt) + + numeric::fdiv(tmp * tmp, cnt - 1); } } diff --git a/boost/accumulators/statistics/variates/covariate.hpp b/boost/accumulators/statistics/variates/covariate.hpp index eeb4835274..aba113a4a3 100644 --- a/boost/accumulators/statistics/variates/covariate.hpp +++ b/boost/accumulators/statistics/variates/covariate.hpp @@ -9,6 +9,7 @@ #define BOOST_ACCUMULATORS_STATISTICS_VARIATES_COVARIATE_HPP_EAN_03_11_2005 #include <boost/parameter/keyword.hpp> +#include <boost/accumulators/accumulators_fwd.hpp> namespace boost { namespace accumulators { @@ -16,6 +17,9 @@ namespace boost { namespace accumulators BOOST_PARAMETER_KEYWORD(tag, covariate1) BOOST_PARAMETER_KEYWORD(tag, covariate2) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(covariate1) +BOOST_ACCUMULATORS_IGNORE_GLOBAL(covariate2) + }} // namespace boost::accumulators #endif diff --git a/boost/accumulators/statistics/weighted_covariance.hpp b/boost/accumulators/statistics/weighted_covariance.hpp index 83585b1b65..25d613c120 100644 --- a/boost/accumulators/statistics/weighted_covariance.hpp +++ b/boost/accumulators/statistics/weighted_covariance.hpp @@ -57,8 +57,8 @@ namespace impl struct weighted_covariance_impl : accumulator_base { - typedef typename numeric::functional::multiplies<Weight, typename numeric::functional::average<Sample, std::size_t>::result_type>::result_type weighted_sample_type; - typedef typename numeric::functional::multiplies<Weight, typename numeric::functional::average<VariateType, std::size_t>::result_type>::result_type weighted_variate_type; + typedef typename numeric::functional::multiplies<Weight, typename numeric::functional::fdiv<Sample, std::size_t>::result_type>::result_type weighted_sample_type; + typedef typename numeric::functional::multiplies<Weight, typename numeric::functional::fdiv<VariateType, std::size_t>::result_type>::result_type weighted_variate_type; // for boost::result_of typedef typename numeric::functional::outer_product<weighted_sample_type, weighted_variate_type>::result_type result_type; @@ -66,9 +66,9 @@ namespace impl weighted_covariance_impl(Args const &args) : cov_( numeric::outer_product( - numeric::average(args[sample | Sample()], (std::size_t)1) + numeric::fdiv(args[sample | Sample()], (std::size_t)1) * numeric::one<Weight>::value - , numeric::average(args[parameter::keyword<VariateTag>::get() | VariateType()], (std::size_t)1) + , numeric::fdiv(args[parameter::keyword<VariateTag>::get() | VariateType()], (std::size_t)1) * numeric::one<Weight>::value ) ) diff --git a/boost/accumulators/statistics/weighted_density.hpp b/boost/accumulators/statistics/weighted_density.hpp index 68dc639377..1407368016 100644 --- a/boost/accumulators/statistics/weighted_density.hpp +++ b/boost/accumulators/statistics/weighted_density.hpp @@ -50,7 +50,7 @@ namespace impl struct weighted_density_impl : accumulator_base { - typedef typename numeric::functional::average<Weight, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Weight, std::size_t>::result_type float_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; typedef std::vector<float_type> array_type; // for boost::result_of @@ -66,8 +66,8 @@ namespace impl , histogram( num_bins + 2 , std::make_pair( - numeric::average(args[sample | Sample()],(std::size_t)1) - , numeric::average(args[sample | Sample()],(std::size_t)1) + numeric::fdiv(args[sample | Sample()],(std::size_t)1) + , numeric::fdiv(args[sample | Sample()],(std::size_t)1) ) ) , is_dirty(true) @@ -92,9 +92,9 @@ namespace impl // Store their lower bounds (bin_positions) and fill the bins with the cached samples (samples_in_bin). if (cnt == this->cache_size) { - float_type minimum = numeric::average((min)(args),(std::size_t)1); - float_type maximum = numeric::average((max)(args),(std::size_t)1); - float_type bin_size = numeric::average(maximum - minimum, this->num_bins); + float_type minimum = numeric::fdiv((min)(args),(std::size_t)1); + float_type maximum = numeric::fdiv((max)(args),(std::size_t)1); + float_type bin_size = numeric::fdiv(maximum - minimum, this->num_bins); // determine bin positions (their lower bounds) for (std::size_t i = 0; i < this->num_bins + 2; ++i) @@ -163,7 +163,7 @@ namespace impl for (std::size_t i = 0; i < this->num_bins + 2; ++i) { - this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::average(this->samples_in_bin[i], sum_of_weights(args))); + this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::fdiv(this->samples_in_bin[i], sum_of_weights(args))); } } diff --git a/boost/accumulators/statistics/weighted_extended_p_square.hpp b/boost/accumulators/statistics/weighted_extended_p_square.hpp index 7d7f38c77c..ac857e056d 100644 --- a/boost/accumulators/statistics/weighted_extended_p_square.hpp +++ b/boost/accumulators/statistics/weighted_extended_p_square.hpp @@ -54,9 +54,9 @@ namespace impl K. E. E. Raatikainen, Simultaneous estimation of several quantiles, Simulation, Volume 49, Number 4 (October), 1986, p. 159-164. - The extended \f$ P^2 \f$ algorithm generalizess the \f$ P^2 \f$ algorithm of + The extended \f$ P^2 \f$ algorithm generalizes the \f$ P^2 \f$ algorithm of - R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and + R. Jain and I. Chlamtac, The P^2 algorithm for dynamic calculation of quantiles and histograms without storing observations, Communications of the ACM, Volume 28 (October), Number 10, 1985, p. 1076-1085. @@ -67,7 +67,7 @@ namespace impl : accumulator_base { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; - typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type float_type; typedef std::vector<float_type> array_type; // for boost::result_of typedef iterator_range< diff --git a/boost/accumulators/statistics/weighted_kurtosis.hpp b/boost/accumulators/statistics/weighted_kurtosis.hpp index d51db5cd38..3fd4ed7b41 100644 --- a/boost/accumulators/statistics/weighted_kurtosis.hpp +++ b/boost/accumulators/statistics/weighted_kurtosis.hpp @@ -52,7 +52,7 @@ namespace impl { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, weighted_sample>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, weighted_sample>::result_type result_type; weighted_kurtosis_impl(dont_care) { @@ -61,7 +61,7 @@ namespace impl template<typename Args> result_type result(Args const &args) const { - return numeric::average( + return numeric::fdiv( accumulators::weighted_moment<4>(args) - 4. * accumulators::weighted_moment<3>(args) * weighted_mean(args) + 6. * accumulators::weighted_moment<2>(args) * weighted_mean(args) * weighted_mean(args) diff --git a/boost/accumulators/statistics/weighted_mean.hpp b/boost/accumulators/statistics/weighted_mean.hpp index c8d651353a..a80ef0984c 100644 --- a/boost/accumulators/statistics/weighted_mean.hpp +++ b/boost/accumulators/statistics/weighted_mean.hpp @@ -36,7 +36,7 @@ namespace impl { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, Weight>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, Weight>::result_type result_type; weighted_mean_impl(dont_care) {} @@ -53,7 +53,7 @@ namespace impl extractor<weighted_sum_tag> const some_weighted_sum = {}; - return numeric::average(some_weighted_sum(args), sum_of_weights(args)); + return numeric::fdiv(some_weighted_sum(args), sum_of_weights(args)); } }; @@ -66,12 +66,12 @@ namespace impl { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, Weight>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, Weight>::result_type result_type; template<typename Args> immediate_weighted_mean_impl(Args const &args) : mean( - numeric::average( + numeric::fdiv( args[parameter::keyword<Tag>::get() | Sample()] * numeric::one<Weight>::value , numeric::one<Weight>::value @@ -89,7 +89,7 @@ namespace impl Weight w_sum = sum_of_weights(args); Weight w = args[weight]; weighted_sample const &s = args[parameter::keyword<Tag>::get()] * w; - this->mean = numeric::average(this->mean * (w_sum - w) + s, w_sum); + this->mean = numeric::fdiv(this->mean * (w_sum - w) + s, w_sum); } result_type result(dont_care) const diff --git a/boost/accumulators/statistics/weighted_median.hpp b/boost/accumulators/statistics/weighted_median.hpp index b8b94f9f9f..ed7cadb331 100644 --- a/boost/accumulators/statistics/weighted_median.hpp +++ b/boost/accumulators/statistics/weighted_median.hpp @@ -40,7 +40,7 @@ namespace impl : accumulator_base { // for boost::result_of - typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type; weighted_median_impl(dont_care) {} @@ -65,7 +65,7 @@ namespace impl struct with_density_weighted_median_impl : accumulator_base { - typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; typedef iterator_range<typename histogram_type::iterator> range_type; // for boost::result_of @@ -73,7 +73,7 @@ namespace impl template<typename Args> with_density_weighted_median_impl(Args const &args) - : sum(numeric::average(args[sample | Sample()], (std::size_t)1)) + : sum(numeric::fdiv(args[sample | Sample()], (std::size_t)1)) , is_dirty(true) { } @@ -99,7 +99,7 @@ namespace impl ++it; } --it; - float_type over = numeric::average(this->sum - 0.5 * cnt, it->second * cnt); + float_type over = numeric::fdiv(this->sum - 0.5 * cnt, it->second * cnt); this->median = it->first * over + (it + 1)->first * ( 1. - over ); } @@ -127,7 +127,7 @@ namespace impl : accumulator_base { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; - typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type float_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; typedef iterator_range<typename histogram_type::iterator> range_type; // for boost::result_of @@ -156,7 +156,7 @@ namespace impl { ++it; } - float_type over = numeric::average(it->second - 0.5, it->second - (it - 1)->second); + float_type over = numeric::fdiv(it->second - 0.5, it->second - (it - 1)->second); this->median = it->first * over + (it + 1)->first * ( 1. - over ); } diff --git a/boost/accumulators/statistics/weighted_moment.hpp b/boost/accumulators/statistics/weighted_moment.hpp index f49c362d95..011701c704 100644 --- a/boost/accumulators/statistics/weighted_moment.hpp +++ b/boost/accumulators/statistics/weighted_moment.hpp @@ -40,7 +40,7 @@ namespace impl BOOST_MPL_ASSERT_RELATION(N::value, >, 0); typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, Weight>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, Weight>::result_type result_type; template<typename Args> weighted_moment_impl(Args const &args) @@ -57,7 +57,7 @@ namespace impl template<typename Args> result_type result(Args const &args) const { - return numeric::average(this->sum, sum_of_weights(args)); + return numeric::fdiv(this->sum, sum_of_weights(args)); } private: diff --git a/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp b/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp index 832e231414..ce750ed1f5 100644 --- a/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp +++ b/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp @@ -42,7 +42,7 @@ namespace impl For further details, see - R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and + R. Jain and I. Chlamtac, The P^2 algorithm for dynamic calculation of quantiles and histograms without storing observations, Communications of the ACM, Volume 28 (October), Number 10, 1985, p. 1076-1085. @@ -53,7 +53,7 @@ namespace impl : accumulator_base { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; - typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type float_type; typedef std::vector<std::pair<float_type, float_type> > histogram_type; typedef std::vector<float_type> array_type; // for boost::result_of @@ -153,7 +153,7 @@ namespace impl for (std::size_t i = 1; i < b + 1; ++i) { this->desired_positions[i] = this->actual_positions[0] - + numeric::average((i-1) * (sum_of_weights(args) - this->actual_positions[0]), b); + + numeric::fdiv((i-1) * (sum_of_weights(args) - this->actual_positions[0]), b); } // adjust heights of markers 2 to num_cells if necessary @@ -214,7 +214,7 @@ namespace impl for (std::size_t i = 0; i < this->histogram.size(); ++i) { - this->histogram[i] = std::make_pair(this->heights[i], numeric::average(this->actual_positions[i], sum_of_weights(args))); + this->histogram[i] = std::make_pair(this->heights[i], numeric::fdiv(this->actual_positions[i], sum_of_weights(args))); } } diff --git a/boost/accumulators/statistics/weighted_p_square_quantile.hpp b/boost/accumulators/statistics/weighted_p_square_quantile.hpp index 5dc84f4764..2ebc7b1845 100644 --- a/boost/accumulators/statistics/weighted_p_square_quantile.hpp +++ b/boost/accumulators/statistics/weighted_p_square_quantile.hpp @@ -44,7 +44,7 @@ namespace impl { For further details, see - R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and + R. Jain and I. Chlamtac, The P^2 algorithm for dynamic calculation of quantiles and histograms without storing observations, Communications of the ACM, Volume 28 (October), Number 10, 1985, p. 1076-1085. @@ -55,7 +55,7 @@ namespace impl { : accumulator_base { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; - typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type float_type; typedef array<float_type, 5> array_type; // for boost::result_of typedef float_type result_type; @@ -80,7 +80,7 @@ namespace impl { this->heights[cnt - 1] = args[sample]; // In this initialization phase, actual_positions stores the weights of the - // inital samples that are needed at the end of the initialization phase to + // initial samples that are needed at the end of the initialization phase to // compute the correct initial positions of the markers. this->actual_positions[cnt - 1] = args[weight]; diff --git a/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp b/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp index 8ee2c56005..418b38cfe0 100644 --- a/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp +++ b/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp @@ -56,16 +56,16 @@ namespace impl : accumulator_base { typedef typename numeric::functional::multiplies<Weight, Sample>::result_type weighted_sample; - typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type float_type; // for boost::result_of typedef boost::tuple<float_type, float_type, float_type> result_type; template<typename Args> weighted_peaks_over_threshold_impl(Args const &args) : sign_((is_same<LeftRight, left>::value) ? -1 : 1) - , mu_(sign_ * numeric::average(args[sample | Sample()], (std::size_t)1)) - , sigma2_(numeric::average(args[sample | Sample()], (std::size_t)1)) - , w_sum_(numeric::average(args[weight | Weight()], (std::size_t)1)) + , mu_(sign_ * numeric::fdiv(args[sample | Sample()], (std::size_t)1)) + , sigma2_(numeric::fdiv(args[sample | Sample()], (std::size_t)1)) + , w_sum_(numeric::fdiv(args[weight | Weight()], (std::size_t)1)) , threshold_(sign_ * args[pot_threshold_value]) , fit_parameters_(boost::make_tuple(0., 0., 0.)) , is_dirty_(true) @@ -92,13 +92,13 @@ namespace impl { this->is_dirty_ = false; - this->mu_ = this->sign_ * numeric::average(this->mu_, this->w_sum_); - this->sigma2_ = numeric::average(this->sigma2_, this->w_sum_); + this->mu_ = this->sign_ * numeric::fdiv(this->mu_, this->w_sum_); + this->sigma2_ = numeric::fdiv(this->sigma2_, this->w_sum_); this->sigma2_ -= this->mu_ * this->mu_; - float_type threshold_probability = numeric::average(sum_of_weights(args) - this->w_sum_, sum_of_weights(args)); + float_type threshold_probability = numeric::fdiv(sum_of_weights(args) - this->w_sum_, sum_of_weights(args)); - float_type tmp = numeric::average(( this->mu_ - this->threshold_ )*( this->mu_ - this->threshold_ ), this->sigma2_); + float_type tmp = numeric::fdiv(( this->mu_ - this->threshold_ )*( this->mu_ - this->threshold_ ), this->sigma2_); float_type xi_hat = 0.5 * ( 1. - tmp ); float_type beta_hat = 0.5 * ( this->mu_ - this->threshold_ ) * ( 1. + tmp ); float_type beta_bar = beta_hat * std::pow(1. - threshold_probability, xi_hat); @@ -135,15 +135,15 @@ namespace impl : accumulator_base { typedef typename numeric::functional::multiplies<Weight, Sample>::result_type weighted_sample; - typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type float_type; // for boost::result_of typedef boost::tuple<float_type, float_type, float_type> result_type; template<typename Args> weighted_peaks_over_threshold_prob_impl(Args const &args) : sign_((is_same<LeftRight, left>::value) ? -1 : 1) - , mu_(sign_ * numeric::average(args[sample | Sample()], (std::size_t)1)) - , sigma2_(numeric::average(args[sample | Sample()], (std::size_t)1)) + , mu_(sign_ * numeric::fdiv(args[sample | Sample()], (std::size_t)1)) + , sigma2_(numeric::fdiv(args[sample | Sample()], (std::size_t)1)) , threshold_probability_(args[pot_threshold_probability]) , fit_parameters_(boost::make_tuple(0., 0., 0.)) , is_dirty_(true) @@ -200,14 +200,14 @@ namespace impl float_type u = *(tail(args).begin() + n - 1) * this->sign_; - this->mu_ = this->sign_ * numeric::average(this->mu_, sum); - this->sigma2_ = numeric::average(this->sigma2_, sum); + this->mu_ = this->sign_ * numeric::fdiv(this->mu_, sum); + this->sigma2_ = numeric::fdiv(this->sigma2_, sum); this->sigma2_ -= this->mu_ * this->mu_; if (is_same<LeftRight, left>::value) this->threshold_probability_ = 1. - this->threshold_probability_; - float_type tmp = numeric::average(( this->mu_ - u )*( this->mu_ - u ), this->sigma2_); + float_type tmp = numeric::fdiv(( this->mu_ - u )*( this->mu_ - u ), this->sigma2_); float_type xi_hat = 0.5 * ( 1. - tmp ); float_type beta_hat = 0.5 * ( this->mu_ - u ) * ( 1. + tmp ); float_type beta_bar = beta_hat * std::pow(1. - threshold_probability_, xi_hat); diff --git a/boost/accumulators/statistics/weighted_skewness.hpp b/boost/accumulators/statistics/weighted_skewness.hpp index 6ccbc45ca1..a3ac3876f5 100644 --- a/boost/accumulators/statistics/weighted_skewness.hpp +++ b/boost/accumulators/statistics/weighted_skewness.hpp @@ -51,14 +51,14 @@ namespace impl { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, weighted_sample>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, weighted_sample>::result_type result_type; weighted_skewness_impl(dont_care) {} template<typename Args> result_type result(Args const &args) const { - return numeric::average( + return numeric::fdiv( accumulators::weighted_moment<3>(args) - 3. * accumulators::weighted_moment<2>(args) * weighted_mean(args) + 2. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) diff --git a/boost/accumulators/statistics/weighted_tail_mean.hpp b/boost/accumulators/statistics/weighted_tail_mean.hpp index 5bdee8aadc..bae8530674 100644 --- a/boost/accumulators/statistics/weighted_tail_mean.hpp +++ b/boost/accumulators/statistics/weighted_tail_mean.hpp @@ -82,9 +82,9 @@ namespace impl : accumulator_base { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; - typedef typename numeric::functional::average<Weight, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Weight, std::size_t>::result_type float_type; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type result_type; non_coherent_weighted_tail_mean_impl(dont_care) {} @@ -120,7 +120,7 @@ namespace impl } } - return numeric::average( + return numeric::fdiv( std::inner_product( tail(args).begin() , tail(args).begin() + n diff --git a/boost/accumulators/statistics/weighted_tail_quantile.hpp b/boost/accumulators/statistics/weighted_tail_quantile.hpp index 88c32d1f61..b143457dd0 100644 --- a/boost/accumulators/statistics/weighted_tail_quantile.hpp +++ b/boost/accumulators/statistics/weighted_tail_quantile.hpp @@ -66,7 +66,7 @@ namespace impl struct weighted_tail_quantile_impl : accumulator_base { - typedef typename numeric::functional::average<Weight, std::size_t>::result_type float_type; + typedef typename numeric::functional::fdiv<Weight, std::size_t>::result_type float_type; // for boost::result_of typedef Sample result_type; diff --git a/boost/accumulators/statistics/weighted_tail_variate_means.hpp b/boost/accumulators/statistics/weighted_tail_variate_means.hpp index da181896a1..2c9078335d 100644 --- a/boost/accumulators/statistics/weighted_tail_variate_means.hpp +++ b/boost/accumulators/statistics/weighted_tail_variate_means.hpp @@ -37,7 +37,7 @@ namespace boost { // for _BinaryOperatrion2 in std::inner_product below - // mutliplies two values and promotes the result to double + // multiplies two values and promotes the result to double namespace numeric { namespace functional { /////////////////////////////////////////////////////////////////////////////// @@ -107,8 +107,8 @@ namespace impl struct weighted_tail_variate_means_impl : accumulator_base { - typedef typename numeric::functional::average<Weight, Weight>::result_type float_type; - typedef typename numeric::functional::average<typename numeric::functional::multiplies<VariateType, Weight>::result_type, Weight>::result_type array_type; + typedef typename numeric::functional::fdiv<Weight, Weight>::result_type float_type; + typedef typename numeric::functional::fdiv<typename numeric::functional::multiplies<VariateType, Weight>::result_type, Weight>::result_type array_type; // for boost::result_of typedef iterator_range<typename array_type::iterator> result_type; diff --git a/boost/accumulators/statistics/weighted_variance.hpp b/boost/accumulators/statistics/weighted_variance.hpp index e91fdc1bc6..bc199affa4 100644 --- a/boost/accumulators/statistics/weighted_variance.hpp +++ b/boost/accumulators/statistics/weighted_variance.hpp @@ -41,7 +41,7 @@ namespace impl { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, Weight>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, Weight>::result_type result_type; lazy_weighted_variance_impl(dont_care) {} @@ -64,7 +64,7 @@ namespace impl ,\quad n\ge2,\quad\hat{\sigma}_0^2 = 0. \f] where \f$\bar{w}_n\f$ is the sum of the \f$n\f$ weights \f$w_i\f$ and \f$\hat{\mu}_n\f$ - the estimate of the mean of the weighted smaples. Note that the sample variance is not defined for + the estimate of the mean of the weighted samples. Note that the sample variance is not defined for \f$n <= 1\f$. */ template<typename Sample, typename Weight, typename MeanFeature, typename Tag> @@ -73,11 +73,11 @@ namespace impl { typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample; // for boost::result_of - typedef typename numeric::functional::average<weighted_sample, Weight>::result_type result_type; + typedef typename numeric::functional::fdiv<weighted_sample, Weight>::result_type result_type; template<typename Args> weighted_variance_impl(Args const &args) - : weighted_variance(numeric::average(args[sample | Sample()], numeric::one<Weight>::value)) + : weighted_variance(numeric::fdiv(args[sample | Sample()], numeric::one<Weight>::value)) { } @@ -93,8 +93,8 @@ namespace impl result_type tmp = args[parameter::keyword<Tag>::get()] - some_mean(args); this->weighted_variance = - numeric::average(this->weighted_variance * (sum_of_weights(args) - args[weight]), sum_of_weights(args)) - + numeric::average(tmp * tmp * args[weight], sum_of_weights(args) - args[weight] ); + numeric::fdiv(this->weighted_variance * (sum_of_weights(args) - args[weight]), sum_of_weights(args)) + + numeric::fdiv(tmp * tmp * args[weight], sum_of_weights(args) - args[weight] ); } } |