|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2008-06-19 23:47:54
Author: eric_niebler
Date: 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
New Revision: 46542
URL: http://svn.boost.org/trac/boost/changeset/46542
Log:
integrate accumulators
Added:
branches/release/boost/accumulators/
branches/release/boost/accumulators/accumulators.hpp (contents, props changed)
branches/release/boost/accumulators/accumulators_fwd.hpp (contents, props changed)
branches/release/boost/accumulators/framework/
branches/release/boost/accumulators/framework/accumulator_base.hpp (contents, props changed)
branches/release/boost/accumulators/framework/accumulator_concept.hpp (contents, props changed)
branches/release/boost/accumulators/framework/accumulator_set.hpp (contents, props changed)
branches/release/boost/accumulators/framework/accumulators/
branches/release/boost/accumulators/framework/accumulators/droppable_accumulator.hpp (contents, props changed)
branches/release/boost/accumulators/framework/accumulators/external_accumulator.hpp (contents, props changed)
branches/release/boost/accumulators/framework/accumulators/reference_accumulator.hpp (contents, props changed)
branches/release/boost/accumulators/framework/accumulators/value_accumulator.hpp (contents, props changed)
branches/release/boost/accumulators/framework/depends_on.hpp (contents, props changed)
branches/release/boost/accumulators/framework/external.hpp (contents, props changed)
branches/release/boost/accumulators/framework/extractor.hpp (contents, props changed)
branches/release/boost/accumulators/framework/features.hpp (contents, props changed)
branches/release/boost/accumulators/framework/parameters/
branches/release/boost/accumulators/framework/parameters/accumulator.hpp (contents, props changed)
branches/release/boost/accumulators/framework/parameters/sample.hpp (contents, props changed)
branches/release/boost/accumulators/framework/parameters/weight.hpp (contents, props changed)
branches/release/boost/accumulators/framework/parameters/weights.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/
branches/release/boost/accumulators/numeric/detail/
branches/release/boost/accumulators/numeric/detail/function1.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/detail/function2.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/detail/function3.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/detail/function4.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/detail/function_n.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/detail/pod_singleton.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/functional/
branches/release/boost/accumulators/numeric/functional.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/functional/complex.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/functional/valarray.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/functional/vector.hpp (contents, props changed)
branches/release/boost/accumulators/numeric/functional_fwd.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/
branches/release/boost/accumulators/statistics.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/count.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/covariance.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/density.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/error_of.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/error_of_mean.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/extended_p_square.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/extended_p_square_quantile.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/kurtosis.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/max.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/mean.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/median.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/min.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/moment.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/p_square_cumulative_distribution.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/p_square_quantile.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/parameters/
branches/release/boost/accumulators/statistics/parameters/quantile_probability.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/peaks_over_threshold.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/pot_quantile.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/pot_tail_mean.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/skewness.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/stats.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/sum.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/tail.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/tail_mean.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/tail_quantile.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/tail_variate.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/tail_variate_means.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/times2_iterator.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/variance.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/variates/
branches/release/boost/accumulators/statistics/variates/covariate.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_covariance.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_density.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_extended_p_square.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_kurtosis.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_mean.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_median.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_moment.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_p_square_quantile.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_skewness.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_sum.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_tail_mean.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_tail_quantile.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_tail_variate_means.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/weighted_variance.hpp (contents, props changed)
branches/release/boost/accumulators/statistics/with_error.hpp (contents, props changed)
branches/release/boost/accumulators/statistics_fwd.hpp (contents, props changed)
branches/release/libs/accumulators/
branches/release/libs/accumulators/doc/
branches/release/libs/accumulators/doc/Jamfile.v2 (contents, props changed)
branches/release/libs/accumulators/doc/accumulators.qbk (contents, props changed)
branches/release/libs/accumulators/example/
branches/release/libs/accumulators/example/Jamfile.v2 (contents, props changed)
branches/release/libs/accumulators/example/main.cpp (contents, props changed)
branches/release/libs/accumulators/index.html (contents, props changed)
branches/release/libs/accumulators/test/
branches/release/libs/accumulators/test/Jamfile.v2 (contents, props changed)
branches/release/libs/accumulators/test/count.cpp (contents, props changed)
branches/release/libs/accumulators/test/covariance.cpp (contents, props changed)
branches/release/libs/accumulators/test/droppable.cpp (contents, props changed)
branches/release/libs/accumulators/test/error_of.cpp (contents, props changed)
branches/release/libs/accumulators/test/extended_p_square.cpp (contents, props changed)
branches/release/libs/accumulators/test/extended_p_square_quantile.cpp (contents, props changed)
branches/release/libs/accumulators/test/external_accumulator.cpp (contents, props changed)
branches/release/libs/accumulators/test/external_weights.cpp (contents, props changed)
branches/release/libs/accumulators/test/kurtosis.cpp (contents, props changed)
branches/release/libs/accumulators/test/max.cpp (contents, props changed)
branches/release/libs/accumulators/test/mean.cpp (contents, props changed)
branches/release/libs/accumulators/test/median.cpp (contents, props changed)
branches/release/libs/accumulators/test/min.cpp (contents, props changed)
branches/release/libs/accumulators/test/moment.cpp (contents, props changed)
branches/release/libs/accumulators/test/p_square_cumulative_distribution.cpp (contents, props changed)
branches/release/libs/accumulators/test/p_square_quantile.cpp (contents, props changed)
branches/release/libs/accumulators/test/p_square_quantile_extended.cpp (contents, props changed)
branches/release/libs/accumulators/test/pot_quantile.cpp (contents, props changed)
branches/release/libs/accumulators/test/reference.cpp (contents, props changed)
branches/release/libs/accumulators/test/skewness.cpp (contents, props changed)
branches/release/libs/accumulators/test/sum.cpp (contents, props changed)
branches/release/libs/accumulators/test/tail.cpp (contents, props changed)
branches/release/libs/accumulators/test/tail_mean.cpp (contents, props changed)
branches/release/libs/accumulators/test/tail_quantile.cpp (contents, props changed)
branches/release/libs/accumulators/test/tail_variate_means.cpp (contents, props changed)
branches/release/libs/accumulators/test/valarray.cpp (contents, props changed)
branches/release/libs/accumulators/test/value.cpp (contents, props changed)
branches/release/libs/accumulators/test/variance.cpp (contents, props changed)
branches/release/libs/accumulators/test/vector.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_covariance.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_extended_p_square.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_kurtosis.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_mean.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_median.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_moment.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_p_square_cum_dist.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_p_square_quantile.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_pot_quantile.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_skewness.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_sum.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_tail_mean.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_tail_quantile.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_tail_variate_means.cpp (contents, props changed)
branches/release/libs/accumulators/test/weighted_variance.cpp (contents, props changed)
Text files modified:
branches/release/doc/Jamfile.v2 | 5 +++++
branches/release/doc/src/boost.xml | 2 ++
branches/release/status/Jamfile.v2 | 1 +
branches/release/status/explicit-failures-markup.xml | 29 +++++++++++++++++++++++++++++
4 files changed, 37 insertions(+), 0 deletions(-)
Added: branches/release/boost/accumulators/accumulators.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/accumulators.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file accumulators.hpp
+/// Includes all of the Accumulators Framework
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_ACCUMULATORS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_ACCUMULATORS_HPP_EAN_28_10_2005
+
+#include <boost/accumulators/framework/accumulator_set.hpp>
+#include <boost/accumulators/framework/accumulator_concept.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/external.hpp>
+#include <boost/accumulators/framework/features.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/parameters/weight.hpp>
+#include <boost/accumulators/framework/parameters/weights.hpp>
+#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
+#include <boost/accumulators/framework/accumulators/droppable_accumulator.hpp>
+#include <boost/accumulators/framework/accumulators/reference_accumulator.hpp>
+#include <boost/accumulators/framework/accumulators/value_accumulator.hpp>
+
+#endif
Added: branches/release/boost/accumulators/accumulators_fwd.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/accumulators_fwd.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,211 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulators_fwd.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_ACCUMULATORS_FWD_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_ACCUMULATORS_FWD_HPP_EAN_28_10_2005
+
+#include <boost/config.hpp>
+#include <boost/mpl/apply_fwd.hpp> // for mpl::na
+#include <boost/mpl/limits/vector.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>
+#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
+#include <boost/preprocessor/repetition/repeat_from_to.hpp>
+#include <boost/accumulators/numeric/functional_fwd.hpp>
+
+#ifndef BOOST_ACCUMULATORS_MAX_FEATURES
+ /// The maximum number of accumulators that may be put in an accumulator_set.
+ /// Defaults to BOOST_MPL_LIMIT_VECTOR_SIZE (which defaults to 20).
+# define BOOST_ACCUMULATORS_MAX_FEATURES BOOST_MPL_LIMIT_VECTOR_SIZE
+#endif
+
+#if BOOST_ACCUMULATORS_MAX_FEATURES > BOOST_MPL_LIMIT_VECTOR_SIZE
+# error BOOST_ACCUMULATORS_MAX_FEATURES cannot be larger than BOOST_MPL_LIMIT_VECTOR_SIZE
+#endif
+
+#ifndef BOOST_ACCUMULATORS_MAX_ARGS
+ /// The maximum number of arguments that may be specified to an accumulator_set's
+ /// accumulation function. Defaults to 15.
+# define BOOST_ACCUMULATORS_MAX_ARGS 15
+#endif
+
+#if BOOST_WORKAROUND(__GNUC__, == 3) \
+ || BOOST_WORKAROUND(__EDG_VERSION__, BOOST_TESTED_AT(306))
+# define BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS
+#endif
+
+#ifdef BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS
+# include <boost/utility/enable_if.hpp>
+# include <boost/type_traits/is_const.hpp>
+# define BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(T)\
+ , typename boost::disable_if<boost::is_const<T> >::type * = 0
+#else
+# define BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(T)
+#endif
+
+namespace boost { namespace accumulators
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// Named parameters tags
+//
+namespace tag
+{
+ struct sample;
+ struct weight;
+ struct accumulator;
+ struct weights;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// User-level features
+//
+namespace tag
+{
+ template<typename ValueType, typename Tag>
+ struct value;
+
+ template<typename Tag>
+ struct value_tag;
+
+ template<typename Referent, typename Tag>
+ struct reference;
+
+ template<typename Tag>
+ struct reference_tag;
+
+ template<typename Type, typename Tag = void, typename AccumulatorSet = void>
+ struct external;
+
+ template<typename Feature>
+ struct droppable;
+}
+
+template<typename Accumulator>
+struct droppable_accumulator_base;
+
+template<typename Accumulator>
+struct droppable_accumulator;
+
+template<typename Accumulator>
+struct with_cached_result;
+
+template<typename Sample, typename Features, typename Weight = void>
+struct accumulator_set;
+
+template<typename Feature>
+struct extractor;
+
+template<typename Feature>
+struct feature_of;
+
+template<typename Feature>
+struct as_feature;
+
+template<typename Feature>
+struct as_weighted_feature;
+
+template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
+struct depends_on;
+
+template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
+struct features;
+
+template<typename Feature, typename AccumulatorSet>
+typename mpl::apply<AccumulatorSet, Feature>::type const &
+find_accumulator(AccumulatorSet const &acc);
+
+template<typename Feature, typename AccumulatorSet>
+typename mpl::apply<AccumulatorSet, Feature>::type::result_type
+extract_result(AccumulatorSet const &acc);
+
+template<typename Feature, typename AccumulatorSet, typename A1>
+typename mpl::apply<AccumulatorSet, Feature>::type::result_type
+extract_result(AccumulatorSet const &acc, A1 const &a1);
+
+// ... other overloads generated by Boost.Preprocessor:
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD(z, n, _) \
+ template< \
+ typename Feature \
+ , typename AccumulatorSet \
+ BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
+ > \
+ typename mpl::apply<AccumulatorSet, Feature>::type::result_type \
+ extract_result( \
+ AccumulatorSet const &acc \
+ BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \
+ );
+
+/// INTERNAL ONLY
+///
+BOOST_PP_REPEAT_FROM_TO(
+ 2
+ , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
+ , BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD
+ , _
+)
+
+#ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+template<typename Feature, typename AccumulatorSet, typename A1, typename A2 ...>
+typename mpl::apply<AccumulatorSet, Feature>::type::result_type
+extract_result(AccumulatorSet const &acc, A1 const &a1, A2 const &a2 ...);
+#endif
+
+namespace impl
+{
+ using namespace numeric::operators;
+
+ template<typename Accumulator, typename Tag>
+ struct external_impl;
+}
+
+namespace detail
+{
+ template<typename Accumulator>
+ struct feature_tag;
+
+ template<typename Feature, typename Sample, typename Weight>
+ struct to_accumulator;
+
+ struct accumulator_set_base;
+
+ template<typename T>
+ struct is_accumulator_set;
+}
+
+}} // namespace boost::accumulators
+
+// For defining boost::parameter keywords that can be inherited from to
+// get a nested, class-scoped keyword with the requested alias
+#define BOOST_PARAMETER_NESTED_KEYWORD(tag_namespace, name, alias) \
+ namespace tag_namespace \
+ { \
+ template<int Dummy = 0> \
+ struct name ## _ \
+ { \
+ static char const* keyword_name() \
+ { \
+ return #name; \
+ } \
+ static ::boost::parameter::keyword<name ## _<Dummy> > &alias; \
+ }; \
+ template<int Dummy> \
+ ::boost::parameter::keyword<name ## _<Dummy> > &name ## _<Dummy>::alias = \
+ ::boost::parameter::keyword<name ## _<Dummy> >::get(); \
+ typedef name ## _ <> name; \
+ } \
+ namespace \
+ { \
+ ::boost::parameter::keyword<tag_namespace::name> &name = \
+ ::boost::parameter::keyword<tag_namespace::name>::get(); \
+ }
+
+#endif
Added: branches/release/boost/accumulators/framework/accumulator_base.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/accumulator_base.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,65 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator_base.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_BASE_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_BASE_HPP_EAN_28_10_2005
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/joint_view.hpp>
+#include <boost/mpl/single_view.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/contains.hpp>
+#include <boost/mpl/empty_sequence.hpp>
+#include <boost/accumulators/framework/accumulator_concept.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace detail
+{
+ typedef void void_;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// dont_care
+//
+struct dont_care
+{
+ template<typename Args>
+ dont_care(Args const &)
+ {
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// accumulator_base
+//
+struct accumulator_base
+{
+ // hidden if defined in derived classes
+ detail::void_ operator ()(dont_care)
+ {
+ }
+
+ typedef mpl::false_ is_droppable;
+
+ detail::void_ add_ref(dont_care)
+ {
+ }
+
+ detail::void_ drop(dont_care)
+ {
+ }
+
+ detail::void_ on_drop(dont_care)
+ {
+ }
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/accumulator_concept.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/accumulator_concept.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,29 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator_concept.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_CONCEPT_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_CONCEPT_HPP_EAN_28_10_2005
+
+#include <boost/concept_check.hpp>
+
+namespace boost { namespace accumulators
+{
+
+template<typename Stat>
+struct accumulator_concept
+{
+ void constraints()
+ {
+ // TODO: define the stat concept
+ }
+
+ Stat stat;
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/accumulator_set.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/accumulator_set.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,397 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator_set.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_SET_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_SET_HPP_EAN_28_10_2005
+
+#include <boost/version.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/protect.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/is_sequence.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/parameter/parameters.hpp>
+#include <boost/preprocessor/repetition/repeat_from_to.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+#include <boost/accumulators/accumulators_fwd.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/framework/accumulator_concept.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
+#include <boost/accumulators/framework/accumulators/droppable_accumulator.hpp>
+#include <boost/fusion/include/any.hpp>
+#include <boost/fusion/include/find_if.hpp>
+#include <boost/fusion/include/for_each.hpp>
+#include <boost/fusion/include/filter_view.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace detail
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // accumulator_visitor
+ // wrap a boost::parameter argument pack in a Fusion extractor object
+ template<typename Args>
+ struct accumulator_visitor
+ {
+ explicit accumulator_visitor(Args const &args)
+ : args(args)
+ {
+ }
+
+ template<typename Accumulator>
+ void operator ()(Accumulator &accumulator) const
+ {
+ accumulator(this->args);
+ }
+
+ private:
+ accumulator_visitor &operator =(accumulator_visitor const &);
+ Args const &args;
+ };
+
+ template<typename Args>
+ inline accumulator_visitor<Args> const make_accumulator_visitor(Args const &args)
+ {
+ return accumulator_visitor<Args>(args);
+ }
+
+ typedef
+ parameter::parameters<
+ parameter::required<tag::accumulator>
+ , parameter::optional<tag::sample>
+ // ... and others which are not specified here...
+ >
+ accumulator_params;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // accumulator_set_base
+ struct accumulator_set_base
+ {
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // is_accumulator_set
+ template<typename T>
+ struct is_accumulator_set
+ : is_base_and_derived<accumulator_set_base, T>
+ {
+ };
+
+} // namespace detail
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable: 4355) // warning C4355: 'this' : used in base member initializer list
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief A set of accumulators.
+///
+/// accumulator_set resolves the dependencies between features and ensures that
+/// the accumulators in the set are updated in the proper order.
+///
+/// acccumulator_set provides a general mechanism to visit the accumulators
+/// in the set in order, with or without a filter. You can also fetch a reference
+/// to an accumulator that corresponds to a feature.
+///
+template<typename Sample, typename Features, typename Weight>
+struct accumulator_set
+ : detail::accumulator_set_base
+{
+ typedef Sample sample_type; ///< The type of the samples that will be accumulated
+ typedef Features features_type; ///< An MPL sequence of the features that should be accumulated.
+ typedef Weight weight_type; ///< The type of the weight parameter. Must be a scalar. Defaults to void.
+
+ /// INTERNAL ONLY
+ ///
+ typedef
+ typename detail::make_accumulator_tuple<
+ Features
+ , Sample
+ , Weight
+ >::type
+ accumulators_mpl_vector;
+
+ // generate a fusion::list of accumulators
+ /// INTERNAL ONLY
+ ///
+ typedef
+ typename detail::meta::make_acc_list<
+ accumulators_mpl_vector
+ >::type
+ accumulators_type;
+
+ /// INTERNAL ONLY
+ ///
+ //BOOST_MPL_ASSERT((mpl::is_sequence<accumulators_type>));
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// default-construct all contained accumulators
+ accumulator_set()
+ : accumulators(
+ detail::make_acc_list(
+ accumulators_mpl_vector()
+ , detail::accumulator_params()(*this)
+ )
+ )
+ {
+ // Add-ref the Features that the user has specified
+ this->template visit_if<detail::contains_feature_of_<Features> >(
+ detail::make_add_ref_visitor(detail::accumulator_params()(*this))
+ );
+ }
+
+ /// \overload
+ ///
+ /// \param a1 Optional named parameter to be passed to all the accumulators
+ template<typename A1>
+ explicit accumulator_set(A1 const &a1)
+ : accumulators(
+ detail::make_acc_list(
+ accumulators_mpl_vector()
+ , detail::accumulator_params()(*this, a1)
+ )
+ )
+ {
+ // Add-ref the Features that the user has specified
+ this->template visit_if<detail::contains_feature_of_<Features> >(
+ detail::make_add_ref_visitor(detail::accumulator_params()(*this))
+ );
+ }
+
+ // ... other overloads generated by Boost.Preprocessor:
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_ACCUMULATORS_ACCUMULATOR_SET_CTOR(z, n, _) \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
+ accumulator_set(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a)) \
+ : accumulators( \
+ detail::make_acc_list( \
+ accumulators_mpl_vector() \
+ , detail::accumulator_params()( \
+ *this BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \
+ ) \
+ ) \
+ ) \
+ { \
+ /* Add-ref the Features that the user has specified */ \
+ this->template visit_if<detail::contains_feature_of_<Features> >( \
+ detail::make_add_ref_visitor(detail::accumulator_params()(*this)) \
+ ); \
+ }
+
+ /// INTERNAL ONLY
+ ///
+ BOOST_PP_REPEAT_FROM_TO(
+ 2
+ , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
+ , BOOST_ACCUMULATORS_ACCUMULATOR_SET_CTOR
+ , _
+ )
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// \overload
+ ///
+ template<typename A1, typename A2, ...>
+ accumulator_set(A1 const &a1, A2 const &a2, ...);
+ #endif
+
+ // ... other overloads generated by Boost.Preprocessor below ...
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// Visitation
+ /// \param func UnaryFunction which is invoked with each accumulator in turn.
+ template<typename UnaryFunction>
+ void visit(UnaryFunction const &func)
+ {
+ fusion::for_each(this->accumulators, func);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// Conditional visitation
+ /// \param func UnaryFunction which is invoked with each accumulator in turn,
+ /// provided the accumulator satisfies the MPL predicate FilterPred.
+ template<typename FilterPred, typename UnaryFunction>
+ void visit_if(UnaryFunction const &func)
+ {
+ fusion::filter_view<accumulators_type, FilterPred> filtered_accs(this->accumulators);
+ fusion::for_each(filtered_accs, func);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// Accumulation
+ /// \param a1 Optional named parameter to be passed to all the accumulators
+ void operator ()()
+ {
+ this->visit(
+ detail::make_accumulator_visitor(
+ detail::accumulator_params()(*this)
+ )
+ );
+ }
+
+ template<typename A1>
+ void operator ()(A1 const &a1)
+ {
+ this->visit(
+ detail::make_accumulator_visitor(
+ detail::accumulator_params()(*this, a1)
+ )
+ );
+ }
+
+ // ... other overloads generated by Boost.Preprocessor:
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP(z, n, _) \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
+ void operator ()(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a)) \
+ { \
+ this->visit( \
+ detail::make_accumulator_visitor( \
+ detail::accumulator_params()( \
+ *this BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \
+ ) \
+ ) \
+ ); \
+ }
+
+ /// INTERNAL ONLY
+ ///
+ BOOST_PP_REPEAT_FROM_TO(
+ 2
+ , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
+ , BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP
+ , _
+ )
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// \overload
+ ///
+ template<typename A1, typename A2, ...>
+ void operator ()(A1 const &a1, A2 const &a2, ...);
+ #endif
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// Extraction
+ template<typename Feature>
+ struct apply
+ : fusion::result_of::value_of<
+ typename fusion::result_of::find_if<
+ accumulators_type
+ , detail::matches_feature<Feature>
+ >::type
+ >
+ {
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// Extraction
+ template<typename Feature>
+ typename apply<Feature>::type &extract()
+ {
+ return *fusion::find_if<detail::matches_feature<Feature> >(this->accumulators);
+ }
+
+ /// \overload
+ template<typename Feature>
+ typename apply<Feature>::type const &extract() const
+ {
+ return *fusion::find_if<detail::matches_feature<Feature> >(this->accumulators);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// Drop
+ template<typename Feature>
+ void drop()
+ {
+ // You can only drop the features that you have specified explicitly
+ typedef typename apply<Feature>::type the_accumulator;
+ BOOST_MPL_ASSERT((detail::contains_feature_of<Features, the_accumulator>));
+
+ typedef
+ typename feature_of<typename as_feature<Feature>::type>::type
+ the_feature;
+
+ (*fusion::find_if<detail::matches_feature<Feature> >(this->accumulators))
+ .drop(detail::accumulator_params()(*this));
+
+ // Also drop accumulators that this feature depends on
+ typedef typename the_feature::dependencies dependencies;
+ this->template visit_if<detail::contains_feature_of_<dependencies> >(
+ detail::make_drop_visitor(detail::accumulator_params()(*this))
+ );
+ }
+
+private:
+
+ accumulators_type accumulators;
+};
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// find_accumulator
+// find an accumulator in an accumulator_set corresponding to a feature
+template<typename Feature, typename AccumulatorSet>
+typename mpl::apply<AccumulatorSet, Feature>::type &
+find_accumulator(AccumulatorSet &acc BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(AccumulatorSet))
+{
+ return acc.template extract<Feature>();
+}
+
+/// \overload
+template<typename Feature, typename AccumulatorSet>
+typename mpl::apply<AccumulatorSet, Feature>::type const &
+find_accumulator(AccumulatorSet const &acc)
+{
+ return acc.template extract<Feature>();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract_result
+// extract a result from an accumulator set
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_EXTRACT_RESULT_FUN(z, n, _) \
+ template< \
+ typename Feature \
+ , typename AccumulatorSet \
+ BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
+ > \
+ typename mpl::apply<AccumulatorSet, Feature>::type::result_type \
+ extract_result( \
+ AccumulatorSet const &acc \
+ BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \
+ ) \
+ { \
+ return find_accumulator<Feature>(acc).result( \
+ detail::accumulator_params()( \
+ acc \
+ BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \
+ ) \
+ ); \
+ }
+
+BOOST_PP_REPEAT(
+ BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
+ , BOOST_ACCUMULATORS_EXTRACT_RESULT_FUN
+ , _
+)
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/accumulators/droppable_accumulator.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/accumulators/droppable_accumulator.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,317 @@
+///////////////////////////////////////////////////////////////////////////////
+// droppable_accumulator.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_DROPPABLE_ACCUMULATOR_HPP_EAN_13_12_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_DROPPABLE_ACCUMULATOR_HPP_EAN_13_12_2005
+
+#include <new>
+#include <boost/assert.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/aligned_storage.hpp>
+#include <boost/accumulators/framework/depends_on.hpp> // for feature_of
+#include <boost/accumulators/framework/parameters/accumulator.hpp> // for accumulator
+
+namespace boost { namespace accumulators
+{
+
+ template<typename Accumulator>
+ struct droppable_accumulator;
+
+ namespace detail
+ {
+ ///////////////////////////////////////////////////////////////////////////////
+ // add_ref_visitor
+ // a fusion function object for add_ref'ing accumulators
+ template<typename Args>
+ struct add_ref_visitor
+ {
+ explicit add_ref_visitor(Args const &args)
+ : args_(args)
+ {
+ }
+
+ template<typename Accumulator>
+ void operator ()(Accumulator &acc) const
+ {
+ typedef typename Accumulator::feature_tag::dependencies dependencies;
+
+ acc.add_ref(this->args_);
+
+ // Also add_ref accumulators that this feature depends on
+ this->args_[accumulator].template
+ visit_if<detail::contains_feature_of_<dependencies> >(
+ *this
+ );
+ }
+
+ private:
+ add_ref_visitor &operator =(add_ref_visitor const &);
+ Args const &args_;
+ };
+
+ template<typename Args>
+ add_ref_visitor<Args> make_add_ref_visitor(Args const &args)
+ {
+ return add_ref_visitor<Args>(args);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // drop_visitor
+ // a fusion function object for dropping accumulators
+ template<typename Args>
+ struct drop_visitor
+ {
+ explicit drop_visitor(Args const &args)
+ : args_(args)
+ {
+ }
+
+ template<typename Accumulator>
+ void operator ()(Accumulator &acc) const
+ {
+ if(typename Accumulator::is_droppable())
+ {
+ typedef typename Accumulator::feature_tag::dependencies dependencies;
+
+ acc.drop(this->args_);
+ // Also drop accumulators that this feature depends on
+ this->args_[accumulator].template
+ visit_if<detail::contains_feature_of_<dependencies> >(
+ *this
+ );
+ }
+ }
+
+ private:
+ drop_visitor &operator =(drop_visitor const &);
+ Args const &args_;
+ };
+
+ template<typename Args>
+ drop_visitor<Args> make_drop_visitor(Args const &args)
+ {
+ return drop_visitor<Args>(args);
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ // droppable_accumulator_base
+ template<typename Accumulator>
+ struct droppable_accumulator_base
+ : Accumulator
+ {
+ typedef droppable_accumulator_base base;
+ typedef mpl::true_ is_droppable;
+ typedef typename Accumulator::result_type result_type;
+
+ template<typename Args>
+ droppable_accumulator_base(Args const &args)
+ : Accumulator(args)
+ , ref_count_(0)
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ if(!this->is_dropped())
+ {
+ this->Accumulator::operator ()(args);
+ }
+ }
+
+ template<typename Args>
+ void add_ref(Args const &)
+ {
+ ++this->ref_count_;
+ }
+
+ template<typename Args>
+ void drop(Args const &args)
+ {
+ BOOST_ASSERT(0 < this->ref_count_);
+ if(1 == this->ref_count_)
+ {
+ static_cast<droppable_accumulator<Accumulator> *>(this)->on_drop(args);
+ }
+ --this->ref_count_;
+ }
+
+ bool is_dropped() const
+ {
+ return 0 == this->ref_count_;
+ }
+
+ private:
+ int ref_count_;
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // droppable_accumulator
+ // this can be specialized for any type that needs special handling
+ template<typename Accumulator>
+ struct droppable_accumulator
+ : droppable_accumulator_base<Accumulator>
+ {
+ template<typename Args>
+ droppable_accumulator(Args const &args)
+ : droppable_accumulator::base(args)
+ {
+ }
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // with_cached_result
+ template<typename Accumulator>
+ struct with_cached_result
+ : Accumulator
+ {
+ typedef typename Accumulator::result_type result_type;
+
+ template<typename Args>
+ with_cached_result(Args const &args)
+ : Accumulator(args)
+ , cache()
+ {
+ }
+
+ with_cached_result(with_cached_result const &that)
+ : Accumulator(*static_cast<Accumulator const *>(&that))
+ , cache()
+ {
+ if(that.has_result())
+ {
+ this->set(that.get());
+ }
+ }
+
+ ~with_cached_result()
+ {
+ // Since this is a base class of droppable_accumulator_base,
+ // this destructor is called before any of droppable_accumulator_base's
+ // members get cleaned up, including is_dropped, so the following
+ // call to has_result() is valid.
+ if(this->has_result())
+ {
+ this->get().~result_type();
+ }
+ }
+
+ template<typename Args>
+ void on_drop(Args const &args)
+ {
+ // cache the result at the point this calcuation was dropped
+ BOOST_ASSERT(!this->has_result());
+ this->set(this->Accumulator::result(args));
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return this->has_result() ? this->get() : this->Accumulator::result(args);
+ }
+
+ private:
+ with_cached_result &operator =(with_cached_result const &);
+
+ void set(result_type const &result)
+ {
+ ::new(this->cache.address()) result_type(result);
+ }
+
+ result_type const &get() const
+ {
+ return *static_cast<result_type const *>(this->cache.address());
+ }
+
+ bool has_result() const
+ {
+ typedef with_cached_result<Accumulator> this_type;
+ typedef droppable_accumulator_base<this_type> derived_type;
+ return static_cast<derived_type const *>(this)->is_dropped();
+ }
+
+ aligned_storage<sizeof(result_type)> cache;
+ };
+
+ namespace tag
+ {
+ template<typename Feature>
+ struct as_droppable
+ {
+ typedef droppable<Feature> type;
+ };
+
+ template<typename Feature>
+ struct as_droppable<droppable<Feature> >
+ {
+ typedef droppable<Feature> type;
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // droppable
+ template<typename Feature>
+ struct droppable
+ : as_feature<Feature>::type
+ {
+ typedef typename as_feature<Feature>::type feature_type;
+ typedef typename feature_type::dependencies tmp_dependencies_;
+
+ typedef
+ typename mpl::transform<
+ typename feature_type::dependencies
+ , as_droppable<mpl::_1>
+ >::type
+ dependencies;
+
+ struct impl
+ {
+ template<typename Sample, typename Weight>
+ struct apply
+ {
+ typedef
+ droppable_accumulator<
+ typename mpl::apply2<typename feature_type::impl, Sample, Weight>::type
+ >
+ type;
+ };
+ };
+ };
+ }
+
+ // make droppable<tag::feature(modifier)> work
+ template<typename Feature>
+ struct as_feature<tag::droppable<Feature> >
+ {
+ typedef tag::droppable<typename as_feature<Feature>::type> type;
+ };
+
+ // make droppable<tag::mean> work with non-void weights (should become
+ // droppable<tag::weighted_mean>
+ template<typename Feature>
+ struct as_weighted_feature<tag::droppable<Feature> >
+ {
+ typedef tag::droppable<typename as_weighted_feature<Feature>::type> type;
+ };
+
+ // for the purposes of feature-based dependency resolution,
+ // droppable<Foo> provides the same feature as Foo
+ template<typename Feature>
+ struct feature_of<tag::droppable<Feature> >
+ : feature_of<Feature>
+ {
+ };
+
+ // Note: Usually, the extractor is pulled into the accumulators namespace with
+ // a using directive, not the tag. But the droppable<> feature doesn't have an
+ // extractor, so we can put the droppable tag in the accumulators namespace
+ // without fear of a name conflict.
+ using tag::droppable;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/accumulators/external_accumulator.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/accumulators/external_accumulator.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,108 @@
+///////////////////////////////////////////////////////////////////////////////
+// external_accumulator.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_EXTERNAL_ACCUMULATOR_HPP_EAN_01_12_2005
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/accumulators/reference_accumulator.hpp>
+
+namespace boost { namespace accumulators { namespace impl
+{
+
+ //////////////////////////////////////////////////////////////////////////
+ // external_impl
+ /// INTERNAL ONLY
+ ///
+ template<typename Accumulator, typename Tag>
+ struct external_impl
+ : accumulator_base
+ {
+ typedef typename Accumulator::result_type result_type;
+ typedef typename detail::feature_tag<Accumulator>::type feature_tag;
+
+ external_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return this->extract_(args, args[parameter::keyword<Tag>::get() | 0]);
+ }
+
+ private:
+
+ template<typename Args>
+ static result_type extract_(Args const &args, int)
+ {
+ // No named parameter passed to the extractor. Maybe the external
+ // feature is held by reference<>.
+ extractor<feature_tag> extract;
+ return extract(reference_tag<Tag>(args));
+ }
+
+ template<typename Args, typename AccumulatorSet>
+ static result_type extract_(Args const &, AccumulatorSet const &acc)
+ {
+ // OK, a named parameter for this external feature was passed to the
+ // extractor, so use that.
+ extractor<feature_tag> extract;
+ return extract(acc);
+ }
+ };
+
+} // namespace impl
+
+namespace tag
+{
+ //////////////////////////////////////////////////////////////////////////
+ // external
+ template<typename Feature, typename Tag, typename AccumulatorSet>
+ struct external
+ : depends_on<reference<AccumulatorSet, Tag> >
+ {
+ typedef
+ accumulators::impl::external_impl<
+ detail::to_accumulator<Feature, mpl::_1, mpl::_2>
+ , Tag
+ >
+ impl;
+ };
+
+ template<typename Feature, typename Tag>
+ struct external<Feature, Tag, void>
+ : depends_on<>
+ {
+ typedef
+ accumulators::impl::external_impl<
+ detail::to_accumulator<Feature, mpl::_1, mpl::_2>
+ , Tag
+ >
+ impl;
+ };
+}
+
+// for the purposes of feature-based dependency resolution,
+// external_accumulator<Feature, Tag> provides the same feature as Feature
+template<typename Feature, typename Tag, typename AccumulatorSet>
+struct feature_of<tag::external<Feature, Tag, AccumulatorSet> >
+ : feature_of<Feature>
+{
+};
+
+// Note: Usually, the extractor is pulled into the accumulators namespace with
+// a using directive, not the tag. But the external<> feature doesn't have an
+// extractor, so we can put the external tag in the accumulators namespace
+// without fear of a name conflict.
+using tag::external;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/accumulators/reference_accumulator.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/accumulators/reference_accumulator.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,89 @@
+///////////////////////////////////////////////////////////////////////////////
+// reference_accumulator.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_REFERENCE_ACCUMULATOR_HPP_EAN_03_23_2006
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_REFERENCE_ACCUMULATOR_HPP_EAN_03_23_2006
+
+#include <boost/ref.hpp>
+#include <boost/mpl/always.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ //////////////////////////////////////////////////////////////////////////
+ // reference_accumulator_impl
+ //
+ template<typename Referent, typename Tag>
+ struct reference_accumulator_impl
+ : accumulator_base
+ {
+ typedef Referent &result_type;
+
+ template<typename Args>
+ reference_accumulator_impl(Args const &args)
+ : ref(args[parameter::keyword<Tag>::get()])
+ {
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->ref;
+ }
+
+ private:
+ reference_wrapper<Referent> ref;
+ };
+} // namespace impl
+
+namespace tag
+{
+ //////////////////////////////////////////////////////////////////////////
+ // reference_tag
+ template<typename Tag>
+ struct reference_tag
+ {
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // reference
+ template<typename Referent, typename Tag>
+ struct reference
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef mpl::always<accumulators::impl::reference_accumulator_impl<Referent, Tag> > impl;
+ };
+}
+
+namespace extract
+{
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, reference, (typename)(typename))
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, reference_tag, (typename))
+}
+
+using extract::reference;
+using extract::reference_tag;
+
+// Map all reference<V,T> features to reference_tag<T> so
+// that references can be extracted using reference_tag<T>
+// without specifying the referent type.
+template<typename ValueType, typename Tag>
+struct feature_of<tag::reference<ValueType, Tag> >
+ : feature_of<tag::reference_tag<Tag> >
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/accumulators/value_accumulator.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/accumulators/value_accumulator.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,89 @@
+///////////////////////////////////////////////////////////////////////////////
+// value_accumulator.hpp
+//
+// Copyright 2005 Eric Niebler, Daniel Egloff. 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_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
+
+#include <boost/mpl/always.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+
+ //////////////////////////////////////////////////////////////////////////
+ // value_accumulator_impl
+ template<typename ValueType, typename Tag>
+ struct value_accumulator_impl
+ : accumulator_base
+ {
+ typedef ValueType result_type;
+
+ template<typename Args>
+ value_accumulator_impl(Args const &args)
+ : val(args[parameter::keyword<Tag>::get()])
+ {
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->val;
+ }
+
+ private:
+ ValueType val;
+ };
+
+} // namespace impl
+
+namespace tag
+{
+ //////////////////////////////////////////////////////////////////////////
+ // value_tag
+ template<typename Tag>
+ struct value_tag
+ {
+ };
+
+ //////////////////////////////////////////////////////////////////////////
+ // value
+ template<typename ValueType, typename Tag>
+ struct value
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef mpl::always<accumulators::impl::value_accumulator_impl<ValueType, Tag> > impl;
+ };
+}
+
+namespace extract
+{
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, value, (typename)(typename))
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, value_tag, (typename))
+}
+
+using extract::value;
+using extract::value_tag;
+
+// Map all value<V,T> features to value_tag<T> so
+// that values can be extracted using value_tag<T>
+// without specifying the value type.
+template<typename ValueType, typename Tag>
+struct feature_of<tag::value<ValueType, Tag> >
+ : feature_of<tag::value_tag<Tag> >
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/depends_on.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/depends_on.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,411 @@
+///////////////////////////////////////////////////////////////////////////////
+// depends_on.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_DEPENDS_ON_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_DEPENDS_ON_HPP_EAN_28_10_2005
+
+#include <boost/version.hpp>
+#include <boost/mpl/end.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/sort.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/remove.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/inherit.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/equal_to.hpp>
+#include <boost/mpl/contains.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/is_sequence.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/insert_range.hpp>
+#include <boost/mpl/transform_view.hpp>
+#include <boost/mpl/inherit_linearly.hpp>
+#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/facilities/intercept.hpp>
+#include <boost/accumulators/accumulators_fwd.hpp>
+#include <boost/fusion/include/next.hpp>
+#include <boost/fusion/include/equal_to.hpp>
+#include <boost/fusion/include/value_of.hpp>
+#include <boost/fusion/include/mpl.hpp>
+#include <boost/fusion/include/end.hpp>
+#include <boost/fusion/include/begin.hpp>
+#include <boost/fusion/include/cons.hpp>
+
+namespace boost { namespace accumulators
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // as_feature
+ template<typename Feature>
+ struct as_feature
+ {
+ typedef Feature type;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // weighted_feature
+ template<typename Feature>
+ struct as_weighted_feature
+ {
+ typedef Feature type;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // feature_of
+ template<typename Feature>
+ struct feature_of
+ {
+ typedef Feature type;
+ };
+
+ namespace detail
+ {
+ ///////////////////////////////////////////////////////////////////////////
+ // feature_tag
+ template<typename Accumulator>
+ struct feature_tag
+ {
+ typedef typename Accumulator::feature_tag type;
+ };
+
+ template<typename Feature>
+ struct undroppable
+ {
+ typedef Feature type;
+ };
+
+ template<typename Feature>
+ struct undroppable<tag::droppable<Feature> >
+ {
+ typedef Feature type;
+ };
+
+ // For the purpose of determining whether one feature depends on another,
+ // disregard whether the feature is droppable or not.
+ template<typename A, typename B>
+ struct is_dependent_on
+ : is_base_and_derived<
+ typename undroppable<B>::type
+ , typename undroppable<A>::type
+ >
+ {};
+
+ template<typename Features>
+ struct depends_on_base
+ : mpl::inherit_linearly<
+ typename mpl::sort<Features, is_dependent_on<mpl::_1, mpl::_2> >::type
+ // Don't inherit multiply from a feature
+ , mpl::if_<
+ is_dependent_on<mpl::_1, mpl::_2>
+ , mpl::_1
+ , mpl::inherit<mpl::_1, mpl::_2>
+ >
+ >::type
+ {
+ };
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ /// depends_on
+ template<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature)>
+ struct depends_on
+ : detail::depends_on_base<
+ typename mpl::transform<
+ mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
+ , as_feature<mpl::_1>
+ >::type
+ >
+ {
+ typedef mpl::false_ is_weight_accumulator;
+ typedef
+ typename mpl::transform<
+ mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
+ , as_feature<mpl::_1>
+ >::type
+ dependencies;
+ };
+
+ namespace detail
+ {
+ template<typename Feature>
+ struct matches_feature
+ {
+ template<typename Accumulator>
+ struct apply
+ : is_same<
+ typename feature_of<typename as_feature<Feature>::type>::type
+ , typename feature_of<typename as_feature<typename feature_tag<Accumulator>::type>::type>::type
+ >
+ {};
+ };
+
+ template<typename Features, typename Accumulator>
+ struct contains_feature_of
+ {
+ typedef
+ mpl::transform_view<Features, feature_of<as_feature<mpl::_> > >
+ features_list;
+
+ typedef
+ typename feature_of<typename feature_tag<Accumulator>::type>::type
+ the_feature;
+
+ typedef
+ typename mpl::contains<features_list, the_feature>::type
+ type;
+ };
+
+ // This is to work around a bug in early versions of Fusion which caused
+ // a compile error if contains_feature_of<List, mpl::_> is used as a
+ // predicate to fusion::find_if
+ template<typename Features>
+ struct contains_feature_of_
+ {
+ template<typename Accumulator>
+ struct apply
+ : contains_feature_of<Features, Accumulator>
+ {};
+ };
+
+ template<
+ typename First
+ , typename Last
+ , bool is_empty = fusion::result_of::equal_to<First, Last>::value
+ >
+ struct build_acc_list;
+
+ template<typename First, typename Last>
+ struct build_acc_list<First, Last, true>
+ {
+ typedef fusion::nil type;
+
+ template<typename Args>
+ static fusion::nil
+ call(Args const &, First const&, Last const&)
+ {
+ return fusion::nil();
+ }
+ };
+
+ template<typename First, typename Last>
+ struct build_acc_list<First, Last, false>
+ {
+ typedef
+ build_acc_list<typename fusion::result_of::next<First>::type, Last>
+ next_build_acc_list;
+
+ typedef fusion::cons<
+ typename fusion::result_of::value_of<First>::type
+ , typename next_build_acc_list::type>
+ type;
+
+ template<typename Args>
+ static type
+ call(Args const &args, First const& f, Last const& l)
+ {
+ return type(args, next_build_acc_list::call(args, fusion::next(f), l));
+ }
+ };
+
+ namespace meta
+ {
+ template<typename Sequence>
+ struct make_acc_list
+ : build_acc_list<
+ typename fusion::result_of::begin<Sequence>::type
+ , typename fusion::result_of::end<Sequence>::type
+ >
+ {};
+ }
+
+ template<typename Sequence, typename Args>
+ typename meta::make_acc_list<Sequence>::type
+ make_acc_list(Sequence const &seq, Args const &args)
+ {
+ return meta::make_acc_list<Sequence>::call(args, fusion::begin(seq), fusion::end(seq));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // checked_as_weighted_feature
+ template<typename Feature>
+ struct checked_as_weighted_feature
+ {
+ typedef typename as_feature<Feature>::type feature_type;
+ typedef typename as_weighted_feature<feature_type>::type type;
+ // weighted and non-weighted flavors should provide the same feature.
+ BOOST_MPL_ASSERT((
+ is_same<
+ typename feature_of<feature_type>::type
+ , typename feature_of<type>::type
+ >
+ ));
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // as_feature_list
+ template<typename Features, typename Weight>
+ struct as_feature_list
+ : mpl::transform_view<Features, checked_as_weighted_feature<mpl::_1> >
+ {
+ };
+
+ template<typename Features>
+ struct as_feature_list<Features, void>
+ : mpl::transform_view<Features, as_feature<mpl::_1> >
+ {
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // accumulator_wrapper
+ template<typename Accumulator, typename Feature>
+ struct accumulator_wrapper
+ : Accumulator
+ {
+ typedef Feature feature_tag;
+
+ accumulator_wrapper(accumulator_wrapper const &that)
+ : Accumulator(*static_cast<Accumulator const *>(&that))
+ {
+ }
+
+ template<typename Args>
+ accumulator_wrapper(Args const &args)
+ : Accumulator(args)
+ {
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // to_accumulator
+ template<typename Feature, typename Sample, typename Weight>
+ struct to_accumulator
+ {
+ typedef
+ accumulator_wrapper<
+ typename mpl::apply2<typename Feature::impl, Sample, Weight>::type
+ , Feature
+ >
+ type;
+ };
+
+ template<typename Feature, typename Sample, typename Weight, typename Tag, typename AccumulatorSet>
+ struct to_accumulator<Feature, Sample, tag::external<Weight, Tag, AccumulatorSet> >
+ {
+ BOOST_MPL_ASSERT((is_same<Tag, void>));
+ BOOST_MPL_ASSERT((is_same<AccumulatorSet, void>));
+
+ typedef
+ accumulator_wrapper<
+ typename mpl::apply2<typename Feature::impl, Sample, Weight>::type
+ , Feature
+ >
+ accumulator_type;
+
+ typedef
+ typename mpl::if_<
+ typename Feature::is_weight_accumulator
+ , accumulator_wrapper<impl::external_impl<accumulator_type, tag::weights>, Feature>
+ , accumulator_type
+ >::type
+ type;
+ };
+
+ // BUGBUG work around a MPL bug wrt map insertion
+ template<typename FeatureMap, typename Feature>
+ struct insert_feature
+ : mpl::eval_if<
+ mpl::has_key<FeatureMap, typename feature_of<Feature>::type>
+ , mpl::identity<FeatureMap>
+ , mpl::insert<FeatureMap, mpl::pair<typename feature_of<Feature>::type, Feature> >
+ >
+ {
+ };
+
+ template<typename FeatureMap, typename Feature, typename Weight>
+ struct insert_dependencies
+ : mpl::fold<
+ as_feature_list<typename Feature::dependencies, Weight>
+ , FeatureMap
+ , insert_dependencies<
+ insert_feature<mpl::_1, mpl::_2>
+ , mpl::_2
+ , Weight
+ >
+ >
+ {
+ };
+
+ template<typename FeatureMap, typename Features, typename Weight>
+ struct insert_sequence
+ : mpl::fold< // BUGBUG should use insert_range, but doesn't seem to work for maps
+ as_feature_list<Features, Weight>
+ , FeatureMap
+ , insert_feature<mpl::_1, mpl::_2>
+ >
+ {
+ };
+
+ template<typename Features, typename Sample, typename Weight>
+ struct make_accumulator_tuple
+ {
+ typedef
+ typename mpl::fold<
+ as_feature_list<Features, Weight>
+ , mpl::map0<>
+ , mpl::if_<
+ mpl::is_sequence<mpl::_2>
+ , insert_sequence<mpl::_1, mpl::_2, Weight>
+ , insert_feature<mpl::_1, mpl::_2>
+ >
+ >::type
+ feature_map;
+
+ // for each element in the map, add its dependencies also
+ typedef
+ typename mpl::fold<
+ feature_map
+ , feature_map
+ , insert_dependencies<mpl::_1, mpl::second<mpl::_2>, Weight>
+ >::type
+ feature_map_with_dependencies;
+
+ // turn the map into a vector so we can sort it
+ typedef
+ typename mpl::insert_range<
+ mpl::vector<>
+ , mpl::end<mpl::vector<> >::type
+ , mpl::transform_view<feature_map_with_dependencies, mpl::second<mpl::_1> >
+ >::type
+ feature_vector_with_dependencies;
+
+ // sort the features according to which is derived from which
+ typedef
+ typename mpl::sort<
+ feature_vector_with_dependencies
+ , is_dependent_on<mpl::_2, mpl::_1>
+ >::type
+ sorted_feature_vector;
+
+ // From the vector of features, construct a vector of accumulators
+ typedef
+ typename mpl::transform<
+ sorted_feature_vector
+ , to_accumulator<mpl::_1, Sample, Weight>
+ >::type
+ type;
+ };
+
+ } // namespace detail
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/external.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/external.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+// external.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_EXTERNAL_HPP_EAN_01_12_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_EXTERNAL_HPP_EAN_01_12_2005
+
+#include <boost/mpl/apply.hpp>
+#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
+
+//namespace boost { namespace accumulators
+//{
+//
+/////////////////////////////////////////////////////////////////////////////////
+//// external
+////
+//template<typename Type>
+//struct external
+//{
+//};
+//
+//}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/extractor.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/extractor.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,229 @@
+///////////////////////////////////////////////////////////////////////////////
+// extractor.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005
+
+#include <boost/preprocessor/tuple/rem.hpp>
+#include <boost/preprocessor/array/size.hpp>
+#include <boost/preprocessor/array/data.hpp>
+#include <boost/preprocessor/array/elem.hpp>
+#include <boost/preprocessor/seq/to_array.hpp>
+#include <boost/preprocessor/seq/transform.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
+#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
+#include <boost/parameter/binding.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/accumulators/accumulators_fwd.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace detail
+{
+ template<typename AccumulatorSet, typename Feature>
+ struct accumulator_set_result
+ {
+ typedef typename as_feature<Feature>::type feature_type;
+ typedef typename mpl::apply<AccumulatorSet, feature_type>::type::result_type type;
+ };
+
+ template<typename Args, typename Feature>
+ struct argument_pack_result
+ : accumulator_set_result<
+ typename remove_reference<
+ typename parameter::binding<Args, tag::accumulator>::type
+ >::type
+ , Feature
+ >
+ {
+ };
+
+ template<typename A, typename Feature>
+ struct extractor_result
+ : mpl::eval_if<
+ detail::is_accumulator_set<A>
+ , accumulator_set_result<A, Feature>
+ , argument_pack_result<A, Feature>
+ >
+ {
+ };
+
+ template<typename Feature, typename AccumulatorSet>
+ typename extractor_result<AccumulatorSet, Feature>::type
+ do_extract(AccumulatorSet const &acc, mpl::true_)
+ {
+ typedef typename as_feature<Feature>::type feature_type;
+ return extract_result<feature_type>(acc);
+ }
+
+ template<typename Feature, typename Args>
+ typename extractor_result<Args, Feature>::type
+ do_extract(Args const &args, mpl::false_)
+ {
+ typedef typename as_feature<Feature>::type feature_type;
+ return find_accumulator<feature_type>(args[accumulator]).result(args);
+ }
+
+} // namespace detail
+
+
+///////////////////////////////////////////////////////////////////////////////
+/// Extracts the result associated with Feature from the specified accumulator_set.
+template<typename Feature>
+struct extractor
+{
+ typedef extractor<Feature> this_type;
+
+ /// The result meta-function for determining the return type of the extractor
+ template<typename F>
+ struct result;
+
+ template<typename A1>
+ struct result<this_type(A1)>
+ : detail::extractor_result<A1, Feature>
+ {
+ };
+
+ /// Extract the result associated with Feature from the accumulator set
+ /// \param acc The accumulator set object from which to extract the result
+ template<typename Arg1>
+ typename detail::extractor_result<Arg1, Feature>::type
+ operator ()(Arg1 const &arg1) const
+ {
+ // Arg1 could be an accumulator_set or an argument pack containing
+ // an accumulator_set. Dispatch accordingly.
+ return detail::do_extract<Feature>(arg1, detail::is_accumulator_set<Arg1>());
+ }
+
+ /// \overload
+ ///
+ /// \param a1 Optional named parameter to be passed to the accumulator's result() function.
+ template<typename AccumulatorSet, typename A1>
+ typename detail::extractor_result<AccumulatorSet, Feature>::type
+ operator ()(AccumulatorSet const &acc, A1 const &a1) const
+ {
+ BOOST_MPL_ASSERT((detail::is_accumulator_set<AccumulatorSet>));
+ typedef typename as_feature<Feature>::type feature_type;
+ return extract_result<feature_type>(acc, a1);
+ }
+
+ // ... other overloads generated by Boost.Preprocessor:
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP(z, n, _) \
+ template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)> \
+ struct result<this_type(BOOST_PP_ENUM_PARAMS_Z(z, n, A))> \
+ : detail::extractor_result<A1, Feature> \
+ {}; \
+ template< \
+ typename AccumulatorSet \
+ BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
+ > \
+ typename detail::extractor_result<AccumulatorSet, Feature>::type \
+ operator ()( \
+ AccumulatorSet const &acc \
+ BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \
+ ) const \
+ { \
+ BOOST_MPL_ASSERT((detail::is_accumulator_set<AccumulatorSet>)); \
+ typedef typename as_feature<Feature>::type feature_type; \
+ return extract_result<feature_type>(acc BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a));\
+ }
+
+ BOOST_PP_REPEAT_FROM_TO(
+ 2
+ , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
+ , BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP
+ , _
+ )
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// \overload
+ ///
+ template<typename AccumulatorSet, typename A1, typename A2, ...>
+ typename detail::extractor_result<AccumulatorSet, Feature>::type
+ operator ()(AccumulatorSet const &acc, A1 const &a1, A2 const &a2, ...);
+ #endif
+};
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_ARRAY_REM(Array) \
+ BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_ARRAY_SIZE(Array), BOOST_PP_ARRAY_DATA(Array))
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_SEQ_REM(Seq) \
+ BOOST_ACCUMULATORS_ARRAY_REM(BOOST_PP_SEQ_TO_ARRAY(Seq))
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_ARGS_OP(s, data, elem) \
+ T ## s
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_PARAMS_OP(s, data, elem) \
+ elem T ## s
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) \
+ Tag::Feature< \
+ BOOST_ACCUMULATORS_SEQ_REM( \
+ BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_ARGS_OP, ~, ParamsSeq) \
+ ) \
+ >
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN_IMPL(z, n, Tag, Feature, ParamsSeq) \
+ template< \
+ BOOST_ACCUMULATORS_SEQ_REM( \
+ BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_PARAMS_OP, ~, ParamsSeq) \
+ ) \
+ , typename Arg1 \
+ BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \
+ > \
+ typename boost::accumulators::detail::extractor_result< \
+ Arg1 \
+ , BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) \
+ >::type \
+ Feature(Arg1 const &arg1 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) ) \
+ { \
+ typedef BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) feature_type; \
+ return boost::accumulators::extractor<feature_type>()( \
+ arg1 BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a)); \
+ }
+
+/// INTERNAL ONLY
+///
+#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN(z, n, _) \
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN_IMPL( \
+ z \
+ , n \
+ , BOOST_PP_ARRAY_ELEM(0, _) \
+ , BOOST_PP_ARRAY_ELEM(1, _) \
+ , BOOST_PP_ARRAY_ELEM(2, _) \
+ )
+
+#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(Tag, Feature, ParamSeq) \
+ BOOST_PP_REPEAT( \
+ BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS) \
+ , BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN \
+ , (3, (Tag, Feature, ParamSeq)) \
+ )
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/features.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/features.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,29 @@
+///////////////////////////////////////////////////////////////////////////////
+// features.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_08_12_2005
+#define BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_08_12_2005
+
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/accumulators/accumulators_fwd.hpp>
+
+namespace boost { namespace accumulators
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// features
+//
+template<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature)>
+struct features
+ : mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/parameters/accumulator.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/parameters/accumulator.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,20 @@
+///////////////////////////////////////////////////////////////////////////////
+// accumulator.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005
+
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { namespace accumulators
+{
+
+BOOST_PARAMETER_KEYWORD(tag, accumulator)
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/parameters/sample.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/parameters/sample.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,20 @@
+///////////////////////////////////////////////////////////////////////////////
+// sample.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005
+
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { namespace accumulators
+{
+
+BOOST_PARAMETER_KEYWORD(tag, sample)
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/parameters/weight.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/parameters/weight.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,21 @@
+///////////////////////////////////////////////////////////////////////////////
+// weight.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005
+
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { namespace accumulators
+{
+
+// The weight of a single sample
+BOOST_PARAMETER_KEYWORD(tag, weight)
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/framework/parameters/weights.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/framework/parameters/weights.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,21 @@
+///////////////////////////////////////////////////////////////////////////////
+// weights.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005
+
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { namespace accumulators
+{
+
+// The weight accumulator
+BOOST_PARAMETER_KEYWORD(tag, weights)
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/numeric/detail/function1.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/detail/function1.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,75 @@
+// Copyright David Abrahams 2006. 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_DETAIL_FUNCTION1_DWA200655_HPP
+# define BOOST_DETAIL_FUNCTION1_DWA200655_HPP
+
+# include <boost/concept_check.hpp>
+# include <boost/type_traits/remove_reference.hpp>
+# include <boost/type_traits/add_const.hpp>
+# include <boost/mpl/apply.hpp>
+
+namespace boost { namespace detail {
+
+// A utility for creating unary function objects that play nicely with
+// boost::result_of and that handle the forwarding problem.
+//
+// mpl::apply<F, A0>::type is expected to be a stateless function
+// object that accepts an argument of type A0&. It is also expected
+// to have a nested ::result_type identical to its return type.
+template<typename F>
+struct function1
+{
+ template<typename Signature>
+ struct result
+ {};
+
+ template<typename This, typename A0>
+ struct result<This(A0)>
+ {
+ // How adding const to arguments handles rvalues.
+ //
+ // if A0 is arg0 is represents actual argument
+ // -------- ------- --------------------------
+ // T const & T const const T lvalue
+ // T & T non-const T lvalue
+ // T const T const const T rvalue
+ // T T const non-const T rvalue
+ typedef typename remove_reference<
+ typename add_const< A0 >::type
+ >::type arg0;
+
+ typedef typename mpl::apply1<F, arg0>::type impl;
+ typedef typename impl::result_type type;
+ };
+
+ // Handles mutable lvalues
+ template<typename A0>
+ typename result<function1(A0 &)>::type
+ operator ()(A0 &a0) const
+ {
+ typedef typename result<function1(A0 &)>::impl impl;
+ typedef typename result<function1(A0 &)>::type type;
+ typedef A0 &arg0;
+ BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
+ //boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
+ return impl()(a0);
+ }
+
+ // Handles const lvalues and all rvalues
+ template<typename A0>
+ typename result<function1(A0 const &)>::type
+ operator ()(A0 const &a0) const
+ {
+ typedef typename result<function1(A0 const &)>::impl impl;
+ typedef typename result<function1(A0 const &)>::type type;
+ typedef A0 const &arg0;
+ BOOST_CONCEPT_ASSERT((UnaryFunction<impl, type, arg0>));
+ //boost::function_requires<UnaryFunctionConcept<impl, type, arg0> >();
+ return impl()(a0);
+ }
+};
+
+}} // namespace boost::detail
+
+#endif // BOOST_DETAIL_FUNCTION1_DWA200655_HPP
Added: branches/release/boost/accumulators/numeric/detail/function2.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/detail/function2.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,10 @@
+// Copyright David Abrahams 2006. 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_DETAIL_FUNCTION2_DWA200655_HPP
+# define BOOST_DETAIL_FUNCTION2_DWA200655_HPP
+
+# define args (2)
+# include <boost/accumulators/numeric/detail/function_n.hpp>
+
+#endif // BOOST_DETAIL_FUNCTION2_DWA200655_HPP
Added: branches/release/boost/accumulators/numeric/detail/function3.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/detail/function3.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,10 @@
+// Copyright David Abrahams 2006. 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_DETAIL_FUNCTION3_DWA2006514_HPP
+# define BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
+
+# define args (3)
+# include <boost/accumulators/numeric/detail/function_n.hpp>
+
+#endif // BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
Added: branches/release/boost/accumulators/numeric/detail/function4.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/detail/function4.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,10 @@
+// Copyright David Abrahams 2006. 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_DETAIL_FUNCTION4_DWA2006514_HPP
+# define BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
+
+# define args (4)
+# include <boost/accumulators/numeric/detail/function_n.hpp>
+
+#endif // BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
Added: branches/release/boost/accumulators/numeric/detail/function_n.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/detail/function_n.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,148 @@
+// Copyright David Abrahams 2006. 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)
+//
+// #include guards intentionally disabled.
+// #ifndef BOOST_DETAIL_FUNCTION_N_DWA2006514_HPP
+// # define BOOST_DETAIL_FUNCTION_N_DWA2006514_HPP
+
+#include <boost/mpl/void.hpp>
+#include <boost/mpl/apply.hpp>
+
+#include <boost/preprocessor/control/if.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/seq/fold_left.hpp>
+#include <boost/preprocessor/seq/seq.hpp>
+#include <boost/preprocessor/seq/for_each.hpp>
+#include <boost/preprocessor/seq/for_each_i.hpp>
+#include <boost/preprocessor/seq/for_each_product.hpp>
+#include <boost/preprocessor/seq/size.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+
+namespace boost { namespace detail {
+
+# define BOOST_DETAIL_default_arg(z, n, _) \
+ typedef mpl::void_ BOOST_PP_CAT(arg, n);
+
+# define BOOST_DETAIL_function_arg(z, n, _) \
+ typedef typename remove_reference< \
+ typename add_const< BOOST_PP_CAT(A, n) >::type \
+ >::type BOOST_PP_CAT(arg, n);
+
+#define BOOST_DETAIL_cat_arg_counts(s, state, n) \
+ BOOST_PP_IF( \
+ n \
+ , BOOST_PP_CAT(state, BOOST_PP_CAT(_, n)) \
+ , state \
+ ) \
+ /**/
+
+#define function_name \
+ BOOST_PP_SEQ_FOLD_LEFT( \
+ BOOST_DETAIL_cat_arg_counts \
+ , BOOST_PP_CAT(function, BOOST_PP_SEQ_HEAD(args)) \
+ , BOOST_PP_SEQ_TAIL(args)(0) \
+ ) \
+ /**/
+
+template<typename F>
+struct function_name
+{
+ BOOST_PP_REPEAT(
+ BOOST_MPL_LIMIT_METAFUNCTION_ARITY
+ , BOOST_DETAIL_default_arg
+ , ~
+ )
+
+ template<typename Signature>
+ struct result {};
+
+#define BOOST_DETAIL_function_result(r, _, n) \
+ template<typename This BOOST_PP_ENUM_TRAILING_PARAMS(n, typename A)> \
+ struct result<This(BOOST_PP_ENUM_PARAMS(n, A))> \
+ { \
+ BOOST_PP_REPEAT(n, BOOST_DETAIL_function_arg, ~) \
+ typedef \
+ typename BOOST_PP_CAT(mpl::apply, BOOST_MPL_LIMIT_METAFUNCTION_ARITY)<\
+ F \
+ BOOST_PP_ENUM_TRAILING_PARAMS( \
+ BOOST_MPL_LIMIT_METAFUNCTION_ARITY \
+ , arg \
+ ) \
+ >::type \
+ impl; \
+ typedef typename impl::result_type type; \
+ }; \
+ /**/
+
+ BOOST_PP_SEQ_FOR_EACH(BOOST_DETAIL_function_result, _, args)
+
+# define arg_type(r, _, i, is_const) \
+ BOOST_PP_COMMA_IF(i) BOOST_PP_CAT(A, i) BOOST_PP_CAT(const_if, is_const) &
+
+# define result_(r, n, constness) \
+ typename result< \
+ function_name( \
+ BOOST_PP_SEQ_FOR_EACH_I_R(r, arg_type, ~, constness) \
+ ) \
+ > \
+ /**/
+
+# define param(r, _, i, is_const) BOOST_PP_COMMA_IF(i) \
+ BOOST_PP_CAT(A, i) BOOST_PP_CAT(const_if, is_const) & BOOST_PP_CAT(x, i)
+
+# define param_list(r, n, constness) \
+ BOOST_PP_SEQ_FOR_EACH_I_R(r, param, ~, constness)
+
+# define call_operator(r, constness) \
+ template<BOOST_PP_ENUM_PARAMS(BOOST_PP_SEQ_SIZE(constness), typename A)> \
+ result_(r, BOOST_PP_SEQ_SIZE(constness), constness)::type \
+ operator ()( param_list(r, BOOST_PP_SEQ_SIZE(constness), constness) ) const \
+ { \
+ typedef result_(r, BOOST_PP_SEQ_SIZE(constness), constness)::impl impl; \
+ return impl()(BOOST_PP_ENUM_PARAMS(BOOST_PP_SEQ_SIZE(constness), x)); \
+ } \
+ /**/
+
+# define const_if0
+# define const_if1 const
+
+# define bits(z, n, _) ((0)(1))
+
+# define gen_operator(r, _, n) \
+ BOOST_PP_SEQ_FOR_EACH_PRODUCT_R( \
+ r \
+ , call_operator \
+ , BOOST_PP_REPEAT(n, bits, ~) \
+ ) \
+ /**/
+
+ BOOST_PP_SEQ_FOR_EACH(
+ gen_operator
+ , ~
+ , args
+ )
+
+# undef bits
+# undef const_if1
+# undef const_if0
+# undef call_operator
+# undef param_list
+# undef param
+# undef result_
+# undef default_
+# undef arg_type
+# undef gen_operator
+# undef function_name
+
+# undef args
+};
+
+}} // namespace boost::detail
+
+//#endif // BOOST_DETAIL_FUNCTION_N_DWA2006514_HPP
Added: branches/release/boost/accumulators/numeric/detail/pod_singleton.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/detail/pod_singleton.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,20 @@
+// Copyright David Abrahams 2006. 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_DETAIL_POD_SINGLETON_DWA200655_HPP
+# define BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
+
+namespace boost { namespace detail {
+
+template<typename T>
+struct pod_singleton
+{
+ static T instance;
+};
+
+template<typename T>
+T pod_singleton<T>::instance;
+
+}} // namespace boost::detail
+
+#endif // BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
Added: branches/release/boost/accumulators/numeric/functional.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/functional.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,490 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file functional.hpp
+///
+// Copyright 2005 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)
+
+#ifndef BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005
+
+#include <limits>
+#include <functional>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/type_traits/add_reference.hpp>
+#include <boost/type_traits/is_empty.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/type_traits/is_floating_point.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/accumulators/numeric/functional_fwd.hpp>
+#include <boost/accumulators/numeric/detail/function1.hpp>
+#include <boost/accumulators/numeric/detail/function2.hpp>
+#include <boost/accumulators/numeric/detail/pod_singleton.hpp>
+
+#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+# include <boost/accumulators/numeric/functional/vector.hpp>
+#endif
+
+#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
+# include <boost/accumulators/numeric/functional/valarray.hpp>
+#endif
+
+#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
+# include <boost/accumulators/numeric/functional/complex.hpp>
+#endif
+
+/// INTERNAL ONLY
+///
+#define BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
+
+#ifdef BOOST_NUMERIC_FUNCTIONAL_DOXYGEN_INVOKED
+// Hack to make Doxygen show the inheritance relationships
+/// INTERNAL ONLY
+///
+namespace std
+{
+ /// INTERNAL ONLY
+ ///
+ template<class Arg, class Ret> struct unary_function {};
+ /// INTERNAL ONLY
+ ///
+ template<class Left, class Right, class Ret> struct binary_function {};
+}
+#endif
+
+namespace boost { namespace numeric
+{
+ namespace functional
+ {
+ /// INTERNAL ONLY
+ ///
+ template<typename A0, typename A1>
+ struct are_integral
+ : mpl::and_<is_integral<A0>, is_integral<A1> >
+ {};
+
+ template<typename Left, typename Right>
+ struct left_ref
+ {
+ typedef Left &type;
+ };
+
+ namespace detail
+ {
+ template<typename T>
+ T &lvalue_of();
+ }
+ }
+
+ // TODO: handle complex weight, valarray, MTL vectors
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(Name, Op) \
+ namespace functional \
+ { \
+ template<typename Arg> \
+ struct result_of_ ## Name \
+ { \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL( \
+ nested \
+ , Op boost::numeric::functional::detail::lvalue_of<Arg>() \
+ ) \
+ typedef typename nested::type type; \
+ }; \
+ template<typename Arg, typename EnableIf> \
+ struct Name ## _base \
+ : std::unary_function< \
+ typename remove_const<Arg>::type \
+ , typename result_of_ ## Name<Arg>::type \
+ > \
+ { \
+ typename result_of_ ## Name<Arg>::type operator ()(Arg &arg) const \
+ { \
+ return Op arg; \
+ } \
+ }; \
+ template<typename Arg, typename ArgTag> \
+ struct Name \
+ : Name ## _base<Arg, void> \
+ {}; \
+ } \
+ namespace op \
+ { \
+ struct Name \
+ : boost::detail::function1<functional::Name<_, functional::tag<_> > > \
+ {}; \
+ } \
+ namespace \
+ { \
+ op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance; \
+ } \
+ /**/
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(Name, Op, RetType) \
+ namespace functional \
+ { \
+ template<typename Left, typename Right, typename EnableIf> \
+ struct result_of_ ## Name \
+ { \
+ RetType(Left, Op, Right) \
+ }; \
+ template<typename Left, typename Right, typename EnableIf> \
+ struct Name ## _base \
+ : std::binary_function< \
+ typename remove_const<Left>::type \
+ , typename remove_const<Right>::type \
+ , typename result_of_ ## Name<Left, Right>::type \
+ > \
+ { \
+ typename result_of_ ## Name<Left, Right>::type \
+ operator ()(Left &left, Right &right) const \
+ { \
+ return left Op right; \
+ } \
+ }; \
+ template<typename Left, typename Right, typename LeftTag, typename RightTag> \
+ struct Name \
+ : Name ## _base<Left, Right, void> \
+ {}; \
+ } \
+ namespace op \
+ { \
+ struct Name \
+ : boost::detail::function2< \
+ functional::Name<_1, _2, functional::tag<_1>, functional::tag<_2> > \
+ > \
+ {}; \
+ } \
+ namespace \
+ { \
+ op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance; \
+ } \
+ /**/
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_NUMERIC_FUNCTIONAL_DEDUCED(Left, Op, Right) \
+ BOOST_TYPEOF_NESTED_TYPEDEF_TPL( \
+ nested \
+ , boost::numeric::functional::detail::lvalue_of<Left>() Op \
+ boost::numeric::functional::detail::lvalue_of<Right>() \
+ ) \
+ typedef typename nested::type type; \
+ /**/
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_NUMERIC_FUNCTIONAL_LEFT(Left, Op, Right) \
+ typedef Left &type; \
+ /**/
+
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(plus, +, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(minus, -, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(multiplies, *, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(divides, /, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(modulus, %, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(greater, >, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(greater_equal, >=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(less, <, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(less_equal, <=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(equal_to, ==, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(not_equal_to, !=, BOOST_NUMERIC_FUNCTIONAL_DEDUCED)
+
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(assign, =, BOOST_NUMERIC_FUNCTIONAL_LEFT)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(plus_assign, +=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(minus_assign, -=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(multiplies_assign, *=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(divides_assign, /=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(modulus_assign, %=, BOOST_NUMERIC_FUNCTIONAL_LEFT)
+
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(unary_plus, +)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(unary_minus, -)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(complement, ~)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(logical_not, !)
+
+#undef BOOST_NUMERIC_FUNCTIONAL_LEFT
+#undef BOOST_NUMERIC_FUNCTIONAL_DEDUCED
+#undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP
+#undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP
+
+ namespace functional
+ {
+ template<typename Left, typename Right, typename EnableIf>
+ struct min_assign_base
+ : std::binary_function<Left, Right, void>
+ {
+ void operator ()(Left &left, Right &right) const
+ {
+ if(numeric::less(right, left))
+ {
+ left = right;
+ }
+ }
+ };
+
+ template<typename Left, typename Right, typename EnableIf>
+ struct max_assign_base
+ : std::binary_function<Left, Right, void>
+ {
+ void operator ()(Left &left, Right &right) const
+ {
+ if(numeric::greater(right, left))
+ {
+ left = right;
+ }
+ }
+ };
+
+ template<typename Left, typename Right, typename EnableIf>
+ struct average_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>
+ : functional::divides<double const, double const>
+ {};
+
+ template<typename To, typename From, typename EnableIf>
+ struct promote_base
+ : std::unary_function<From, To>
+ {
+ To operator ()(From &from) const
+ {
+ return from;
+ }
+ };
+
+ template<typename ToFrom>
+ struct promote_base<ToFrom, ToFrom, void>
+ : std::unary_function<ToFrom, ToFrom>
+ {
+ ToFrom &operator ()(ToFrom &tofrom)
+ {
+ return tofrom;
+ }
+ };
+
+ template<typename Arg, typename EnableIf>
+ struct as_min_base
+ : std::unary_function<Arg, typename remove_const<Arg>::type>
+ {
+ typename remove_const<Arg>::type operator ()(Arg &) const
+ {
+ return (std::numeric_limits<typename remove_const<Arg>::type>::min)();
+ }
+ };
+
+ template<typename Arg>
+ struct as_min_base<Arg, typename enable_if<is_floating_point<Arg> >::type>
+ : std::unary_function<Arg, typename remove_const<Arg>::type>
+ {
+ typename remove_const<Arg>::type operator ()(Arg &) const
+ {
+ return -(std::numeric_limits<typename remove_const<Arg>::type>::max)();
+ }
+ };
+
+ template<typename Arg, typename EnableIf>
+ struct as_max_base
+ : std::unary_function<Arg, typename remove_const<Arg>::type>
+ {
+ typename remove_const<Arg>::type operator ()(Arg &) const
+ {
+ return (std::numeric_limits<typename remove_const<Arg>::type>::max)();
+ }
+ };
+
+ template<typename Arg, typename EnableIf>
+ struct as_zero_base
+ : std::unary_function<Arg, typename remove_const<Arg>::type>
+ {
+ typename remove_const<Arg>::type operator ()(Arg &) const
+ {
+ return numeric::zero<typename remove_const<Arg>::type>::value;
+ }
+ };
+
+ template<typename Arg, typename EnableIf>
+ struct as_one_base
+ : std::unary_function<Arg, typename remove_const<Arg>::type>
+ {
+ typename remove_const<Arg>::type operator ()(Arg &) const
+ {
+ return numeric::one<typename remove_const<Arg>::type>::value;
+ }
+ };
+
+ template<typename To, typename From, typename ToTag, typename FromTag>
+ struct promote
+ : promote_base<To, From, void>
+ {};
+
+ template<typename Left, typename Right, typename LeftTag, typename RightTag>
+ struct min_assign
+ : min_assign_base<Left, Right, void>
+ {};
+
+ template<typename Left, typename Right, typename LeftTag, typename RightTag>
+ struct max_assign
+ : max_assign_base<Left, Right, void>
+ {};
+
+ template<typename Left, typename Right, typename LeftTag, typename RightTag>
+ struct average
+ : average_base<Left, Right, void>
+ {};
+
+ template<typename Arg, typename Tag>
+ struct as_min
+ : as_min_base<Arg, void>
+ {};
+
+ template<typename Arg, typename Tag>
+ struct as_max
+ : as_max_base<Arg, void>
+ {};
+
+ template<typename Arg, typename Tag>
+ struct as_zero
+ : as_zero_base<Arg, void>
+ {};
+
+ template<typename Arg, typename Tag>
+ struct as_one
+ : as_one_base<Arg, void>
+ {};
+ }
+
+ namespace op
+ {
+ template<typename To>
+ struct promote
+ : boost::detail::function1<functional::promote<To, _, typename functional::tag<To>::type, functional::tag<_> > >
+ {};
+
+ struct min_assign
+ : boost::detail::function2<functional::min_assign<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ {};
+
+ struct max_assign
+ : boost::detail::function2<functional::max_assign<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ {};
+
+ struct average
+ : boost::detail::function2<functional::average<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ {};
+
+ struct as_min
+ : boost::detail::function1<functional::as_min<_, functional::tag<_> > >
+ {};
+
+ struct as_max
+ : boost::detail::function1<functional::as_max<_, functional::tag<_> > >
+ {};
+
+ struct as_zero
+ : boost::detail::function1<functional::as_zero<_, functional::tag<_> > >
+ {};
+
+ struct as_one
+ : boost::detail::function1<functional::as_one<_, functional::tag<_> > >
+ {};
+ }
+
+ namespace
+ {
+ 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::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;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // promote
+ template<typename To, typename From>
+ typename lazy_disable_if<is_const<From>, mpl::if_<is_same<To, From>, To &, To> >::type
+ promote(From &from)
+ {
+ return functional::promote<To, From>()(from);
+ }
+
+ template<typename To, typename From>
+ typename mpl::if_<is_same<To const, From const>, To const &, To const>::type
+ promote(From const &from)
+ {
+ return functional::promote<To const, From const>()(from);
+ }
+
+ template<typename T>
+ struct default_
+ {
+ typedef default_ type;
+ typedef T value_type;
+ static T const value;
+
+ operator T const & () const
+ {
+ return default_::value;
+ }
+ };
+
+ template<typename T>
+ T const default_<T>::value = T();
+
+ template<typename T>
+ struct one
+ {
+ typedef one type;
+ typedef T value_type;
+ static T const value;
+
+ operator T const & () const
+ {
+ return one::value;
+ }
+ };
+
+ template<typename T>
+ T const one<T>::value = T(1);
+
+ template<typename T>
+ struct zero
+ {
+ typedef zero type;
+ typedef T value_type;
+ static T const value;
+
+ operator T const & () const
+ {
+ return zero::value;
+ }
+ };
+
+ template<typename T>
+ T const zero<T>::value = T();
+
+ template<typename T>
+ struct one_or_default
+ : mpl::if_<is_empty<T>, default_<T>, one<T> >::type
+ {};
+
+ template<typename T>
+ struct zero_or_default
+ : mpl::if_<is_empty<T>, default_<T>, zero<T> >::type
+ {};
+
+}} // namespace boost::numeric
+
+#endif
Added: branches/release/boost/accumulators/numeric/functional/complex.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/functional/complex.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,82 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file complex.hpp
+///
+// Copyright 2005 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)
+
+#ifndef BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
+#define BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
+
+#ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
+# error Include this file before boost/accumulators/numeric/functional.hpp
+#endif
+
+#include <complex>
+#include <boost/mpl/or.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/typeof/std/complex.hpp>
+#include <boost/accumulators/numeric/functional_fwd.hpp>
+
+namespace boost { namespace numeric { namespace operators
+{
+ // So that the stats compile when Sample type is std::complex
+ template<typename T, typename U>
+ typename
+ disable_if<
+ mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
+ , std::complex<T>
+ >::type
+ operator *(std::complex<T> ri, U const &u)
+ {
+ // BUGBUG promote result to typeof(T()*u) ?
+ return ri *= static_cast<T>(u);
+ }
+
+ template<typename T, typename U>
+ typename
+ disable_if<
+ mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
+ , std::complex<T>
+ >::type
+ operator /(std::complex<T> ri, U const &u)
+ {
+ // BUGBUG promote result to typeof(T()*u) ?
+ return ri /= static_cast<T>(u);
+ }
+
+}}} // namespace boost::numeric::operators
+
+namespace boost { namespace numeric
+{
+ namespace detail
+ {
+ template<typename T>
+ struct one_complex
+ {
+ static std::complex<T> const value;
+ };
+
+ template<typename T>
+ std::complex<T> const one_complex<T>::value
+ = std::complex<T>(numeric::one<T>::value, numeric::one<T>::value);
+ }
+
+ /// INTERNAL ONLY
+ ///
+ template<typename T>
+ struct one<std::complex<T> >
+ : detail::one_complex<T>
+ {
+ typedef one type;
+ typedef std::complex<T> value_type;
+ operator value_type const & () const
+ {
+ return detail::one_complex<T>::value;
+ }
+ };
+
+}} // namespace boost::numeric
+
+#endif
Added: branches/release/boost/accumulators/numeric/functional/valarray.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/functional/valarray.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,351 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file valarray.hpp
+///
+// Copyright 2005 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)
+
+#ifndef BOOST_NUMERIC_FUNCTIONAL_VALARRAY_HPP_EAN_12_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_VALARRAY_HPP_EAN_12_12_2005
+
+#ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
+# error Include this file before boost/accumulators/numeric/functional.hpp
+#endif
+
+#include <valarray>
+#include <functional>
+#include <boost/assert.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_scalar.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/typeof/std/valarray.hpp>
+#include <boost/accumulators/numeric/functional_fwd.hpp>
+
+namespace boost { namespace numeric
+{
+ namespace operators
+ {
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle valarray<Left> / Right where Right is a scalar and Right != Left.
+ template<typename Left, typename Right>
+ typename enable_if<
+ mpl::and_<is_scalar<Right>, mpl::not_<is_same<Left, Right> > >
+ , std::valarray<typename functional::divides<Left, Right>::result_type>
+ >::type
+ operator /(std::valarray<Left> const &left, Right const &right)
+ {
+ typedef typename functional::divides<Left, Right>::result_type value_type;
+ std::valarray<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::divides(left[i], right);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle valarray<Left> * Right where Right is a scalar and Right != Left.
+ template<typename Left, typename Right>
+ typename enable_if<
+ mpl::and_<is_scalar<Right>, mpl::not_<is_same<Left, Right> > >
+ , std::valarray<typename functional::multiplies<Left, Right>::result_type>
+ >::type
+ operator *(std::valarray<Left> const &left, Right const &right)
+ {
+ typedef typename functional::multiplies<Left, Right>::result_type value_type;
+ std::valarray<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::multiplies(left[i], right);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle valarray<Left> + valarray<Right> where Right != Left.
+ template<typename Left, typename Right>
+ typename disable_if<
+ is_same<Left, Right>
+ , std::valarray<typename functional::plus<Left, Right>::result_type>
+ >::type
+ operator +(std::valarray<Left> const &left, std::valarray<Right> const &right)
+ {
+ typedef typename functional::plus<Left, Right>::result_type value_type;
+ std::valarray<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::plus(left[i], right[i]);
+ }
+ return result;
+ }
+ }
+
+ namespace functional
+ {
+ struct std_valarray_tag;
+
+ template<typename T>
+ struct tag<std::valarray<T> >
+ {
+ typedef std_valarray_tag type;
+ };
+
+ #ifdef __GLIBCXX__
+ template<typename T, typename U>
+ struct tag<std::_Expr<T, U> >
+ {
+ typedef std_valarray_tag type;
+ };
+ #endif
+
+ /// INTERNAL ONLY
+ ///
+ // This is necessary because the GCC stdlib uses expression templates, and
+ // typeof(som-valarray-expression) is not an instance of std::valarray
+ #define BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(Name, Op) \
+ template<typename Left, typename Right> \
+ struct Name<Left, Right, std_valarray_tag, std_valarray_tag> \
+ : std::binary_function< \
+ Left \
+ , Right \
+ , std::valarray< \
+ typename Name< \
+ typename Left::value_type \
+ , typename Right::value_type \
+ >::result_type \
+ > \
+ > \
+ { \
+ typedef typename Left::value_type left_value_type; \
+ typedef typename Right::value_type right_value_type; \
+ typedef \
+ std::valarray< \
+ typename Name<left_value_type, right_value_type>::result_type \
+ > \
+ result_type; \
+ result_type \
+ operator ()(Left &left, Right &right) const \
+ { \
+ return numeric::promote<std::valarray<left_value_type> >(left) \
+ Op numeric::promote<std::valarray<right_value_type> >(right); \
+ } \
+ }; \
+ template<typename Left, typename Right> \
+ struct Name<Left, Right, std_valarray_tag, void> \
+ : std::binary_function< \
+ Left \
+ , Right \
+ , std::valarray< \
+ typename Name<typename Left::value_type, Right>::result_type \
+ > \
+ > \
+ { \
+ typedef typename Left::value_type left_value_type; \
+ typedef \
+ std::valarray< \
+ typename Name<left_value_type, Right>::result_type \
+ > \
+ result_type; \
+ result_type \
+ operator ()(Left &left, Right &right) const \
+ { \
+ return numeric::promote<std::valarray<left_value_type> >(left) Op right;\
+ } \
+ }; \
+ template<typename Left, typename Right> \
+ struct Name<Left, Right, void, std_valarray_tag> \
+ : std::binary_function< \
+ Left \
+ , Right \
+ , std::valarray< \
+ typename Name<Left, typename Right::value_type>::result_type \
+ > \
+ > \
+ { \
+ typedef typename Right::value_type right_value_type; \
+ typedef \
+ std::valarray< \
+ typename Name<Left, right_value_type>::result_type \
+ > \
+ result_type; \
+ result_type \
+ operator ()(Left &left, Right &right) const \
+ { \
+ return left Op numeric::promote<std::valarray<right_value_type> >(right);\
+ } \
+ };
+
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(plus, +)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(minus, -)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(multiplies, *)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(divides, /)
+ BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP(modulus, %)
+
+ #undef BOOST_NUMERIC_FUNCTIONAL_DEFINE_VALARRAY_BIN_OP
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // element-wise min of std::valarray
+ template<typename Left, typename Right>
+ struct min_assign<Left, Right, std_valarray_tag, std_valarray_tag>
+ : std::binary_function<Left, Right, void>
+ {
+ void operator ()(Left &left, Right &right) const
+ {
+ BOOST_ASSERT(left.size() == right.size());
+ for(std::size_t i = 0, size = left.size(); i != size; ++i)
+ {
+ if(numeric::less(right[i], left[i]))
+ {
+ left[i] = right[i];
+ }
+ }
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // element-wise max of std::valarray
+ template<typename Left, typename Right>
+ struct max_assign<Left, Right, std_valarray_tag, std_valarray_tag>
+ : std::binary_function<Left, Right, void>
+ {
+ void operator ()(Left &left, Right &right) const
+ {
+ BOOST_ASSERT(left.size() == right.size());
+ for(std::size_t i = 0, size = left.size(); i != size; ++i)
+ {
+ if(numeric::greater(right[i], left[i]))
+ {
+ left[i] = right[i];
+ }
+ }
+ }
+ };
+
+ // partial specialization of numeric::average<> for std::valarray.
+ template<typename Left, typename Right, typename RightTag>
+ struct average<Left, Right, std_valarray_tag, RightTag>
+ : mpl::if_<
+ are_integral<typename Left::value_type, Right>
+ , divides<Left, double const>
+ , divides<Left, Right>
+ >::type
+ {};
+
+ // promote
+ template<typename To, typename From>
+ struct promote<To, From, std_valarray_tag, std_valarray_tag>
+ : std::unary_function<From, To>
+ {
+ To operator ()(From &arr) const
+ {
+ typename remove_const<To>::type res(arr.size());
+ for(std::size_t i = 0, size = arr.size(); i != size; ++i)
+ {
+ res[i] = numeric::promote<typename To::value_type>(arr[i]);
+ }
+ return res;
+ }
+ };
+
+ template<typename ToFrom>
+ struct promote<ToFrom, ToFrom, std_valarray_tag, std_valarray_tag>
+ : std::unary_function<ToFrom, ToFrom>
+ {
+ ToFrom &operator ()(ToFrom &tofrom) const
+ {
+ return tofrom;
+ }
+ };
+
+ // for "promoting" a std::valarray<bool> to a bool, useful for
+ // comparing 2 valarrays for equality:
+ // if(numeric::promote<bool>(a == b))
+ template<typename From>
+ struct promote<bool, From, void, std_valarray_tag>
+ : std::unary_function<From, bool>
+ {
+ bool operator ()(From &arr) const
+ {
+ BOOST_MPL_ASSERT((is_same<bool, typename From::value_type>));
+ for(std::size_t i = 0, size = arr.size(); i != size; ++i)
+ {
+ if(!arr[i])
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ };
+
+ template<typename From>
+ struct promote<bool const, From, void, std_valarray_tag>
+ : promote<bool, From, void, std_valarray_tag>
+ {};
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_min
+ template<typename T>
+ struct as_min<T, std_valarray_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(numeric::as_min(arr[0]), arr.size());
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_max
+ template<typename T>
+ struct as_max<T, std_valarray_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(numeric::as_max(arr[0]), arr.size());
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_zero
+ template<typename T>
+ struct as_zero<T, std_valarray_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(numeric::as_zero(arr[0]), arr.size());
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_one
+ template<typename T>
+ struct as_one<T, std_valarray_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(numeric::as_one(arr[0]), arr.size());
+ }
+ };
+
+ } // namespace functional
+
+}} // namespace boost::numeric
+
+#endif
+
Added: branches/release/boost/accumulators/numeric/functional/vector.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/functional/vector.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,320 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file vector.hpp
+///
+// Copyright 2005 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)
+
+#ifndef BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005
+
+#ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
+# error Include this file before boost/accumulators/numeric/functional.hpp
+#endif
+
+#include <vector>
+#include <functional>
+#include <boost/assert.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_scalar.hpp>
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/typeof/std/vector.hpp>
+#include <boost/accumulators/numeric/functional_fwd.hpp>
+
+namespace boost { namespace numeric
+{
+ namespace operators
+ {
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle vector<Left> / Right where Right is a scalar.
+ template<typename Left, typename Right>
+ typename enable_if<
+ is_scalar<Right>
+ , std::vector<typename functional::divides<Left, Right>::result_type>
+ >::type
+ operator /(std::vector<Left> const &left, Right const &right)
+ {
+ typedef typename functional::divides<Left, Right>::result_type value_type;
+ std::vector<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::divides(left[i], right);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle vector<Left> / vector<Right>.
+ template<typename Left, typename Right>
+ std::vector<typename functional::divides<Left, Right>::result_type>
+ operator /(std::vector<Left> const &left, std::vector<Right> const &right)
+ {
+ typedef typename functional::divides<Left, Right>::result_type value_type;
+ std::vector<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::divides(left[i], right[i]);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle vector<Left> * Right where Right is a scalar.
+ template<typename Left, typename Right>
+ typename enable_if<
+ is_scalar<Right>
+ , std::vector<typename functional::multiplies<Left, Right>::result_type>
+ >::type
+ operator *(std::vector<Left> const &left, Right const &right)
+ {
+ typedef typename functional::multiplies<Left, Right>::result_type value_type;
+ std::vector<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::multiplies(left[i], right);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle Left * vector<Right> where Left is a scalar.
+ template<typename Left, typename Right>
+ typename enable_if<
+ is_scalar<Left>
+ , std::vector<typename functional::multiplies<Left, Right>::result_type>
+ >::type
+ operator *(Left const &left, std::vector<Right> const &right)
+ {
+ typedef typename functional::multiplies<Left, Right>::result_type value_type;
+ std::vector<value_type> result(right.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::multiplies(left, right[i]);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle vector<Left> * vector<Right>
+ template<typename Left, typename Right>
+ std::vector<typename functional::multiplies<Left, Right>::result_type>
+ operator *(std::vector<Left> const &left, std::vector<Right> const &right)
+ {
+ typedef typename functional::multiplies<Left, Right>::result_type value_type;
+ std::vector<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::multiplies(left[i], right[i]);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle vector<Left> + vector<Right>
+ template<typename Left, typename Right>
+ std::vector<typename functional::plus<Left, Right>::result_type>
+ operator +(std::vector<Left> const &left, std::vector<Right> const &right)
+ {
+ typedef typename functional::plus<Left, Right>::result_type value_type;
+ std::vector<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::plus(left[i], right[i]);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle vector<Left> - vector<Right>
+ template<typename Left, typename Right>
+ std::vector<typename functional::minus<Left, Right>::result_type>
+ operator -(std::vector<Left> const &left, std::vector<Right> const &right)
+ {
+ typedef typename functional::minus<Left, Right>::result_type value_type;
+ std::vector<value_type> result(left.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::minus(left[i], right[i]);
+ }
+ return result;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle vector<Left> += vector<Left>
+ template<typename Left>
+ std::vector<Left> &
+ operator +=(std::vector<Left> &left, std::vector<Left> const &right)
+ {
+ BOOST_ASSERT(left.size() == right.size());
+ for(std::size_t i = 0, size = left.size(); i != size; ++i)
+ {
+ numeric::plus_assign(left[i], right[i]);
+ }
+ return left;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Handle -vector<Arg>
+ template<typename Arg>
+ std::vector<typename functional::unary_minus<Arg>::result_type>
+ operator -(std::vector<Arg> const &arg)
+ {
+ typedef typename functional::unary_minus<Arg>::result_type value_type;
+ std::vector<value_type> result(arg.size());
+ for(std::size_t i = 0, size = result.size(); i != size; ++i)
+ {
+ result[i] = numeric::unary_minus(arg[i]);
+ }
+ return result;
+ }
+ }
+
+ namespace functional
+ {
+ struct std_vector_tag;
+
+ template<typename T, typename Al>
+ struct tag<std::vector<T, Al> >
+ {
+ typedef std_vector_tag type;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // element-wise min of std::vector
+ template<typename Left, typename Right>
+ struct min_assign<Left, Right, std_vector_tag, std_vector_tag>
+ : std::binary_function<Left, Right, void>
+ {
+ void operator ()(Left &left, Right &right) const
+ {
+ BOOST_ASSERT(left.size() == right.size());
+ for(std::size_t i = 0, size = left.size(); i != size; ++i)
+ {
+ if(numeric::less(right[i], left[i]))
+ {
+ left[i] = right[i];
+ }
+ }
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // element-wise max of std::vector
+ template<typename Left, typename Right>
+ struct max_assign<Left, Right, std_vector_tag, std_vector_tag>
+ : std::binary_function<Left, Right, void>
+ {
+ void operator ()(Left &left, Right &right) const
+ {
+ BOOST_ASSERT(left.size() == right.size());
+ for(std::size_t i = 0, size = left.size(); i != size; ++i)
+ {
+ if(numeric::greater(right[i], left[i]))
+ {
+ left[i] = right[i];
+ }
+ }
+ }
+ };
+
+ // partial specialization for std::vector.
+ template<typename Left, typename Right>
+ struct average<Left, Right, std_vector_tag, void>
+ : mpl::if_<
+ are_integral<typename Left::value_type, Right>
+ , divides<Left, double const>
+ , divides<Left, Right>
+ >::type
+ {};
+
+ // promote
+ template<typename To, typename From>
+ struct promote<To, From, std_vector_tag, std_vector_tag>
+ : std::unary_function<From, To>
+ {
+ To operator ()(From &arr) const
+ {
+ typename remove_const<To>::type res(arr.size());
+ for(std::size_t i = 0, size = arr.size(); i != size; ++i)
+ {
+ res[i] = numeric::promote<typename To::value_type>(arr[i]);
+ }
+ return res;
+ }
+ };
+
+ template<typename ToFrom>
+ struct promote<ToFrom, ToFrom, std_vector_tag, std_vector_tag>
+ : std::unary_function<ToFrom, ToFrom>
+ {
+ ToFrom &operator ()(ToFrom &tofrom) const
+ {
+ return tofrom;
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_min
+ template<typename T>
+ struct as_min<T, std_vector_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(arr.size(), numeric::as_min(arr[0]));
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_max
+ template<typename T>
+ struct as_max<T, std_vector_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(arr.size(), numeric::as_max(arr[0]));
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_zero
+ template<typename T>
+ struct as_zero<T, std_vector_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(arr.size(), numeric::as_zero(arr[0]));
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::as_one
+ template<typename T>
+ struct as_one<T, std_vector_tag>
+ : std::unary_function<T, typename remove_const<T>::type>
+ {
+ typename remove_const<T>::type operator ()(T &arr) const
+ {
+ return 0 == arr.size()
+ ? T()
+ : T(arr.size(), numeric::as_one(arr[0]));
+ }
+ };
+
+ } // namespace functional
+
+}} // namespace boost::numeric
+
+#endif
+
Added: branches/release/boost/accumulators/numeric/functional_fwd.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/numeric/functional_fwd.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,221 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file functional_fwd.hpp
+///
+// Copyright 2005 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)
+
+#ifndef BOOST_NUMERIC_FUNCTIONAL_FWD_HPP_EAN_08_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_FWD_HPP_EAN_08_12_2005
+
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_const.hpp>
+
+namespace boost { namespace numeric
+{
+ // For using directives -- this namespace may be re-opened elsewhere
+ namespace operators
+ {}
+
+ namespace op
+ {
+ using mpl::_;
+ using mpl::_1;
+ using mpl::_2;
+ }
+
+ namespace functional
+ {
+ using namespace operators;
+
+ template<typename T>
+ struct tag
+ {
+ typedef void type;
+ };
+
+ template<typename T>
+ struct tag<T const>
+ : tag<T>
+ {};
+
+ template<typename T>
+ struct tag<T volatile>
+ : tag<T>
+ {};
+
+ template<typename T>
+ struct tag<T const volatile>
+ : tag<T>
+ {};
+
+ template<typename T>
+ struct static_;
+
+ template<typename A0, typename A1>
+ struct are_integral;
+ }
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(Name, Op) \
+ namespace functional \
+ { \
+ template<typename Arg, typename EnableIf = void> \
+ struct Name ## _base; \
+ template<typename Arg, typename ArgTag = typename tag<Arg>::type> \
+ struct Name; \
+ } \
+ namespace op \
+ { \
+ struct Name; \
+ } \
+ namespace \
+ { \
+ extern op::Name const &Name; \
+ }
+
+ /// INTERNAL ONLY
+ ///
+#define BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(Name) \
+ namespace functional \
+ { \
+ template<typename Left, typename Right, typename EnableIf = void> \
+ struct result_of_ ## Name; \
+ template<typename Left, typename Right, typename EnableIf = void> \
+ struct Name ## _base; \
+ template< \
+ typename Left \
+ , typename Right \
+ , typename LeftTag = typename tag<Left>::type \
+ , typename RightTag = typename tag<Right>::type \
+ > \
+ struct Name; \
+ } \
+ namespace op \
+ { \
+ struct Name; \
+ } \
+ namespace \
+ { \
+ extern op::Name const &Name; \
+ }
+
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(plus)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(minus)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(multiplies)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(divides)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(modulus)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(greater)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(greater_equal)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(less)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(less_equal)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(equal_to)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(not_equal_to)
+
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(assign)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(plus_assign)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(minus_assign)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(multiplies_assign)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(divides_assign)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(modulus_assign)
+
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(unary_plus, +)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(unary_minus, -)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(complement, ~)
+ BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(logical_not, !)
+
+#undef BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP
+#undef BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP
+
+
+ namespace functional
+ {
+ template<typename To, typename From, typename EnableIf = void>
+ struct promote_base;
+ template<typename Left, typename Right, typename EnableIf = void>
+ struct min_assign_base;
+ template<typename Left, typename Right, typename EnableIf = void>
+ struct max_assign_base;
+ template<typename Left, typename Right, typename EnableIf = void>
+ struct average_base;
+ template<typename Arg, typename EnableIf = void>
+ struct as_min_base;
+ template<typename Arg, typename EnableIf = void>
+ struct as_max_base;
+ template<typename Arg, typename EnableIf = void>
+ struct as_zero_base;
+ template<typename Arg, typename EnableIf = void>
+ struct as_one_base;
+
+ template<typename To, typename From, typename ToTag = typename tag<To>::type, typename FromTag = typename tag<From>::type>
+ struct promote;
+ template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type>
+ struct min_assign;
+ 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;
+ template<typename Arg, typename Tag = typename tag<Arg>::type>
+ struct as_min;
+ template<typename Arg, typename Tag = typename tag<Arg>::type>
+ struct as_max;
+ template<typename Arg, typename Tag = typename tag<Arg>::type>
+ struct as_zero;
+ template<typename Arg, typename Tag = typename tag<Arg>::type>
+ struct as_one;
+ }
+
+ namespace op
+ {
+ template<typename To>
+ struct promote;
+ struct min_assign;
+ struct max_assign;
+ struct average;
+ struct as_min;
+ struct as_max;
+ struct as_zero;
+ struct as_one;
+ }
+
+ namespace
+ {
+ extern op::min_assign const &min_assign;
+ extern op::max_assign const &max_assign;
+ extern op::average const &average;
+ extern op::as_min const &as_min;
+ extern op::as_max const &as_max;
+ extern op::as_zero const &as_zero;
+ extern op::as_one const &as_one;
+ }
+
+ template<typename To, typename From>
+ typename lazy_disable_if<is_const<From>, mpl::if_<is_same<To, From>, To &, To> >::type
+ promote(From &from);
+
+ template<typename To, typename From>
+ typename mpl::if_<is_same<To const, From const>, To const &, To const>::type
+ promote(From const &from);
+
+ template<typename T>
+ struct default_;
+
+ template<typename T>
+ struct one;
+
+ template<typename T>
+ struct zero;
+
+ template<typename T>
+ struct one_or_default;
+
+ template<typename T>
+ struct zero_or_default;
+
+}} // namespace boost::numeric
+
+#endif
Added: branches/release/boost/accumulators/statistics.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,59 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file statistics.hpp
+/// Includes all of the Statistical Accumulators Library
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_HPP_EAN_01_17_2006
+#define BOOST_ACCUMULATORS_STATISTICS_HPP_EAN_01_17_2006
+
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/covariance.hpp>
+#include <boost/accumulators/statistics/density.hpp>
+#include <boost/accumulators/statistics/error_of.hpp>
+#include <boost/accumulators/statistics/error_of_mean.hpp>
+#include <boost/accumulators/statistics/extended_p_square.hpp>
+#include <boost/accumulators/statistics/extended_p_square_quantile.hpp>
+#include <boost/accumulators/statistics/kurtosis.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/median.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/moment.hpp>
+#include <boost/accumulators/statistics/peaks_over_threshold.hpp>
+#include <boost/accumulators/statistics/pot_tail_mean.hpp>
+#include <boost/accumulators/statistics/pot_quantile.hpp>
+#include <boost/accumulators/statistics/p_square_cumulative_distribution.hpp>
+#include <boost/accumulators/statistics/p_square_quantile.hpp>
+#include <boost/accumulators/statistics/skewness.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/tail_quantile.hpp>
+#include <boost/accumulators/statistics/tail_mean.hpp>
+#include <boost/accumulators/statistics/tail_variate.hpp>
+#include <boost/accumulators/statistics/tail_variate_means.hpp>
+#include <boost/accumulators/statistics/variance.hpp>
+#include <boost/accumulators/statistics/weighted_covariance.hpp>
+#include <boost/accumulators/statistics/weighted_density.hpp>
+#include <boost/accumulators/statistics/weighted_kurtosis.hpp>
+#include <boost/accumulators/statistics/weighted_extended_p_square.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+#include <boost/accumulators/statistics/weighted_median.hpp>
+#include <boost/accumulators/statistics/weighted_moment.hpp>
+#include <boost/accumulators/statistics/weighted_peaks_over_threshold.hpp>
+#include <boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp>
+#include <boost/accumulators/statistics/weighted_p_square_quantile.hpp>
+#include <boost/accumulators/statistics/weighted_skewness.hpp>
+#include <boost/accumulators/statistics/weighted_sum.hpp>
+#include <boost/accumulators/statistics/weighted_tail_quantile.hpp>
+#include <boost/accumulators/statistics/weighted_tail_mean.hpp>
+#include <boost/accumulators/statistics/weighted_tail_variate_means.hpp>
+#include <boost/accumulators/statistics/weighted_variance.hpp>
+#include <boost/accumulators/statistics/with_error.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+
+#endif
Added: branches/release/boost/accumulators/statistics/count.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/count.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,78 @@
+///////////////////////////////////////////////////////////////////////////////
+// count.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
+
+#include <boost/mpl/always.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // count_impl
+ struct count_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef std::size_t result_type;
+
+ count_impl(dont_care)
+ : cnt(0)
+ {
+ }
+
+ void operator ()(dont_care)
+ {
+ ++this->cnt;
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->cnt;
+ }
+
+ private:
+ std::size_t cnt;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::count
+//
+namespace tag
+{
+ struct count
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef mpl::always<accumulators::impl::count_impl> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::count
+//
+namespace extract
+{
+ extractor<tag::count> const count = {};
+}
+
+using extract::count;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/covariance.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/covariance.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,218 @@
+///////////////////////////////////////////////////////////////////////////////
+// covariance.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_COVARIANCE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_COVARIANCE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <numeric>
+#include <functional>
+#include <complex>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/range.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/numeric/ublas/io.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/type_traits/is_scalar.hpp>
+#include <boost/type_traits/is_same.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+namespace boost { namespace numeric
+{
+ namespace functional
+ {
+ struct std_vector_tag;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // functional::outer_product
+ template<typename Left, typename Right, typename EnableIf = void>
+ struct outer_product_base
+ : functional::multiplies<Left, Right>
+ {};
+
+ template<typename Left, typename Right, typename LeftTag = typename tag<Left>::type, typename RightTag = typename tag<Right>::type>
+ struct outer_product
+ : outer_product_base<Left, Right, void>
+ {};
+
+ template<typename Left, typename Right>
+ struct outer_product<Left, Right, std_vector_tag, std_vector_tag>
+ : std::binary_function<
+ Left
+ , Right
+ , ublas::matrix<
+ typename functional::multiplies<
+ typename Left::value_type
+ , typename Right::value_type
+ >::result_type
+ >
+ >
+ {
+ typedef
+ ublas::matrix<
+ typename functional::multiplies<
+ typename Left::value_type
+ , typename Right::value_type
+ >::result_type
+ >
+ result_type;
+
+ result_type
+ operator ()(Left & left, Right & right) const
+ {
+ std::size_t left_size = left.size();
+ std::size_t right_size = right.size();
+ result_type result(left_size, right_size);
+ for (std::size_t i = 0; i < left_size; ++i)
+ for (std::size_t j = 0; j < right_size; ++j)
+ result(i,j) = numeric::multiplies(left[i], right[j]);
+ return result;
+ }
+ };
+ }
+
+ namespace op
+ {
+ struct outer_product
+ : boost::detail::function2<functional::outer_product<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ {};
+ }
+
+ namespace
+ {
+ op::outer_product const &outer_product = boost::detail::pod_singleton<op::outer_product>::instance;
+ }
+
+}}
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // covariance_impl
+ //
+ /**
+ @brief Covariance Estimator
+
+ An iterative Monte Carlo estimator for the covariance \f$\mathrm{Cov}(X,X')\f$, where \f$X\f$ is a sample
+ and \f$X'\f$ is a variate, is given by:
+
+ \f[
+ \hat{c}_n = \frac{n-1}{n} \hat{c}_{n-1} + \frac{1}{n-1}(X_n - \hat{\mu}_n)(X_n' - \hat{\mu}_n'),\quad n\ge2,\quad\hat{c}_1 = 0,
+ \f]
+
+ \f$\hat{\mu}_n\f$ and \f$\hat{\mu}_n'\f$ being the means of the samples and variates.
+ */
+ template<typename Sample, typename VariateType, typename VariateTag>
+ 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;
+ // for boost::result_of
+ typedef typename numeric::functional::outer_product<sample_type, variate_type>::result_type result_type;
+
+ template<typename Args>
+ 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)
+ )
+ )
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+
+ if (cnt > 1)
+ {
+ extractor<tag::mean_of_variates<VariateType, VariateTag> > const some_mean_of_variates = {};
+
+ this->cov_ = this->cov_*(cnt-1.)/cnt
+ + numeric::outer_product(
+ some_mean_of_variates(args) - args[parameter::keyword<VariateTag>::get()]
+ , mean(args) - args[sample]
+ ) / (cnt-1.);
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->cov_;
+ }
+
+ private:
+ result_type cov_;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::covariance
+//
+namespace tag
+{
+ template<typename VariateType, typename VariateTag>
+ struct covariance
+ : depends_on<count, mean, mean_of_variates<VariateType, VariateTag> >
+ {
+ typedef accumulators::impl::covariance_impl<mpl::_1, VariateType, VariateTag> impl;
+ };
+
+ struct abstract_covariance
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::covariance
+//
+namespace extract
+{
+ extractor<tag::abstract_covariance> const covariance = {};
+}
+
+using extract::covariance;
+
+template<typename VariateType, typename VariateTag>
+struct feature_of<tag::covariance<VariateType, VariateTag> >
+ : feature_of<tag::abstract_covariance>
+{
+};
+
+// So that covariance can be automatically substituted with
+// weighted_covariance when the weight parameter is non-void.
+template<typename VariateType, typename VariateTag>
+struct as_weighted_feature<tag::covariance<VariateType, VariateTag> >
+{
+ typedef tag::weighted_covariance<VariateType, VariateTag> type;
+};
+
+template<typename VariateType, typename VariateTag>
+struct feature_of<tag::weighted_covariance<VariateType, VariateTag> >
+ : feature_of<tag::covariance<VariateType, VariateTag> >
+{};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/density.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/density.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,241 @@
+
+///////////////////////////////////////////////////////////////////////////////
+// density.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_DENSITY_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_DENSITY_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <functional>
+#include <boost/range.hpp>
+#include <boost/parameter/keyword.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/count.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+
+namespace boost { namespace accumulators
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// cache_size and num_bins named parameters
+//
+BOOST_PARAMETER_NESTED_KEYWORD(tag, density_cache_size, cache_size)
+BOOST_PARAMETER_NESTED_KEYWORD(tag, density_num_bins, num_bins)
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // density_impl
+ // density histogram
+ /**
+ @brief Histogram density estimator
+
+ The histogram density estimator returns a histogram of the sample distribution. The positions and sizes of the bins
+ are determined using a specifiable number of cached samples (cache_size). The range between the minimum and the
+ maximum of the cached samples is subdivided into a specifiable number of bins (num_bins) of same size. Additionally,
+ an under- and an overflow bin is added to capture future under- and overflow samples. Once the bins are determined,
+ the cached samples and all subsequent samples are added to the correct bins. At the end, a range of std::pair is
+ return, where each pair contains the position of the bin (lower bound) and the samples count (normalized with the
+ total number of samples).
+
+ @param density_cache_size Number of first samples used to determine min and max.
+ @param density_num_bins Number of bins (two additional bins collect under- and overflow samples).
+ */
+ template<typename Sample>
+ struct density_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef iterator_range<typename histogram_type::iterator> result_type;
+
+ template<typename Args>
+ density_impl(Args const &args)
+ : cache_size(args[density_cache_size])
+ , cache(cache_size)
+ , num_bins(args[density_num_bins])
+ , samples_in_bin(num_bins + 2, 0.)
+ , bin_positions(num_bins + 2)
+ , 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)
+ )
+ )
+ , is_dirty(true)
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->is_dirty = true;
+
+ std::size_t cnt = count(args);
+
+ // Fill up cache with cache_size first samples
+ if (cnt <= this->cache_size)
+ {
+ this->cache[cnt - 1] = args[sample];
+ }
+
+ // 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.
+ // 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 );
+
+ // determine bin positions (their lower bounds)
+ for (std::size_t i = 0; i < this->num_bins + 2; ++i)
+ {
+ this->bin_positions[i] = minimum + (i - 1.) * bin_size;
+ }
+
+ for (typename array_type::const_iterator iter = this->cache.begin(); iter != this->cache.end(); ++iter)
+ {
+ if (*iter < this->bin_positions[1])
+ {
+ ++(this->samples_in_bin[0]);
+ }
+ else if (*iter >= this->bin_positions[this->num_bins + 1])
+ {
+ ++(this->samples_in_bin[this->num_bins + 1]);
+ }
+ else
+ {
+ typename array_type::iterator it = std::upper_bound(
+ this->bin_positions.begin()
+ , this->bin_positions.end()
+ , *iter
+ );
+
+ std::size_t d = std::distance(this->bin_positions.begin(), it);
+ ++(this->samples_in_bin[d - 1]);
+ }
+ }
+ }
+ // Add each subsequent sample to the correct bin
+ else if (cnt > this->cache_size)
+ {
+ if (args[sample] < this->bin_positions[1])
+ {
+ ++(this->samples_in_bin[0]);
+ }
+ else if (args[sample] >= this->bin_positions[this->num_bins + 1])
+ {
+ ++(this->samples_in_bin[this->num_bins + 1]);
+ }
+ else
+ {
+ typename array_type::iterator it = std::upper_bound(
+ this->bin_positions.begin()
+ , this->bin_positions.end()
+ , args[sample]
+ );
+
+ std::size_t d = std::distance(this->bin_positions.begin(), it);
+ ++(this->samples_in_bin[d - 1]);
+ }
+ }
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ // creates a vector of std::pair where each pair i holds
+ // the values bin_positions[i] (x-axis of histogram) and
+ // samples_in_bin[i] / cnt (y-axis of histogram).
+
+ 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)));
+ }
+ }
+ // returns a range of pairs
+ return make_iterator_range(this->histogram);
+ }
+
+ private:
+ std::size_t cache_size; // number of cached samples
+ array_type cache; // cache to store the first cache_size samples
+ std::size_t num_bins; // number of bins
+ array_type samples_in_bin; // number of samples in each bin
+ array_type bin_positions; // lower bounds of bins
+ mutable histogram_type histogram; // histogram
+ mutable bool is_dirty;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::density
+//
+namespace tag
+{
+ struct density
+ : depends_on<count, min, max>
+ , density_cache_size
+ , density_num_bins
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::density_impl<mpl::_1> impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::density::cache_size named parameter
+ /// tag::density::num_bins named parameter
+ static boost::parameter::keyword<density_cache_size> const cache_size;
+ static boost::parameter::keyword<density_num_bins> const num_bins;
+ #endif
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::density
+//
+namespace extract
+{
+ extractor<tag::density> const density = {};
+}
+
+using extract::density;
+
+// So that density can be automatically substituted
+// with weighted_density when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::density>
+{
+ typedef tag::weighted_density type;
+};
+
+template<>
+struct feature_of<tag::weighted_density>
+ : feature_of<tag::density>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/error_of.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/error_of.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,99 @@
+///////////////////////////////////////////////////////////////////////////////
+// error_of.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ /// INTERNAL ONLY
+ ///
+ template<typename Feature>
+ struct this_feature_has_no_error_calculation
+ : mpl::false_
+ {
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // error_of_impl
+ /// INTERNAL ONLY
+ ///
+ template<typename Sample, typename Feature>
+ struct error_of_impl
+ : accumulator_base
+ {
+ // TODO: specialize this on the specific features that have errors we're
+ // interested in.
+ BOOST_MPL_ASSERT((this_feature_has_no_error_calculation<Feature>));
+
+ // for boost::result_of
+ typedef int result_type;
+
+ error_of_impl(dont_care)
+ {
+ }
+
+ result_type result(dont_care) const
+ {
+ return 0;
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::error_of
+//
+namespace tag
+{
+ template<typename Feature>
+ struct error_of
+ : depends_on<Feature>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::error_of_impl<mpl::_1, Feature> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::error_of
+//
+namespace extract
+{
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, error_of, (typename))
+}
+
+using extract::error_of;
+
+// make tag::error_of<tag::feature(modifier)> work
+template<typename Feature>
+struct as_feature<tag::error_of<Feature> >
+{
+ typedef tag::error_of<typename as_feature<Feature>::type> type;
+};
+
+// make error_of<tag::mean> work with non-void weights (should become
+// error_of<tag::weighted_mean>
+template<typename Feature>
+struct as_weighted_feature<tag::error_of<Feature> >
+{
+ typedef tag::error_of<typename as_weighted_feature<Feature>::type> type;
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/error_of_mean.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/error_of_mean.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,73 @@
+///////////////////////////////////////////////////////////////////////////////
+// error_of.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
+#define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/error_of.hpp>
+#include <boost/accumulators/statistics/variance.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // error_of_mean_impl
+ template<typename Sample, typename Variance>
+ struct error_of_mean_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ error_of_mean_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ using namespace std;
+ extractor<Variance> const variance = {};
+ return sqrt(numeric::average(variance(args), count(args) - 1));
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::error_of
+//
+namespace tag
+{
+ template<>
+ struct error_of<mean>
+ : depends_on<variance, count>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::error_of_mean_impl<mpl::_1, variance> impl;
+ };
+
+ template<>
+ struct error_of<immediate_mean>
+ : depends_on<immediate_variance, count>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::error_of_mean_impl<mpl::_1, immediate_variance> impl;
+ };
+}
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/extended_p_square.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/extended_p_square.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,291 @@
+///////////////////////////////////////////////////////////////////////////////
+// extended_p_square.hpp
+//
+// Copyright 2005 Daniel Egloff. 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_EXTENDED_SINGLE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <functional>
+#include <boost/range/begin.hpp>
+#include <boost/range/end.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/iterator/counting_iterator.hpp>
+#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/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/count.hpp>
+#include <boost/accumulators/statistics/times2_iterator.hpp>
+
+namespace boost { namespace accumulators
+{
+///////////////////////////////////////////////////////////////////////////////
+// probabilities named parameter
+//
+BOOST_PARAMETER_NESTED_KEYWORD(tag, extended_p_square_probabilities, probabilities)
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // extended_p_square_impl
+ // multiple quantile estimation
+ /**
+ @brief Multiple quantile estimation with the extended \f$P^2\f$ algorithm
+
+ Extended \f$P^2\f$ algorithm for estimation of several quantiles without storing samples.
+ Assume that \f$m\f$ quantiles \f$\xi_{p_1}, \ldots, \xi_{p_m}\f$ are to be estimated.
+ Instead of storing the whole sample cumulative distribution, the algorithm maintains only
+ \f$m+2\f$ principal markers and \f$m+1\f$ middle markers, whose positions are updated
+ with each sample and whose heights are adjusted (if necessary) using a piecewise-parablic
+ formula. The heights of these central markers are the current estimates of the quantiles
+ and returned as an iterator range.
+
+ For further details, see
+
+ 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
+
+ R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and
+ histograms without storing observations, Communications of the ACM,
+ Volume 28 (October), Number 10, 1985, p. 1076-1085.
+
+ @param extended_p_square_probabilities A vector of quantile probabilities.
+ */
+ template<typename Sample>
+ struct extended_p_square_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
+ typedef std::vector<float_type> array_type;
+ // for boost::result_of
+ typedef iterator_range<
+ detail::lvalue_index_iterator<
+ permutation_iterator<
+ typename array_type::const_iterator
+ , detail::times2_iterator
+ >
+ >
+ > result_type;
+
+ template<typename Args>
+ extended_p_square_impl(Args const &args)
+ : probabilities(
+ boost::begin(args[extended_p_square_probabilities])
+ , boost::end(args[extended_p_square_probabilities])
+ )
+ , heights(2 * probabilities.size() + 3)
+ , actual_positions(heights.size())
+ , desired_positions(heights.size())
+ , positions_increments(heights.size())
+ {
+ std::size_t num_quantiles = this->probabilities.size();
+ std::size_t num_markers = this->heights.size();
+
+ for(std::size_t i = 0; i < num_markers; ++i)
+ {
+ this->actual_positions[i] = i + 1;
+ }
+
+ this->positions_increments[0] = 0.;
+ this->positions_increments[num_markers - 1] = 1.;
+
+ for(std::size_t i = 0; i < num_quantiles; ++i)
+ {
+ this->positions_increments[2 * i + 2] = probabilities[i];
+ }
+
+ for(std::size_t i = 0; i <= num_quantiles; ++i)
+ {
+ this->positions_increments[2 * i + 1] =
+ 0.5 * (this->positions_increments[2 * i] + this->positions_increments[2 * i + 2]);
+ }
+
+ for(std::size_t i = 0; i < num_markers; ++i)
+ {
+ this->desired_positions[i] = 1. + 2. * (num_quantiles + 1.) * this->positions_increments[i];
+ }
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+
+ // m+2 principal markers and m+1 middle markers
+ std::size_t num_markers = 2 * this->probabilities.size() + 3;
+
+ // first accumulate num_markers samples
+ if(cnt <= num_markers)
+ {
+ this->heights[cnt - 1] = args[sample];
+
+ // complete the initialization of heights by sorting
+ if(cnt == num_markers)
+ {
+ std::sort(this->heights.begin(), this->heights.end());
+ }
+ }
+ else
+ {
+ std::size_t sample_cell = 1;
+
+ // find cell k = sample_cell such that heights[k-1] <= sample < heights[k]
+ if(args[sample] < this->heights[0])
+ {
+ this->heights[0] = args[sample];
+ sample_cell = 1;
+ }
+ else if(args[sample] >= this->heights[num_markers - 1])
+ {
+ this->heights[num_markers - 1] = args[sample];
+ sample_cell = num_markers - 1;
+ }
+ else
+ {
+ typedef typename array_type::iterator iterator;
+ iterator it = std::upper_bound(
+ this->heights.begin()
+ , this->heights.end()
+ , args[sample]
+ );
+
+ sample_cell = std::distance(this->heights.begin(), it);
+ }
+
+ // update actual positions of all markers above sample_cell index
+ for(std::size_t i = sample_cell; i < num_markers; ++i)
+ {
+ ++this->actual_positions[i];
+ }
+
+ // update desired positions of all markers
+ for(std::size_t i = 0; i < num_markers; ++i)
+ {
+ this->desired_positions[i] += this->positions_increments[i];
+ }
+
+ // adjust heights and actual positions of markers 1 to num_markers-2 if necessary
+ for(std::size_t i = 1; i <= num_markers - 2; ++i)
+ {
+ // offset to desired position
+ float_type d = this->desired_positions[i] - this->actual_positions[i];
+
+ // offset to next position
+ float_type dp = this->actual_positions[i+1] - this->actual_positions[i];
+
+ // offset to previous position
+ float_type dm = this->actual_positions[i-1] - this->actual_positions[i];
+
+ // height ds
+ float_type hp = (this->heights[i+1] - this->heights[i]) / dp;
+ float_type hm = (this->heights[i-1] - this->heights[i]) / dm;
+
+ if((d >= 1 && dp > 1) || (d <= -1 && dm < -1))
+ {
+ short sign_d = static_cast<short>(d / std::abs(d));
+
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ((sign_d - dm)*hp
+ + (dp - sign_d) * hm);
+
+ // try adjusting heights[i] using p-squared formula
+ if(this->heights[i - 1] < h && h < this->heights[i + 1])
+ {
+ this->heights[i] = h;
+ }
+ else
+ {
+ // use linear formula
+ if(d > 0)
+ {
+ this->heights[i] += hp;
+ }
+ if(d < 0)
+ {
+ this->heights[i] -= hm;
+ }
+ }
+ this->actual_positions[i] += sign_d;
+ }
+ }
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ // for i in [1,probabilities.size()], return heights[i * 2]
+ detail::times2_iterator idx_begin = detail::make_times2_iterator(1);
+ detail::times2_iterator idx_end = detail::make_times2_iterator(this->probabilities.size() + 1);
+
+ return result_type(
+ make_permutation_iterator(this->heights.begin(), idx_begin)
+ , make_permutation_iterator(this->heights.begin(), idx_end)
+ );
+ }
+
+ private:
+ array_type probabilities; // the quantile probabilities
+ array_type heights; // q_i
+ array_type actual_positions; // n_i
+ array_type desired_positions; // d_i
+ array_type positions_increments; // f_i
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::extended_p_square
+//
+namespace tag
+{
+ struct extended_p_square
+ : depends_on<count>
+ , extended_p_square_probabilities
+ {
+ typedef accumulators::impl::extended_p_square_impl<mpl::_1> impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::extended_p_square::probabilities named paramter
+ static boost::parameter::keyword<tag::probabilities> const probabilities;
+ #endif
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::extended_p_square
+//
+namespace extract
+{
+ extractor<tag::extended_p_square> const extended_p_square = {};
+}
+
+using extract::extended_p_square;
+
+// So that extended_p_square can be automatically substituted with
+// weighted_extended_p_square when the weight parameter is non-void
+template<>
+struct as_weighted_feature<tag::extended_p_square>
+{
+ typedef tag::weighted_extended_p_square type;
+};
+
+template<>
+struct feature_of<tag::weighted_extended_p_square>
+ : feature_of<tag::extended_p_square>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/extended_p_square_quantile.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/extended_p_square_quantile.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,314 @@
+///////////////////////////////////////////////////////////////////////////////
+// extended_p_square_quantile.hpp
+//
+// Copyright 2005 Daniel Egloff. 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_EXTENDED_SINGLE_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_QUANTILE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <functional>
+#include <boost/range/begin.hpp>
+#include <boost/range/end.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/iterator/counting_iterator.hpp>
+#include <boost/iterator/permutation_iterator.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.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/count.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+#include <boost/accumulators/statistics/extended_p_square.hpp>
+#include <boost/accumulators/statistics/weighted_extended_p_square.hpp>
+#include <boost/accumulators/statistics/times2_iterator.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // extended_p_square_quantile_impl
+ // single quantile estimation
+ /**
+ @brief Quantile estimation using the extended \f$P^2\f$ algorithm for weighted and unweighted samples
+
+ Uses the quantile estimates calculated by the extended \f$P^2\f$ algorithm to compute
+ intermediate quantile estimates by means of quadratic interpolation.
+
+ @param quantile_probability The probability of the quantile to be estimated.
+ */
+ template<typename Sample, typename Impl1, typename Impl2> // Impl1: weighted/unweighted // Impl2: linear/quadratic
+ struct extended_p_square_quantile_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
+ typedef std::vector<float_type> array_type;
+ typedef iterator_range<
+ detail::lvalue_index_iterator<
+ permutation_iterator<
+ typename array_type::const_iterator
+ , detail::times2_iterator
+ >
+ >
+ > range_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ template<typename Args>
+ extended_p_square_quantile_impl(Args const &args)
+ : probabilities(
+ boost::begin(args[extended_p_square_probabilities])
+ , boost::end(args[extended_p_square_probabilities])
+ )
+ {
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ typedef
+ typename mpl::if_<
+ is_same<Impl1, weighted>
+ , tag::weighted_extended_p_square
+ , tag::extended_p_square
+ >::type
+ extended_p_square_tag;
+
+ extractor<extended_p_square_tag> const some_extended_p_square = {};
+
+ array_type heights(some_extended_p_square(args).size());
+ std::copy(some_extended_p_square(args).begin(), some_extended_p_square(args).end(), heights.begin());
+
+ this->probability = args[quantile_probability];
+
+ typename array_type::const_iterator iter_probs = std::lower_bound(this->probabilities.begin(), this->probabilities.end(), this->probability);
+ std::size_t dist = std::distance(this->probabilities.begin(), iter_probs);
+ typename array_type::const_iterator iter_heights = heights.begin() + dist;
+
+ // If this->probability is not in a valid range return NaN or throw exception
+ if (this->probability < *this->probabilities.begin() || this->probability > *(this->probabilities.end() - 1))
+ {
+ if (std::numeric_limits<result_type>::has_quiet_NaN)
+ {
+ return std::numeric_limits<result_type>::quiet_NaN();
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "probability = " << this->probability << " is not in valid range (";
+ msg << *this->probabilities.begin() << ", " << *(this->probabilities.end() - 1) << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ return Sample(0);
+ }
+
+ }
+
+ if (*iter_probs == this->probability)
+ {
+ return heights[dist];
+ }
+ else
+ {
+ result_type result;
+
+ if (is_same<Impl2, linear>::value)
+ {
+ /////////////////////////////////////////////////////////////////////////////////
+ // LINEAR INTERPOLATION
+ //
+ float_type p1 = *iter_probs;
+ float_type p0 = *(iter_probs - 1);
+ float_type h1 = *iter_heights;
+ float_type h0 = *(iter_heights - 1);
+
+ float_type a = numeric::average(h1 - h0, p1 - p0);
+ float_type b = h1 - p1 * a;
+
+ result = a * this->probability + b;
+ }
+ else
+ {
+ /////////////////////////////////////////////////////////////////////////////////
+ // QUADRATIC INTERPOLATION
+ //
+ float_type p0, p1, p2;
+ float_type h0, h1, h2;
+
+ if ( (dist == 1 || *iter_probs - this->probability <= this->probability - *(iter_probs - 1) ) && dist != this->probabilities.size() - 1 )
+ {
+ p0 = *(iter_probs - 1);
+ p1 = *iter_probs;
+ p2 = *(iter_probs + 1);
+ h0 = *(iter_heights - 1);
+ h1 = *iter_heights;
+ h2 = *(iter_heights + 1);
+ }
+ else
+ {
+ p0 = *(iter_probs - 2);
+ p1 = *(iter_probs - 1);
+ p2 = *iter_probs;
+ h0 = *(iter_heights - 2);
+ h1 = *(iter_heights - 1);
+ 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 a = numeric::average(hp21 - hp10, p21 - p10);
+ float_type b = hp21 - a * p21;
+ float_type c = h2 - a * p2 * p2 - b * p2;
+
+ result = a * this->probability * this-> probability + b * this->probability + c;
+ }
+
+ return result;
+ }
+
+ }
+ private:
+
+ array_type probabilities;
+ mutable float_type probability;
+
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::extended_p_square_quantile
+//
+namespace tag
+{
+ struct extended_p_square_quantile
+ : depends_on<extended_p_square>
+ {
+ typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, unweighted, linear> impl;
+ };
+ struct extended_p_square_quantile_quadratic
+ : depends_on<extended_p_square>
+ {
+ typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, unweighted, quadratic> impl;
+ };
+ struct weighted_extended_p_square_quantile
+ : depends_on<weighted_extended_p_square>
+ {
+ typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, weighted, linear> impl;
+ };
+ struct weighted_extended_p_square_quantile_quadratic
+ : depends_on<weighted_extended_p_square>
+ {
+ typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, weighted, quadratic> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::extended_p_square_quantile
+// extract::weighted_extended_p_square_quantile
+//
+namespace extract
+{
+ extractor<tag::extended_p_square_quantile> const extended_p_square_quantile = {};
+ extractor<tag::extended_p_square_quantile_quadratic> const extended_p_square_quantile_quadratic = {};
+ extractor<tag::weighted_extended_p_square_quantile> const weighted_extended_p_square_quantile = {};
+ extractor<tag::weighted_extended_p_square_quantile_quadratic> const weighted_extended_p_square_quantile_quadratic = {};
+}
+
+using extract::extended_p_square_quantile;
+using extract::extended_p_square_quantile_quadratic;
+using extract::weighted_extended_p_square_quantile;
+using extract::weighted_extended_p_square_quantile_quadratic;
+
+// extended_p_square_quantile(linear) -> extended_p_square_quantile
+template<>
+struct as_feature<tag::extended_p_square_quantile(linear)>
+{
+ typedef tag::extended_p_square_quantile type;
+};
+
+// extended_p_square_quantile(quadratic) -> extended_p_square_quantile_quadratic
+template<>
+struct as_feature<tag::extended_p_square_quantile(quadratic)>
+{
+ typedef tag::extended_p_square_quantile_quadratic type;
+};
+
+// weighted_extended_p_square_quantile(linear) -> weighted_extended_p_square_quantile
+template<>
+struct as_feature<tag::weighted_extended_p_square_quantile(linear)>
+{
+ typedef tag::weighted_extended_p_square_quantile type;
+};
+
+// weighted_extended_p_square_quantile(quadratic) -> weighted_extended_p_square_quantile_quadratic
+template<>
+struct as_feature<tag::weighted_extended_p_square_quantile(quadratic)>
+{
+ typedef tag::weighted_extended_p_square_quantile_quadratic type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// extended_p_square_quantile and weighted_extended_p_square_quantile
+// provide the same feature as quantile
+template<>
+struct feature_of<tag::extended_p_square_quantile>
+ : feature_of<tag::quantile>
+{
+};
+template<>
+struct feature_of<tag::extended_p_square_quantile_quadratic>
+ : feature_of<tag::quantile>
+{
+};
+// So that extended_p_square_quantile can be automatically substituted with
+// weighted_extended_p_square_quantile when the weight parameter is non-void
+template<>
+struct as_weighted_feature<tag::extended_p_square_quantile>
+{
+ typedef tag::weighted_extended_p_square_quantile type;
+};
+
+template<>
+struct feature_of<tag::weighted_extended_p_square_quantile>
+ : feature_of<tag::extended_p_square_quantile>
+{
+};
+
+// So that extended_p_square_quantile_quadratic can be automatically substituted with
+// weighted_extended_p_square_quantile_quadratic when the weight parameter is non-void
+template<>
+struct as_weighted_feature<tag::extended_p_square_quantile_quadratic>
+{
+ typedef tag::weighted_extended_p_square_quantile_quadratic type;
+};
+template<>
+struct feature_of<tag::weighted_extended_p_square_quantile_quadratic>
+ : feature_of<tag::extended_p_square_quantile_quadratic>
+{
+};
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/kurtosis.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/kurtosis.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,110 @@
+///////////////////////////////////////////////////////////////////////////////
+// kurtosis.hpp
+//
+// Copyright 2006 Olivier Gygi, Daniel Egloff. 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_KURTOSIS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
+
+#include <limits>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/moment.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // kurtosis_impl
+ /**
+ @brief Kurtosis estimation
+
+ The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
+ moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
+ has zero kurtosis. The kurtosis can also be expressed by the simple moments:
+
+ \f[
+ \hat{g}_2 =
+ \frac
+ {\widehat{m}_n^{(4)}-4\widehat{m}_n^{(3)}\hat{\mu}_n+6\widehat{m}_n^{(2)}\hat{\mu}_n^2-3\hat{\mu}_n^4}
+ {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
+ \f]
+
+ where \f$ \widehat{m}_n^{(i)} \f$ are the \f$ i \f$-th moment and \f$ \hat{\mu}_n \f$ the mean (first moment) of the
+ \f$ n \f$ samples.
+ */
+ template<typename Sample>
+ struct kurtosis_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, Sample>::result_type result_type;
+
+ kurtosis_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return numeric::average(
+ moment<4>(args)
+ - 4. * moment<3>(args) * mean(args)
+ + 6. * moment<2>(args) * mean(args) * mean(args)
+ - 3. * mean(args) * mean(args) * mean(args) * mean(args)
+ , ( moment<2>(args) - mean(args) * mean(args) )
+ * ( moment<2>(args) - mean(args) * mean(args) )
+ ) - 3.;
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::kurtosis
+//
+namespace tag
+{
+ struct kurtosis
+ : depends_on<mean, moment<2>, moment<3>, moment<4> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::kurtosis
+//
+namespace extract
+{
+ extractor<tag::kurtosis> const kurtosis = {};
+}
+
+using extract::kurtosis;
+
+// So that kurtosis can be automatically substituted with
+// weighted_kurtosis when the weight parameter is non-void
+template<>
+struct as_weighted_feature<tag::kurtosis>
+{
+ typedef tag::weighted_kurtosis type;
+};
+
+template<>
+struct feature_of<tag::weighted_kurtosis>
+ : feature_of<tag::kurtosis>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/max.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/max.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,83 @@
+///////////////////////////////////////////////////////////////////////////////
+// max.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MAX_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MAX_HPP_EAN_28_10_2005
+
+#include <limits>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // max_impl
+ template<typename Sample>
+ struct max_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef Sample result_type;
+
+ template<typename Args>
+ max_impl(Args const &args)
+ : max_(numeric::as_min(args[sample | Sample()]))
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ numeric::max_assign(this->max_, args[sample]);
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->max_;
+ }
+
+ private:
+ Sample max_;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::max
+//
+namespace tag
+{
+ struct max
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::max_impl<mpl::_1> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::max
+//
+namespace extract
+{
+ extractor<tag::max> const max = {};
+}
+
+using extract::max;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/mean.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/mean.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,295 @@
+///////////////////////////////////////////////////////////////////////////////
+// mean.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MEAN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MEAN_HPP_EAN_28_10_2005
+
+#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/count.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // mean_impl
+ // lazy, by default
+ template<typename Sample, typename SumFeature>
+ struct mean_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ mean_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ extractor<SumFeature> sum;
+ return numeric::average(sum(args), count(args));
+ }
+ };
+
+ template<typename Sample, typename Tag>
+ struct immediate_mean_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<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))
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+ this->mean = numeric::average(
+ (this->mean * (cnt - 1)) + args[parameter::keyword<Tag>::get()]
+ , cnt
+ );
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->mean;
+ }
+
+ private:
+ result_type mean;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::mean
+// tag::immediate_mean
+// tag::mean_of_weights
+// tag::immediate_mean_of_weights
+// tag::mean_of_variates
+// tag::immediate_mean_of_variates
+//
+namespace tag
+{
+ struct mean
+ : depends_on<count, sum>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::mean_impl<mpl::_1, sum> impl;
+ };
+ struct immediate_mean
+ : depends_on<count>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::immediate_mean_impl<mpl::_1, tag::sample> impl;
+ };
+ struct mean_of_weights
+ : depends_on<count, sum_of_weights>
+ {
+ typedef mpl::true_ is_weight_accumulator;
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::mean_impl<mpl::_2, sum_of_weights> impl;
+ };
+ struct immediate_mean_of_weights
+ : depends_on<count>
+ {
+ typedef mpl::true_ is_weight_accumulator;
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::immediate_mean_impl<mpl::_2, tag::weight> impl;
+ };
+ template<typename VariateType, typename VariateTag>
+ struct mean_of_variates
+ : depends_on<count, sum_of_variates<VariateType, VariateTag> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef mpl::always<accumulators::impl::mean_impl<VariateType, sum_of_variates<VariateType, VariateTag> > > impl;
+ };
+ template<typename VariateType, typename VariateTag>
+ struct immediate_mean_of_variates
+ : depends_on<count>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef mpl::always<accumulators::impl::immediate_mean_impl<VariateType, VariateTag> > impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::mean
+// extract::mean_of_weights
+// extract::mean_of_variates
+//
+namespace extract
+{
+ extractor<tag::mean> const mean = {};
+ extractor<tag::mean_of_weights> const mean_of_weights = {};
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, mean_of_variates, (typename)(typename))
+}
+
+using extract::mean;
+using extract::mean_of_weights;
+using extract::mean_of_variates;
+
+// mean(lazy) -> mean
+template<>
+struct as_feature<tag::mean(lazy)>
+{
+ typedef tag::mean type;
+};
+
+// mean(immediate) -> immediate_mean
+template<>
+struct as_feature<tag::mean(immediate)>
+{
+ typedef tag::immediate_mean type;
+};
+
+// mean_of_weights(lazy) -> mean_of_weights
+template<>
+struct as_feature<tag::mean_of_weights(lazy)>
+{
+ typedef tag::mean_of_weights type;
+};
+
+// mean_of_weights(immediate) -> immediate_mean_of_weights
+template<>
+struct as_feature<tag::mean_of_weights(immediate)>
+{
+ typedef tag::immediate_mean_of_weights type;
+};
+
+// mean_of_variates<VariateType, VariateTag>(lazy) -> mean_of_variates<VariateType, VariateTag>
+template<typename VariateType, typename VariateTag>
+struct as_feature<tag::mean_of_variates<VariateType, VariateTag>(lazy)>
+{
+ typedef tag::mean_of_variates<VariateType, VariateTag> type;
+};
+
+// mean_of_variates<VariateType, VariateTag>(immediate) -> immediate_mean_of_variates<VariateType, VariateTag>
+template<typename VariateType, typename VariateTag>
+struct as_feature<tag::mean_of_variates<VariateType, VariateTag>(immediate)>
+{
+ typedef tag::immediate_mean_of_variates<VariateType, VariateTag> type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// immediate_mean provides the same feature as mean
+template<>
+struct feature_of<tag::immediate_mean>
+ : feature_of<tag::mean>
+{
+};
+
+// for the purposes of feature-based dependency resolution,
+// immediate_mean provides the same feature as mean
+template<>
+struct feature_of<tag::immediate_mean_of_weights>
+ : feature_of<tag::mean_of_weights>
+{
+};
+
+// for the purposes of feature-based dependency resolution,
+// immediate_mean provides the same feature as mean
+template<typename VariateType, typename VariateTag>
+struct feature_of<tag::immediate_mean_of_variates<VariateType, VariateTag> >
+ : feature_of<tag::mean_of_variates<VariateType, VariateTag> >
+{
+};
+
+// So that mean can be automatically substituted with
+// weighted_mean when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::mean>
+{
+ typedef tag::weighted_mean type;
+};
+
+template<>
+struct feature_of<tag::weighted_mean>
+ : feature_of<tag::mean>
+{};
+
+// So that immediate_mean can be automatically substituted with
+// immediate_weighted_mean when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::immediate_mean>
+{
+ typedef tag::immediate_weighted_mean type;
+};
+
+template<>
+struct feature_of<tag::immediate_weighted_mean>
+ : feature_of<tag::immediate_mean>
+{};
+
+// So that mean_of_weights<> can be automatically substituted with
+// weighted_mean_of_variates<> when the weight parameter is non-void.
+template<typename VariateType, typename VariateTag>
+struct as_weighted_feature<tag::mean_of_variates<VariateType, VariateTag> >
+{
+ typedef tag::weighted_mean_of_variates<VariateType, VariateTag> type;
+};
+
+template<typename VariateType, typename VariateTag>
+struct feature_of<tag::weighted_mean_of_variates<VariateType, VariateTag> >
+ : feature_of<tag::mean_of_variates<VariateType, VariateTag> >
+{
+};
+
+// So that immediate_mean_of_weights<> can be automatically substituted with
+// immediate_weighted_mean_of_variates<> when the weight parameter is non-void.
+template<typename VariateType, typename VariateTag>
+struct as_weighted_feature<tag::immediate_mean_of_variates<VariateType, VariateTag> >
+{
+ typedef tag::immediate_weighted_mean_of_variates<VariateType, VariateTag> type;
+};
+
+template<typename VariateType, typename VariateTag>
+struct feature_of<tag::immediate_weighted_mean_of_variates<VariateType, VariateTag> >
+ : feature_of<tag::immediate_mean_of_variates<VariateType, VariateTag> >
+{
+};
+
+////////////////////////////////////////////////////////////////////////////
+//// droppable_accumulator<mean_impl>
+//// need to specialize droppable lazy mean to cache the result at the
+//// point the accumulator is dropped.
+///// INTERNAL ONLY
+/////
+//template<typename Sample, typename SumFeature>
+//struct droppable_accumulator<impl::mean_impl<Sample, SumFeature> >
+// : droppable_accumulator_base<
+// with_cached_result<impl::mean_impl<Sample, SumFeature> >
+// >
+//{
+// template<typename Args>
+// droppable_accumulator(Args const &args)
+// : droppable_accumulator::base(args)
+// {
+// }
+//};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/median.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/median.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,297 @@
+///////////////////////////////////////////////////////////////////////////////
+// median.hpp
+//
+// Copyright 2006 Eric Niebler, Olivier Gygi. 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_MEDIAN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MEDIAN_HPP_EAN_28_10_2005
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/range/iterator_range.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/count.hpp>
+#include <boost/accumulators/statistics/p_square_quantile.hpp>
+#include <boost/accumulators/statistics/density.hpp>
+#include <boost/accumulators/statistics/p_square_cumulative_distribution.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // median_impl
+ //
+ /**
+ @brief Median estimation based on the \f$P^2\f$ quantile estimator
+
+ The \f$P^2\f$ algorithm is invoked with a quantile probability of 0.5.
+ */
+ template<typename Sample>
+ struct median_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ median_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return p_square_quantile_for_median(args);
+ }
+ };
+ ///////////////////////////////////////////////////////////////////////////////
+ // with_density_median_impl
+ //
+ /**
+ @brief Median estimation based on the density estimator
+
+ The algorithm determines the bin in which the \f$0.5*cnt\f$-th sample lies, \f$cnt\f$ being
+ the total number of samples. It returns the approximate horizontal position of this sample,
+ based on a linear interpolation inside the bin.
+ */
+ template<typename Sample>
+ struct with_density_median_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef float_type result_type;
+
+ template<typename Args>
+ with_density_median_impl(Args const &args)
+ : sum(numeric::average(args[sample | Sample()], (std::size_t)1))
+ , is_dirty(true)
+ {
+ }
+
+ void operator ()(dont_care)
+ {
+ this->is_dirty = true;
+ }
+
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ std::size_t cnt = count(args);
+ range_type histogram = density(args);
+ typename range_type::iterator it = histogram.begin();
+ while (this->sum < 0.5 * cnt)
+ {
+ this->sum += it->second * cnt;
+ ++it;
+ }
+ --it;
+ float_type over = numeric::average(this->sum - 0.5 * cnt, it->second * cnt);
+ this->median = it->first * over + (it + 1)->first * (1. - over);
+ }
+
+ return this->median;
+ }
+
+ private:
+ mutable float_type sum;
+ mutable bool is_dirty;
+ mutable float_type median;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // with_p_square_cumulative_distribution_median_impl
+ //
+ /**
+ @brief Median estimation based on the \f$P^2\f$ cumulative distribution estimator
+
+ The algorithm determines the first (leftmost) bin with a height exceeding 0.5. It
+ returns the approximate horizontal position of where the cumulative distribution
+ equals 0.5, based on a linear interpolation inside the bin.
+ */
+ template<typename Sample>
+ struct with_p_square_cumulative_distribution_median_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef float_type result_type;
+
+ with_p_square_cumulative_distribution_median_impl(dont_care)
+ : is_dirty(true)
+ {
+ }
+
+ void operator ()(dont_care)
+ {
+ this->is_dirty = true;
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ range_type histogram = p_square_cumulative_distribution(args);
+ typename range_type::iterator it = histogram.begin();
+ while (it->second < 0.5)
+ {
+ ++it;
+ }
+ float_type over = numeric::average(it->second - 0.5, it->second - (it - 1)->second);
+ this->median = it->first * over + (it + 1)->first * ( 1. - over );
+ }
+
+ return this->median;
+ }
+ private:
+
+ mutable bool is_dirty;
+ mutable float_type median;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::median
+// tag::with_densisty_median
+// tag::with_p_square_cumulative_distribution_median
+//
+namespace tag
+{
+ struct median
+ : depends_on<p_square_quantile_for_median>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::median_impl<mpl::_1> impl;
+ };
+ struct with_density_median
+ : depends_on<count, density>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::with_density_median_impl<mpl::_1> impl;
+ };
+ struct with_p_square_cumulative_distribution_median
+ : depends_on<p_square_cumulative_distribution>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::with_p_square_cumulative_distribution_median_impl<mpl::_1> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::median
+// extract::with_density_median
+// extract::with_p_square_cumulative_distribution_median
+//
+namespace extract
+{
+ extractor<tag::median> const median = {};
+ extractor<tag::with_density_median> const with_density_median = {};
+ extractor<tag::with_p_square_cumulative_distribution_median> const with_p_square_cumulative_distribution_median = {};
+}
+
+using extract::median;
+using extract::with_density_median;
+using extract::with_p_square_cumulative_distribution_median;
+
+// median(with_p_square_quantile) -> median
+template<>
+struct as_feature<tag::median(with_p_square_quantile)>
+{
+ typedef tag::median type;
+};
+
+// median(with_density) -> with_density_median
+template<>
+struct as_feature<tag::median(with_density)>
+{
+ typedef tag::with_density_median type;
+};
+
+// median(with_p_square_cumulative_distribution) -> with_p_square_cumulative_distribution_median
+template<>
+struct as_feature<tag::median(with_p_square_cumulative_distribution)>
+{
+ typedef tag::with_p_square_cumulative_distribution_median type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// with_density_median and with_p_square_cumulative_distribution_median
+// provide the same feature as median
+template<>
+struct feature_of<tag::with_density_median>
+ : feature_of<tag::median>
+{
+};
+
+template<>
+struct feature_of<tag::with_p_square_cumulative_distribution_median>
+ : feature_of<tag::median>
+{
+};
+
+// So that median can be automatically substituted with
+// weighted_median when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::median>
+{
+ typedef tag::weighted_median type;
+};
+
+template<>
+struct feature_of<tag::weighted_median>
+ : feature_of<tag::median>
+{
+};
+
+// So that with_density_median can be automatically substituted with
+// with_density_weighted_median when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::with_density_median>
+{
+ typedef tag::with_density_weighted_median type;
+};
+
+template<>
+struct feature_of<tag::with_density_weighted_median>
+ : feature_of<tag::with_density_median>
+{
+};
+
+// So that with_p_square_cumulative_distribution_median can be automatically substituted with
+// with_p_square_cumulative_distribution_weighted_median when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::with_p_square_cumulative_distribution_median>
+{
+ typedef tag::with_p_square_cumulative_distribution_weighted_median type;
+};
+
+template<>
+struct feature_of<tag::with_p_square_cumulative_distribution_weighted_median>
+ : feature_of<tag::with_p_square_cumulative_distribution_median>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/min.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/min.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,83 @@
+///////////////////////////////////////////////////////////////////////////////
+// min.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MIN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MIN_HPP_EAN_28_10_2005
+
+#include <limits>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // min_impl
+ template<typename Sample>
+ struct min_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef Sample result_type;
+
+ template<typename Args>
+ min_impl(Args const &args)
+ : min_(numeric::as_max(args[sample | Sample()]))
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ numeric::min_assign(this->min_, args[sample]);
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->min_;
+ }
+
+ private:
+ Sample min_;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::min
+//
+namespace tag
+{
+ struct min
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::min_impl<mpl::_1> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::min
+//
+namespace extract
+{
+ extractor<tag::min> const min = {};
+}
+
+using extract::min;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/moment.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/moment.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,125 @@
+///////////////////////////////////////////////////////////////////////////////
+// moment.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MOMENT_HPP_EAN_15_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MOMENT_HPP_EAN_15_11_2005
+
+#include <cmath>
+#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/count.hpp>
+
+namespace boost { namespace numeric
+{
+ /// INTERNAL ONLY
+ ///
+ template<typename T>
+ T const &pow(T const &x, mpl::int_<1>)
+ {
+ return x;
+ }
+
+ /// INTERNAL ONLY
+ ///
+ template<typename T, int N>
+ T pow(T const &x, mpl::int_<N>)
+ {
+ using namespace operators;
+ T y = numeric::pow(x, mpl::int_<N/2>());
+ T z = y * y;
+ return (N % 2) ? (z * x) : z;
+ }
+}}
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // moment_impl
+ template<typename N, typename Sample>
+ struct moment_impl
+ : accumulator_base // TODO: also depends_on sum of powers
+ {
+ BOOST_MPL_ASSERT_RELATION(N::value, >, 0);
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ template<typename Args>
+ moment_impl(Args const &args)
+ : sum(args[sample | Sample()])
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->sum += numeric::pow(args[sample], N());
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return numeric::average(this->sum, count(args));
+ }
+
+ private:
+ Sample sum;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::moment
+//
+namespace tag
+{
+ template<int N>
+ struct moment
+ : depends_on<count>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::moment_impl<mpl::int_<N>, mpl::_1> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::moment
+//
+namespace extract
+{
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, moment, (int))
+}
+
+using extract::moment;
+
+// So that moment<N> can be automatically substituted with
+// weighted_moment<N> when the weight parameter is non-void
+template<int N>
+struct as_weighted_feature<tag::moment<N> >
+{
+ typedef tag::weighted_moment<N> type;
+};
+
+template<int N>
+struct feature_of<tag::weighted_moment<N> >
+ : feature_of<tag::moment<N> >
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/p_square_cumulative_distribution.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/p_square_cumulative_distribution.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,258 @@
+///////////////////////////////////////////////////////////////////////////////
+// p_square_cumulative_distribution.hpp
+//
+// Copyright 2005 Daniel Egloff, Olivier Gygi. 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_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_DE_01_01_2006
+
+#include <vector>
+#include <functional>
+#include <boost/parameter/keyword.hpp>
+#include <boost/range.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+namespace boost { namespace accumulators
+{
+///////////////////////////////////////////////////////////////////////////////
+// num_cells named parameter
+//
+BOOST_PARAMETER_NESTED_KEYWORD(tag, p_square_cumulative_distribution_num_cells, num_cells)
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // p_square_cumulative_distribution_impl
+ // cumulative_distribution calculation (as histogram)
+ /**
+ @brief Histogram calculation of the cumulative distribution with the \f$P^2\f$ algorithm
+
+ A histogram of the sample cumulative distribution is computed dynamically without storing samples
+ based on the \f$ P^2 \f$ algorithm. The returned histogram has a specifiable amount (num_cells)
+ equiprobable (and not equal-sized) cells.
+
+ For further details, see
+
+ R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and
+ histograms without storing observations, Communications of the ACM,
+ Volume 28 (October), Number 10, 1985, p. 1076-1085.
+
+ @param p_square_cumulative_distribution_num_cells.
+ */
+ template<typename Sample>
+ struct p_square_cumulative_distribution_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef iterator_range<typename histogram_type::iterator> result_type;
+
+ template<typename Args>
+ p_square_cumulative_distribution_impl(Args const &args)
+ : num_cells(args[p_square_cumulative_distribution_num_cells])
+ , heights(num_cells + 1)
+ , actual_positions(num_cells + 1)
+ , desired_positions(num_cells + 1)
+ , positions_increments(num_cells + 1)
+ , histogram(num_cells + 1)
+ , is_dirty(true)
+ {
+ std::size_t b = this->num_cells;
+
+ for (std::size_t i = 0; i < b + 1; ++i)
+ {
+ this->actual_positions[i] = i + 1.;
+ this->desired_positions[i] = i + 1.;
+ this->positions_increments[i] = numeric::average(i, b);
+ }
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->is_dirty = true;
+
+ std::size_t cnt = count(args);
+ std::size_t sample_cell = 1; // k
+ std::size_t b = this->num_cells;
+
+ // accumulate num_cells + 1 first samples
+ if (cnt <= b + 1)
+ {
+ this->heights[cnt - 1] = args[sample];
+
+ // complete the initialization of heights by sorting
+ if (cnt == b + 1)
+ {
+ std::sort(this->heights.begin(), this->heights.end());
+ }
+ }
+ else
+ {
+ // 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];
+ sample_cell = 1;
+ }
+ else if (this->heights[b] <= args[sample])
+ {
+ this->heights[b] = args[sample];
+ sample_cell = b;
+ }
+ else
+ {
+ typename array_type::iterator it;
+ it = std::upper_bound(
+ this->heights.begin()
+ , this->heights.end()
+ , args[sample]
+ );
+
+ sample_cell = std::distance(this->heights.begin(), it);
+ }
+
+ // increment positions of markers above sample_cell
+ for (std::size_t i = sample_cell; i < b + 1; ++i)
+ {
+ ++this->actual_positions[i];
+ }
+
+ // update desired position of markers 2 to num_cells + 1
+ // (desired position of first marker is always 1)
+ for (std::size_t i = 1; i < b + 1; ++i)
+ {
+ this->desired_positions[i] += this->positions_increments[i];
+ }
+
+ // adjust heights of markers 2 to num_cells if necessary
+ for (std::size_t i = 1; i < b; ++i)
+ {
+ // offset to desire position
+ float_type d = this->desired_positions[i] - this->actual_positions[i];
+
+ // offset to next position
+ float_type dp = this->actual_positions[i + 1] - this->actual_positions[i];
+
+ // offset to previous position
+ float_type dm = this->actual_positions[i - 1] - this->actual_positions[i];
+
+ // height ds
+ float_type hp = (this->heights[i + 1] - this->heights[i]) / dp;
+ float_type hm = (this->heights[i - 1] - this->heights[i]) / dm;
+
+ if ( ( d >= 1. && dp > 1. ) || ( d <= -1. && dm < -1. ) )
+ {
+ short sign_d = static_cast<short>(d / std::abs(d));
+
+ // try adjusting heights[i] using p-squared formula
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ( (sign_d - dm) * hp + (dp - sign_d) * hm );
+
+ if ( this->heights[i - 1] < h && h < this->heights[i + 1] )
+ {
+ this->heights[i] = h;
+ }
+ else
+ {
+ // use linear formula
+ if (d>0)
+ {
+ this->heights[i] += hp;
+ }
+ if (d<0)
+ {
+ this->heights[i] -= hm;
+ }
+ }
+ this->actual_positions[i] += sign_d;
+ }
+ }
+ }
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ // creates a vector of std::pair where each pair i holds
+ // the values heights[i] (x-axis of histogram) and
+ // actual_positions[i] / cnt (y-axis of histogram)
+
+ std::size_t cnt = count(args);
+
+ 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));
+ }
+ }
+ //return histogram;
+ return make_iterator_range(this->histogram);
+ }
+
+ private:
+ std::size_t num_cells; // number of cells b
+ array_type heights; // q_i
+ array_type actual_positions; // n_i
+ array_type desired_positions; // n'_i
+ array_type positions_increments; // dn'_i
+ mutable histogram_type histogram; // histogram
+ mutable bool is_dirty;
+ };
+
+} // namespace detail
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::p_square_cumulative_distribution
+//
+namespace tag
+{
+ struct p_square_cumulative_distribution
+ : depends_on<count>
+ , p_square_cumulative_distribution_num_cells
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::p_square_cumulative_distribution_impl<mpl::_1> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::p_square_cumulative_distribution
+//
+namespace extract
+{
+ extractor<tag::p_square_cumulative_distribution> const p_square_cumulative_distribution = {};
+}
+
+using extract::p_square_cumulative_distribution;
+
+// So that p_square_cumulative_distribution can be automatically substituted with
+// weighted_p_square_cumulative_distribution when the weight parameter is non-void
+template<>
+struct as_weighted_feature<tag::p_square_cumulative_distribution>
+{
+ typedef tag::weighted_p_square_cumulative_distribution type;
+};
+
+template<>
+struct feature_of<tag::weighted_p_square_cumulative_distribution>
+ : feature_of<tag::p_square_cumulative_distribution>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/p_square_quantile.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/p_square_quantile.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,253 @@
+///////////////////////////////////////////////////////////////////////////////
+// p_square_quantile.hpp
+//
+// Copyright 2005 Daniel Egloff. 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_P_SQUARE_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_P_SQUARE_QUANTILE_HPP_DE_01_01_2006
+
+#include <functional>
+#include <boost/array.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/parameter/keyword.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/count.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // p_square_quantile_impl
+ // single quantile estimation
+ /**
+ @brief Single quantile estimation with the \f$P^2\f$ algorithm
+
+ The \f$P^2\f$ algorithm estimates a quantile dynamically without storing samples. Instead of
+ storing the whole sample cumulative distribution, only five points (markers) are stored. The heights
+ of these markers are the minimum and the maximum of the samples and the current estimates of the
+ \f$(p/2)\f$-, \f$p\f$- and \f$(1+p)/2\f$-quantiles. Their positions are equal to the number
+ of samples that are smaller or equal to the markers. Each time a new samples is recorded, the
+ positions of the markers are updated and if necessary their heights are adjusted using a piecewise-
+ parabolic formula.
+
+ For further details, see
+
+ R. Jain and I. Chlamtac, The P^2 algorithmus fordynamic calculation of quantiles and
+ histograms without storing observations, Communications of the ACM,
+ Volume 28 (October), Number 10, 1985, p. 1076-1085.
+
+ @param quantile_probability
+ */
+ template<typename Sample, typename Impl>
+ struct p_square_quantile_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
+ typedef array<float_type, 5> array_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ template<typename Args>
+ p_square_quantile_impl(Args const &args)
+ : p(is_same<Impl, for_median>::value ? 0.5 : args[quantile_probability | 0.5])
+ , heights()
+ , actual_positions()
+ , desired_positions()
+ , positions_increments()
+ {
+ for(std::size_t i = 0; i < 5; ++i)
+ {
+ this->actual_positions[i] = i + 1;
+ }
+
+ this->desired_positions[0] = 1.;
+ this->desired_positions[1] = 1. + 2. * this->p;
+ this->desired_positions[2] = 1. + 4. * this->p;
+ this->desired_positions[3] = 3. + 2. * this->p;
+ this->desired_positions[4] = 5.;
+
+ this->positions_increments[0] = 0.;
+ this->positions_increments[1] = this->p / 2.;
+ this->positions_increments[2] = this->p;
+ this->positions_increments[3] = (1. + this->p) / 2.;
+ this->positions_increments[4] = 1.;
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+
+ // accumulate 5 first samples
+ if(cnt <= 5)
+ {
+ this->heights[cnt - 1] = args[sample];
+
+ // complete the initialization of heights by sorting
+ if(cnt == 5)
+ {
+ std::sort(this->heights.begin(), this->heights.end());
+ }
+ }
+ else
+ {
+ std::size_t sample_cell = 1; // k
+
+ // find cell k such that heights[k-1] <= args[sample] < heights[k] and ajust extreme values
+ if (args[sample] < this->heights[0])
+ {
+ this->heights[0] = args[sample];
+ sample_cell = 1;
+ }
+ else if (this->heights[4] <= args[sample])
+ {
+ this->heights[4] = args[sample];
+ sample_cell = 4;
+ }
+ else
+ {
+ typedef typename array_type::iterator iterator;
+ iterator it = std::upper_bound(
+ this->heights.begin()
+ , this->heights.end()
+ , args[sample]
+ );
+
+ sample_cell = std::distance(this->heights.begin(), it);
+ }
+
+ // update positions of markers above sample_cell
+ for(std::size_t i = sample_cell; i < 5; ++i)
+ {
+ ++this->actual_positions[i];
+ }
+
+ // update desired positions of all markers
+ for(std::size_t i = 0; i < 5; ++i)
+ {
+ this->desired_positions[i] += this->positions_increments[i];
+ }
+
+ // adjust heights and actual positions of markers 1 to 3 if necessary
+ for(std::size_t i = 1; i <= 3; ++i)
+ {
+ // offset to desired positions
+ float_type d = this->desired_positions[i] - this->actual_positions[i];
+
+ // offset to next position
+ float_type dp = this->actual_positions[i + 1] - this->actual_positions[i];
+
+ // offset to previous position
+ float_type dm = this->actual_positions[i - 1] - this->actual_positions[i];
+
+ // height ds
+ float_type hp = (this->heights[i + 1] - this->heights[i]) / dp;
+ float_type hm = (this->heights[i - 1] - this->heights[i]) / dm;
+
+ if((d >= 1. && dp > 1.) || (d <= -1. && dm < -1.))
+ {
+ short sign_d = static_cast<short>(d / std::abs(d));
+
+ // try adjusting heights[i] using p-squared formula
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ((sign_d - dm) * hp
+ + (dp - sign_d) * hm);
+
+ if(this->heights[i - 1] < h && h < this->heights[i + 1])
+ {
+ this->heights[i] = h;
+ }
+ else
+ {
+ // use linear formula
+ if(d > 0)
+ {
+ this->heights[i] += hp;
+ }
+ if(d < 0)
+ {
+ this->heights[i] -= hm;
+ }
+ }
+ this->actual_positions[i] += sign_d;
+ }
+ }
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->heights[2];
+ }
+
+ private:
+ float_type p; // the quantile probability p
+ array_type heights; // q_i
+ array_type actual_positions; // n_i
+ array_type desired_positions; // n'_i
+ array_type positions_increments; // dn'_i
+ };
+
+} // namespace detail
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::p_square_quantile
+//
+namespace tag
+{
+ struct p_square_quantile
+ : depends_on<count>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::p_square_quantile_impl<mpl::_1, regular> impl;
+ };
+ struct p_square_quantile_for_median
+ : depends_on<count>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::p_square_quantile_impl<mpl::_1, for_median> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::p_square_quantile
+// extract::p_square_quantile_for_median
+//
+namespace extract
+{
+ extractor<tag::p_square_quantile> const p_square_quantile = {};
+ extractor<tag::p_square_quantile_for_median> const p_square_quantile_for_median = {};
+}
+
+using extract::p_square_quantile;
+using extract::p_square_quantile_for_median;
+
+// So that p_square_quantile can be automatically substituted with
+// weighted_p_square_quantile when the weight parameter is non-void
+template<>
+struct as_weighted_feature<tag::p_square_quantile>
+{
+ typedef tag::weighted_p_square_quantile type;
+};
+
+template<>
+struct feature_of<tag::weighted_p_square_quantile>
+ : feature_of<tag::p_square_quantile>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/parameters/quantile_probability.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/parameters/quantile_probability.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,20 @@
+///////////////////////////////////////////////////////////////////////////////
+// quantile_probability.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_PARAMETERS_QUANTILE_PROBABILITY_HPP_EAN_03_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_PARAMETERS_QUANTILE_PROBABILITY_HPP_EAN_03_11_2005
+
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { namespace accumulators
+{
+
+BOOST_PARAMETER_KEYWORD(tag, quantile_probability)
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/peaks_over_threshold.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/peaks_over_threshold.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,399 @@
+///////////////////////////////////////////////////////////////////////////////
+// peaks_over_threshold.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_PEAKS_OVER_THRESHOLD_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_PEAKS_OVER_THRESHOLD_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <numeric>
+#include <functional>
+#include <cmath> // pow
+#include <sstream> // stringstream
+#include <stdexcept> // runtime_error
+#include <boost/throw_exception.hpp>
+#include <boost/range.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/tuple/tuple.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/parameters/quantile_probability.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// threshold_probability and threshold named parameters
+//
+BOOST_PARAMETER_NESTED_KEYWORD(tag, pot_threshold_value, threshold_value)
+BOOST_PARAMETER_NESTED_KEYWORD(tag, pot_threshold_probability, threshold_probability)
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // peaks_over_threshold_impl
+ // works with an explicit threshold value and does not depend on order statistics
+ /**
+ @brief Peaks over Threshold Method for Quantile and Tail Mean Estimation
+
+ According to the theorem of Pickands-Balkema-de Haan, the distribution function \f$F_u(x)\f$ of
+ the excesses \f$x\f$ over some sufficiently high threshold \f$u\f$ of a distribution function \f$F(x)\f$
+ may be approximated by a generalized Pareto distribution
+ \f[
+ G_{\xi,\beta}(x) =
+ \left\{
+ \begin{array}{ll}
+ \beta^{-1}\left(1+\frac{\xi x}{\beta}\right)^{-1/\xi-1} & \textrm{if }\xi\neq0\\
+ \beta^{-1}\exp\left(-\frac{x}{\beta}\right) & \textrm{if }\xi=0,
+ \end{array}
+ \right.
+ \f]
+ with suitable parameters \f$\xi\f$ and \f$\beta\f$ that can be estimated, e.g., with the method of moments, cf.
+ Hosking and Wallis (1987),
+ \f[
+ \begin{array}{lll}
+ \hat{\xi} & = & \frac{1}{2}\left[1-\frac{(\hat{\mu}-u)^2}{\hat{\sigma}^2}\right]\\
+ \hat{\beta} & = & \frac{\hat{\mu}-u}{2}\left[\frac{(\hat{\mu}-u)^2}{\hat{\sigma}^2}+1\right],
+ \end{array}
+ \f]
+ \f$\hat{\mu}\f$ and \f$\hat{\sigma}^2\f$ being the empirical mean and variance of the samples over
+ the threshold \f$u\f$. Equivalently, the distribution function
+ \f$F_u(x-u)\f$ of the exceedances \f$x-u\f$ can be approximated by
+ \f$G_{\xi,\beta}(x-u)=G_{\xi,\beta,u}(x)\f$. Since for \f$x\geq u\f$ the distribution function \f$F(x)\f$
+ can be written as
+ \f[
+ F(x) = [1 - \P(X \leq u)]F_u(x - u) + \P(X \leq u)
+ \f]
+ and the probability \f$\P(X \leq u)\f$ can be approximated by the empirical distribution function
+ \f$F_n(u)\f$ evaluated at \f$u\f$, an estimator of \f$F(x)\f$ is given by
+ \f[
+ \widehat{F}(x) = [1 - F_n(u)]G_{\xi,\beta,u}(x) + F_n(u).
+ \f]
+ It can be shown that \f$\widehat{F}(x)\f$ is a generalized
+ Pareto distribution \f$G_{\xi,\bar{\beta},\bar{u}}(x)\f$ with \f$\bar{\beta}=\beta[1-F_n(u)]^{\xi}\f$
+ and \f$\bar{u}=u-\bar{\beta}\left\{[1-F_n(u)]^{-\xi}-1\right\}/\xi\f$. By inverting \f$\widehat{F}(x)\f$,
+ one obtains an estimator for the \f$\alpha\f$-quantile,
+ \f[
+ \hat{q}_{\alpha} = \bar{u} + \frac{\bar{\beta}}{\xi}\left[(1-\alpha)^{-\xi}-1\right],
+ \f]
+ and similarly an estimator for the (coherent) tail mean,
+ \f[
+ \widehat{CTM}_{\alpha} = \hat{q}_{\alpha} - \frac{\bar{\beta}}{\xi-1}(1-\alpha)^{-\xi},
+ \f]
+ cf. McNeil and Frey (2000).
+
+ Note that in case extreme values of the left tail are fitted, the distribution is mirrored with respect to the
+ \f$y\f$ axis such that the left tail can be treated as a right tail. The computed fit parameters thus define
+ the Pareto distribution that fits the mirrored left tail. When quantities like a quantile or a tail mean are
+ computed using the fit parameters obtained from the mirrored data, the result is mirrored back, yielding the
+ correct result.
+
+ For further details, see
+
+ J. R. M. Hosking and J. R. Wallis, Parameter and quantile estimation for the generalized Pareto distribution,
+ Technometrics, Volume 29, 1987, p. 339-349
+
+ A. J. McNeil and R. Frey, Estimation of Tail-Related Risk Measures for Heteroscedastic Financial Time Series:
+ an Extreme Value Approach, Journal of Empirical Finance, Volume 7, 2000, p. 271-300
+
+ @param quantile_probability
+ @param pot_threshold_value
+ */
+ template<typename Sample, typename LeftRight>
+ struct peaks_over_threshold_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef mpl::int_<is_same<LeftRight, left>::value ? -1 : 1> sign;
+
+ 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))
+ , threshold_(sign::value * args[pot_threshold_value])
+ , fit_parameters_(boost::make_tuple(0., 0., 0.))
+ , is_dirty_(true)
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->is_dirty_ = true;
+
+ if (sign::value * args[sample] > this->threshold_)
+ {
+ this->mu_ += args[sample];
+ this->sigma2_ += args[sample] * args[sample];
+ ++this->Nu_;
+ }
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty_)
+ {
+ this->is_dirty_ = false;
+
+ 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->sigma2_ -= this->mu_ * this->mu_;
+
+ float_type threshold_probability = numeric::average(cnt - this->Nu_, cnt);
+
+ float_type tmp = numeric::average(( 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);
+ float_type u_bar = this->threshold_ - beta_bar * ( std::pow(1. - threshold_probability, -xi_hat) - 1.)/xi_hat;
+ this->fit_parameters_ = boost::make_tuple(u_bar, beta_bar, xi_hat);
+ }
+
+ return this->fit_parameters_;
+ }
+
+ private:
+ std::size_t Nu_; // number of samples larger than threshold
+ mutable float_type mu_; // mean of Nu_ largest samples
+ mutable float_type sigma2_; // variance of Nu_ largest samples
+ float_type threshold_;
+ mutable result_type fit_parameters_; // boost::tuple that stores fit parameters
+ mutable bool is_dirty_;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // peaks_over_threshold_prob_impl
+ // determines threshold from a given threshold probability using order statistics
+ /**
+ @brief Peaks over Threshold Method for Quantile and Tail Mean Estimation
+
+ @sa peaks_over_threshold_impl
+
+ @param quantile_probability
+ @param pot_threshold_probability
+ */
+ template<typename Sample, typename LeftRight>
+ struct peaks_over_threshold_prob_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef mpl::int_<is_same<LeftRight, left>::value ? -1 : 1> sign;
+
+ 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))
+ , threshold_probability_(args[pot_threshold_probability])
+ , fit_parameters_(boost::make_tuple(0., 0., 0.))
+ , is_dirty_(true)
+ {
+ }
+
+ void operator ()(dont_care)
+ {
+ this->is_dirty_ = true;
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty_)
+ {
+ this->is_dirty_ = false;
+
+ std::size_t cnt = count(args);
+
+ // the n'th cached sample provides an approximate threshold value u
+ std::size_t n = static_cast<std::size_t>(
+ std::ceil(
+ cnt * ( ( is_same<LeftRight, left>::value ) ? this->threshold_probability_ : 1. - this->threshold_probability_ )
+ )
+ );
+
+ // 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()))
+ {
+ if (std::numeric_limits<float_type>::has_quiet_NaN)
+ {
+ return boost::make_tuple(
+ std::numeric_limits<float_type>::quiet_NaN()
+ , std::numeric_limits<float_type>::quiet_NaN()
+ , std::numeric_limits<float_type>::quiet_NaN()
+ );
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ return boost::make_tuple(Sample(0), Sample(0), Sample(0));
+ }
+ }
+ else
+ {
+ float_type u = *(tail(args).begin() + n - 1) * sign::value;
+
+ // compute mean and variance of samples above/under threshold value u
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ mu_ += *(tail(args).begin() + i);
+ 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->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 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);
+ float_type u_bar = u - beta_bar * ( std::pow(1. - threshold_probability_, -xi_hat) - 1.)/xi_hat;
+ this->fit_parameters_ = boost::make_tuple(u_bar, beta_bar, xi_hat);
+ }
+ }
+
+ return this->fit_parameters_;
+ }
+
+ private:
+ mutable float_type mu_; // mean of samples above threshold u
+ mutable float_type sigma2_; // variance of samples above threshold u
+ mutable float_type threshold_probability_;
+ mutable result_type fit_parameters_; // boost::tuple that stores fit parameters
+ mutable bool is_dirty_;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::peaks_over_threshold
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct peaks_over_threshold
+ : depends_on<count>
+ , pot_threshold_value
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::peaks_over_threshold_impl<mpl::_1, LeftRight> impl;
+ };
+
+ template<typename LeftRight>
+ struct peaks_over_threshold_prob
+ : depends_on<count, tail<LeftRight> >
+ , pot_threshold_probability
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::peaks_over_threshold_prob_impl<mpl::_1, LeftRight> impl;
+ };
+
+ struct abstract_peaks_over_threshold
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::peaks_over_threshold
+//
+namespace extract
+{
+ extractor<tag::abstract_peaks_over_threshold> const peaks_over_threshold = {};
+}
+
+using extract::peaks_over_threshold;
+
+// peaks_over_threshold<LeftRight>(with_threshold_value) -> peaks_over_threshold<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::peaks_over_threshold<LeftRight>(with_threshold_value)>
+{
+ typedef tag::peaks_over_threshold<LeftRight> type;
+};
+
+// peaks_over_threshold<LeftRight>(with_threshold_probability) -> peaks_over_threshold_prob<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::peaks_over_threshold<LeftRight>(with_threshold_probability)>
+{
+ typedef tag::peaks_over_threshold_prob<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::peaks_over_threshold<LeftRight> >
+ : feature_of<tag::abstract_peaks_over_threshold>
+{
+};
+
+template<typename LeftRight>
+struct feature_of<tag::peaks_over_threshold_prob<LeftRight> >
+ : feature_of<tag::abstract_peaks_over_threshold>
+{
+};
+
+// So that peaks_over_threshold can be automatically substituted
+// with weighted_peaks_over_threshold when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::peaks_over_threshold<LeftRight> >
+{
+ typedef tag::weighted_peaks_over_threshold<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::weighted_peaks_over_threshold<LeftRight> >
+ : feature_of<tag::peaks_over_threshold<LeftRight> >
+{};
+
+// So that peaks_over_threshold_prob can be automatically substituted
+// with weighted_peaks_over_threshold_prob when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::peaks_over_threshold_prob<LeftRight> >
+{
+ typedef tag::weighted_peaks_over_threshold_prob<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::weighted_peaks_over_threshold_prob<LeftRight> >
+ : feature_of<tag::peaks_over_threshold_prob<LeftRight> >
+{};
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/pot_quantile.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/pot_quantile.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,205 @@
+///////////////////////////////////////////////////////////////////////////////
+// pot_quantile.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_POT_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_POT_QUANTILE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <numeric>
+#include <functional>
+#include <boost/parameter/keyword.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits/is_same.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/peaks_over_threshold.hpp>
+#include <boost/accumulators/statistics/weighted_peaks_over_threshold.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // pot_quantile_impl
+ //
+ /**
+ @brief Quantile Estimation based on Peaks over Threshold Method (for both left and right tails)
+
+ Computes an estimate
+ \f[
+ \hat{q}_{\alpha} = \bar{u} + \frac{\bar{\beta}}{\xi}\left[(1-\alpha)^{-\xi}-1\right]
+ \f]
+ for a right or left extreme quantile, \f$\bar[u]\f$, \f$\bar{\beta}\f$ and \f$\xi\f$ being the parameters of the
+ generalized Pareto distribution that approximates the right tail of the distribution (or the mirrored left tail,
+ in case the left tail is used). In the latter case, the result is mirrored back, yielding the correct result.
+ */
+ template<typename Sample, typename Impl, typename LeftRight>
+ struct pot_quantile_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ pot_quantile_impl(dont_care)
+ : sign_((is_same<LeftRight, left>::value) ? -1 : 1)
+ {
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ typedef
+ typename mpl::if_<
+ is_same<Impl, weighted>
+ , tag::weighted_peaks_over_threshold<LeftRight>
+ , tag::peaks_over_threshold<LeftRight>
+ >::type
+ peaks_over_threshold_tag;
+
+ extractor<peaks_over_threshold_tag> const some_peaks_over_threshold = {};
+
+ float_type u_bar = some_peaks_over_threshold(args).template get<0>();
+ float_type beta_bar = some_peaks_over_threshold(args).template get<1>();
+ float_type xi_hat = some_peaks_over_threshold(args).template get<2>();
+
+ return this->sign_ * (u_bar + beta_bar/xi_hat * ( std::pow(
+ is_same<LeftRight, left>::value ? args[quantile_probability] : 1. - args[quantile_probability]
+ , -xi_hat
+ ) - 1.));
+ }
+
+ private:
+ short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::pot_quantile<>
+// tag::pot_quantile_prob<>
+// tag::weighted_pot_quantile<>
+// tag::weighted_pot_quantile_prob<>
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct pot_quantile
+ : depends_on<peaks_over_threshold<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_quantile_impl<mpl::_1, unweighted, LeftRight> impl;
+ };
+ template<typename LeftRight>
+ struct pot_quantile_prob
+ : depends_on<peaks_over_threshold_prob<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_quantile_impl<mpl::_1, unweighted, LeftRight> impl;
+ };
+ template<typename LeftRight>
+ struct weighted_pot_quantile
+ : depends_on<weighted_peaks_over_threshold<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_quantile_impl<mpl::_1, weighted, LeftRight> impl;
+ };
+ template<typename LeftRight>
+ struct weighted_pot_quantile_prob
+ : depends_on<weighted_peaks_over_threshold_prob<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_quantile_impl<mpl::_1, weighted, LeftRight> impl;
+ };
+}
+
+// pot_quantile<LeftRight>(with_threshold_value) -> pot_quantile<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::pot_quantile<LeftRight>(with_threshold_value)>
+{
+ typedef tag::pot_quantile<LeftRight> type;
+};
+
+// pot_quantile<LeftRight>(with_threshold_probability) -> pot_quantile_prob<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::pot_quantile<LeftRight>(with_threshold_probability)>
+{
+ typedef tag::pot_quantile_prob<LeftRight> type;
+};
+
+// weighted_pot_quantile<LeftRight>(with_threshold_value) -> weighted_pot_quantile<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::weighted_pot_quantile<LeftRight>(with_threshold_value)>
+{
+ typedef tag::weighted_pot_quantile<LeftRight> type;
+};
+
+// weighted_pot_quantile<LeftRight>(with_threshold_probability) -> weighted_pot_quantile_prob<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::weighted_pot_quantile<LeftRight>(with_threshold_probability)>
+{
+ typedef tag::weighted_pot_quantile_prob<LeftRight> type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// pot_quantile<LeftRight> and pot_quantile_prob<LeftRight> provide
+// the same feature as quantile
+template<typename LeftRight>
+struct feature_of<tag::pot_quantile<LeftRight> >
+ : feature_of<tag::quantile>
+{
+};
+
+template<typename LeftRight>
+struct feature_of<tag::pot_quantile_prob<LeftRight> >
+ : feature_of<tag::quantile>
+{
+};
+
+// So that pot_quantile can be automatically substituted
+// with weighted_pot_quantile when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::pot_quantile<LeftRight> >
+{
+ typedef tag::weighted_pot_quantile<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::weighted_pot_quantile<LeftRight> >
+ : feature_of<tag::pot_quantile<LeftRight> >
+{
+};
+
+// So that pot_quantile_prob can be automatically substituted
+// with weighted_pot_quantile_prob when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::pot_quantile_prob<LeftRight> >
+{
+ typedef tag::weighted_pot_quantile_prob<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::weighted_pot_quantile_prob<LeftRight> >
+ : feature_of<tag::pot_quantile_prob<LeftRight> >
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/pot_tail_mean.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/pot_tail_mean.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,211 @@
+///////////////////////////////////////////////////////////////////////////////
+// pot_tail_mean.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_POT_TAIL_MEAN_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_POT_TAIL_MEAN_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <numeric>
+#include <functional>
+#include <boost/range.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/peaks_over_threshold.hpp>
+#include <boost/accumulators/statistics/weighted_peaks_over_threshold.hpp>
+#include <boost/accumulators/statistics/pot_quantile.hpp>
+#include <boost/accumulators/statistics/tail_mean.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // pot_tail_mean_impl
+ //
+ /**
+ @brief Estimation of the (coherent) tail mean based on the peaks over threshold method (for both left and right tails)
+
+ Computes an estimate for the (coherent) tail mean
+ \f[
+ \widehat{CTM}_{\alpha} = \hat{q}_{\alpha} - \frac{\bar{\beta}}{\xi-1}(1-\alpha)^{-\xi},
+ \f]
+ where \f$\bar[u]\f$, \f$\bar{\beta}\f$ and \f$\xi\f$ are the parameters of the
+ generalized Pareto distribution that approximates the right tail of the distribution (or the
+ mirrored left tail, in case the left tail is used). In the latter case, the result is mirrored
+ back, yielding the correct result.
+ */
+ template<typename Sample, typename Impl, typename LeftRight>
+ struct pot_tail_mean_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ pot_tail_mean_impl(dont_care)
+ : sign_((is_same<LeftRight, left>::value) ? -1 : 1)
+ {
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ typedef
+ typename mpl::if_<
+ is_same<Impl, weighted>
+ , tag::weighted_peaks_over_threshold<LeftRight>
+ , tag::peaks_over_threshold<LeftRight>
+ >::type
+ peaks_over_threshold_tag;
+
+ typedef
+ typename mpl::if_<
+ is_same<Impl, weighted>
+ , tag::weighted_pot_quantile<LeftRight>
+ , tag::pot_quantile<LeftRight>
+ >::type
+ pot_quantile_tag;
+
+ extractor<peaks_over_threshold_tag> const some_peaks_over_threshold = {};
+ extractor<pot_quantile_tag> const some_pot_quantile = {};
+
+ float_type beta_bar = some_peaks_over_threshold(args).template get<1>();
+ float_type xi_hat = some_peaks_over_threshold(args).template get<2>();
+
+ return some_pot_quantile(args) - this->sign_ * beta_bar/( xi_hat - 1. ) * std::pow(
+ is_same<LeftRight, left>::value ? args[quantile_probability] : 1. - args[quantile_probability]
+ , -xi_hat);
+ }
+ private:
+ short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result
+ };
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::pot_tail_mean
+// tag::pot_tail_mean_prob
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct pot_tail_mean
+ : depends_on<peaks_over_threshold<LeftRight>, pot_quantile<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, unweighted, LeftRight> impl;
+ };
+ template<typename LeftRight>
+ struct pot_tail_mean_prob
+ : depends_on<peaks_over_threshold_prob<LeftRight>, pot_quantile_prob<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, unweighted, LeftRight> impl;
+ };
+ template<typename LeftRight>
+ struct weighted_pot_tail_mean
+ : depends_on<weighted_peaks_over_threshold<LeftRight>, weighted_pot_quantile<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, weighted, LeftRight> impl;
+ };
+ template<typename LeftRight>
+ struct weighted_pot_tail_mean_prob
+ : depends_on<weighted_peaks_over_threshold_prob<LeftRight>, weighted_pot_quantile_prob<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, weighted, LeftRight> impl;
+ };
+}
+
+// pot_tail_mean<LeftRight>(with_threshold_value) -> pot_tail_mean<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::pot_tail_mean<LeftRight>(with_threshold_value)>
+{
+ typedef tag::pot_tail_mean<LeftRight> type;
+};
+
+// pot_tail_mean<LeftRight>(with_threshold_probability) -> pot_tail_mean_prob<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::pot_tail_mean<LeftRight>(with_threshold_probability)>
+{
+ typedef tag::pot_tail_mean_prob<LeftRight> type;
+};
+
+// weighted_pot_tail_mean<LeftRight>(with_threshold_value) -> weighted_pot_tail_mean<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::weighted_pot_tail_mean<LeftRight>(with_threshold_value)>
+{
+ typedef tag::weighted_pot_tail_mean<LeftRight> type;
+};
+
+// weighted_pot_tail_mean<LeftRight>(with_threshold_probability) -> weighted_pot_tail_mean_prob<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::weighted_pot_tail_mean<LeftRight>(with_threshold_probability)>
+{
+ typedef tag::weighted_pot_tail_mean_prob<LeftRight> type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// pot_tail_mean<LeftRight> and pot_tail_mean_prob<LeftRight> provide
+// the same feature as tail_mean
+template<typename LeftRight>
+struct feature_of<tag::pot_tail_mean<LeftRight> >
+ : feature_of<tag::tail_mean>
+{
+};
+
+template<typename LeftRight>
+struct feature_of<tag::pot_tail_mean_prob<LeftRight> >
+ : feature_of<tag::tail_mean>
+{
+};
+
+// So that pot_tail_mean can be automatically substituted
+// with weighted_pot_tail_mean when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::pot_tail_mean<LeftRight> >
+{
+ typedef tag::weighted_pot_tail_mean<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::weighted_pot_tail_mean<LeftRight> >
+ : feature_of<tag::pot_tail_mean<LeftRight> >
+{
+};
+
+// So that pot_tail_mean_prob can be automatically substituted
+// with weighted_pot_tail_mean_prob when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::pot_tail_mean_prob<LeftRight> >
+{
+ typedef tag::weighted_pot_tail_mean_prob<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::weighted_pot_tail_mean_prob<LeftRight> >
+ : feature_of<tag::pot_tail_mean_prob<LeftRight> >
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/skewness.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/skewness.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,112 @@
+///////////////////////////////////////////////////////////////////////////////
+// skewness.hpp
+//
+// Copyright 2006 Olivier Gygi, Daniel Egloff. 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_SKEWNESS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_HPP_EAN_28_10_2005
+
+#include <limits>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/moment.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // skewness_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:
+
+ \f[
+ \hat{g}_1 =
+ \frac
+ {\widehat{m}_n^{(3)}-3\widehat{m}_n^{(2)}\hat{\mu}_n+2\hat{\mu}_n^3}
+ {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^{3/2}}
+ \f]
+
+ where \f$ \widehat{m}_n^{(i)} \f$ are the \f$ i \f$-th moment and \f$ \hat{\mu}_n \f$ the mean (first moment) of the
+ \f$ n \f$ samples.
+ */
+ template<typename Sample>
+ struct skewness_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, Sample>::result_type result_type;
+
+ skewness_impl(dont_care)
+ {
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return numeric::average(
+ moment<3>(args)
+ - 3. * moment<2>(args) * mean(args)
+ + 2. * mean(args) * mean(args) * mean(args)
+ , ( moment<2>(args) - mean(args) * mean(args) )
+ * std::sqrt( moment<2>(args) - mean(args) * mean(args) )
+ );
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::skewness
+//
+namespace tag
+{
+ struct skewness
+ : depends_on<mean, moment<2>, moment<3> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::skewness_impl<mpl::_1> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::skewness
+//
+namespace extract
+{
+ extractor<tag::skewness> const skewness = {};
+}
+
+using extract::skewness;
+
+// So that skewness can be automatically substituted with
+// weighted_skewness when the weight parameter is non-void
+template<>
+struct as_weighted_feature<tag::skewness>
+{
+ typedef tag::weighted_skewness type;
+};
+
+template<>
+struct feature_of<tag::weighted_skewness>
+ : feature_of<tag::skewness>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/stats.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/stats.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,29 @@
+///////////////////////////////////////////////////////////////////////////////
+/// \file stats.hpp
+/// Contains the stats<> template.
+///
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_28_10_2005
+
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+namespace boost { namespace accumulators
+{
+
+///////////////////////////////////////////////////////////////////////////////
+/// An MPL sequence of statistics.
+template<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, typename Stat)>
+struct stats
+ : mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Stat)>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/sum.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/sum.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,137 @@
+///////////////////////////////////////////////////////////////////////////////
+// sum.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
+
+#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/parameters/weight.hpp>
+#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // sum_impl
+ template<typename Sample, typename Tag>
+ struct sum_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef Sample result_type;
+
+ template<typename Args>
+ sum_impl(Args const &args)
+ : sum(args[parameter::keyword<Tag>::get() | Sample()])
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ // what about overflow?
+ this->sum += args[parameter::keyword<Tag>::get()];
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->sum;
+ }
+
+ private:
+
+ Sample sum;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::sum
+// tag::sum_of_weights
+// tag::sum_of_variates
+//
+namespace tag
+{
+ struct sum
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::sum_impl<mpl::_1, tag::sample> impl;
+ };
+
+ struct sum_of_weights
+ : depends_on<>
+ {
+ typedef mpl::true_ is_weight_accumulator;
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::sum_impl<mpl::_2, tag::weight> impl;
+ };
+
+ template<typename VariateType, typename VariateTag>
+ struct sum_of_variates
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef mpl::always<accumulators::impl::sum_impl<VariateType, VariateTag> > impl;
+ };
+
+ struct abstract_sum_of_variates
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::sum
+// extract::sum_of_weights
+// extract::sum_of_variates
+//
+namespace extract
+{
+ extractor<tag::sum> const sum = {};
+ extractor<tag::sum_of_weights> const sum_of_weights = {};
+ extractor<tag::abstract_sum_of_variates> const sum_of_variates = {};
+}
+
+using extract::sum;
+using extract::sum_of_weights;
+using extract::sum_of_variates;
+
+// So that mean can be automatically substituted with
+// weighted_mean when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::sum>
+{
+ typedef tag::weighted_sum type;
+};
+
+template<>
+struct feature_of<tag::weighted_sum>
+ : feature_of<tag::sum>
+{};
+
+template<typename VariateType, typename VariateTag>
+struct feature_of<tag::sum_of_variates<VariateType, VariateTag> >
+ : feature_of<tag::abstract_sum_of_variates>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/tail.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/tail.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,330 @@
+///////////////////////////////////////////////////////////////////////////////
+// tail.hpp
+//
+// Copyright 2005 Eric Niebler, Michael Gauckler. 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_TAIL_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_HPP_EAN_28_10_2005
+
+#include <vector>
+#include <functional>
+#include <boost/range.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/or.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/iterator/reverse_iterator.hpp>
+#include <boost/iterator/permutation_iterator.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>
+
+namespace boost { namespace accumulators
+{
+///////////////////////////////////////////////////////////////////////////////
+// cache_size named parameters
+BOOST_PARAMETER_NESTED_KEYWORD(tag, right_tail_cache_size, cache_size)
+BOOST_PARAMETER_NESTED_KEYWORD(tag, left_tail_cache_size, cache_size)
+
+namespace detail
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // tail_range
+ /// INTERNAL ONLY
+ ///
+ template<typename ElementIterator, typename IndexIterator>
+ struct tail_range
+ {
+ typedef boost::iterator_range<
+ boost::reverse_iterator<boost::permutation_iterator<ElementIterator, IndexIterator> >
+ > type;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // make_tail_range
+ /// INTERNAL ONLY
+ ///
+ template<typename ElementIterator, typename IndexIterator>
+ typename tail_range<ElementIterator, IndexIterator>::type
+ make_tail_range(ElementIterator elem_begin, IndexIterator index_begin, IndexIterator index_end)
+ {
+ return boost::make_iterator_range(
+ boost::make_reverse_iterator(
+ boost::make_permutation_iterator(elem_begin, index_end)
+ )
+ , boost::make_reverse_iterator(
+ boost::make_permutation_iterator(elem_begin, index_begin)
+ )
+ );
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // stat_assign_visitor
+ /// INTERNAL ONLY
+ ///
+ template<typename Args>
+ struct stat_assign_visitor
+ {
+ stat_assign_visitor(Args const &args, std::size_t index)
+ : args(args)
+ , index(index)
+ {
+ }
+
+ template<typename Stat>
+ void operator ()(Stat &stat) const
+ {
+ stat.assign(this->args, this->index);
+ }
+
+ private:
+ stat_assign_visitor &operator =(stat_assign_visitor const &);
+ Args const &args;
+ std::size_t index;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // stat_assign
+ /// INTERNAL ONLY
+ ///
+ template<typename Args>
+ inline stat_assign_visitor<Args> const stat_assign(Args const &args, std::size_t index)
+ {
+ return stat_assign_visitor<Args>(args, index);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // is_tail_variate_feature
+ /// INTERNAL ONLY
+ ///
+ template<typename Stat, typename LeftRight>
+ struct is_tail_variate_feature
+ : mpl::false_
+ {
+ };
+
+ /// INTERNAL ONLY
+ ///
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct is_tail_variate_feature<tag::tail_variate<VariateType, VariateTag, LeftRight>, LeftRight>
+ : mpl::true_
+ {
+ };
+
+ /// INTERNAL ONLY
+ ///
+ template<typename LeftRight>
+ struct is_tail_variate_feature<tag::tail_weights<LeftRight>, LeftRight>
+ : mpl::true_
+ {
+ };
+
+} // namespace detail
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // tail_impl
+ template<typename Sample, typename LeftRight>
+ struct tail_impl
+ : accumulator_base
+ {
+ // LeftRight must be either right or left
+ BOOST_MPL_ASSERT((
+ mpl::or_<is_same<LeftRight, right>, is_same<LeftRight, left> >
+ ));
+
+ typedef
+ typename mpl::if_<
+ is_same<LeftRight, right>
+ , numeric::functional::greater<Sample const, Sample const>
+ , numeric::functional::less<Sample const, Sample const>
+ >::type
+ predicate_type;
+
+ // for boost::result_of
+ typedef typename detail::tail_range<
+ typename std::vector<Sample>::const_iterator
+ , std::vector<std::size_t>::iterator
+ >::type result_type;
+
+ template<typename Args>
+ tail_impl(Args const &args)
+ : is_sorted(false)
+ , indices()
+ , samples(args[tag::tail<LeftRight>::cache_size], args[sample | Sample()])
+ {
+ this->indices.reserve(this->samples.size());
+ }
+
+ tail_impl(tail_impl const &that)
+ : is_sorted(that.is_sorted)
+ , indices(that.indices)
+ , samples(that.samples)
+ {
+ this->indices.reserve(that.indices.capacity());
+ }
+
+ // This just stores the heap and the samples.
+ // In operator()() below, if we are adding a new sample
+ // to the sample cache, we force all the
+ // tail_variates to update also. (It's not
+ // good enough to wait for the accumulator_set to do it
+ // for us because then information about whether a sample
+ // was stored and where is lost, and would need to be
+ // queried at runtime, which would be slow.) This is
+ // implemented as a filtered visitation over the stats,
+ // which we can access because args[accumulator] gives us
+ // all the stats.
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ if(this->indices.size() < this->indices.capacity())
+ {
+ this->indices.push_back(this->indices.size());
+ this->assign(args, this->indices.back());
+ }
+ else if(predicate_type()(args[sample], this->samples[this->indices[0]]))
+ {
+ std::pop_heap(this->indices.begin(), this->indices.end(), indirect_cmp(this->samples));
+ this->assign(args, this->indices.back());
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ if(!this->is_sorted)
+ {
+ // Must use the same predicate here as in push_heap/pop_heap above.
+ std::sort_heap(this->indices.begin(), this->indices.end(), indirect_cmp(this->samples));
+ // sort_heap puts elements in reverse order. Calling std::reverse
+ // turns the sorted sequence back into a valid heap.
+ std::reverse(this->indices.begin(), this->indices.end());
+ this->is_sorted = true;
+ }
+
+ return detail::make_tail_range(
+ this->samples.begin()
+ , this->indices.begin()
+ , this->indices.end()
+ );
+ }
+
+ private:
+
+ struct is_tail_variate
+ {
+ template<typename T>
+ struct apply
+ : detail::is_tail_variate_feature<
+ typename detail::feature_tag<T>::type
+ , LeftRight
+ >
+ {};
+ };
+
+ template<typename Args>
+ void assign(Args const &args, std::size_t index)
+ {
+ this->samples[index] = args[sample];
+ std::push_heap(this->indices.begin(), this->indices.end(), indirect_cmp(this->samples));
+ this->is_sorted = false;
+ // Tell the tail variates to store their values also
+ args[accumulator].template visit_if<is_tail_variate>(detail::stat_assign(args, index));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ //
+ struct indirect_cmp
+ : std::binary_function<std::size_t, std::size_t, bool>
+ {
+ indirect_cmp(std::vector<Sample> const &samples)
+ : samples(samples)
+ {
+ }
+
+ bool operator ()(std::size_t left, std::size_t right) const
+ {
+ return predicate_type()(this->samples[left], this->samples[right]);
+ }
+
+ private:
+ indirect_cmp &operator =(indirect_cmp const &);
+ std::vector<Sample> const &samples;
+ };
+
+ mutable bool is_sorted;
+ mutable std::vector<std::size_t> indices;
+ std::vector<Sample> samples;
+ };
+
+} // namespace impl
+
+// TODO The templatized tag::tail below should inherit from the correct named parameter.
+// The following lines provide a workaround, but there must be a better way of doing this.
+template<typename T>
+struct tail_cache_size_named_arg
+{
+};
+template<>
+struct tail_cache_size_named_arg<left>
+ : tag::left_tail_cache_size
+{
+};
+template<>
+struct tail_cache_size_named_arg<right>
+ : tag::right_tail_cache_size
+{
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::tail<>
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct tail
+ : depends_on<>
+ , tail_cache_size_named_arg<LeftRight>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::tail_impl<mpl::_1, LeftRight> impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::tail<LeftRight>::cache_size named parameter
+ static boost::parameter::keyword<tail_cache_size_named_arg<LeftRight> > const cache_size;
+ #endif
+ };
+
+ struct abstract_tail
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::tail
+//
+namespace extract
+{
+ extractor<tag::abstract_tail> const tail = {};
+}
+
+using extract::tail;
+
+template<typename LeftRight>
+struct feature_of<tag::tail<LeftRight> >
+ : feature_of<tag::abstract_tail>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/tail_mean.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/tail_mean.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,243 @@
+///////////////////////////////////////////////////////////////////////////////
+// tail_mean.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_TAIL_MEAN_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_MEAN_HPP_DE_01_01_2006
+
+#include <numeric>
+#include <vector>
+#include <limits>
+#include <functional>
+#include <sstream>
+#include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/tail_quantile.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // coherent_tail_mean_impl
+ //
+ /**
+ @brief Estimation of the coherent tail mean based on order statistics (for both left and right tails)
+
+ The coherent tail mean \f$\widehat{CTM}_{n,\alpha}(X)\f$ is equal to the non-coherent tail mean \f$\widehat{NCTM}_{n,\alpha}(X)\f$
+ plus a correction term that ensures coherence in case of non-continuous distributions.
+
+ \f[
+ \widehat{CTM}_{n,\alpha}^{\mathrm{right}}(X) = \widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X) +
+ \frac{1}{\lceil n(1-\alpha)\rceil}\hat{q}_{n,\alpha}(X)\left(1 - \alpha - \frac{1}{n}\lceil n(1-\alpha)\rceil \right)
+ \f]
+
+ \f[
+ \widehat{CTM}_{n,\alpha}^{\mathrm{left}}(X) = \widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X) +
+ \frac{1}{\lceil n\alpha\rceil}\hat{q}_{n,\alpha}(X)\left(\alpha - \frac{1}{n}\lceil n\alpha\rceil \right)
+ \f]
+ */
+ template<typename Sample, typename LeftRight>
+ struct coherent_tail_mean_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ coherent_tail_mean_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ std::size_t cnt = count(args);
+
+ std::size_t n = static_cast<std::size_t>(
+ std::ceil(
+ cnt * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] )
+ )
+ );
+
+ 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)
+ * (
+ ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability]
+ - numeric::average(n, count(args))
+ );
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // non_coherent_tail_mean_impl
+ //
+ /**
+ @brief Estimation of the (non-coherent) tail mean based on order statistics (for both left and right tails)
+
+ An estimation of the non-coherent tail mean \f$\widehat{NCTM}_{n,\alpha}(X)\f$ is given by the mean of the
+ \f$\lceil n\alpha\rceil\f$ smallest samples (left tail) or the mean of the \f$\lceil n(1-\alpha)\rceil\f$
+ largest samples (right tail), \f$n\f$ being the total number of samples and \f$\alpha\f$ the quantile level:
+
+ \f[
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X) = \frac{1}{\lceil n(1-\alpha)\rceil} \sum_{i=\lceil \alpha n \rceil}^n X_{i:n}
+ \f]
+
+ \f[
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X) = \frac{1}{\lceil n\alpha\rceil} \sum_{i=1}^{\lceil \alpha n \rceil} X_{i:n}
+ \f]
+
+ It thus requires the caching of at least the \f$\lceil n\alpha\rceil\f$ smallest or the \f$\lceil n(1-\alpha)\rceil\f$
+ largest samples.
+
+ @param quantile_probability
+ */
+ template<typename Sample, typename LeftRight>
+ struct non_coherent_tail_mean_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type float_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ non_coherent_tail_mean_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ std::size_t cnt = count(args);
+
+ std::size_t n = static_cast<std::size_t>(
+ std::ceil(
+ cnt * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] )
+ )
+ );
+
+ // 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(
+ std::accumulate(
+ tail(args).begin()
+ , tail(args).begin() + n
+ , Sample(0)
+ )
+ , n
+ );
+ else
+ {
+ if (std::numeric_limits<result_type>::has_quiet_NaN)
+ {
+ return std::numeric_limits<result_type>::quiet_NaN();
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ return Sample(0);
+ }
+ }
+ }
+ };
+
+} // namespace impl
+
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::coherent_tail_mean<>
+// tag::non_coherent_tail_mean<>
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct coherent_tail_mean
+ : depends_on<count, quantile, non_coherent_tail_mean<LeftRight> >
+ {
+ typedef accumulators::impl::coherent_tail_mean_impl<mpl::_1, LeftRight> impl;
+ };
+
+ template<typename LeftRight>
+ struct non_coherent_tail_mean
+ : depends_on<count, tail<LeftRight> >
+ {
+ typedef accumulators::impl::non_coherent_tail_mean_impl<mpl::_1, LeftRight> impl;
+ };
+
+ struct abstract_non_coherent_tail_mean
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::non_coherent_tail_mean;
+// extract::coherent_tail_mean;
+//
+namespace extract
+{
+ extractor<tag::abstract_non_coherent_tail_mean> const non_coherent_tail_mean = {};
+ extractor<tag::tail_mean> const coherent_tail_mean = {};
+}
+
+using extract::non_coherent_tail_mean;
+using extract::coherent_tail_mean;
+
+// for the purposes of feature-based dependency resolution,
+// coherent_tail_mean<LeftRight> provides the same feature as tail_mean
+template<typename LeftRight>
+struct feature_of<tag::coherent_tail_mean<LeftRight> >
+ : feature_of<tag::tail_mean>
+{
+};
+
+template<typename LeftRight>
+struct feature_of<tag::non_coherent_tail_mean<LeftRight> >
+ : feature_of<tag::abstract_non_coherent_tail_mean>
+{
+};
+
+// So that non_coherent_tail_mean can be automatically substituted
+// with weighted_non_coherent_tail_mean when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::non_coherent_tail_mean<LeftRight> >
+{
+ typedef tag::non_coherent_weighted_tail_mean<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::non_coherent_weighted_tail_mean<LeftRight> >
+ : feature_of<tag::non_coherent_tail_mean<LeftRight> >
+{};
+
+// NOTE that non_coherent_tail_mean cannot be feature-grouped with tail_mean,
+// which is the base feature for coherent tail means, since (at least for
+// non-continuous distributions) non_coherent_tail_mean is a different measure!
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/tail_quantile.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/tail_quantile.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,156 @@
+///////////////////////////////////////////////////////////////////////////////
+// tail_quantile.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_TAIL_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_QUANTILE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <functional>
+#include <sstream>
+#include <stdexcept>
+#include <cmath> // For ceil
+#include <boost/throw_exception.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/accumulators/framework/depends_on.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // tail_quantile_impl
+ // Tail quantile estimation based on order statistics
+ /**
+ @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,
+ \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:
+
+ \f[
+ \hat{q}_{n,\alpha} = X_{\lceil \alpha n \rceil:n}
+ \f]
+
+ @param quantile_probability
+ */
+ template<typename Sample, typename LeftRight>
+ struct tail_quantile_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef Sample result_type;
+
+ tail_quantile_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ std::size_t cnt = count(args);
+
+ std::size_t n = static_cast<std::size_t>(
+ std::ceil(
+ cnt * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] )
+ )
+ );
+
+ // 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()))
+ {
+ // Note that the cached samples of the left are sorted in ascending order,
+ // whereas the samples of the right tail are sorted in descending order
+ return *(boost::begin(tail(args)) + n - 1);
+ }
+ else
+ {
+ if (std::numeric_limits<result_type>::has_quiet_NaN)
+ {
+ return std::numeric_limits<result_type>::quiet_NaN();
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ return Sample(0);
+ }
+ }
+ }
+ };
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::tail_quantile<>
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct tail_quantile
+ : depends_on<count, tail<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::tail_quantile_impl<mpl::_1, LeftRight> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::tail_quantile
+//
+namespace extract
+{
+ extractor<tag::quantile> const tail_quantile = {};
+}
+
+using extract::tail_quantile;
+
+// for the purposes of feature-based dependency resolution,
+// tail_quantile<LeftRight> provide the same feature as quantile
+template<typename LeftRight>
+struct feature_of<tag::tail_quantile<LeftRight> >
+ : feature_of<tag::quantile>
+{
+};
+
+// So that tail_quantile can be automatically substituted with
+// weighted_tail_quantile when the weight parameter is non-void.
+template<typename LeftRight>
+struct as_weighted_feature<tag::tail_quantile<LeftRight> >
+{
+ typedef tag::weighted_tail_quantile<LeftRight> type;
+};
+
+template<typename LeftRight>
+struct feature_of<tag::weighted_tail_quantile<LeftRight> >
+ : feature_of<tag::tail_quantile<LeftRight> >
+{};
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/tail_variate.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/tail_variate.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,138 @@
+///////////////////////////////////////////////////////////////////////////////
+// tail_variate.hpp
+//
+// Copyright 2005 Eric Niebler, Michael Gauckler. 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_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
+#define BOOST_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
+
+#include <boost/range.hpp>
+#include <boost/mpl/always.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/iterator/reverse_iterator.hpp>
+#include <boost/iterator/permutation_iterator.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // tail_variate_impl
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct tail_variate_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef
+ typename detail::tail_range<
+ typename std::vector<VariateType>::const_iterator
+ , std::vector<std::size_t>::iterator
+ >::type
+ result_type;
+
+ template<typename Args>
+ tail_variate_impl(Args const &args)
+ : variates(args[tag::tail<LeftRight>::cache_size], args[parameter::keyword<VariateTag>::get() | VariateType()])
+ {
+ }
+
+ template<typename Args>
+ void assign(Args const &args, std::size_t index)
+ {
+ this->variates[index] = args[parameter::keyword<VariateTag>::get()];
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ // getting the order result causes the indices vector to be sorted.
+ extractor<tag::tail<LeftRight> > const some_tail = {};
+ return this->do_result(some_tail(args));
+ }
+
+ private:
+ template<typename TailRng>
+ result_type do_result(TailRng const &rng) const
+ {
+ return detail::make_tail_range(
+ this->variates.begin()
+ , rng.end().base().base() // the index iterator
+ , rng.begin().base().base() // (begin and end reversed because these are reverse iterators)
+ );
+ }
+
+ std::vector<VariateType> variates;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::tail_variate<>
+//
+namespace tag
+{
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct tail_variate
+ : depends_on<tail<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef mpl::always<accumulators::impl::tail_variate_impl<VariateType, VariateTag, LeftRight> > impl;
+ };
+
+ struct abstract_tail_variate
+ : depends_on<>
+ {
+ };
+
+ template<typename LeftRight>
+ struct tail_weights
+ : depends_on<tail<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::tail_variate_impl<mpl::_2, tag::weight, LeftRight> impl;
+ };
+
+ struct abstract_tail_weights
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::tail_variate
+// extract::tail_weights
+//
+namespace extract
+{
+ extractor<tag::abstract_tail_variate> const tail_variate = {};
+ extractor<tag::abstract_tail_weights> const tail_weights = {};
+}
+
+using extract::tail_variate;
+using extract::tail_weights;
+
+template<typename VariateType, typename VariateTag, typename LeftRight>
+struct feature_of<tag::tail_variate<VariateType, VariateTag, LeftRight> >
+ : feature_of<tag::abstract_tail_variate>
+{
+};
+
+template<typename LeftRight>
+struct feature_of<tag::tail_weights<LeftRight> >
+{
+ typedef tag::abstract_tail_weights type;
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/tail_variate_means.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/tail_variate_means.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,255 @@
+///////////////////////////////////////////////////////////////////////////////
+// tail_variate_means.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_TAIL_VARIATE_MEANS_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_VARIATE_MEANS_HPP_DE_01_01_2006
+
+#include <numeric>
+#include <vector>
+#include <limits>
+#include <functional>
+#include <sstream>
+#include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/tail_variate.hpp>
+#include <boost/accumulators/statistics/tail_mean.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ /**
+ @brief Estimation of the absolute and relative tail variate means (for both left and right tails)
+
+ For all \f$j\f$-th variates associated to the \f$\lceil n(1-\alpha)\rceil\f$ largest samples (or the
+ \f$\lceil n(1-\alpha)\rceil\f$ smallest samples in case of the left tail), the absolute tail means
+ \f$\widehat{ATM}_{n,\alpha}(X, j)\f$ are computed and returned as an iterator range. Alternatively,
+ the relative tail means \f$\widehat{RTM}_{n,\alpha}(X, j)\f$ are returned, which are the absolute
+ tail means normalized with the (non-coherent) sample tail mean \f$\widehat{NCTM}_{n,\alpha}(X)\f$.
+
+ \f[
+ \widehat{ATM}_{n,\alpha}^{\mathrm{right}}(X, j) =
+ \frac{1}{\lceil n(1-\alpha) \rceil}
+ \sum_{i=\lceil \alpha n \rceil}^n \xi_{j,i}
+ \f]
+
+ \f[
+ \widehat{ATM}_{n,\alpha}^{\mathrm{left}}(X, j) =
+ \frac{1}{\lceil n\alpha \rceil}
+ \sum_{i=1}^{\lceil n\alpha \rceil} \xi_{j,i}
+ \f]
+
+ \f[
+ \widehat{RTM}_{n,\alpha}^{\mathrm{right}}(X, j) =
+ \frac{\sum_{i=\lceil n\alpha \rceil}^n \xi_{j,i}}
+ {\lceil n(1-\alpha)\rceil\widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X)}
+ \f]
+
+ \f[
+ \widehat{RTM}_{n,\alpha}^{\mathrm{left}}(X, j) =
+ \frac{\sum_{i=1}^{\lceil n\alpha \rceil} \xi_{j,i}}
+ {\lceil n\alpha\rceil\widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X)}
+ \f]
+ */
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // tail_variate_means_impl
+ // by default: absolute tail_variate_means
+ template<typename Sample, typename Impl, typename LeftRight, typename VariateTag>
+ struct tail_variate_means_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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;
+
+ tail_variate_means_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ std::size_t cnt = count(args);
+
+ std::size_t n = static_cast<std::size_t>(
+ std::ceil(
+ cnt * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] )
+ )
+ );
+
+ std::size_t num_variates = tail_variate(args).begin()->size();
+
+ this->tail_means_.clear();
+ this->tail_means_.resize(num_variates, Sample(0));
+
+ // 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()))
+ {
+ this->tail_means_ = std::accumulate(
+ tail_variate(args).begin()
+ , tail_variate(args).begin() + n
+ , this->tail_means_
+ , numeric::plus
+ );
+
+ float_type factor = n * ( (is_same<Impl, relative>::value) ? non_coherent_tail_mean(args) : 1. );
+
+ std::transform(
+ this->tail_means_.begin()
+ , this->tail_means_.end()
+ , this->tail_means_.begin()
+ , std::bind2nd(std::divides<float_type>(), factor)
+ );
+ }
+ else
+ {
+ if (std::numeric_limits<float_type>::has_quiet_NaN)
+ {
+ std::fill(
+ this->tail_means_.begin()
+ , this->tail_means_.end()
+ , std::numeric_limits<float_type>::quiet_NaN()
+ );
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ }
+ }
+ return make_iterator_range(this->tail_means_);
+ }
+
+ private:
+
+ mutable array_type tail_means_;
+
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::absolute_tail_variate_means
+// tag::relative_tail_variate_means
+//
+namespace tag
+{
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct absolute_tail_variate_means
+ : depends_on<count, non_coherent_tail_mean<LeftRight>, tail_variate<VariateType, VariateTag, LeftRight> >
+ {
+ typedef accumulators::impl::tail_variate_means_impl<mpl::_1, absolute, LeftRight, VariateTag> impl;
+ };
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct relative_tail_variate_means
+ : depends_on<count, non_coherent_tail_mean<LeftRight>, tail_variate<VariateType, VariateTag, LeftRight> >
+ {
+ typedef accumulators::impl::tail_variate_means_impl<mpl::_1, relative, LeftRight, VariateTag> impl;
+ };
+ struct abstract_absolute_tail_variate_means
+ : depends_on<>
+ {
+ };
+ struct abstract_relative_tail_variate_means
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::tail_variate_means
+// extract::relative_tail_variate_means
+//
+namespace extract
+{
+ extractor<tag::abstract_absolute_tail_variate_means> const tail_variate_means = {};
+ extractor<tag::abstract_relative_tail_variate_means> const relative_tail_variate_means = {};
+}
+
+using extract::tail_variate_means;
+using extract::relative_tail_variate_means;
+
+// tail_variate_means<LeftRight, VariateType, VariateTag>(absolute) -> absolute_tail_variate_means<LeftRight, VariateType, VariateTag>
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct as_feature<tag::tail_variate_means<LeftRight, VariateType, VariateTag>(absolute)>
+{
+ typedef tag::absolute_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+};
+
+// tail_variate_means<LeftRight, VariateType, VariateTag>(relative) ->relative_tail_variate_means<LeftRight, VariateType, VariateTag>
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct as_feature<tag::tail_variate_means<LeftRight, VariateType, VariateTag>(relative)>
+{
+ typedef tag::relative_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+};
+
+// Provides non-templatized extractor
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct feature_of<tag::absolute_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ : feature_of<tag::abstract_absolute_tail_variate_means>
+{
+};
+
+// Provides non-templatized extractor
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct feature_of<tag::relative_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ : feature_of<tag::abstract_relative_tail_variate_means>
+{
+};
+
+// So that absolute_tail_means can be automatically substituted
+// with absolute_weighted_tail_means when the weight parameter is non-void.
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct as_weighted_feature<tag::absolute_tail_variate_means<LeftRight, VariateType, VariateTag> >
+{
+ typedef tag::absolute_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+};
+
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct feature_of<tag::absolute_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ : feature_of<tag::absolute_tail_variate_means<LeftRight, VariateType, VariateTag> >
+{
+};
+
+// So that relative_tail_means can be automatically substituted
+// with relative_weighted_tail_means when the weight parameter is non-void.
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct as_weighted_feature<tag::relative_tail_variate_means<LeftRight, VariateType, VariateTag> >
+{
+ typedef tag::relative_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+};
+
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct feature_of<tag::relative_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ : feature_of<tag::relative_tail_variate_means<LeftRight, VariateType, VariateTag> >
+{
+};
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/times2_iterator.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/times2_iterator.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// times2_iterator.hpp
+//
+// Copyright 2006 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_TIMES2_ITERATOR_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TIMES2_ITERATOR_HPP_DE_01_01_2006
+
+#include <functional>
+#include <boost/range/begin.hpp>
+#include <boost/range/end.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/iterator/counting_iterator.hpp>
+#include <boost/iterator/permutation_iterator.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace detail
+{
+ typedef transform_iterator<
+ std::binder1st<std::multiplies<std::size_t> >
+ , counting_iterator<std::size_t>
+ > times2_iterator;
+
+ inline times2_iterator make_times2_iterator(std::size_t i)
+ {
+ return make_transform_iterator(
+ make_counting_iterator(i)
+ , std::bind1st(std::multiplies<std::size_t>(), 2)
+ );
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // lvalue_index_iterator
+ template<typename Base>
+ struct lvalue_index_iterator
+ : Base
+ {
+ lvalue_index_iterator(Base base)
+ : Base(base)
+ {
+ }
+
+ typename Base::reference operator [](typename Base::difference_type n) const
+ {
+ return *(*this + n);
+ }
+ };
+} // namespace detail
+
+}}
+
+#endif
Added: branches/release/boost/accumulators/statistics/variance.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/variance.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,232 @@
+///////////////////////////////////////////////////////////////////////////////
+// variance.hpp
+//
+// Copyright 2005 Daniel Egloff, 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_VARIANCE_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_VARIANCE_HPP_EAN_28_10_2005
+
+#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/count.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/moment.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ //! Lazy calculaation of variance.
+ /*!
+ Default sample variance implementation based on the second moment \f$ M_n^{(2)} \f$ moment<2>, mean and count.
+ \f[
+ \sigma_n^2 = M_n^{(2)} - \mu_n^2.
+ \f]
+ where
+ \f[
+ \mu_n = \frac{1}{n} \sum_{i = 1}^n x_i.
+ \f]
+ is the estimate of the sample mean and \f$n\f$ is the number of samples.
+ */
+ template<typename Sample, typename MeanFeature>
+ struct variance_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ variance_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ extractor<MeanFeature> mean;
+ result_type tmp = mean(args);
+ return moment<2>(args) - tmp * tmp;
+ }
+ };
+
+ //! Iterative calculation of variance.
+ /*!
+ Iterative calculation of sample variance \f$\sigma_n^2\f$ according to the formula
+ \f[
+ \sigma_n^2 = \frac{1}{n} \sum_{i = 1}^n (x_i - \mu_n)^2 = \frac{n-1}{n} \sigma_{n-1}^2 + \frac{1}{n-1}(x_n - \mu_n)^2.
+ \f]
+ where
+ \f[
+ \mu_n = \frac{1}{n} \sum_{i = 1}^n x_i.
+ \f]
+ is the estimate of the sample mean and \f$n\f$ is the number of samples.
+
+ Note that the sample variance is not defined for \f$n <= 1\f$.
+
+ A simplification can be obtained by the approximate recursion
+ \f[
+ \sigma_n^2 \approx \frac{n-1}{n} \sigma_{n-1}^2 + \frac{1}{n}(x_n - \mu_n)^2.
+ \f]
+ because the difference
+ \f[
+ \left(\frac{1}{n-1} - \frac{1}{n}\right)(x_n - \mu_n)^2 = \frac{1}{n(n-1)}(x_n - \mu_n)^2.
+ \f]
+ converges to zero as \f$n \rightarrow \infty\f$. However, for small \f$ n \f$ the difference
+ can be non-negligible.
+ */
+ template<typename Sample, typename MeanFeature, typename Tag>
+ struct immediate_variance_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ template<typename Args>
+ immediate_variance_impl(Args const &args)
+ : variance(numeric::average(args[sample | Sample()], numeric::one<std::size_t>::value))
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+
+ if(cnt > 1)
+ {
+ 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);
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->variance;
+ }
+
+ private:
+ result_type variance;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::variance
+// tag::immediate_variance
+//
+namespace tag
+{
+ struct variance
+ : depends_on<moment<2>, mean>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::variance_impl<mpl::_1, mean> impl;
+ };
+ struct immediate_variance
+ : depends_on<count, immediate_mean>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::immediate_variance_impl<mpl::_1, mean, sample> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::variance
+// extract::immediate_variance
+//
+namespace extract
+{
+ extractor<tag::variance> const variance = {};
+ extractor<tag::immediate_variance> const immediate_variance = {};
+}
+
+using extract::variance;
+using extract::immediate_variance;
+
+// variance(lazy) -> variance
+template<>
+struct as_feature<tag::variance(lazy)>
+{
+ typedef tag::variance type;
+};
+
+// variance(immediate) -> immediate_variance
+template<>
+struct as_feature<tag::variance(immediate)>
+{
+ typedef tag::immediate_variance type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// immediate_variance provides the same feature as variance
+template<>
+struct feature_of<tag::immediate_variance>
+ : feature_of<tag::variance>
+{
+};
+
+// So that variance can be automatically substituted with
+// weighted_variance when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::variance>
+{
+ typedef tag::weighted_variance type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// weighted_variance provides the same feature as variance
+template<>
+struct feature_of<tag::weighted_variance>
+ : feature_of<tag::variance>
+{
+};
+
+// So that immediate_variance can be automatically substituted with
+// immediate_weighted_variance when the weight parameter is non-void.
+template<>
+struct as_weighted_feature<tag::immediate_variance>
+{
+ typedef tag::immediate_weighted_variance type;
+};
+
+// for the purposes of feature-based dependency resolution,
+// immediate_weighted_variance provides the same feature as immediate_variance
+template<>
+struct feature_of<tag::immediate_weighted_variance>
+ : feature_of<tag::immediate_variance>
+{
+};
+
+////////////////////////////////////////////////////////////////////////////
+//// droppable_accumulator<variance_impl>
+//// need to specialize droppable lazy variance to cache the result at the
+//// point the accumulator is dropped.
+///// INTERNAL ONLY
+/////
+//template<typename Sample, typename MeanFeature>
+//struct droppable_accumulator<impl::variance_impl<Sample, MeanFeature> >
+// : droppable_accumulator_base<
+// with_cached_result<impl::variance_impl<Sample, MeanFeature> >
+// >
+//{
+// template<typename Args>
+// droppable_accumulator(Args const &args)
+// : droppable_accumulator::base(args)
+// {
+// }
+//};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/variates/covariate.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/variates/covariate.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,21 @@
+///////////////////////////////////////////////////////////////////////////////
+// weight.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_VARIATES_COVARIATE_HPP_EAN_03_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_VARIATES_COVARIATE_HPP_EAN_03_11_2005
+
+#include <boost/parameter/keyword.hpp>
+
+namespace boost { namespace accumulators
+{
+
+BOOST_PARAMETER_KEYWORD(tag, covariate1)
+BOOST_PARAMETER_KEYWORD(tag, covariate2)
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_covariance.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_covariance.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,131 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_covariance.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_WEIGHTED_COVARIANCE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_COVARIANCE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <numeric>
+#include <functional>
+#include <complex>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/range.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/numeric/ublas/io.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/type_traits/is_scalar.hpp>
+#include <boost/type_traits/is_same.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/covariance.hpp> // for numeric::outer_product() and type traits
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_covariance_impl
+ //
+ /**
+ @brief Weighted Covariance Estimator
+
+ An iterative Monte Carlo estimator for the weighted covariance \f$\mathrm{Cov}(X,X')\f$, where \f$X\f$ is a sample
+ and \f$X'\f$ a variate, is given by:
+
+ \f[
+ \hat{c}_n = \frac{\bar{w}_n-w_n}{\bar{w}_n} \hat{c}_{n-1} + \frac{w_n}{\bar{w}_n-w_n}(X_n - \hat{\mu}_n)(X_n' - \hat{\mu}_n'),
+ \quad n\ge2,\quad\hat{c}_1 = 0,
+ \f]
+
+ \f$\hat{\mu}_n\f$ and \f$\hat{\mu}_n'\f$ being the weighted means of the samples and variates and
+ \f$\bar{w}_n\f$ the sum of the \f$n\f$ first weights \f$w_i\f$.
+ */
+ template<typename Sample, typename Weight, typename VariateType, typename VariateTag>
+ 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;
+ // for boost::result_of
+ typedef typename numeric::functional::outer_product<weighted_sample_type, weighted_variate_type>::result_type result_type;
+
+ template<typename Args>
+ weighted_covariance_impl(Args const &args)
+ : cov_(
+ numeric::outer_product(
+ numeric::average(args[sample | Sample()], (std::size_t)1)
+ * numeric::one<Weight>::value
+ , numeric::average(args[parameter::keyword<VariateTag>::get() | VariateType()], (std::size_t)1)
+ * numeric::one<Weight>::value
+ )
+ )
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+
+ if (cnt > 1)
+ {
+ extractor<tag::weighted_mean_of_variates<VariateType, VariateTag> > const some_weighted_mean_of_variates = {};
+
+ this->cov_ = this->cov_ * (sum_of_weights(args) - args[weight]) / sum_of_weights(args)
+ + numeric::outer_product(
+ some_weighted_mean_of_variates(args) - args[parameter::keyword<VariateTag>::get()]
+ , weighted_mean(args) - args[sample]
+ ) * args[weight] / (sum_of_weights(args) - args[weight]);
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->cov_;
+ }
+
+ private:
+ result_type cov_;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_covariance
+//
+namespace tag
+{
+ template<typename VariateType, typename VariateTag>
+ struct weighted_covariance
+ : depends_on<count, sum_of_weights, weighted_mean, weighted_mean_of_variates<VariateType, VariateTag> >
+ {
+ typedef accumulators::impl::weighted_covariance_impl<mpl::_1, mpl::_2, VariateType, VariateTag> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_covariance
+//
+namespace extract
+{
+ extractor<tag::abstract_covariance> const weighted_covariance = {};
+}
+
+using extract::weighted_covariance;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_density.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_density.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,219 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_density.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_WEIGHTED_DENSITY_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_DENSITY_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <functional>
+#include <boost/range.hpp>
+#include <boost/parameter/keyword.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/density.hpp> // for named parameters density_cache_size and density_num_bins
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_density_impl
+ // density histogram for weighted samples
+ /**
+ @brief Histogram density estimator for weighted samples
+
+ The histogram density estimator returns a histogram of the sample distribution. The positions and sizes of the bins
+ are determined using a specifiable number of cached samples (cache_size). The range between the minimum and the
+ maximum of the cached samples is subdivided into a specifiable number of bins (num_bins) of same size. Additionally,
+ an under- and an overflow bin is added to capture future under- and overflow samples. Once the bins are determined,
+ the cached samples and all subsequent samples are added to the correct bins. At the end, a range of std::pair is
+ returned, where each pair contains the position of the bin (lower bound) and the sum of the weights (normalized with the
+ sum of all weights).
+
+ @param density_cache_size Number of first samples used to determine min and max.
+ @param density_num_bins Number of bins (two additional bins collect under- and overflow samples).
+ */
+ template<typename Sample, typename Weight>
+ struct weighted_density_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef iterator_range<typename histogram_type::iterator> result_type;
+
+ template<typename Args>
+ weighted_density_impl(Args const &args)
+ : cache_size(args[density_cache_size])
+ , cache(cache_size)
+ , num_bins(args[density_num_bins])
+ , samples_in_bin(num_bins + 2, 0.)
+ , bin_positions(num_bins + 2)
+ , 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)
+ )
+ )
+ , is_dirty(true)
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->is_dirty = true;
+
+ std::size_t cnt = count(args);
+
+ // Fill up cache with cache_size first samples
+ if (cnt <= this->cache_size)
+ {
+ this->cache[cnt - 1] = std::make_pair(args[sample], args[weight]);
+ }
+
+ // 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 an overflow bin.
+ // 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);
+
+ // determine bin positions (their lower bounds)
+ for (std::size_t i = 0; i < this->num_bins + 2; ++i)
+ {
+ this->bin_positions[i] = minimum + (i - 1.) * bin_size;
+ }
+
+ for (typename histogram_type::const_iterator iter = this->cache.begin(); iter != this->cache.end(); ++iter)
+ {
+ if (iter->first < this->bin_positions[1])
+ {
+ this->samples_in_bin[0] += iter->second;
+ }
+ else if (iter->first >= this->bin_positions[this->num_bins + 1])
+ {
+ this->samples_in_bin[this->num_bins + 1] += iter->second;
+ }
+ else
+ {
+ typename array_type::iterator it = std::upper_bound(
+ this->bin_positions.begin()
+ , this->bin_positions.end()
+ , iter->first
+ );
+
+ std::size_t d = std::distance(this->bin_positions.begin(), it);
+ this->samples_in_bin[d - 1] += iter->second;
+ }
+ }
+ }
+ // Add each subsequent sample to the correct bin
+ else if (cnt > this->cache_size)
+ {
+ if (args[sample] < this->bin_positions[1])
+ {
+ this->samples_in_bin[0] += args[weight];
+ }
+ else if (args[sample] >= this->bin_positions[this->num_bins + 1])
+ {
+ this->samples_in_bin[this->num_bins + 1] += args[weight];
+ }
+ else
+ {
+ typename array_type::iterator it = std::upper_bound(
+ this->bin_positions.begin()
+ , this->bin_positions.end()
+ , args[sample]
+ );
+
+ std::size_t d = std::distance(this->bin_positions.begin(), it);
+ this->samples_in_bin[d - 1] += args[weight];
+ }
+ }
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ // creates a vector of std::pair where each pair i holds
+ // the values bin_positions[i] (x-axis of histogram) and
+ // samples_in_bin[i] / cnt (y-axis of histogram).
+
+ 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)));
+ }
+ }
+
+ // returns a range of pairs
+ return make_iterator_range(this->histogram);
+ }
+
+ private:
+ std::size_t cache_size; // number of cached samples
+ histogram_type cache; // cache to store the first cache_size samples with their weights as std::pair
+ std::size_t num_bins; // number of bins
+ array_type samples_in_bin; // number of samples in each bin
+ array_type bin_positions; // lower bounds of bins
+ mutable histogram_type histogram; // histogram
+ mutable bool is_dirty;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_density
+//
+namespace tag
+{
+ struct weighted_density
+ : depends_on<count, sum_of_weights, min, max>
+ , density_cache_size
+ , density_num_bins
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_density_impl<mpl::_1, mpl::_2> impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ static boost::parameter::keyword<density_cache_size> const cache_size;
+ static boost::parameter::keyword<density_num_bins> const num_bins;
+ #endif
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_density
+//
+namespace extract
+{
+ extractor<tag::density> const weighted_density = {};
+}
+
+using extract::weighted_density;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_extended_p_square.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_extended_p_square.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,288 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_extended_p_square.hpp
+//
+// Copyright 2005 Daniel Egloff. 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_WEIGHTED_EXTENDED_P_SQUARE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_EXTENDED_P_SQUARE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <functional>
+#include <boost/range/begin.hpp>
+#include <boost/range/end.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/iterator/counting_iterator.hpp>
+#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/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/count.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/times2_iterator.hpp>
+#include <boost/accumulators/statistics/extended_p_square.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_extended_p_square_impl
+ // multiple quantile estimation with weighted samples
+ /**
+ @brief Multiple quantile estimation with the extended \f$P^2\f$ algorithm for weighted samples
+
+ This version of the extended \f$P^2\f$ algorithm extends the extended \f$P^2\f$ algorithm to
+ support weighted samples. The extended \f$P^2\f$ algorithm dynamically estimates several
+ quantiles without storing samples. Assume that \f$m\f$ quantiles
+ \f$\xi_{p_1}, \ldots, \xi_{p_m}\f$ are to be estimated. Instead of storing the whole sample
+ cumulative distribution, the algorithm maintains only \f$m+2\f$ principal markers and
+ \f$m+1\f$ middle markers, whose positions are updated with each sample and whose heights
+ are adjusted (if necessary) using a piecewise-parablic formula. The heights of the principal
+ markers are the current estimates of the quantiles and are returned as an iterator range.
+
+ For further details, see
+
+ 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
+
+ R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and
+ histograms without storing observations, Communications of the ACM,
+ Volume 28 (October), Number 10, 1985, p. 1076-1085.
+
+ @param extended_p_square_probabilities A vector of quantile probabilities.
+ */
+ template<typename Sample, typename Weight>
+ struct weighted_extended_p_square_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 std::vector<float_type> array_type;
+ // for boost::result_of
+ typedef iterator_range<
+ detail::lvalue_index_iterator<
+ permutation_iterator<
+ typename array_type::const_iterator
+ , detail::times2_iterator
+ >
+ >
+ > result_type;
+
+ template<typename Args>
+ weighted_extended_p_square_impl(Args const &args)
+ : probabilities(
+ boost::begin(args[extended_p_square_probabilities])
+ , boost::end(args[extended_p_square_probabilities])
+ )
+ , heights(2 * probabilities.size() + 3)
+ , actual_positions(heights.size())
+ , desired_positions(heights.size())
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+ std::size_t sample_cell = 1; // k
+ std::size_t num_quantiles = this->probabilities.size();
+
+ // m+2 principal markers and m+1 middle markers
+ std::size_t num_markers = 2 * num_quantiles + 3;
+
+ // first accumulate num_markers samples
+ if(cnt <= num_markers)
+ {
+ this->heights[cnt - 1] = args[sample];
+ this->actual_positions[cnt - 1] = args[weight];
+
+ // complete the initialization of heights (and actual_positions) by sorting
+ if(cnt == num_markers)
+ {
+ // TODO: we need to sort the initial samples (in heights) in ascending order and
+ // sort their weights (in actual_positions) the same way. The following lines do
+ // it, but there must be a better and more efficient way of doing this.
+ typename array_type::iterator it_begin, it_end, it_min;
+
+ it_begin = this->heights.begin();
+ it_end = this->heights.end();
+
+ std::size_t pos = 0;
+
+ while (it_begin != it_end)
+ {
+ it_min = std::min_element(it_begin, it_end);
+ std::size_t d = std::distance(it_begin, it_min);
+ std::swap(*it_begin, *it_min);
+ std::swap(this->actual_positions[pos], this->actual_positions[pos + d]);
+ ++it_begin;
+ ++pos;
+ }
+
+ // calculate correct initial actual positions
+ for (std::size_t i = 1; i < num_markers; ++i)
+ {
+ actual_positions[i] += actual_positions[i - 1];
+ }
+ }
+ }
+ else
+ {
+ if(args[sample] < this->heights[0])
+ {
+ this->heights[0] = args[sample];
+ this->actual_positions[0] = args[weight];
+ sample_cell = 1;
+ }
+ else if(args[sample] >= this->heights[num_markers - 1])
+ {
+ this->heights[num_markers - 1] = args[sample];
+ sample_cell = num_markers - 1;
+ }
+ else
+ {
+ // find cell k = sample_cell such that heights[k-1] <= sample < heights[k]
+
+ typedef typename array_type::iterator iterator;
+ iterator it = std::upper_bound(
+ this->heights.begin()
+ , this->heights.end()
+ , args[sample]
+ );
+
+ sample_cell = std::distance(this->heights.begin(), it);
+ }
+
+ // update actual position of all markers above sample_cell
+ for(std::size_t i = sample_cell; i < num_markers; ++i)
+ {
+ this->actual_positions[i] += args[weight];
+ }
+
+ // compute desired positions
+ {
+ this->desired_positions[0] = this->actual_positions[0];
+ this->desired_positions[num_markers - 1] = sum_of_weights(args);
+ this->desired_positions[1] = (sum_of_weights(args) - this->actual_positions[0]) * probabilities[0]
+ / 2. + this->actual_positions[0];
+ this->desired_positions[num_markers - 2] = (sum_of_weights(args) - this->actual_positions[0])
+ * (probabilities[num_quantiles - 1] + 1.)
+ / 2. + this->actual_positions[0];
+
+ for (std::size_t i = 0; i < num_quantiles; ++i)
+ {
+ this->desired_positions[2 * i + 2] = (sum_of_weights(args) - this->actual_positions[0])
+ * probabilities[i] + this->actual_positions[0];
+ }
+
+ for (std::size_t i = 1; i < num_quantiles; ++i)
+ {
+ this->desired_positions[2 * i + 1] = (sum_of_weights(args) - this->actual_positions[0])
+ * (probabilities[i - 1] + probabilities[i])
+ / 2. + this->actual_positions[0];
+ }
+ }
+
+ // adjust heights and actual_positions of markers 1 to num_markers - 2 if necessary
+ for (std::size_t i = 1; i <= num_markers - 2; ++i)
+ {
+ // offset to desired position
+ float_type d = this->desired_positions[i] - this->actual_positions[i];
+
+ // offset to next position
+ float_type dp = this->actual_positions[i + 1] - this->actual_positions[i];
+
+ // offset to previous position
+ float_type dm = this->actual_positions[i - 1] - this->actual_positions[i];
+
+ // height ds
+ float_type hp = (this->heights[i + 1] - this->heights[i]) / dp;
+ float_type hm = (this->heights[i - 1] - this->heights[i]) / dm;
+
+ if((d >= 1 && dp > 1) || (d <= -1 && dm < -1))
+ {
+ short sign_d = static_cast<short>(d / std::abs(d));
+
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ((sign_d - dm)*hp + (dp - sign_d) * hm);
+
+ // try adjusting heights[i] using p-squared formula
+ if(this->heights[i - 1] < h && h < this->heights[i + 1])
+ {
+ this->heights[i] = h;
+ }
+ else
+ {
+ // use linear formula
+ if(d > 0)
+ {
+ this->heights[i] += hp;
+ }
+ if(d < 0)
+ {
+ this->heights[i] -= hm;
+ }
+ }
+ this->actual_positions[i] += sign_d;
+ }
+ }
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ // for i in [1,probabilities.size()], return heights[i * 2]
+ detail::times2_iterator idx_begin = detail::make_times2_iterator(1);
+ detail::times2_iterator idx_end = detail::make_times2_iterator(this->probabilities.size() + 1);
+
+ return result_type(
+ make_permutation_iterator(this->heights.begin(), idx_begin)
+ , make_permutation_iterator(this->heights.begin(), idx_end)
+ );
+ }
+
+ private:
+ array_type probabilities; // the quantile probabilities
+ array_type heights; // q_i
+ array_type actual_positions; // n_i
+ array_type desired_positions; // d_i
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_extended_p_square
+//
+namespace tag
+{
+ struct weighted_extended_p_square
+ : depends_on<count, sum_of_weights>
+ , extended_p_square_probabilities
+ {
+ typedef accumulators::impl::weighted_extended_p_square_impl<mpl::_1, mpl::_2> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_extended_p_square
+//
+namespace extract
+{
+ extractor<tag::weighted_extended_p_square> const weighted_extended_p_square = {};
+}
+
+using extract::weighted_extended_p_square;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_kurtosis.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_kurtosis.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,103 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_kurtosis.hpp
+//
+// Copyright 2006 Olivier Gygi, Daniel Egloff. 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_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
+
+#include <limits>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/weighted_moment.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_kurtosis_impl
+ /**
+ @brief Kurtosis estimation for weighted samples
+
+ The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the square of the 2nd central
+ moment (the variance) of the samples, minus 3. The term \f$ -3 \f$ is added in order to ensure that the normal distribution
+ has zero kurtosis. The kurtosis can also be expressed by the simple moments:
+
+ \f[
+ \hat{g}_2 =
+ \frac
+ {\widehat{m}_n^{(4)}-4\widehat{m}_n^{(3)}\hat{\mu}_n+6\widehat{m}_n^{(2)}\hat{\mu}_n^2-3\hat{\mu}_n^4}
+ {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^2} - 3,
+ \f]
+
+ where \f$ \widehat{m}_n^{(i)} \f$ are the \f$ i \f$-th moment and \f$ \hat{\mu}_n \f$ the mean (first moment) of the
+ \f$ n \f$ samples.
+
+ The kurtosis estimator for weighted samples is formally identical to the estimator for unweighted samples, except that
+ the weighted counterparts of all measures it depends on are to be taken.
+ */
+ template<typename Sample, typename Weight>
+ struct weighted_kurtosis_impl
+ : accumulator_base
+ {
+ 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;
+
+ weighted_kurtosis_impl(dont_care)
+ {
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return numeric::average(
+ weighted_moment<4>(args)
+ - 4. * weighted_moment<3>(args) * weighted_mean(args)
+ + 6. * weighted_moment<2>(args) * weighted_mean(args) * weighted_mean(args)
+ - 3. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) * weighted_mean(args)
+ , ( weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
+ * ( weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
+ ) - 3.;
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_kurtosis
+//
+namespace tag
+{
+ struct weighted_kurtosis
+ : depends_on<weighted_mean, weighted_moment<2>, weighted_moment<3>, weighted_moment<4> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_kurtosis_impl<mpl::_1, mpl::_2> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_kurtosis
+//
+namespace extract
+{
+ extractor<tag::weighted_kurtosis> const weighted_kurtosis = {};
+}
+
+using extract::weighted_kurtosis;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_mean.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_mean.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,187 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_mean.hpp
+//
+// Copyright 2006 Eric Niebler, Olivier Gygi. 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_WEIGHTED_MEAN_HPP_EAN_03_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MEAN_HPP_EAN_03_11_2005
+
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.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/weights.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/weighted_sum.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_mean_impl
+ // lazy, by default
+ template<typename Sample, typename Weight, typename Tag>
+ struct weighted_mean_impl
+ : accumulator_base
+ {
+ 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;
+
+ weighted_mean_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ typedef
+ typename mpl::if_<
+ is_same<Tag, tag::sample>
+ , tag::weighted_sum
+ , tag::weighted_sum_of_variates<Sample, Tag>
+ >::type
+ weighted_sum_tag;
+
+ extractor<weighted_sum_tag> const some_weighted_sum = {};
+
+ return numeric::average(some_weighted_sum(args), sum_of_weights(args));
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // immediate_weighted_mean_impl
+ // immediate
+ template<typename Sample, typename Weight, typename Tag>
+ struct immediate_weighted_mean_impl
+ : accumulator_base
+ {
+ 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;
+
+ template<typename Args>
+ immediate_weighted_mean_impl(Args const &args)
+ : mean(
+ numeric::average(
+ args[parameter::keyword<Tag>::get() | Sample()]
+ * numeric::one<Weight>::value
+ , numeric::one<Weight>::value
+ )
+ )
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ // Matthias:
+ // need to pass the argument pack since the weight might be an external
+ // accumulator set passed as a named parameter
+ 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);
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->mean;
+ }
+
+ private:
+ result_type mean;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_mean
+// tag::immediate_weighted_mean
+//
+namespace tag
+{
+ struct weighted_mean
+ : depends_on<sum_of_weights, weighted_sum>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_mean_impl<mpl::_1, mpl::_2, tag::sample> impl;
+ };
+ struct immediate_weighted_mean
+ : depends_on<sum_of_weights>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::immediate_weighted_mean_impl<mpl::_1, mpl::_2, tag::sample> impl;
+ };
+ template<typename VariateType, typename VariateTag>
+ struct weighted_mean_of_variates
+ : depends_on<sum_of_weights, weighted_sum_of_variates<VariateType, VariateTag> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_mean_impl<VariateType, mpl::_2, VariateTag> impl;
+ };
+ template<typename VariateType, typename VariateTag>
+ struct immediate_weighted_mean_of_variates
+ : depends_on<sum_of_weights>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::immediate_weighted_mean_impl<VariateType, mpl::_2, VariateTag> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_mean
+// extract::weighted_mean_of_variates
+//
+namespace extract
+{
+ extractor<tag::mean> const weighted_mean = {};
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, weighted_mean_of_variates, (typename)(typename))
+}
+
+using extract::weighted_mean;
+using extract::weighted_mean_of_variates;
+
+// weighted_mean(lazy) -> weighted_mean
+template<>
+struct as_feature<tag::weighted_mean(lazy)>
+{
+ typedef tag::weighted_mean type;
+};
+
+// weighted_mean(immediate) -> immediate_weighted_mean
+template<>
+struct as_feature<tag::weighted_mean(immediate)>
+{
+ typedef tag::immediate_weighted_mean type;
+};
+
+// weighted_mean_of_variates<VariateType, VariateTag>(lazy) -> weighted_mean_of_variates<VariateType, VariateTag>
+template<typename VariateType, typename VariateTag>
+struct as_feature<tag::weighted_mean_of_variates<VariateType, VariateTag>(lazy)>
+{
+ typedef tag::weighted_mean_of_variates<VariateType, VariateTag> type;
+};
+
+// weighted_mean_of_variates<VariateType, VariateTag>(immediate) -> immediate_weighted_mean_of_variates<VariateType, VariateTag>
+template<typename VariateType, typename VariateTag>
+struct as_feature<tag::weighted_mean_of_variates<VariateType, VariateTag>(immediate)>
+{
+ typedef tag::immediate_weighted_mean_of_variates<VariateType, VariateTag> type;
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_median.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_median.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,235 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_median.hpp
+//
+// Copyright 2006 Eric Niebler, Olivier Gygi. 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_WEIGHTED_MEDIAN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MEDIAN_HPP_EAN_28_10_2005
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/range/iterator_range.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/count.hpp>
+#include <boost/accumulators/statistics/median.hpp>
+#include <boost/accumulators/statistics/weighted_p_square_quantile.hpp>
+#include <boost/accumulators/statistics/weighted_density.hpp>
+#include <boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_median_impl
+ //
+ /**
+ @brief Median estimation for weighted samples based on the \f$P^2\f$ quantile estimator
+
+ The \f$P^2\f$ algorithm for weighted samples is invoked with a quantile probability of 0.5.
+ */
+ template<typename Sample>
+ struct weighted_median_impl
+ : accumulator_base
+ {
+ // for boost::result_of
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ weighted_median_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return weighted_p_square_quantile_for_median(args);
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // with_density_weighted_median_impl
+ //
+ /**
+ @brief Median estimation for weighted samples based on the density estimator
+
+ The algorithm determines the bin in which the \f$0.5*cnt\f$-th sample lies, \f$cnt\f$ being
+ the total number of samples. It returns the approximate horizontal position of this sample,
+ based on a linear interpolation inside the bin.
+ */
+ template<typename Sample>
+ struct with_density_weighted_median_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<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
+ typedef float_type result_type;
+
+ template<typename Args>
+ with_density_weighted_median_impl(Args const &args)
+ : sum(numeric::average(args[sample | Sample()], (std::size_t)1))
+ , is_dirty(true)
+ {
+ }
+
+ void operator ()(dont_care)
+ {
+ this->is_dirty = true;
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ std::size_t cnt = count(args);
+ range_type histogram = weighted_density(args);
+ typename range_type::iterator it = histogram.begin();
+ while (this->sum < 0.5 * cnt)
+ {
+ this->sum += it->second * cnt;
+ ++it;
+ }
+ --it;
+ float_type over = numeric::average(this->sum - 0.5 * cnt, it->second * cnt);
+ this->median = it->first * over + (it + 1)->first * ( 1. - over );
+ }
+
+ return this->median;
+ }
+
+ private:
+ mutable float_type sum;
+ mutable bool is_dirty;
+ mutable float_type median;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // with_p_square_cumulative_distribution_weighted_median_impl
+ //
+ /**
+ @brief Median estimation for weighted samples based on the \f$P^2\f$ cumulative distribution estimator
+
+ The algorithm determines the first (leftmost) bin with a height exceeding 0.5. It
+ returns the approximate horizontal position of where the cumulative distribution
+ equals 0.5, based on a linear interpolation inside the bin.
+ */
+ template<typename Sample, typename Weight>
+ struct with_p_square_cumulative_distribution_weighted_median_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 std::vector<std::pair<float_type, float_type> > histogram_type;
+ typedef iterator_range<typename histogram_type::iterator> range_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ with_p_square_cumulative_distribution_weighted_median_impl(dont_care)
+ : is_dirty(true)
+ {
+ }
+
+ void operator ()(dont_care)
+ {
+ this->is_dirty = true;
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ range_type histogram = weighted_p_square_cumulative_distribution(args);
+ typename range_type::iterator it = histogram.begin();
+ while (it->second < 0.5)
+ {
+ ++it;
+ }
+ float_type over = numeric::average(it->second - 0.5, it->second - (it - 1)->second);
+ this->median = it->first * over + (it + 1)->first * ( 1. - over );
+ }
+
+ return this->median;
+ }
+ private:
+ mutable bool is_dirty;
+ mutable float_type median;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_median
+// tag::with_density_weighted_median
+// tag::with_p_square_cumulative_distribution_weighted_median
+//
+namespace tag
+{
+ struct weighted_median
+ : depends_on<weighted_p_square_quantile_for_median>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_median_impl<mpl::_1> impl;
+ };
+ struct with_density_weighted_median
+ : depends_on<count, weighted_density>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::with_density_weighted_median_impl<mpl::_1> impl;
+ };
+ struct with_p_square_cumulative_distribution_weighted_median
+ : depends_on<weighted_p_square_cumulative_distribution>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::with_p_square_cumulative_distribution_weighted_median_impl<mpl::_1, mpl::_2> impl;
+ };
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_median
+//
+namespace extract
+{
+ extractor<tag::median> const weighted_median = {};
+}
+
+using extract::weighted_median;
+// weighted_median(with_p_square_quantile) -> weighted_median
+template<>
+struct as_feature<tag::weighted_median(with_p_square_quantile)>
+{
+ typedef tag::weighted_median type;
+};
+
+// weighted_median(with_density) -> with_density_weighted_median
+template<>
+struct as_feature<tag::weighted_median(with_density)>
+{
+ typedef tag::with_density_weighted_median type;
+};
+
+// weighted_median(with_p_square_cumulative_distribution) -> with_p_square_cumulative_distribution_weighted_median
+template<>
+struct as_feature<tag::weighted_median(with_p_square_cumulative_distribution)>
+{
+ typedef tag::with_p_square_cumulative_distribution_weighted_median type;
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_moment.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_moment.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,96 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_moment.hpp
+//
+// Copyright 2006, Eric Niebler, Olivier Gygi. 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_WEIGHTED_MOMENT_HPP_EAN_15_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MOMENT_HPP_EAN_15_11_2005
+
+#include <cmath>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/preprocessor/arithmetic/inc.hpp>
+#include <boost/preprocessor/repetition/repeat_from_to.hpp>
+#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
+#include <boost/preprocessor/repetition/enum_trailing_binary_params.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/count.hpp>
+#include <boost/accumulators/statistics/moment.hpp> // for pow()
+#include <boost/accumulators/statistics/sum.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_moment_impl
+ template<typename N, typename Sample, typename Weight>
+ struct weighted_moment_impl
+ : accumulator_base // TODO: also depends_on sum of powers
+ {
+ 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;
+
+ template<typename Args>
+ weighted_moment_impl(Args const &args)
+ : sum(args[sample | Sample()] * numeric::one<Weight>::value)
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->sum += args[weight] * numeric::pow(args[sample], N());
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return numeric::average(this->sum, sum_of_weights(args));
+ }
+
+ private:
+ weighted_sample sum;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_moment
+//
+namespace tag
+{
+ template<int N>
+ struct weighted_moment
+ : depends_on<count, sum_of_weights>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_moment_impl<mpl::int_<N>, mpl::_1, mpl::_2> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_moment
+//
+namespace extract
+{
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, weighted_moment, (int))
+}
+
+using extract::weighted_moment;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,260 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_p_square_cumulative_distribution.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_WEIGHTED_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_DE_01_01_2006
+
+#include <vector>
+#include <functional>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/range.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/p_square_cumulative_distribution.hpp> // for named parameter p_square_cumulative_distribution_num_cells
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_p_square_cumulative_distribution_impl
+ // cumulative distribution calculation (as histogram)
+ /**
+ @brief Histogram calculation of the cumulative distribution with the \f$P^2\f$ algorithm for weighted samples
+
+ A histogram of the sample cumulative distribution is computed dynamically without storing samples
+ based on the \f$ P^2 \f$ algorithm for weighted samples. The returned histogram has a specifiable
+ amount (num_cells) equiprobable (and not equal-sized) cells.
+
+ Note that applying importance sampling results in regions to be more and other regions to be less
+ accurately estimated than without importance sampling, i.e., with unweighted samples.
+
+ For further details, see
+
+ R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and
+ histograms without storing observations, Communications of the ACM,
+ Volume 28 (October), Number 10, 1985, p. 1076-1085.
+
+ @param p_square_cumulative_distribution_num_cells
+ */
+ template<typename Sample, typename Weight>
+ struct weighted_p_square_cumulative_distribution_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 std::vector<std::pair<float_type, float_type> > histogram_type;
+ typedef std::vector<float_type> array_type;
+ // for boost::result_of
+ typedef iterator_range<typename histogram_type::iterator> result_type;
+
+ template<typename Args>
+ weighted_p_square_cumulative_distribution_impl(Args const &args)
+ : num_cells(args[p_square_cumulative_distribution_num_cells])
+ , heights(num_cells + 1)
+ , actual_positions(num_cells + 1)
+ , desired_positions(num_cells + 1)
+ , histogram(num_cells + 1)
+ , is_dirty(true)
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->is_dirty = true;
+
+ std::size_t cnt = count(args);
+ std::size_t sample_cell = 1; // k
+ std::size_t b = this->num_cells;
+
+ // accumulate num_cells + 1 first samples
+ if (cnt <= b + 1)
+ {
+ this->heights[cnt - 1] = args[sample];
+ this->actual_positions[cnt - 1] = args[weight];
+
+ // complete the initialization of heights by sorting
+ if (cnt == b + 1)
+ {
+ //std::sort(this->heights.begin(), this->heights.end());
+
+ // TODO: we need to sort the initial samples (in heights) in ascending order and
+ // sort their weights (in actual_positions) the same way. The following lines do
+ // it, but there must be a better and more efficient way of doing this.
+ typename array_type::iterator it_begin, it_end, it_min;
+
+ it_begin = this->heights.begin();
+ it_end = this->heights.end();
+
+ std::size_t pos = 0;
+
+ while (it_begin != it_end)
+ {
+ it_min = std::min_element(it_begin, it_end);
+ std::size_t d = std::distance(it_begin, it_min);
+ std::swap(*it_begin, *it_min);
+ std::swap(this->actual_positions[pos], this->actual_positions[pos + d]);
+ ++it_begin;
+ ++pos;
+ }
+
+ // calculate correct initial actual positions
+ for (std::size_t i = 1; i < b; ++i)
+ {
+ this->actual_positions[i] += this->actual_positions[i - 1];
+ }
+ }
+ }
+ else
+ {
+ // 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];
+ this->actual_positions[0] = args[weight];
+ sample_cell = 1;
+ }
+ else if (this->heights[b] <= args[sample])
+ {
+ this->heights[b] = args[sample];
+ sample_cell = b;
+ }
+ else
+ {
+ typename array_type::iterator it;
+ it = std::upper_bound(
+ this->heights.begin()
+ , this->heights.end()
+ , args[sample]
+ );
+
+ sample_cell = std::distance(this->heights.begin(), it);
+ }
+
+ // increment positions of markers above sample_cell
+ for (std::size_t i = sample_cell; i < b + 1; ++i)
+ {
+ this->actual_positions[i] += args[weight];
+ }
+
+ // determine desired marker positions
+ 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);
+ }
+
+ // adjust heights of markers 2 to num_cells if necessary
+ for (std::size_t i = 1; i < b; ++i)
+ {
+ // offset to desire position
+ float_type d = this->desired_positions[i] - this->actual_positions[i];
+
+ // offset to next position
+ float_type dp = this->actual_positions[i + 1] - this->actual_positions[i];
+
+ // offset to previous position
+ float_type dm = this->actual_positions[i - 1] - this->actual_positions[i];
+
+ // height ds
+ float_type hp = (this->heights[i + 1] - this->heights[i]) / dp;
+ float_type hm = (this->heights[i - 1] - this->heights[i]) / dm;
+
+ if ( ( d >= 1. && dp > 1. ) || ( d <= -1. && dm < -1. ) )
+ {
+ short sign_d = static_cast<short>(d / std::abs(d));
+
+ // try adjusting heights[i] using p-squared formula
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ( (sign_d - dm) * hp + (dp - sign_d) * hm );
+
+ if ( this->heights[i - 1] < h && h < this->heights[i + 1] )
+ {
+ this->heights[i] = h;
+ }
+ else
+ {
+ // use linear formula
+ if (d>0)
+ {
+ this->heights[i] += hp;
+ }
+ if (d<0)
+ {
+ this->heights[i] -= hm;
+ }
+ }
+ this->actual_positions[i] += sign_d;
+ }
+ }
+ }
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty)
+ {
+ this->is_dirty = false;
+
+ // creates a vector of std::pair where each pair i holds
+ // the values heights[i] (x-axis of histogram) and
+ // actual_positions[i] / sum_of_weights (y-axis of histogram)
+
+ 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)));
+ }
+ }
+
+ return make_iterator_range(this->histogram);
+ }
+
+ private:
+ std::size_t num_cells; // number of cells b
+ array_type heights; // q_i
+ array_type actual_positions; // n_i
+ array_type desired_positions; // n'_i
+ mutable histogram_type histogram; // histogram
+ mutable bool is_dirty;
+ };
+
+} // namespace detail
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_p_square_cumulative_distribution
+//
+namespace tag
+{
+ struct weighted_p_square_cumulative_distribution
+ : depends_on<count, sum_of_weights>
+ , p_square_cumulative_distribution_num_cells
+ {
+ typedef accumulators::impl::weighted_p_square_cumulative_distribution_impl<mpl::_1, mpl::_2> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_p_square_cumulative_distribution
+//
+namespace extract
+{
+ extractor<tag::weighted_p_square_cumulative_distribution> const weighted_p_square_cumulative_distribution = {};
+}
+
+using extract::weighted_p_square_cumulative_distribution;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_p_square_quantile.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_p_square_quantile.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,251 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_p_square_quantile.hpp
+//
+// Copyright 2005 Daniel Egloff. 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_WEIGHTED_P_SQUARE_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_P_SQUARE_QUANTILE_HPP_DE_01_01_2006
+
+#include <functional>
+#include <boost/array.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.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/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl {
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_p_square_quantile_impl
+ // single quantile estimation with weighted samples
+ /**
+ @brief Single quantile estimation with the \f$P^2\f$ algorithm for weighted samples
+
+ This version of the \f$P^2\f$ algorithm extends the \f$P^2\f$ algorithm to support weighted samples.
+ The \f$P^2\f$ algorithm estimates a quantile dynamically without storing samples. Instead of
+ storing the whole sample cumulative distribution, only five points (markers) are stored. The heights
+ of these markers are the minimum and the maximum of the samples and the current estimates of the
+ \f$(p/2)\f$-, \f$p\f$ - and \f$(1+p)/2\f$ -quantiles. Their positions are equal to the number
+ of samples that are smaller or equal to the markers. Each time a new sample is added, the
+ positions of the markers are updated and if necessary their heights are adjusted using a piecewise-
+ parabolic formula.
+
+ For further details, see
+
+ R. Jain and I. Chlamtac, The P^2 algorithmus for dynamic calculation of quantiles and
+ histograms without storing observations, Communications of the ACM,
+ Volume 28 (October), Number 10, 1985, p. 1076-1085.
+
+ @param quantile_probability
+ */
+ template<typename Sample, typename Weight, typename Impl>
+ struct weighted_p_square_quantile_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 array<float_type, 5> array_type;
+ // for boost::result_of
+ typedef float_type result_type;
+
+ template<typename Args>
+ weighted_p_square_quantile_impl(Args const &args)
+ : p(is_same<Impl, for_median>::value ? 0.5 : args[quantile_probability | 0.5])
+ , heights()
+ , actual_positions()
+ , desired_positions()
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+
+ // accumulate 5 first samples
+ if (cnt <= 5)
+ {
+ 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
+ // compute the correct initial positions of the markers.
+ this->actual_positions[cnt - 1] = args[weight];
+
+ // complete the initialization of heights and actual_positions by sorting
+ if (cnt == 5)
+ {
+ // TODO: we need to sort the initial samples (in heights) in ascending order and
+ // sort their weights (in actual_positions) the same way. The following lines do
+ // it, but there must be a better and more efficient way of doing this.
+ typename array_type::iterator it_begin, it_end, it_min;
+
+ it_begin = this->heights.begin();
+ it_end = this->heights.end();
+
+ std::size_t pos = 0;
+
+ while (it_begin != it_end)
+ {
+ it_min = std::min_element(it_begin, it_end);
+ std::size_t d = std::distance(it_begin, it_min);
+ std::swap(*it_begin, *it_min);
+ std::swap(this->actual_positions[pos], this->actual_positions[pos + d]);
+ ++it_begin;
+ ++pos;
+ }
+
+ // calculate correct initial actual positions
+ for (std::size_t i = 1; i < 5; ++i)
+ {
+ this->actual_positions[i] += this->actual_positions[i - 1];
+ }
+ }
+ }
+ else
+ {
+ std::size_t sample_cell = 1; // k
+
+ // 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];
+ this->actual_positions[0] = args[weight];
+ sample_cell = 1;
+ }
+ else if (this->heights[4] <= args[sample])
+ {
+ this->heights[4] = args[sample];
+ sample_cell = 4;
+ }
+ else
+ {
+ typedef typename array_type::iterator iterator;
+ iterator it = std::upper_bound(
+ this->heights.begin()
+ , this->heights.end()
+ , args[sample]
+ );
+
+ sample_cell = std::distance(this->heights.begin(), it);
+ }
+
+ // increment positions of markers above sample_cell
+ for (std::size_t i = sample_cell; i < 5; ++i)
+ {
+ this->actual_positions[i] += args[weight];
+ }
+
+ // update desired positions for all markers
+ this->desired_positions[0] = this->actual_positions[0];
+ this->desired_positions[1] = (sum_of_weights(args) - this->actual_positions[0])
+ * this->p/2. + this->actual_positions[0];
+ this->desired_positions[2] = (sum_of_weights(args) - this->actual_positions[0])
+ * this->p + this->actual_positions[0];
+ this->desired_positions[3] = (sum_of_weights(args) - this->actual_positions[0])
+ * (1. + this->p)/2. + this->actual_positions[0];
+ this->desired_positions[4] = sum_of_weights(args);
+
+ // adjust height and actual positions of markers 1 to 3 if necessary
+ for (std::size_t i = 1; i <= 3; ++i)
+ {
+ // offset to desired positions
+ float_type d = this->desired_positions[i] - this->actual_positions[i];
+
+ // offset to next position
+ float_type dp = this->actual_positions[i + 1] - this->actual_positions[i];
+
+ // offset to previous position
+ float_type dm = this->actual_positions[i - 1] - this->actual_positions[i];
+
+ // height ds
+ float_type hp = (this->heights[i + 1] - this->heights[i]) / dp;
+ float_type hm = (this->heights[i - 1] - this->heights[i]) / dm;
+
+ if ( ( d >= 1. && dp > 1. ) || ( d <= -1. && dm < -1. ) )
+ {
+ short sign_d = static_cast<short>(d / std::abs(d));
+
+ // try adjusting heights[i] using p-squared formula
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ( (sign_d - dm) * hp + (dp - sign_d) * hm );
+
+ if ( this->heights[i - 1] < h && h < this->heights[i + 1] )
+ {
+ this->heights[i] = h;
+ }
+ else
+ {
+ // use linear formula
+ if (d>0)
+ {
+ this->heights[i] += hp;
+ }
+ if (d<0)
+ {
+ this->heights[i] -= hm;
+ }
+ }
+ this->actual_positions[i] += sign_d;
+ }
+ }
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->heights[2];
+ }
+
+ private:
+ float_type p; // the quantile probability p
+ array_type heights; // q_i
+ array_type actual_positions; // n_i
+ array_type desired_positions; // n'_i
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_p_square_quantile
+//
+namespace tag
+{
+ struct weighted_p_square_quantile
+ : depends_on<count, sum_of_weights>
+ {
+ typedef accumulators::impl::weighted_p_square_quantile_impl<mpl::_1, mpl::_2, regular> impl;
+ };
+ struct weighted_p_square_quantile_for_median
+ : depends_on<count, sum_of_weights>
+ {
+ typedef accumulators::impl::weighted_p_square_quantile_impl<mpl::_1, mpl::_2, for_median> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_p_square_quantile
+// extract::weighted_p_square_quantile_for_median
+//
+namespace extract
+{
+ extractor<tag::weighted_p_square_quantile> const weighted_p_square_quantile = {};
+ extractor<tag::weighted_p_square_quantile_for_median> const weighted_p_square_quantile_for_median = {};
+}
+
+using extract::weighted_p_square_quantile;
+using extract::weighted_p_square_quantile_for_median;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,286 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_peaks_over_threshold.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_WEIGHTED_PEAKS_OVER_THRESHOLD_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_PEAKS_OVER_THRESHOLD_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <numeric>
+#include <functional>
+#include <boost/range.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.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/parameters/quantile_probability.hpp>
+#include <boost/accumulators/statistics/peaks_over_threshold.hpp> // for named parameters pot_threshold_value and pot_threshold_probability
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/tail_variate.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_peaks_over_threshold_impl
+ // works with an explicit threshold value and does not depend on order statistics of weighted samples
+ /**
+ @brief Weighted Peaks over Threshold Method for Weighted Quantile and Weighted Tail Mean Estimation
+
+ @sa peaks_over_threshold_impl
+
+ @param quantile_probability
+ @param pot_threshold_value
+ */
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct weighted_peaks_over_threshold_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;
+ // 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))
+ , threshold_(sign_ * args[pot_threshold_value])
+ , fit_parameters_(boost::make_tuple(0., 0., 0.))
+ , is_dirty_(true)
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->is_dirty_ = true;
+
+ if (this->sign_ * args[sample] > this->threshold_)
+ {
+ this->mu_ += args[weight] * args[sample];
+ this->sigma2_ += args[weight] * args[sample] * args[sample];
+ this->w_sum_ += args[weight];
+ }
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty_)
+ {
+ 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->sigma2_ -= this->mu_ * this->mu_;
+
+ float_type threshold_probability = numeric::average(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 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);
+ float_type u_bar = this->threshold_ - beta_bar * ( std::pow(1. - threshold_probability, -xi_hat) - 1.)/xi_hat;
+ this->fit_parameters_ = boost::make_tuple(u_bar, beta_bar, xi_hat);
+ }
+
+ return this->fit_parameters_;
+ }
+
+ private:
+ short sign_; // for left tail fitting, mirror the extreme values
+ mutable float_type mu_; // mean of samples above threshold
+ mutable float_type sigma2_; // variance of samples above threshold
+ mutable float_type w_sum_; // sum of weights of samples above threshold
+ float_type threshold_;
+ mutable result_type fit_parameters_; // boost::tuple that stores fit parameters
+ mutable bool is_dirty_;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_peaks_over_threshold_prob_impl
+ // determines threshold from a given threshold probability using order statistics
+ /**
+ @brief Peaks over Threshold Method for Quantile and Tail Mean Estimation
+
+ @sa weighted_peaks_over_threshold_impl
+
+ @param quantile_probability
+ @param pot_threshold_probability
+ */
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct weighted_peaks_over_threshold_prob_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;
+ // 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))
+ , threshold_probability_(args[pot_threshold_probability])
+ , fit_parameters_(boost::make_tuple(0., 0., 0.))
+ , is_dirty_(true)
+ {
+ }
+
+ void operator ()(dont_care)
+ {
+ this->is_dirty_ = true;
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ if (this->is_dirty_)
+ {
+ this->is_dirty_ = false;
+
+ float_type threshold = sum_of_weights(args)
+ * ( ( is_same<LeftRight, left>::value ) ? this->threshold_probability_ : 1. - this->threshold_probability_ );
+
+ std::size_t n = 0;
+ Weight sum = Weight(0);
+
+ while (sum < threshold)
+ {
+ if (n < static_cast<std::size_t>(tail_weights(args).size()))
+ {
+ mu_ += *(tail_weights(args).begin() + n) * *(tail(args).begin() + n);
+ sigma2_ += *(tail_weights(args).begin() + n) * *(tail(args).begin() + n) * (*(tail(args).begin() + n));
+ sum += *(tail_weights(args).begin() + n);
+ n++;
+ }
+ else
+ {
+ if (std::numeric_limits<float_type>::has_quiet_NaN)
+ {
+ return boost::make_tuple(
+ std::numeric_limits<float_type>::quiet_NaN()
+ , std::numeric_limits<float_type>::quiet_NaN()
+ , std::numeric_limits<float_type>::quiet_NaN()
+ );
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ return boost::make_tuple(Sample(0), Sample(0), Sample(0));
+ }
+ }
+ }
+
+ 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->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 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);
+ float_type u_bar = u - beta_bar * ( std::pow(1. - threshold_probability_, -xi_hat) - 1.)/xi_hat;
+ this->fit_parameters_ = boost::make_tuple(u_bar, beta_bar, xi_hat);
+
+ }
+
+ return this->fit_parameters_;
+ }
+
+ private:
+ short sign_; // for left tail fitting, mirror the extreme values
+ mutable float_type mu_; // mean of samples above threshold u
+ mutable float_type sigma2_; // variance of samples above threshold u
+ mutable float_type threshold_probability_;
+ mutable result_type fit_parameters_; // boost::tuple that stores fit parameters
+ mutable bool is_dirty_;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_peaks_over_threshold
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct weighted_peaks_over_threshold
+ : depends_on<sum_of_weights>
+ , pot_threshold_value
+ {
+ /// INTERNAL ONLY
+ typedef accumulators::impl::weighted_peaks_over_threshold_impl<mpl::_1, mpl::_2, LeftRight> impl;
+ };
+
+ template<typename LeftRight>
+ struct weighted_peaks_over_threshold_prob
+ : depends_on<sum_of_weights, tail_weights<LeftRight> >
+ , pot_threshold_probability
+ {
+ /// INTERNAL ONLY
+ typedef accumulators::impl::weighted_peaks_over_threshold_prob_impl<mpl::_1, mpl::_2, LeftRight> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_peaks_over_threshold
+//
+namespace extract
+{
+ extractor<tag::abstract_peaks_over_threshold> const weighted_peaks_over_threshold = {};
+}
+
+using extract::weighted_peaks_over_threshold;
+
+// weighted_peaks_over_threshold<LeftRight>(with_threshold_value) -> weighted_peaks_over_threshold<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::weighted_peaks_over_threshold<LeftRight>(with_threshold_value)>
+{
+ typedef tag::weighted_peaks_over_threshold<LeftRight> type;
+};
+
+// weighted_peaks_over_threshold<LeftRight>(with_threshold_probability) -> weighted_peaks_over_threshold_prob<LeftRight>
+template<typename LeftRight>
+struct as_feature<tag::weighted_peaks_over_threshold<LeftRight>(with_threshold_probability)>
+{
+ typedef tag::weighted_peaks_over_threshold_prob<LeftRight> type;
+};
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_skewness.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_skewness.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,99 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_skewness.hpp
+//
+// Copyright 2006 Olivier Gygi, Daniel Egloff. 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_WEIGHTED_SKEWNESS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SKEWNESS_HPP_EAN_28_10_2005
+
+#include <limits>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/weighted_moment.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_skewness_impl
+ /**
+ @brief Skewness estimation for weighted samples
+
+ 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 samples. The skewness can also be expressed by the simple moments:
+
+ \f[
+ \hat{g}_1 =
+ \frac
+ {\widehat{m}_n^{(3)}-3\widehat{m}_n^{(2)}\hat{\mu}_n+2\hat{\mu}_n^3}
+ {\left(\widehat{m}_n^{(2)} - \hat{\mu}_n^{2}\right)^{3/2}}
+ \f]
+
+ where \f$ \widehat{m}_n^{(i)} \f$ are the \f$ i \f$-th moment and \f$ \hat{\mu}_n \f$ the mean (first moment) of the
+ \f$ n \f$ samples.
+
+ The skewness estimator for weighted samples is formally identical to the estimator for unweighted samples, except that
+ the weighted counterparts of all measures it depends on are to be taken.
+ */
+ template<typename Sample, typename Weight>
+ struct weighted_skewness_impl
+ : accumulator_base
+ {
+ 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;
+
+ weighted_skewness_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return numeric::average(
+ weighted_moment<3>(args)
+ - 3. * weighted_moment<2>(args) * weighted_mean(args)
+ + 2. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args)
+ , ( weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
+ * std::sqrt( weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
+ );
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_skewness
+//
+namespace tag
+{
+ struct weighted_skewness
+ : depends_on<weighted_mean, weighted_moment<2>, weighted_moment<3> >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_skewness_impl<mpl::_1, mpl::_2> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_skewness
+//
+namespace extract
+{
+ extractor<tag::weighted_skewness> const weighted_skewness = {};
+}
+
+using extract::weighted_skewness;
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_sum.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_sum.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,113 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_sum.hpp
+//
+// Copyright 2006 Eric Niebler, Olivier Gygi. 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_WEIGHTED_SUM_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SUM_HPP_EAN_28_10_2005
+
+#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/parameters/weight.hpp>
+#include <boost/accumulators/framework/accumulators/external_accumulator.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_sum_impl
+ template<typename Sample, typename Weight, typename Tag>
+ struct weighted_sum_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample;
+
+ // for boost::result_of
+ typedef weighted_sample result_type;
+
+ template<typename Args>
+ weighted_sum_impl(Args const &args)
+ : weighted_sum_(
+ args[parameter::keyword<Tag>::get() | Sample()]
+ * numeric::one<Weight>::value
+ )
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ // what about overflow?
+ this->weighted_sum_ += args[parameter::keyword<Tag>::get()] * args[weight];
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->weighted_sum_;
+ }
+
+ private:
+
+ weighted_sample weighted_sum_;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_sum
+//
+namespace tag
+{
+ struct weighted_sum
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_sum_impl<mpl::_1, mpl::_2, tag::sample> impl;
+ };
+
+ template<typename VariateType, typename VariateTag>
+ struct weighted_sum_of_variates
+ : depends_on<>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_sum_impl<VariateType, mpl::_2, VariateTag> impl;
+ };
+
+ struct abstract_weighted_sum_of_variates
+ : depends_on<>
+ {
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_sum
+//
+namespace extract
+{
+ extractor<tag::weighted_sum> const weighted_sum = {};
+ extractor<tag::abstract_weighted_sum_of_variates> const weighted_sum_of_variates = {};
+}
+
+using extract::weighted_sum;
+using extract::weighted_sum_of_variates;
+
+template<typename VariateType, typename VariateTag>
+struct feature_of<tag::weighted_sum_of_variates<VariateType, VariateTag> >
+ : feature_of<tag::abstract_weighted_sum_of_variates>
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_tail_mean.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_tail_mean.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,167 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_tail_mean.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_WEIGHTED_TAIL_MEAN_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_TAIL_MEAN_HPP_DE_01_01_2006
+
+#include <numeric>
+#include <vector>
+#include <limits>
+#include <functional>
+#include <sstream>
+#include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/tail_mean.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // coherent_weighted_tail_mean_impl
+ //
+ // TODO
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // non_coherent_weighted_tail_mean_impl
+ //
+ /**
+ @brief Estimation of the (non-coherent) weighted tail mean based on order statistics (for both left and right tails)
+
+
+
+ An estimation of the non-coherent, weighted tail mean \f$\widehat{NCTM}_{n,\alpha}(X)\f$ is given by the weighted mean
+ of the
+
+ \f[
+ \lambda = \inf\left\{ l \left| \frac{1}{\bar{w}_n}\sum_{i=1}^{l} w_i \geq \alpha \right. \right\}
+ \f]
+
+ smallest samples (left tail) or the weighted mean of the
+
+ \f[
+ n + 1 - \rho = n + 1 - \sup\left\{ r \left| \frac{1}{\bar{w}_n}\sum_{i=r}^{n} w_i \geq (1 - \alpha) \right. \right\}
+ \f]
+
+ largest samples (right tail) above a quantile \f$\hat{q}_{\alpha}\f$ of level \f$\alpha\f$, \f$n\f$ being the total number of sample
+ and \f$\bar{w}_n\f$ the sum of all \f$n\f$ weights:
+
+ \f[
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X) = \frac{\sum_{i=1}^{\lambda} w_i X_{i:n}}{\sum_{i=1}^{\lambda} w_i},
+ \f]
+
+ \f[
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X) = \frac{\sum_{i=\rho}^n w_i X_{i:n}}{\sum_{i=\rho}^n w_i}.
+ \f]
+
+ @param quantile_probability
+ */
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct non_coherent_weighted_tail_mean_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;
+ // for boost::result_of
+ typedef typename numeric::functional::average<weighted_sample, std::size_t>::result_type result_type;
+
+ non_coherent_weighted_tail_mean_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ float_type threshold = sum_of_weights(args)
+ * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] );
+
+ std::size_t n = 0;
+ Weight sum = Weight(0);
+
+ while (sum < threshold)
+ {
+ if (n < static_cast<std::size_t>(tail_weights(args).size()))
+ {
+ sum += *(tail_weights(args).begin() + n);
+ n++;
+ }
+ else
+ {
+ if (std::numeric_limits<result_type>::has_quiet_NaN)
+ {
+ return std::numeric_limits<result_type>::quiet_NaN();
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ return result_type(0);
+ }
+ }
+ }
+
+ return numeric::average(
+ std::inner_product(
+ tail(args).begin()
+ , tail(args).begin() + n
+ , tail_weights(args).begin()
+ , weighted_sample(0)
+ )
+ , sum
+ );
+ }
+ };
+
+} // namespace impl
+
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::non_coherent_weighted_tail_mean<>
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct non_coherent_weighted_tail_mean
+ : depends_on<sum_of_weights, tail_weights<LeftRight> >
+ {
+ typedef accumulators::impl::non_coherent_weighted_tail_mean_impl<mpl::_1, mpl::_2, LeftRight> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::non_coherent_weighted_tail_mean;
+//
+namespace extract
+{
+ extractor<tag::abstract_non_coherent_tail_mean> const non_coherent_weighted_tail_mean = {};
+}
+
+using extract::non_coherent_weighted_tail_mean;
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_tail_quantile.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_tail_quantile.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,144 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_tail_quantile.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_WEIGHTED_TAIL_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_TAIL_QUANTILE_HPP_DE_01_01_2006
+
+#include <vector>
+#include <limits>
+#include <functional>
+#include <sstream>
+#include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/tail_quantile.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_tail_quantile_impl
+ // Tail quantile estimation based on order statistics of weighted samples
+ /**
+ @brief Tail quantile estimation based on order statistics of weighted samples (for both left and right tails)
+
+ An estimator \f$\hat{q}\f$ of tail quantiles with level \f$\alpha\f$ based on order statistics
+ \f$X_{1:n} \leq X_{2:n} \leq\dots\leq X_{n:n}\f$ of weighted samples are given by \f$X_{\lambda:n}\f$ (left tail)
+ and \f$X_{\rho:n}\f$ (right tail), where
+
+ \f[
+ \lambda = \inf\left\{ l \left| \frac{1}{\bar{w}_n}\sum_{i=1}^{l} w_i \geq \alpha \right. \right\}
+ \f]
+
+ and
+
+ \f[
+ \rho = \sup\left\{ r \left| \frac{1}{\bar{w}_n}\sum_{i=r}^{n} w_i \geq (1 - \alpha) \right. \right\},
+ \f]
+
+ \f$n\f$ being the number of samples and \f$\bar{w}_n\f$ the sum of all weights.
+
+ @param quantile_probability
+ */
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct weighted_tail_quantile_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Weight, std::size_t>::result_type float_type;
+ // for boost::result_of
+ typedef Sample result_type;
+
+ weighted_tail_quantile_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ float_type threshold = sum_of_weights(args)
+ * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] );
+
+ std::size_t n = 0;
+ Weight sum = Weight(0);
+
+ while (sum < threshold)
+ {
+ if (n < static_cast<std::size_t>(tail_weights(args).size()))
+ {
+ sum += *(tail_weights(args).begin() + n);
+ n++;
+ }
+ else
+ {
+ if (std::numeric_limits<result_type>::has_quiet_NaN)
+ {
+ return std::numeric_limits<result_type>::quiet_NaN();
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ return Sample(0);
+ }
+ }
+ }
+
+ // Note that the cached samples of the left are sorted in ascending order,
+ // whereas the samples of the right tail are sorted in descending order
+ return *(boost::begin(tail(args)) + n - 1);
+ }
+ };
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_tail_quantile<>
+//
+namespace tag
+{
+ template<typename LeftRight>
+ struct weighted_tail_quantile
+ : depends_on<sum_of_weights, tail_weights<LeftRight> >
+ {
+ /// INTERNAL ONLY
+ typedef accumulators::impl::weighted_tail_quantile_impl<mpl::_1, mpl::_2, LeftRight> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_tail_quantile
+//
+namespace extract
+{
+ extractor<tag::quantile> const weighted_tail_quantile = {};
+}
+
+using extract::weighted_tail_quantile;
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_tail_variate_means.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_tail_variate_means.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,239 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_tail_variate_means.hpp
+//
+// Copyright 2006 Daniel Egloff, Olivier Gygi. 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_WEIGHTED_TAIL_VARIATE_MEANS_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_TAIL_VARIATE_MEANS_HPP_DE_01_01_2006
+
+#include <numeric>
+#include <vector>
+#include <limits>
+#include <functional>
+#include <sstream>
+#include <stdexcept>
+#include <boost/throw_exception.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/tail_variate.hpp>
+#include <boost/accumulators/statistics/tail_variate_means.hpp>
+#include <boost/accumulators/statistics/weighted_tail_mean.hpp>
+#include <boost/accumulators/statistics/parameters/quantile_probability.hpp>
+
+#ifdef _MSC_VER
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+#endif
+
+namespace boost
+{
+ // for _BinaryOperatrion2 in std::inner_product below
+ // mutliplies two values and promotes the result to double
+ namespace numeric { namespace functional
+ {
+ ///////////////////////////////////////////////////////////////////////////////
+ // numeric::functional::multiply_and_promote_to_double
+ template<typename T, typename U>
+ struct multiply_and_promote_to_double
+ : multiplies<T, double const>
+ {
+ };
+ }}
+}
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ /**
+ @brief Estimation of the absolute and relative weighted tail variate means (for both left and right tails)
+
+ For all \f$j\f$-th variates associated to the
+
+ \f[
+ \lambda = \inf\left\{ l \left| \frac{1}{\bar{w}_n}\sum_{i=1}^{l} w_i \geq \alpha \right. \right\}
+ \f]
+
+ smallest samples (left tail) or the weighted mean of the
+
+ \f[
+ n + 1 - \rho = n + 1 - \sup\left\{ r \left| \frac{1}{\bar{w}_n}\sum_{i=r}^{n} w_i \geq (1 - \alpha) \right. \right\}
+ \f]
+
+ largest samples (right tail), the absolute weighted tail means \f$\widehat{ATM}_{n,\alpha}(X, j)\f$
+ are computed and returned as an iterator range. Alternatively, the relative weighted tail means
+ \f$\widehat{RTM}_{n,\alpha}(X, j)\f$ are returned, which are the absolute weighted tail means
+ normalized with the weighted (non-coherent) sample tail mean \f$\widehat{NCTM}_{n,\alpha}(X)\f$.
+
+ \f[
+ \widehat{ATM}_{n,\alpha}^{\mathrm{right}}(X, j) =
+ \frac{1}{\sum_{i=\rho}^n w_i}
+ \sum_{i=\rho}^n w_i \xi_{j,i}
+ \f]
+
+ \f[
+ \widehat{ATM}_{n,\alpha}^{\mathrm{left}}(X, j) =
+ \frac{1}{\sum_{i=1}^{\lambda}}
+ \sum_{i=1}^{\lambda} w_i \xi_{j,i}
+ \f]
+
+ \f[
+ \widehat{RTM}_{n,\alpha}^{\mathrm{right}}(X, j) =
+ \frac{\sum_{i=\rho}^n w_i \xi_{j,i}}
+ {\sum_{i=\rho}^n w_i \widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X)}
+ \f]
+
+ \f[
+ \widehat{RTM}_{n,\alpha}^{\mathrm{left}}(X, j) =
+ \frac{\sum_{i=1}^{\lambda} w_i \xi_{j,i}}
+ {\sum_{i=1}^{\lambda} w_i \widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X)}
+ \f]
+ */
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // weighted_tail_variate_means_impl
+ // by default: absolute weighted_tail_variate_means
+ template<typename Sample, typename Weight, typename Impl, typename LeftRight, typename VariateType>
+ 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;
+ // for boost::result_of
+ typedef iterator_range<typename array_type::iterator> result_type;
+
+ weighted_tail_variate_means_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ float_type threshold = sum_of_weights(args)
+ * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] );
+
+ std::size_t n = 0;
+ Weight sum = Weight(0);
+
+ while (sum < threshold)
+ {
+ if (n < static_cast<std::size_t>(tail_weights(args).size()))
+ {
+ sum += *(tail_weights(args).begin() + n);
+ n++;
+ }
+ else
+ {
+ if (std::numeric_limits<float_type>::has_quiet_NaN)
+ {
+ std::fill(
+ this->tail_means_.begin()
+ , this->tail_means_.end()
+ , std::numeric_limits<float_type>::quiet_NaN()
+ );
+ }
+ else
+ {
+ std::ostringstream msg;
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ boost::throw_exception(std::runtime_error(msg.str()));
+ }
+ }
+ }
+
+ std::size_t num_variates = tail_variate(args).begin()->size();
+
+ this->tail_means_.clear();
+ this->tail_means_.resize(num_variates, Sample(0));
+
+ this->tail_means_ = std::inner_product(
+ tail_variate(args).begin()
+ , tail_variate(args).begin() + n
+ , tail_weights(args).begin()
+ , this->tail_means_
+ , numeric::functional::plus<array_type const, array_type const>()
+ , numeric::functional::multiply_and_promote_to_double<VariateType const, Weight const>()
+ );
+
+ float_type factor = sum * ( (is_same<Impl, relative>::value) ? non_coherent_weighted_tail_mean(args) : 1. );
+
+ std::transform(
+ this->tail_means_.begin()
+ , this->tail_means_.end()
+ , this->tail_means_.begin()
+ , std::bind2nd(numeric::functional::divides<typename array_type::value_type const, float_type const>(), factor)
+ );
+
+ return make_iterator_range(this->tail_means_);
+ }
+
+ private:
+
+ mutable array_type tail_means_;
+
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::absolute_weighted_tail_variate_means
+// tag::relative_weighted_tail_variate_means
+//
+namespace tag
+{
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct absolute_weighted_tail_variate_means
+ : depends_on<non_coherent_weighted_tail_mean<LeftRight>, tail_variate<VariateType, VariateTag, LeftRight>, tail_weights<LeftRight> >
+ {
+ typedef accumulators::impl::weighted_tail_variate_means_impl<mpl::_1, mpl::_2, absolute, LeftRight, VariateType> impl;
+ };
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct relative_weighted_tail_variate_means
+ : depends_on<non_coherent_weighted_tail_mean<LeftRight>, tail_variate<VariateType, VariateTag, LeftRight>, tail_weights<LeftRight> >
+ {
+ typedef accumulators::impl::weighted_tail_variate_means_impl<mpl::_1, mpl::_2, relative, LeftRight, VariateType> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_tail_variate_means
+// extract::relative_weighted_tail_variate_means
+//
+namespace extract
+{
+ extractor<tag::abstract_absolute_tail_variate_means> const weighted_tail_variate_means = {};
+ extractor<tag::abstract_relative_tail_variate_means> const relative_weighted_tail_variate_means = {};
+}
+
+using extract::weighted_tail_variate_means;
+using extract::relative_weighted_tail_variate_means;
+
+// weighted_tail_variate_means<LeftRight, VariateType, VariateTag>(absolute) -> absolute_weighted_tail_variate_means<LeftRight, VariateType, VariateTag>
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct as_feature<tag::weighted_tail_variate_means<LeftRight, VariateType, VariateTag>(absolute)>
+{
+ typedef tag::absolute_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+};
+
+// weighted_tail_variate_means<LeftRight, VariateType, VariateTag>(relative) -> relative_weighted_tail_variate_means<LeftRight, VariateType, VariateTag>
+template<typename LeftRight, typename VariateType, typename VariateTag>
+struct as_feature<tag::weighted_tail_variate_means<LeftRight, VariateType, VariateTag>(relative)>
+{
+ typedef tag::relative_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+};
+
+}} // namespace boost::accumulators
+
+#ifdef _MSC_VER
+# pragma warning(pop)
+#endif
+
+#endif
Added: branches/release/boost/accumulators/statistics/weighted_variance.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/weighted_variance.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,182 @@
+///////////////////////////////////////////////////////////////////////////////
+// weighted_variance.hpp
+//
+// Copyright 2005 Daniel Egloff, 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_VARIANCE_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_VARIANCE_HPP_EAN_28_10_2005
+
+#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/count.hpp>
+#include <boost/accumulators/statistics/variance.hpp>
+#include <boost/accumulators/statistics/weighted_sum.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+#include <boost/accumulators/statistics/weighted_moment.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ //! Lazy calculation of variance of weighted samples.
+ /*!
+ The default implementation of the variance of weighted samples is based on the second moment
+ \f$\widehat{m}_n^{(2)}\f$ (weighted_moment<2>) and the mean\f$ \hat{\mu}_n\f$ (weighted_mean):
+ \f{
+ \hat{\sigma}_n^2 = \widehat{m}_n^{(2)}-\hat{\mu}_n^2,
+ \f]
+ where \f$n\f$ is the number of samples.
+ */
+ template<typename Sample, typename Weight, typename MeanFeature>
+ struct weighted_variance_impl
+ : accumulator_base
+ {
+ 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;
+
+ weighted_variance_impl(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ extractor<MeanFeature> const some_mean = {};
+ result_type tmp = some_mean(args);
+ return weighted_moment<2>(args) - tmp * tmp;
+ }
+ };
+
+ //! Iterative calculation of variance of weighted samples.
+ /*!
+ Iterative calculation of variance of weighted samples:
+ \f[
+ \hat{\sigma}_n^2 =
+ \frac{\bar{w}_n - w_n}{\bar{w}_n}\hat{\sigma}_{n - 1}^2
+ + \frac{w_n}{\bar{w}_n - w_n}\left(X_n - \hat{\mu}_n\right)^2
+ ,\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
+ \f$n <= 1\f$.
+ */
+ template<typename Sample, typename Weight, typename MeanFeature, typename Tag>
+ struct immediate_weighted_variance_impl
+ : accumulator_base
+ {
+ 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;
+
+ template<typename Args>
+ immediate_weighted_variance_impl(Args const &args)
+ : weighted_variance(numeric::average(args[sample | Sample()], numeric::one<Weight>::value))
+ {
+ }
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ std::size_t cnt = count(args);
+
+ if(cnt > 1)
+ {
+ extractor<MeanFeature> const some_mean = {};
+
+ 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] );
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return this->weighted_variance;
+ }
+
+ private:
+ result_type weighted_variance;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::weighted_variance
+// tag::immediate_weighted_variance
+//
+namespace tag
+{
+ struct weighted_variance
+ : depends_on<weighted_moment<2>, weighted_mean>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::weighted_variance_impl<mpl::_1, mpl::_2, weighted_mean> impl;
+ };
+ struct immediate_weighted_variance
+ : depends_on<count, immediate_weighted_mean>
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::immediate_weighted_variance_impl<mpl::_1, mpl::_2, immediate_weighted_mean, sample> impl;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::weighted_variance
+// extract::immediate_weighted_variance
+//
+namespace extract
+{
+ extractor<tag::weighted_variance> const weighted_variance = {};
+ extractor<tag::immediate_weighted_variance> const immediate_weighted_variance = {};
+}
+
+using extract::weighted_variance;
+using extract::immediate_weighted_variance;
+
+// weighted_variance(lazy) -> weighted_variance
+template<>
+struct as_feature<tag::weighted_variance(lazy)>
+{
+ typedef tag::weighted_variance type;
+};
+
+// weighted_variance(immediate) -> immediate_weighted_variance
+template<>
+struct as_feature<tag::weighted_variance(immediate)>
+{
+ typedef tag::immediate_weighted_variance type;
+};
+
+////////////////////////////////////////////////////////////////////////////
+//// droppable_accumulator<weighted_variance_impl>
+//// need to specialize droppable lazy weighted_variance to cache the result at the
+//// point the accumulator is dropped.
+///// INTERNAL ONLY
+/////
+//template<typename Sample, typename Weight, typename MeanFeature>
+//struct droppable_accumulator<impl::weighted_variance_impl<Sample, Weight, MeanFeature> >
+// : droppable_accumulator_base<
+// with_cached_result<impl::weighted_variance_impl<Sample, Weight, MeanFeature> >
+// >
+//{
+// template<typename Args>
+// droppable_accumulator(Args const &args)
+// : droppable_accumulator::base(args)
+// {
+// }
+//};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics/with_error.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics/with_error.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,44 @@
+///////////////////////////////////////////////////////////////////////////////
+// with_error.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WITH_ERROR_HPP_EAN_01_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WITH_ERROR_HPP_EAN_01_11_2005
+
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/transform_view.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/error_of.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace detail
+{
+ template<typename Feature>
+ struct error_of_tag
+ {
+ typedef tag::error_of<Feature> type;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// with_error
+//
+template<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature)>
+struct with_error
+ : mpl::transform_view<
+ mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
+ , detail::error_of_tag<mpl::_1>
+ >
+{
+};
+
+}} // namespace boost::accumulators
+
+#endif
Added: branches/release/boost/accumulators/statistics_fwd.hpp
==============================================================================
--- (empty file)
+++ branches/release/boost/accumulators/statistics_fwd.hpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,397 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics_fwd.hpp
+//
+// Copyright 2005 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)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_STATISTICS_FWD_HPP_EAN_23_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_STATISTICS_FWD_HPP_EAN_23_11_2005
+
+#include <boost/mpl/apply_fwd.hpp> // for mpl::na
+#include <boost/mpl/print.hpp>
+#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
+#include <boost/accumulators/accumulators_fwd.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+
+namespace boost { namespace accumulators
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// base struct and base extractor for quantiles
+namespace tag
+{
+ struct quantile
+ : depends_on<>
+ {
+ typedef mpl::print<class ____MISSING_SPECIFIC_QUANTILE_FEATURE_IN_ACCUMULATOR_SET____ > impl;
+ };
+}
+namespace extract
+{
+ extractor<tag::quantile> const quantile = {};
+}
+using extract::quantile;
+
+///////////////////////////////////////////////////////////////////////////////
+// base struct and base extractor for *coherent* tail means
+namespace tag
+{
+ struct tail_mean
+ : depends_on<>
+ {
+ typedef mpl::print<class ____MISSING_SPECIFIC_TAIL_MEAN_FEATURE_IN_ACCUMULATOR_SET____ > impl;
+ };
+}
+namespace extract
+{
+ extractor<tag::tail_mean> const tail_mean = {};
+}
+using extract::tail_mean;
+
+namespace tag
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // Variates tags
+ struct weights;
+ struct covariate1;
+ struct covariate2;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Statistic tags
+ struct count;
+ template<typename VariateType, typename VariateTag>
+ struct covariance;
+ struct density;
+ template<typename Feature>
+ struct error_of;
+ struct extended_p_square;
+ struct extended_p_square_quantile;
+ struct extended_p_square_quantile_quadratic;
+ struct kurtosis;
+ struct max;
+ struct mean;
+ struct immediate_mean;
+ struct mean_of_weights;
+ struct immediate_mean_of_weights;
+ template<typename VariateType, typename VariateTag>
+ struct mean_of_variates;
+ template<typename VariateType, typename VariateTag>
+ struct immediate_mean_of_variates;
+ struct median;
+ struct with_density_median;
+ struct with_p_square_cumulative_distribution_median;
+ struct min;
+ template<int N>
+ struct moment;
+ template<typename LeftRight>
+ struct peaks_over_threshold;
+ template<typename LeftRight>
+ struct peaks_over_threshold_prob;
+ template<typename LeftRight>
+ struct pot_tail_mean;
+ template<typename LeftRight>
+ struct pot_tail_mean_prob;
+ template<typename LeftRight>
+ struct pot_quantile;
+ template<typename LeftRight>
+ struct pot_quantile_prob;
+ struct p_square_cumulative_distribution;
+ struct p_square_quantile;
+ struct p_square_quantile_for_median;
+ struct skewness;
+ struct sum;
+ struct sum_of_weights;
+ template<typename VariateType, typename VariateTag>
+ struct sum_of_variates;
+ template<typename LeftRight>
+ struct tail;
+ template<typename LeftRight>
+ struct coherent_tail_mean;
+ template<typename LeftRight>
+ struct non_coherent_tail_mean;
+ template<typename LeftRight>
+ struct tail_quantile;
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct tail_variate;
+ template<typename LeftRight>
+ struct tail_weights;
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct right_tail_variate;
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct left_tail_variate;
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct tail_variate_means;
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct absolute_tail_variate_means;
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct relative_tail_variate_means;
+ struct variance;
+ struct immediate_variance;
+ template<typename VariateType, typename VariateTag>
+ struct weighted_covariance;
+ struct weighted_density;
+ struct weighted_kurtosis;
+ struct weighted_mean;
+ struct immediate_weighted_mean;
+ template<typename VariateType, typename VariateTag>
+ struct weighted_mean_of_variates;
+ template<typename VariateType, typename VariateTag>
+ struct immediate_weighted_mean_of_variates;
+ struct weighted_median;
+ struct with_density_weighted_median;
+ struct with_p_square_cumulative_distribution_weighted_median;
+ struct weighted_extended_p_square;
+ struct weighted_extended_p_square_quantile;
+ struct weighted_extended_p_square_quantile_quadratic;
+ template<int N>
+ struct weighted_moment;
+ template<typename LeftRight>
+ struct weighted_peaks_over_threshold;
+ template<typename LeftRight>
+ struct weighted_peaks_over_threshold_prob;
+ template<typename LeftRight>
+ struct weighted_pot_quantile;
+ template<typename LeftRight>
+ struct weighted_pot_quantile_prob;
+ template<typename LeftRight>
+ struct weighted_pot_tail_mean;
+ template<typename LeftRight>
+ struct weighted_pot_tail_mean_prob;
+ struct weighted_p_square_cumulative_distribution;
+ struct weighted_p_square_quantile;
+ struct weighted_p_square_quantile_for_median;
+ struct weighted_skewness;
+ template<typename LeftRight>
+ struct weighted_tail_quantile;
+ template<typename LeftRight>
+ struct non_coherent_weighted_tail_mean;
+ template<typename LeftRight>
+ struct weighted_tail_quantile;
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct weighted_tail_variate_means;
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct absolute_weighted_tail_variate_means;
+ template<typename LeftRight, typename VariateType, typename VariateTag>
+ struct relative_weighted_tail_variate_means;
+ struct weighted_variance;
+ struct immediate_weighted_variance;
+ struct weighted_sum;
+ template<typename VariateType, typename VariateTag>
+ struct weighted_sum_of_variates;
+} // namespace tag
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // Statistics impls
+ struct count_impl;
+
+ template<typename Sample, typename VariateType, typename VariateTag>
+ struct covariance_impl;
+
+ template<typename Sample>
+ struct density_impl;
+
+ template<typename Sample, typename Feature>
+ struct error_of_impl;
+
+ template<typename Sample, typename Variance>
+ struct error_of_mean_impl;
+
+ template<typename Sample>
+ struct extended_p_square_impl;
+
+ template<typename Sample, typename Impl1, typename Impl2>
+ struct extended_p_square_quantile_impl;
+
+ template<typename Sample>
+ struct kurtosis_impl;
+
+ template<typename Sample>
+ struct max_impl;
+
+ template<typename Sample>
+ struct median_impl;
+
+ template<typename Sample>
+ struct with_density_median_impl;
+
+ template<typename Sample>
+ struct with_p_square_cumulative_distribution_median_impl;
+
+ template<typename Sample>
+ struct min_impl;
+
+ template<typename Sample, typename SumFeature = tag::sum>
+ struct mean_impl;
+
+ template<typename Sample, typename Tag = tag::sample>
+ struct immediate_mean_impl;
+
+ template<typename N, typename Sample>
+ struct moment_impl;
+
+ template<typename Sample, typename LeftRight>
+ struct peaks_over_threshold_prob_impl;
+
+ template<typename Sample, typename Impl, typename LeftRight>
+ struct pot_quantile_impl;
+
+ template<typename Sample, typename Impl, typename LeftRight>
+ struct pot_tail_mean_impl;
+
+ template<typename Sample>
+ struct p_square_cumulative_distribution_impl;
+
+ template<typename Sample, typename Impl>
+ struct p_square_quantile_impl;
+
+ template<typename Sample>
+ struct skewness_impl;
+
+ template<typename Sample, typename Tag = tag::sample>
+ struct sum_impl;
+
+ template<typename Sample, typename LeftRight>
+ struct tail_impl;
+
+ template<typename Sample, typename LeftRight>
+ struct coherent_tail_mean_impl;
+
+ template<typename Sample, typename LeftRight>
+ struct non_coherent_tail_mean_impl;
+
+ template<typename Sample, typename LeftRight>
+ struct tail_quantile_impl;
+
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct tail_variate_impl;
+
+ template<typename Sample, typename Impl, typename LeftRight, typename VariateTag>
+ struct tail_variate_means_impl;
+
+ template<typename Sample, typename MeanFeature>
+ struct variance_impl;
+
+ template<typename Sample, typename MeanFeature, typename Tag>
+ struct immediate_variance_impl;
+
+ template<typename Sample, typename Weight, typename VariateType, typename VariateTag>
+ struct weighted_covariance_impl;
+
+ template<typename Sample, typename Weight>
+ struct weighted_density_impl;
+
+ template<typename Sample, typename Weight>
+ struct weighted_kurtosis_impl;
+
+ template<typename Sample>
+ struct weighted_median_impl;
+
+ template<typename Sample>
+ struct with_density_weighted_median_impl;
+
+ template<typename Sample, typename Weight>
+ struct with_p_square_cumulative_distribution_weighted_median_impl;
+
+ template<typename Sample, typename Weight, typename Tag>
+ struct weighted_mean_impl;
+
+ template<typename Sample, typename Weight, typename Tag>
+ struct immediate_weighted_mean_impl;
+
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct weighted_peaks_over_threshold_impl;
+
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct weighted_peaks_over_threshold_prob_impl;
+
+ template<typename Sample, typename Weight>
+ struct with_p_square_cumulative_distribution_weighted_median_impl;
+
+ template<typename Sample, typename Weight>
+ struct weighted_extended_p_square_impl;
+
+ template<typename N, typename Sample, typename Weight>
+ struct weighted_moment_impl;
+
+ template<typename Sample, typename Weight>
+ struct weighted_p_square_cumulative_distribution_impl;
+
+ template<typename Sample, typename Weight, typename Impl>
+ struct weighted_p_square_quantile_impl;
+
+ template<typename Sample, typename Weight>
+ struct weighted_skewness_impl;
+
+ template<typename Sample, typename Weight, typename Tag>
+ struct weighted_sum_impl;
+
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct non_coherent_weighted_tail_mean_impl;
+
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct weighted_tail_quantile_impl;
+
+ template<typename Sample, typename Weight, typename Impl, typename LeftRight, typename VariateType>
+ struct weighted_tail_variate_means_impl;
+
+ template<typename Sample, typename Weight, typename MeanFeature>
+ struct weighted_variance_impl;
+
+ template<typename Sample, typename Weight, typename MeanFeature, typename Tag>
+ struct immediate_weighted_variance_impl;
+
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// stats
+// A more descriptive name for an MPL sequence of statistics.
+template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
+struct stats;
+
+template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
+struct with_error;
+
+// modifiers for the mean and variance stats
+struct lazy {};
+struct immediate {};
+
+// modifiers for the variance stat
+// struct fast {};
+// struct accurate {};
+
+// modifiers for order
+struct right {};
+struct left {};
+// typedef right default_order_tag_type;
+
+// modifiers for the tail_variate_means stat
+struct absolute {};
+struct relative {};
+
+// modifiers for median and weighted_median stats
+struct with_density {};
+struct with_p_square_cumulative_distribution {};
+struct with_p_square_quantile {};
+
+// modifiers for peaks_over_threshold stat
+struct with_threshold_value {};
+struct with_threshold_probability {};
+
+// modifiers for extended_p_square_quantile and weighted_extended_p_square_quantile stats
+struct weighted {};
+struct unweighted {};
+struct linear {};
+struct quadratic {};
+
+// modifiers for p_square_quantile
+struct regular {};
+struct for_median {};
+
+}} // namespace boost::accumulators
+
+#endif
Modified: branches/release/doc/Jamfile.v2
==============================================================================
--- branches/release/doc/Jamfile.v2 (original)
+++ branches/release/doc/Jamfile.v2 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -12,6 +12,10 @@
:
## Build the various generated docs (Doxygen and QuickBook)...
+ <dependency>../libs/accumulators/doc//accdoc.xml
+ <dependency>../libs/accumulators/doc//statsdoc.xml
+ <dependency>../libs/accumulators/doc//opdoc.xml
+ <dependency>../libs/accumulators/doc//accumulators
<dependency>../libs/program_options/doc//autodoc.xml
<dependency>../libs/algorithm/string/doc//autodoc.xml
<dependency>../libs/logic/doc//reference.xml
@@ -40,6 +44,7 @@
## Add path references to the QuickBook generated docs...
+ <implicit-dependency>../libs/accumulators/doc//accumulators
<implicit-dependency>../libs/functional/hash/doc//hash
#<implicit-dependency>../libs/type_traits/doc//type_traits
<implicit-dependency>../libs/static_assert/doc//static_assert
Modified: branches/release/doc/src/boost.xml
==============================================================================
--- branches/release/doc/src/boost.xml (original)
+++ branches/release/doc/src/boost.xml 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -49,6 +49,8 @@
<part id="libraries">
<title>The Boost C++ Libraries (BoostBook Subset)</title>
+ <xi:include href="accumulators.xml"/>
+
<xi:include href="../../libs/any/doc/any.xml"/>
<xi:include href="../../libs/array/doc/array.xml"/>
Added: branches/release/libs/accumulators/doc/Jamfile.v2
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/doc/Jamfile.v2 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,188 @@
+# Copyright Eric Niebler 2005. Use, modification, and distribution are
+# subject to 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)
+
+import os ;
+import common ;
+import doxygen ;
+import quickbook ;
+
+# Use Doxygen to emimt a tagfile with the definition of depends_on<>.
+# That tagfile will be used by Doxygen below when generating the Statistics
+# Library Reference. This is all so that the Doxygen-generated documentation
+# for the features shows the dependency relationships between them.
+doxygen tagfile
+ :
+ ../../../boost/accumulators/framework/depends_on.hpp
+ ../../../boost/accumulators/framework/extractor.hpp
+ :
+ <doxygen:param>MACRO_EXPANSION=YES
+ <doxygen:param>EXPAND_ONLY_PREDEF=YES
+ <doxygen:param>GENERATE_TAGFILE=accumulators.tag
+ <doxygen:param>"PREDEFINED=\"BOOST_ACCUMULATORS_DOXYGEN_INVOKED=1\" \\
+ \"BOOST_PP_REPEAT_FROM_TO(a,b,c,d)=\" \\
+ \"BOOST_PP_ENUM_PARAMS(a,b)=b ## 1, b ## 2, ...\""
+ ;
+
+doxygen accdoc
+ :
+ [ glob ../../../boost/accumulators/accumulators*.hpp ]
+ [ glob ../../../boost/accumulators/framework/*.hpp ]
+ [ glob ../../../boost/accumulators/framework/parameters/*.hpp ]
+ [ glob ../../../boost/accumulators/framework/accumulators/*.hpp ]
+ :
+ <doxygen:param>EXTRACT_ALL=YES
+ <doxygen:param>"PREDEFINED=\"BOOST_ACCUMULATORS_DOXYGEN_INVOKED=1\" \\
+ \"BOOST_PP_REPEAT_FROM_TO(a,b,c,d)=\" \\
+ \"BOOST_PP_REPEAT(a,b,c)=\" \\
+ \"BOOST_PARAMETER_KEYWORD(a,b)=\\
+ namespace a { struct b {}; } \\
+ boost::parameter::keyword<a::b> const b;\" \\
+ \"BOOST_PP_ENUM_PARAMS(a,b)=b ## 1, b ## 2, ...\""
+ <doxygen:param>HIDE_UNDOC_MEMBERS=NO
+ <doxygen:param>EXTRACT_PRIVATE=NO
+ <doxygen:param>ENABLE_PREPROCESSING=YES
+ <doxygen:param>MACRO_EXPANSION=YES
+ <doxygen:param>EXPAND_ONLY_PREDEF=YES
+ <doxygen:param>SEARCH_INCLUDES=NO
+ <reftitle>"Accumulators Framework Reference"
+ ;
+
+# Generate the HTML form of the stats documentation, as this
+# causes Doxygen to generate .png images for the LaTeX formulas
+# embedded in the doc comments.
+doxygen statsdoc.html
+ :
+ [ glob ../../../boost/accumulators/statistics*.hpp ]
+ [ glob ../../../boost/accumulators/statistics/*.hpp ]
+ [ glob ../../../boost/accumulators/statistics/variates/*.hpp ]
+ ;
+
+if [ os.name ] = NT
+{
+ CP = copy /y ;
+ MKDIR = mkdir ;
+ FROM = \\..\\..\\html\\statsdoc\\*.png ;
+ TOHTML = .\\html\\images\\accumulators ;
+ TOPDF = \\images\\accumulators ;
+}
+else
+{
+ CP = cp ;
+ MKDIR = mkdir -p ;
+ FROM = /../../html/statsdoc/*.png ;
+ TOHTML = ./html/images/accumulators ;
+ TOPDF = /images/accumulators ;
+}
+
+actions copy-latex-pngs
+{
+ $(MKDIR) $(TOHTML)
+ $(MKDIR) $(<:D)$(TOPDF)
+ $(CP) $(<:D)$(FROM) $(TOHTML)
+ $(CP) $(<:D)$(FROM) $(<:D)$(TOPDF)
+ echo "Stamped" > "$(<)"
+}
+
+# This causes the png files built above to be copied
+# into the html/images/accumulators directory.
+make statsdoclatex.tag
+ : statsdoc.html
+ : @copy-latex-pngs
+ ;
+
+doxygen statsdoc
+ :
+ [ glob ../../../boost/accumulators/statistics*.hpp ]
+ [ glob ../../../boost/accumulators/statistics/*.hpp ]
+ [ glob ../../../boost/accumulators/statistics/variates/*.hpp ]
+ :
+ <doxygen:param>EXTRACT_ALL=YES
+ <doxygen:param>"PREDEFINED=\"BOOST_ACCUMULATORS_DOXYGEN_INVOKED=1\" \\
+ \"BOOST_PP_REPEAT_FROM_TO(a,b,c,d)=\" \\
+ \"BOOST_PP_REPEAT(a,b,c)=\" \\
+ \"BOOST_PARAMETER_KEYWORD(a,b)=\\
+ namespace a { struct b {}; } \\
+ boost::parameter::keyword<a::b> const b;\" \\
+ \"BOOST_PP_ENUM_PARAMS(a,b)=b ## 1, b ## 2, ...\""
+ <doxygen:param>HIDE_UNDOC_MEMBERS=NO
+ <doxygen:param>EXTRACT_PRIVATE=NO
+ <doxygen:param>ENABLE_PREPROCESSING=YES
+ <doxygen:param>MACRO_EXPANSION=YES
+ <doxygen:param>EXPAND_ONLY_PREDEF=YES
+ <doxygen:param>SEARCH_INCLUDES=NO
+ <doxygen:param>TAGFILES=accumulators.tag
+ <xsl:param>boost.doxygen.formuladir=images/accumulators/
+ <reftitle>"Statistics Library Reference"
+ <dependency>tagfile
+ <dependency>statsdoclatex.tag
+ ;
+
+doxygen opdoc
+ :
+ [ glob ../../../boost/accumulators/numeric/functional.hpp ]
+ [ glob ../../../boost/accumulators/numeric/functional/*.hpp ]
+ :
+ <doxygen:param>EXTRACT_ALL=YES
+ <doxygen:param>"PREDEFINED=\"BOOST_NUMERIC_FUNCTIONAL_DOXYGEN_INVOKED=1\" \\
+ \"BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(a,b,c)=\\
+ namespace functional { \\
+ template<class Left,class Right,class EnableIf=void> struct a ## _base \\
+ : std::binary_function<Left, Right, typeof(lvalue<Left>() b lvalue<Right>())> { \\
+ /** \\return left b right */ \\
+ result_type operator()(Left &left, Right &right) const; }; \\
+ template<class Left,class Right, \\
+ class LeftTag=typename tag<Left>::type, \\
+ class RightTag=typename tag<Right>::type> \\
+ struct a : a ## _base<Left,Right,void> {}; } \\
+ namespace op { \\
+ struct a : boost::detail::function2< \\
+ functional::a<_1,_2,functional::tag<_1>,functional::tag<_2> > > {}; } \\
+ namespace { \\
+ /** \\return functional::a<Left, Right>()(left, right) */ \\
+ op::a const & a = boost::detail::pod_singleton<op::min_assign>::instance; } \" \\
+ \"BOOST_NUMERIC_FUNCTIONAL_DEFINE_UNARY_OP(a,b)=\\
+ namespace functional { \\
+ template<class Arg,class EnableIf=void> struct a ## _base \\
+ : std::unary_function<Arg, typeof(b lvalue<Arg>())> { \\
+ /** \\return b arg */ \\
+ result_type operator()(Arg & arg) const; }; \\
+ template<class Arg,class Tag=typename tag<Arg>::type> \\
+ struct a : a ## _base<Arg,void> {}; } \\
+ namespace op { \\
+ struct a : boost::detail::function1< \\
+ functional::a<_,functional::tag<_> > > {}; } \\
+ namespace { \\
+ /** \\return functional::a<Arg>()(arg) */ \\
+ op::a const & a = boost::detail::pod_singleton<op::min_assign>::instance; }\""
+ <doxygen:param>HIDE_UNDOC_MEMBERS=NO
+ <doxygen:param>EXTRACT_PRIVATE=NO
+ <doxygen:param>ENABLE_PREPROCESSING=YES
+ <doxygen:param>MACRO_EXPANSION=YES
+ <doxygen:param>EXPAND_ONLY_PREDEF=YES
+ <doxygen:param>SEARCH_INCLUDES=NO
+ <reftitle>"Numeric Operators Library Reference"
+ ;
+
+xml accumulators
+ :
+ accumulators.qbk
+ :
+ <xsl:param>boost.max.id.length=1024
+ <xsl:param>toc.max.depth=4
+ <xsl:param>toc.section.depth=4
+ <xsl:param>chunk.section.depth=2
+ ;
+
+boostbook standalone
+ :
+ accumulators
+ :
+ <xsl:param>boost.max.id.length=1024
+ <xsl:param>toc.max.depth=4
+ <xsl:param>toc.section.depth=4
+ <xsl:param>chunk.section.depth=2
+ <dependency>accdoc
+ <dependency>statsdoc
+ <dependency>opdoc
+ ;
Added: branches/release/libs/accumulators/doc/accumulators.qbk
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/doc/accumulators.qbk 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,3208 @@
+
+[library Boost.Accumulators
+ [quickbook 1.3]
+ [authors [Niebler, Eric]]
+ [copyright 2005 2006 Eric Niebler]
+ [category math]
+ [id accumulators]
+ [dirname accumulators]
+ [purpose
+ Incremental accumulation framework and statistical accumulator library.
+ ]
+ [license
+ 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])
+ ]
+]
+
+[/ Images ]
+
+[def _note_ [$images/note.png]]
+[def _alert_ [$images/caution.png]]
+[def _detail_ [$images/note.png]]
+[def _tip_ [$images/tip.png]]
+
+[/ Links ]
+
+[def _sample_type_ '''<replaceable>sample-type</replaceable>''']
+[def _weight_type_ '''<replaceable>weight-type</replaceable>''']
+[def _variate_type_ '''<replaceable>variate-type</replaceable>''']
+[def _variate_tag_ '''<replaceable>variate-tag</replaceable>''']
+[def _left_or_right_ '''<replaceable>left-or-right</replaceable>''']
+[def _implementation_defined_ '''<replaceable>implementation-defined</replaceable>''']
+[def _boost_ [@http://www.boost.org Boost]]
+[def _mpl_ [@../../libs/mpl MPL]]
+[def _mpl_lambda_expression_ [@../../libs/mpl/doc/refmanual/lambda-expression.html MPL Lambda Expression]]
+[def _parameter_ [@../../libs/parameter Boost.Parameter]]
+[def _accumulator_set_ [classref boost::accumulators::accumulator_set `accumulator_set<>`]]
+[def _accumulator_base_ [classref boost::accumulators::accumulator_base `accumulator_base`]]
+[def _depends_on_ [classref boost::accumulators::depends_on `depends_on<>`]]
+[def _feature_of_ [classref boost::accumulators::feature_of `feature_of<>`]]
+[def _as_feature_ [classref boost::accumulators::as_feature `as_feature<>`]]
+[def _features_ [classref boost::accumulators::features `features<>`]]
+[def _external_ [classref boost::accumulators::external `external<>`]]
+[def _droppable_ [classref boost::accumulators::droppable `droppable<>`]]
+[def _droppable_accumulator_ [classref boost::accumulators::droppable_accumulator `droppable_accumulator<>`]]
+[def _extractor_ [classref boost::accumulators::tag::extractor `extractor<>`]]
+[def _tail_ [classref boost::accumulators::tag::tail `tail`]]
+[def _tail_variate_ [classref boost::accumulators::tag::tail_variate `tail_variate<>`]]
+[def _extract_result_ [funcref boost::accumulators::extract_result `extract_result()`]]
+[def _ZKB_ [@http://www.zkb.com Z'''ü'''rcher Kantonalbank]]
+
+[section Preface]
+
+[:["It is better to be approximately right than exactly wrong.]\n['-- Old adage]]
+
+[h2 Description]
+
+Boost.Accumulators is both a library for incremental statistical computation as
+well as an extensible framework for incremental calculation in general. The library
+deals primarily with the concept of an ['accumulator], which is a primitive
+computational entity that accepts data one sample at a time and maintains some
+internal state. These accumulators may offload some of their computations on other
+accumulators, on which they depend. Accumulators are grouped within an ['accumulator
+set]. Boost.Accumulators resolves the inter-dependencies between accumulators in a
+set and ensures that accumulators are processed in the proper order.
+
+[endsect]
+
+[section User's Guide]
+
+This section describes how to use the Boost.Accumulators framework to create new
+accumulators and how to use the existing statistical accumulators to perform incremental
+statistical computation. For detailed information regarding specific components in
+Boost.Accumulators, check the [link accumulators_framework_reference Reference] section.
+
+[h2 Hello, World!]
+
+Below is a complete example of how to use the Accumulators Framework and the
+Statistical Accumulators to perform an incremental statistical calculation. It
+calculates the mean and 2nd moment of a sequence of doubles.
+
+ #include <iostream>
+ #include <boost/accumulators/accumulators.hpp>
+ #include <boost/accumulators/statistics/stats.hpp>
+ #include <boost/accumulators/statistics/mean.hpp>
+ #include <boost/accumulators/statistics/moment.hpp>
+ using namespace boost::accumulators;
+
+ int main()
+ {
+ // Define an accumulator set for calculating the mean and the
+ // 2nd moment ...
+ accumulator_set<double, stats<tag::mean, tag::moment<2> > > acc;
+
+ // push in some data ...
+ acc(1.2);
+ acc(2.3);
+ acc(3.4);
+ acc(4.5);
+
+ // Display the results ...
+ std::cout << "Mean: " << mean(acc) << std::endl;
+ std::cout << "Moment: " << moment<2>(acc) << std::endl;
+
+ return 0;
+ }
+
+This program displays the following:
+
+[pre
+Mean: 2.85
+Moment: 9.635
+]
+
+[section The Accumulators Framework]
+
+The Accumulators Framework is framework for performing incremental calculations. Usage
+of the framework follows the following pattern:
+
+* Users build a computational object, called an ['_accumulator_set_], by selecting
+ the computations in which they are interested, or authoring their own computational
+ primitives which fit within the framework.
+* Users push data into the _accumulator_set_ object one sample at a time.
+* The _accumulator_set_ computes the requested quantities in the most efficient method
+ possible, resolving dependencies between requested calculations, possibly cacheing
+ intermediate results.
+
+The Accumulators Framework defines the utilities needed for defining primitive
+computational elements, called ['accumulators]. It also provides the _accumulator_set_
+type, described above.
+
+[h2 Terminology]
+
+The following terms are used in the rest of the documentation.
+
+[variablelist
+ [[Sample] [[#sample_type] A datum that is pushed into an _accumulator_set_.
+ The type of the sample is the ['sample type].]]
+ [[Weight] [[#weight_type] An optional scalar value passed along with the
+ sample specifying the weight of the sample. Conceptually, each
+ sample is multiplied with its weight. The type of the weight is
+ the ['weight type].]]
+ [[Feature] [An abstract primitive computational entity. When defining an
+ _accumulator_set_, users specify the features in which they are
+ interested, and the _accumulator_set_ figures out which
+ ['accumulators] would best provide those features. Features may
+ depend on other features. If they do, the accumulator set figures
+ out which accumulators to add to satisfy the dependencies.]]
+ [[Accumulator] [A concrete primitive computational entity. An accumulator is a
+ concrete implementation of a feature. It satisfies exactly one
+ abstract feature. Several different accumulators may provide the
+ same feature, but may represent different implementation strategies.]]
+ [[Accumulator Set] [A collection of accumulators. An accumulator set is specified with
+ a sample type and a list of features. The accumulator set uses this
+ information to generate an ordered set of accumulators depending on
+ the feature dependency graph. An accumulator set accepts samples one
+ datum at a time, propogating them to each accumulator in order. At any
+ point, results can be extracted from the accumulator set.]]
+ [[Extractor] [A function or function object that can be used to extract a result
+ from an _accumulator_set_.]]
+]
+
+[h2 Overview]
+
+Here is a list of the important types and functions in the Accumulator Framework and
+a brief description of each.
+
+[table Accumulators Toolbox
+ [[Tool] [Description]]
+ [[_accumulator_set_] [This is the most important type in the Accumulators Framework.
+ It is a collection of accumulators. A datum pushed into an
+ _accumulator_set_ is forwarded to each accumulator, in an order
+ determined by the dependency relationships between the
+ accumulators. Computational results can be extracted from an
+ accumulator at any time.]]
+ [[_depends_on_ ] [Used to specify which other features a feature depends on.]]
+ [[_feature_of_ ] [Trait used to tell the Accumulators Framework that, for the purpose
+ of feature-based dependency resolution, one feature should be
+ treated the same as another.]]
+ [[_as_feature_ ] [Used to create an alias for a feature. For example, if there are
+ two features, fast_X and accurate_X, they can be mapped to
+ X(fast) and X(accurate) with _as_feature_. This is just syntactic
+ sugar.]]
+ [[_features_ ] [An _mpl_ sequence. We can use _features_ as the second template
+ parameter when declaring an _accumulator_set_.]]
+ [[_external_ ] [Used when declaring an _accumulator_set_. If the weight type is
+ specified with _external_, then the weight accumulators are
+ assumed to reside in a separate accumulator set which will be passed
+ in with a named parameter.]]
+ [[_extractor_ ] [A class template useful for creating an extractor function object.
+ It is parameterized on a feature, and it has member functions for
+ extracting from an _accumulator_set_ the result corresponding to
+ that feature.]]
+]
+
+[section Using [^accumulator_set<>]]
+
+Our tour of the _accumulator_set_ class template begins with the forward declaration:
+
+ template< typename Sample, typename Features, typename Weight = void >
+ struct accumulator_set;
+
+The template parameters have the following meaning:
+
+[variablelist
+ [[`Sample`] [The type of the data that will be accumulated.]]
+ [[`Features`] [An _mpl_ sequence of features to be calculated.]]
+ [[`Weight`] [The type of the (optional) weight paramter.]]
+]
+
+For example, the following line declares an _accumulator_set_ that will accept
+a sequence of doubles one at a time and calculate the min and mean:
+
+ accumulator_set< double, features< tag::min, tag::mean > > acc;
+
+Notice that we use the _features_ template to specify a list of features to be calculated.
+_features_ is an MPL sequence of features.
+
+[note _features_ is a synonym of `mpl::vector<>`. In fact, we could use `mpl::vector<>`
+ or any MPL sequence if we prefer, and the meaning would be the same.]
+
+Once we have defined an _accumulator_set_, we can then push data into it,
+and it will calculate the quantities you requested, as shown below.
+
+ // push some data into the accumulator_set ...
+ acc(1.2);
+ acc(2.3);
+ acc(3.4);
+
+Since _accumulator_set_ defines its accumulate function to be the function call operator,
+we might be tempted to use an _accumulator_set_ as a UnaryFunction to a standard
+algorithm such as `std::for_each`. That's fine as long as we keep in mind that the standard
+algorithms take UnaryFunction objects by value, which involves making a copy of the
+_accumulator_set_ object. Consider the following:
+
+ // The data for which we wish to calculate statistical properties:
+ std::vector< double > data( /* stuff */ );
+
+ // The accumulator set which will calculate the properties for us:
+ accumulator_set< double, features< tag::min, tag::mean > > acc;
+
+ // Use std::for_each to accumulate the statistical properties:
+ acc = std::for_each( data.begin(), data.end(), acc );
+
+Notice how we must assign the return value of `std::for_each` back to the _accumulator_set_.
+This works, but some accumulators are not cheap to copy. For
+example, the _tail_ and _tail_variate_ accumulators must store a `std::vector<>`, so copying
+these accumulators involves a dynamic allocation. We might be better off in this
+case passing the accumulator by reference, with the help of `boost::bind()` and
+`boost::ref()`. See below:
+
+ // The data for which we wish to calculate statistical properties:
+ std::vector< double > data( /* stuff */ );
+
+ // The accumulator set which will calculate the properties for us:
+ accumulator_set< double, features< tag::tail<left> > > acc(
+ tag::tail<left>::cache_size = 4 );
+
+ // Use std::for_each to accumulate the statistical properties:
+ std::for_each( data.begin(), data.end(), bind<void>( ref(acc), _1 ) );
+
+Notice now that we don't care about the return value of `std::for_each()` anymore because
+`std::for_each()` is modifying `acc` directly.
+
+[note To use `boost::bind()` and `boost::ref()`, you must `#include` [^<boost/bind.hpp>]
+and [^<boost/ref.hpp>]]
+
+[endsect]
+
+[section Extracting Results]
+
+Once we have declared an _accumulator_set_ and pushed data into it, we need to be able
+to extract results from it. For each feature we can add to an _accumulator_set_, there
+is a corresponding extractor for fetching its result. Usually, the extractor has the
+same name as the feature, but in a different namespace. For example, if we accumulate
+the `tag::min` and `tag::max` features, we can extract the results with the `min` and `max`
+extractors, as follows:
+
+ // Calculate the minimum and maximum for a sequence of integers.
+ accumulator_set< int, features< tag::min, tag::max > > acc;
+ acc( 2 );
+ acc( -1 );
+ acc( 1 );
+
+ // This displays "(-1, 2)"
+ std::cout << '(' << min( acc ) << ", " << max( acc ) << ")\n";
+
+The extractors are all declared in the `boost::accumulators::extract` namespace, but they
+are brought into the `boost::accumulators` namespace with a `using` declaration.
+
+[tip On the Windows platform, `min` and `max` are preprocessor macros defined in [^WinDef.h].
+ To use the `min` and `max` extractors, you should either compile with `NOMINMAX` defined, or
+ you should invoke the extractors like: `(min)( acc )` and `(max)( acc )`. The parentheses
+ keep the macro from being invoked.]
+
+Another way to extract a result from an _accumulator_set_ is with the
+`extract_result()` function. This can be more convenient if there isn't an extractor
+object handy for a certain feature. The line above which displays results could
+equally be written as:
+
+ // This displays "(-1, 2)"
+ std::cout << '(' << extract_result< tag::min >( acc )
+ << ", " << extract_result< tag::max >( acc ) << ")\n";
+
+Finally, we can define our own extractor using the _extractor_ class template. For
+instance, another way to avoid the `min` / `max` macro business would be to define
+extractors with names that don't conflict with the macros, like this:
+
+ extractor< tag::min > min_;
+ extractor< tag::min > max_;
+
+ // This displays "(-1, 2)"
+ std::cout << '(' << min_( acc ) << ", " << max_( acc ) << ")\n";
+
+[endsect]
+
+[section Passing Optional Parameters]
+
+Some accumulators need initialization parameters. In addition, perhaps some auxiliary
+information needs to be passed into the _accumulator_set_ along with each sample.
+Boost.Accumulators handles these cases with named parameters from the _parameter_
+library.
+
+For example, consider the _tail_ and _tail_variate_ features. _tail_ keeps
+an ordered list of the largest [^['N]] samples, where [^['N]] can be specified at
+construction time. Also, the _tail_variate_ feature, which depends on _tail_, keeps
+track of some data that is covariate with the [^['N]] samples tracked by _tail_. The
+code below shows how this all works, and is described in more detail below.
+
+ // Define a feature for tracking covariate data
+ typedef tag::tail_variate< int, tag::covariate1, left > my_tail_variate_tag;
+
+ // This will calculate the left tail and my_tail_variate_tag for N == 2
+ // using the tag::tail<left>::cache_size named parameter
+ accumulator_set< double, features< my_tail_variate_tag > > acc(
+ tag::tail<left>::cache_size = 2 );
+
+ // push in some samples and some covariates by using
+ // the covariate1 named parameter
+ acc( 1.2, covariate1 = 12 );
+ acc( 2.3, covariate1 = -23 );
+ acc( 3.4, covariate1 = 34 );
+ acc( 4.5, covariate1 = -45 );
+
+ // Define an extractor for the my_tail_variate_tag feature
+ extractor< my_tail_variate_tag > my_tail_variate;
+
+ // Write the tail statistic to std::cout. This will print "4.5, 3.4, "
+ std::ostream_iterator< double > dout( std::cout, ", " );
+ std::copy( tail( acc ).begin(), tail( acc ).end(), dout );
+
+ // Write the tail_variate statistic to std::cout. This will print "-45, 34, "
+ std::ostream_iterator< int > iout( std::cout, ", " );
+ std::copy( my_tail_variate( acc ).begin(), my_tail_variate( acc ).end(), iout );
+
+There are several things to note about the code above. First, notice that we didn't have
+to request that the _tail_ feature be calculated. That is implicit because the _tail_variate_
+feature depends on the _tail_ feature. Next, notice how the `acc` object
+is initialized: `acc( tag::tail<left>::cache_size = 2 )`. Here, `cache_size` is a named parameter.
+It is used to tell the _tail_ and _tail_variate_ accumulators how many samples and
+covariates to store. Conceptually, every construction parameter is made available to
+every accumulator in an accumulator set.
+
+We also use a named parameter to pass covariate data into the accumulator set along with
+the samples. As with the constructor parameters, all parameters to the accumulate function
+are made available to all the accumulators in the set. In this case, only the accumulator
+for the `my_tail_variate` feature would be interested in the value of the `covariate1` named
+parameter.
+
+We can make one final observation about the example above. Since _tail_ and _tail_variate_
+are multi-valued features, the result we extract for them is represented as an iterator
+range. That is why we can say `tail( acc ).begin()` and `tail( acc ).end()`.
+
+Even the extractors can accept named parameters. In a bit, we'll see a situation where that
+is useful.
+
+[endsect]
+
+[section Weighted Samples]
+
+Some accumulators, statistical accumulators in particular, deal with data that are
+['weighted]. Each sample pushed into the accumulator has an associated weight, by which
+the sample is conceptually multiplied. The Statistical Accumulators Library provides an
+assortment of these weighted statistical accumulators. And many unweighted statistical
+accumulators have weighted variants. For instance, the weighted variant of the `sum`
+accumulator is called `weighted_sum`, and is calculated by accumulating all the
+samples multiplied by their weights.
+
+To declare an _accumulator_set_ that accepts weighted samples, you must specify the
+type of the weight parameter as the 3rd template parameter, as follows:
+
+ // 3rd template parameter 'int' means this is a weighted
+ // accumulator set where the weights have type 'int'
+ accumulator_set< int, features< tag::sum >, int > acc;
+
+When you specify a weight, all the accumulators in the set are replaced with
+their weighted equivalents. For example, the above _accumulator_set_ declaration
+is equivalent to the following:
+
+ // Since we specified a weight, tag::sum becomes tag::weighted_sum
+ accumulator_set< int, features< tag::weighted_sum >, int > acc;
+
+When passing samples to the accumulator set, you must also specify the
+weight of each sample. You can do that with the `weight` named parameter,
+as follows:
+
+ acc(1, weight = 2); // 1 * 2
+ acc(2, weight = 4); // 2 * 4
+ acc(3, weight = 6); // + 3 * 6
+ // -------
+ // = 28
+
+You can then extract the result with the `sum()` extractor, as follows:
+
+ // This prints "28"
+ std::cout << sum(acc) << std::endl;
+
+[note When working with weighted statistical accumulators from the Statistical
+Accumulators Library, be sure to include the appropriate header. For instance,
+`weighted_sum` is defined in `<boost/accumulators/statistics/weighted_sum.hpp>`.]
+
+[endsect]
+
+[section Numeric Operators Sub-Library]
+
+This section describes the function objects in the `boost::numeric` namespace, which
+is a sub-library that provides function objects and meta-functions corresponding
+to the infix operators in C++.
+
+In the `boost::numeric::operators` namespace are additional operator overloads for
+some useful operations not provided by the standard library, such as multiplication
+of a `std::complex<>` with a scalar.
+
+In the `boost::numeric::functional` namespace are function object equivalents of
+the infix operators. These function object types are heterogeneous, and so are more
+general than the standard ones found in the [^<functional>] header. They use the
+Boost.Typeof library to deduce the return types of the infix expressions they
+evaluate. In addition, they look within the `boost::numeric::operators` namespace
+to consider any additional overloads that might be defined there.
+
+In the `boost::numeric` namespace are global polymorphic function objects
+corresponding to the function object types defined in the `boost::numeric::functional`
+namespace. For example, `boost::numeric::plus(a, b)` is equivalent to
+`boost::numeric::functional::plus<A, B>()(a, b)`, and both are equivalent to
+`using namespace boost::numeric::operators; a + b;`.
+
+The Numeric Operators Sub-Library also gives several ways to sub-class and
+a way to sub-class and specialize operations. One way uses tag dispatching on
+the types of the operands. The other way is based on the compile-time
+properties of the operands.
+
+[endsect]
+
+[section Extending the Accumulators Framework]
+
+This section describes how to extend the Accumulators Framework by defining new accumulators,
+features and extractors. Also covered are how to control the dependency resolution of
+features within an accumulator set.
+
+[section Defining a New Accumulator]
+
+All new accumulators must satisfy the [link
+accumulators.user_s_guide.the_accumulators_framework.concepts.accumulator_concept Accumulator
+Concept]. Below is a sample class that satisfies the accumulator concept, which simply sums
+the values of all samples passed into it.
+
+ #include <boost/accumulators/framework/accumulator_base.hpp>
+ #include <boost/accumulators/framework/parameters/sample.hpp>
+
+ namespace boost { // Putting your accumulators in the
+ namespace accumulators { // impl namespace has some
+ namespace impl { // advantages. See below.
+
+ template<typename Sample>
+ struct sum_accumulator // All accumulators should inherit from
+ : accumulator_base // accumulator_base.
+ {
+ typedef Sample result_type; // The type returned by result() below.
+
+ template<typename Args> // The constructor takes an argument pack.
+ sum_accumulator(Args const & args)
+ : sum(args[sample | Sample()]) // Maybe there is an initial value in the
+ { // argument pack. ('sample' is defined in
+ } // sample.hpp, included above.)
+
+ template<typename Args> // The accumulate function is the function
+ void operator ()(Args const & args) // call operator, and it also accepts an
+ { // argument pack.
+ this->sum += args[sample];
+ }
+
+ result_type result(dont_care) const // The result function will also be passed
+ { // an argument pack, but we don't use it here,
+ return this->sum; // so we use "dont_care" as the argument type.
+ }
+ private:
+ Sample sum;
+ };
+
+ }}}
+
+Much of the above should be pretty self-explanitory, except for the use of argument packs
+which may be confusing if you have never used the _parameter_ library before. An argument
+pack is a cluster of values, each of which can be accessed with a key. So `args[sample]`
+extracts from the pack the value associated with the `sample` key. And the cryptic
+`args[sample | Sample()]` evaluates to the value associated with the `sample` key if it
+exists, or a default-constructed `Sample` if it doesn't.
+
+The example above demonstrates the most common attributes of an accumulator. There are
+other optional member functions that have special meaning. In particular:
+
+[variablelist Optional Accumulator Member Functions
+[[[^on_drop(Args)]] [Defines an action to be taken when this accumulator is
+ dropped. See the section on
+ [link accumulators.user_s_guide.the_accumulators_framework.extending_the_accumulators_framework.defining_a_new_accumulator.droppable_accumulators
+ Droppable Accumulators].]]
+]
+
+[h3 Accessing Other Accumulators in the Set]
+
+Some accumulators depend on other accumulators within the same accumulator set. In those
+cases, it is necessary to be able to access those other accumulators. To make this possible,
+the _accumulator_set_ passes a reference to itself when invoking the member functions of
+its contained accumulators. It can be accessed by using the special `accumulator` key with
+the argument pack. Consider how we might implement `mean_accumulator`:
+
+ // Mean == (Sum / Count)
+ template<typename Sample>
+ struct mean_accumulator : accumulator_base
+ {
+ typedef Sample result_type;
+ mean_accumulator(dont_care) {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return sum(args[accumulator]) / count(args[accumulator]);
+ }
+ };
+
+`mean` depends on the `sum` and `count` accumulators. (We'll see in the next section how
+to specify these dependencies.) The result of the mean accumulator is merely the result of
+the sum accumulator divided by the result of the count accumulator. Consider how we write
+that: `sum(args[accumulator]) / count(args[accumulator])`. The expression `args[accumulator]`
+evaluates to a reference to the _accumulator_set_ that contains this `mean_accumulator`. It
+also contains the `sum` and `count` accumulators, and we can access their results with the
+extractors defined for those features: `sum` and `count`.
+
+[note Accumulators that inherit from _accumulator_base_ get an empty `operator ()`, so
+ accumulators like `mean_accumulator` above need not define one.]
+
+All the member functions that accept an argument pack have access to the enclosing
+_accumulator_set_ via the `accumulator` key, including the constructor. The
+accumulators within the set are constructed in an order determined by their interdependencies.
+As a result, it is safe for an accumulator to access one on which it depends during construction.
+
+[h3 Infix Notation and the Numeric Operators Sub-Library]
+
+Although not necessary, it can be a good idea to put your accumulator implementations in
+the `boost::accumulators::impl` namespace. This namespace pulls in any operators defined
+in the `boost::numeric::operators` namespace with a using directive. The Numeric Operators
+Sub-Library defines some additional overloads that will make your accumulators work with
+all sorts of data types.
+
+Consider `mean_accumulator` defined above. It divides the sum of the samples by the count.
+The type of the count is `std::size_t`. What if the sample type doesn't define division by
+`std::size_t`? That's the case for `std::complex<>`. You might think that if the sample type
+is `std::complex<>`, the code would not work, but in fact it does. That's because
+Numeric Operators Sub-Library defines an overloaded `operator/` for `std::complex<>`
+and `std::size_t`. This operator is defined in the `boost::numeric::operators` namespace and
+will be found within the `boost::accumulators::impl` namespace. That's why it's a good idea
+to put your accumulators there.
+
+[h3 Droppable Accumulators]
+
+The term "droppable" refers to an accumulator that can be removed from the _accumulator_set_.
+You can request that an accumulator be made droppable by using the _droppable_ class template.
+
+ // calculate sum and count, make sum droppable:
+ accumulator_set< double, features< tag::count, droppable<tag::sum> > > acc;
+
+ // add some data
+ acc(3.0);
+ acc(2.0);
+
+ // drop the sum (sum is 5 here)
+ acc.drop<tag::sum>();
+
+ // add more data
+ acc(1.0);
+
+ // This will display "3" and "5"
+ std::cout << count(acc) << ' ' << sum(acc);
+
+Any accumulators that get added to an accumulator set in order to satisfy
+dependencies on droppable accumulators are themselves droppable. Consider
+the following accumulator:
+
+ // Sum is not droppable. Mean is droppable. Count, brought in to
+ // satisfy mean's dependencies, is implicitly droppable, too.
+ accumulator_set< double, features< tag::sum, droppable<tag::mean> > > acc;
+
+`mean` depends on `sum` and `count`. Since `mean` is droppable, so too is `count`.
+However, we have explictitly requested that `sum` be not droppable, so it isn't. Had
+we left `tag::sum` out of the above declaration, the `sum` accumulator would have
+been implicitly droppable.
+
+A droppable accumulator is reference counted, and is only really dropped after all the
+accumulators that depend on it have been dropped. This can lead to some surprising
+behavior in some situations.
+
+ // calculate sum and mean, make mean droppable.
+ accumulator_set< double, features< tag::sum, droppable<tag::mean> > > acc;
+
+ // add some data
+ acc(1.0);
+ acc(2.0);
+
+ // drop the mean. mean's reference count
+ // drops to 0, so it's really dropped. So
+ // too, count's reference count drops to 0
+ // and is really dropped.
+ acc.drop<tag::mean>();
+
+ // add more data. Sum continues to accumulate!
+ acc(3.0);
+
+ // This will display "6 2 3"
+ std::cout << sum(acc) << ' '
+ << count(acc) << ' '
+ << mean(acc);
+
+Note that at the point at which `mean` is dropped, `sum` is 3, `count` is 2, and
+therefore `mean` is 1.5. But since `sum` continues to accumulate even after `mean`
+has been dropped, the value of `mean` continues to change. If you want to remember
+the value of `mean` at the point it is dropped, you should save its value into
+a local variable.
+
+The following rules more precisely specify how droppable and non-droppable
+accumulators behave within an accumulator set.
+
+* There are two types of accumulators: droppable and non-droppable.
+ The default is non-droppable.
+* For any feature `X`, both `X` and `droppable<X>` satisfy the `X` dependency.
+* If feature `X` depends on `Y` and `Z`, then `droppable<X>` depends on
+ `droppable<Y>` and `droppable<Z>`.
+* All accumulators have `add_ref()` and `drop()` member functions.
+* For non-droppable accumulators, `drop()` is a no-op, and `add_ref()`
+ invokes `add_ref()` on all accumulators corresponding to the features
+ upon which the current accumulator depends.
+* Droppable accumulators have a reference count and define `add_ref()`
+ and `drop()` to manipulate the reference count.
+* For droppable accumulators, `add_ref()` increments the accumulator's
+ reference count, and also `add_ref()`'s the accumulators corresponding
+ to the features upon which the current accumulator depends.
+* For droppable accumulators, `drop()` decrements the accumulator's
+ reference count, and also `drop()`'s the accumulators corresponding to
+ the features upon which the current accumulator depends.
+* The accumulator_set constructor walks the list of *user-specified*
+ features and `add_ref()`'s the accumulator that corresponds to each of
+ them. (Note: that means that an accumulator that is not user-specified
+ but in the set merely to satisfy a dependency will be dropped as soon
+ as all its dependencies have been dropped. Ones that have been user
+ specified are not dropped until their dependencies have been
+ dropped *and* the user has explicitly dropped the accumulator.)
+* Droppable accumulators check their reference count in their
+ accumulate member function. If the reference count is 0, the function
+ is a no-op.
+* Users are not allowed to drop a feature that is not user-specified and
+ marked as droppable.
+
+And as an optimization:
+
+* If the user specifies the non-droppable feature `X`, which depends on `Y`
+ and `Z`, then the accumulators for `Y` and `Z` can be safely made
+ non-droppable, as well as any accumulators on which they depend.
+
+[endsect]
+
+[section Defining a New Feature]
+
+Once we have implemented an accumulator, we must define a feature for it so
+that users can specify the feature when declaring an _accumulator_set_. We
+typically put the features into a nested namespace, so that later we can
+define an extractor of the same name. All features must satisfy the
+[link accumulators.user_s_guide.the_accumulators_framework.concepts.feature_concept
+Feature Concept]. Using _depends_on_ makes satisfying the concept simple.
+Below is an example of a feature definition.
+
+ namespace boost { namespace accumulators { namespace tag {
+
+ struct mean // Features should inherit from
+ : depends_on< count, sum > // depends_on<> to specify dependencies
+ {
+ // Define a nested typedef called 'impl' that specifies which
+ // accumulator implements this feature.
+ typedef impl::mean_accumulator< mpl::_1 > impl;
+ };
+
+ }}}
+
+The only two things we must do to define the `mean` feature is to specify the
+dependencies with _depends_on_ and define the nested `impl` typedef. Even features
+that have no dependencies should inherit from _depends_on_. The nested `impl` type
+must be an _mpl_lambda_expression_. The result of
+`mpl::apply< impl, _sample_type_, _weight_type_ >::type` must be
+be the type of the accumulator that implements this feature. The use of _mpl_
+placeholders like `mpl::_1` make it especially easy to make a template such
+as `mean_accumulator<>` an _mpl_lambda_expression_. Here, `mpl::_1` will be
+replaced with the sample type. Had we used `mpl::_2`, it would have been replaced
+with the weight type.
+
+What about accumulator types that are not templates? If you have a `foo_accumulator`
+which is a plain struct and not a template, you could turn it into an
+_mpl_lambda_expression_ using `mpl::always<>`, like this:
+
+ // An MPL lambda expression that always evaluates to
+ // foo_accumulator:
+ typedef mpl::always< foo_accumulator > impl;
+
+If you are ever unsure, or if you are not comfortable with MPL lambda expressions,
+you could always define `impl` explicitly:
+
+ // Same as 'typedef mpl::always< foo_accumulator > impl;'
+ struct impl
+ {
+ template< typename Sample, typename Weight >
+ struct apply
+ {
+ typedef foo_accumulator type;
+ };
+ };
+
+Here, `impl` is a binary [@../../libs/mpl/doc/refmanual/metafunction-class.html
+MPL Metafunction Class], which is a kind of _mpl_lambda_expression_. The nested
+`apply<>` template is part of the metafunction class protocol and tells MPL how
+to to build the accumulator type given the sample and weight types.
+
+All features must also provide a nested `is_weight_accumulator` typedef. It must
+be either `mpl::true_` or `mpl::false_`. _depends_on_ provides a default of
+`mpl::false_` for all features that inherit from it, but that can be overridden
+(or hidden, technically speaking) in the derived type. When the feature represents
+an accumulation of information about the weights instead of the samples, we
+can mark this feature as such with `typedef mpl::true_ is_weight_accumulator;`.
+The weight accumulators are made external if the weight type is specified using
+the _external_ template.
+
+[endsect]
+
+[section Defining a New Extractor]
+
+Now that we have an accumulator and a feature, the only thing lacking is a way
+to get results from the accumulator set. The Accumulators Framework provides the
+_extractor_ class template to make it simple to define an extractor for your
+feature. Here's an extractor for the `mean` feature we defined above:
+
+ namespace boost {
+ namespace accumulators { // By convention, we put extractors
+ namespace extract { // in the 'extract' namespace
+
+ extractor< tag::mean > const mean = {}; // Simply define our extractor with
+ // our feature tag, like this.
+ }
+ using extract::mean; // Pull the extractor into the
+ // enclosing namespace.
+ }}
+
+Once defined, the `mean` extractor can be used to extract the result of the
+`tag::mean` feature from an _accumulator_set_.
+
+Parameterized features complicate this simple picture. Consider the `moment`
+feature, for calculating the [^['N]]-th moment, where [^['N]] is specified as
+a template parameter:
+
+ // An accumulator set for calculating the N-th moment, for N == 2 ...
+ accumulator_set< double, features< tag::moment<2> > > acc;
+
+ // ... add some data ...
+
+ // Display the 2nd moment ...
+ std::cout << "2nd moment is " << moment<2>(acc) << std::endl;
+
+In the expression `moment<2>(acc)`, what is `moment`? It cannot be an object --
+the syntax of C++ will not allow it. Clearly, if we want to provide this syntax,
+we must make `moment` a function template. Here's what the definition of the
+`moment` extractor looks like:
+
+ namespace boost {
+ namespace accumulators { // By convention, we put extractors
+ namespace extract { // in the 'extract' namespace
+
+ template<int N, typename AccumulatorSet>
+ typename mpl::apply<AccumulatorSet, tag::moment<N> >::type::result_type
+ moment(AccumulatorSet const &acc)
+ {
+ return extract_result<tag::moment<N> >(acc);
+ }
+
+ }
+ using extract::moment; // Pull the extractor into the
+ // enclosing namespace.
+ }}
+
+The return type deserves some explanation. Every _accumulator_set_ type
+is actually a unary [@../../libs/mpl/doc/refmanual/metafunction-class.html
+MPL Metafunction Class]. When you `mpl::apply<>` an _accumulator_set_ and
+a feature, the result is the type of the accumulator within the set that
+implements that feature. And every accumulator provides a nested `result_type`
+typedef that tells what its return type is. The extractor simply delegates
+its work to the _extract_result_ function.
+
+[endsect]
+
+[section Controlling Dependencies]
+
+The feature-based dependency resolution of the Accumulators Framework is
+designed to allow multiple different implementation strategies for each
+feature. For instance, two different accumulators may calculate the same
+quantity with different rounding modes, or using different algorithms with
+different size/speed tradeoffs. Other accumulators that depend on that
+quantity shouldn't care how it's calculated. The Accumulators Framework
+handles this by allowing several different accumulators satisfy the same
+feature.
+
+
+* Mapping multiple impls to the same feature with feature_of
+* Creating aliases for features with as_feature
+
+[endsect]
+
+[section:operators_ex Adding or Specializing Operator (Meta-) Functions]
+
+TODO
+
+[endsect]
+
+[endsect]
+
+[section Concepts]
+
+[h2 Accumulator Concept]
+
+In the following table, `Acc` is the type of an accumulator, `acc` and `acc2` are objects of type
+`Acc`, and `args` is the name of an argument pack from the _parameter_ library.
+
+[table Accumulator Requirements
+ [[[*Expression]] [[*Return type]] [[*Assertion / Note /
+ Pre- / Post-condition]]]
+ [[`Acc::result_type`] [['implementation
+ defined]] [The type returned by `Acc::result()`.]]
+ [[`Acc acc(args)`] [none] [Construct from an argument pack.]]
+ [[`Acc acc(acc2)`] [none] [Post: `acc.result(args)` is equivalent
+ to `acc2.result(args)`]]
+ [[`acc(args)`] [['unspecified]] []]
+ [[`acc.on_drop(args)`] [['unspecified]] []]
+ [[`acc.result(args)`] [`Acc::result_type`] []]
+]
+
+[h2 Feature Concept]
+
+In the following table, `F` is the type of a feature and `S` is some scalar type.
+
+[table Featue Requirements
+ [[[*Expression]] [[*Return type]] [[*Assertion / Note /
+ Pre- / Post-condition]]]
+ [[`F::dependencies`] [['unspecified]] [An MPL sequence of other features on
+ which which `F` depends.]]
+ [[`F::is_weight_accumulator`] [`mpl::true_` or
+ `mpl::false_`] [`mpl::true_` if the accumulator for
+ this feature should be made external
+ when the weight type for the accumulator
+ set is `external<S>`, `mpl::false_`
+ otherwise.]]
+ [[`F::impl`] [['unspecified]] [An _mpl_lambda_expression_ that
+ returns the type of the accumulator that
+ implements this feature when passed a
+ sample type and a weight type.]]
+]
+
+[endsect]
+
+[endsect]
+
+[section The Statistical Accumulators Library]
+
+The Statistical Accumulators Library defines accumulators for incremental statistial
+computations. It is built on top of [link accumulators.user_s_guide.the_accumulators_framework
+The Accumulator Framework].
+
+[section:count count]
+
+The `count` feature is a simple counter that tracks the
+number of samples pushed into the accumulator set.
+
+[variablelist
+ [[Result Type] [``
+ std::size_t
+ ``]]
+ [[Depends On] [['none]]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, features<tag::count> > acc;
+ acc(0);
+ acc(0);
+ acc(0);
+ assert(3 == count(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::count_impl `count_impl`]
+
+[endsect]
+
+[section:covariance covariance]
+
+The `covariance` feature is an iterative Monte Carlo estimator for the covariance.
+It is specified as `tag::covariance<_variate_type_, _variate_tag_>`.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::outer_product<
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ , numeric::functional::average<_variate_type_, std::size_t>::result_type
+ >::result_type
+ ``]]
+ [[Depends On] [`count` \n `mean` \n `mean_of_variates<_variate_type_, _variate_tag_>`]]
+ [[Variants] [`abstract_covariance`]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [[~variate-tag]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<double, stats<tag::covariance<double, tag::covariate1> > > acc;
+ acc(1., covariate1 = 2.);
+ acc(1., covariate1 = 4.);
+ acc(2., covariate1 = 3.);
+ acc(6., covariate1 = 1.);
+ assert(covariance(acc) == -1.75);
+
+[*See also]
+
+* [classref boost::accumulators::impl::covariance_impl [^covariance_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
+
+[endsect]
+
+[section:density density]
+
+The `tag::density` feature returns a histogram of the sample distribution. For more
+implementation details, see [classref boost::accumulators::impl::density_impl [^density_impl]].
+
+[variablelist
+ [[Result Type] [``
+ iterator_range<
+ std::vector<
+ std::pair<
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ , numeric::functional::average<_sample_type_, std::size_t>::result_type
+ >
+ >::iterator
+ >
+ ``]]
+ [[Depends On] [`count` \n `min` \n `max`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`density::cache_size` \n `density::num_bins`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(N), when N is `density::num_bins`]]
+]
+
+[/ TODO add example ]
+
+[*See also]
+
+* [classref boost::accumulators::impl::density_impl [^density_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.min [^min]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.max [^max]]
+
+[endsect]
+
+[section:error_of_mean error_of<mean>]
+
+The `error_of<mean>` feature calculates the error of the mean feature. It is equal to
+`sqrt(variance / (count - 1))`.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`count` \n `variance`]]
+ [[Variants] [`error_of<immediate_mean>`]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<double, stats<tag::error_of<tag::mean> > > acc;
+ acc(1.1);
+ acc(1.2);
+ acc(1.3);
+ assert(0.057735 == error_of<tag::mean>(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::error_of_mean_impl [^error_of_mean_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.variance [^variance]]
+
+[endsect]
+
+[section:extended_p_square extended_p_square]
+
+Multiple quantile estimation with the extended [^P^2] algorithm. For further
+details, see [classref boost::accumulators::impl::extended_p_square_impl [^extended_p_square_impl]].
+
+[variablelist
+ [[Result Type] [``
+ boost::iterator_range<
+ _implementation_defined_
+ >
+ ``]]
+ [[Depends On] [`count`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::extended_p_square::probabilities`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ boost::array<double> probs = {0.001,0.01,0.1,0.25,0.5,0.75,0.9,0.99,0.999};
+ accumulator_set<double, stats<tag::extended_p_square> >
+ acc(tag::extended_p_square::probabilities = probs);
+
+ boost::lagged_fibonacci607 rng; // a random number generator
+ for (int i=0; i<10000; ++i)
+ acc(rng());
+
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[0], probs[0], 25);
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[1], probs[1], 10);
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[2], probs[2], 5);
+
+ for (std::size_t i=3; i < probs.size(); ++i)
+ {
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[i], probs[i], 2);
+ }
+
+[*See also]
+
+* [classref boost::accumulators::impl::extended_p_square_impl [^extended_p_square_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+
+[endsect]
+
+[section:extended_p_square_quantile extended_p_square_quantile ['and variants]]
+
+Quantile estimation using the extended [^P^2] algorithm for weighted and unweighted samples.
+By default, the calculation is linear and unweighted, but quadratic and weighted variants
+are also provided. For further implementation details, see
+[classref boost::accumulators::impl::extended_p_square_quantile_impl [^extended_p_square_quantile_impl]].
+
+All the variants share the `tag::quantile` feature and can be extracted using the `quantile()`
+extractor.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [weighted variants depend on `weighted_extended_p_square` \n
+ unweighted variants depend on `extended_p_square`]]
+ [[Variants] [`extended_p_square_quantile_quadratic` \n
+ `weighted_extended_p_square_quantile` \n
+ `weighted_extended_p_square_quantile_quadratic`]]
+ [[Initialization Parameters] [`tag::extended_p_square::probabilities`]]
+ [[Accumulator Parameters] [`weight` for the weighted variants]]
+ [[Extractor Parameters] [`quantile_probability`]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(N) where N is the count of probabilities.]]
+]
+
+[*Example]
+
+ typedef accumulator_set<double, stats<tag::extended_p_square_quantile> >
+ accumulator_t;
+ typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile>, double >
+ accumulator_t_weighted;
+ typedef accumulator_set<double, stats<tag::extended_p_square_quantile(quadratic)> >
+ accumulator_t_quadratic;
+ typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile(quadratic)>, double >
+ accumulator_t_weighted_quadratic;
+
+ // tolerance
+ double epsilon = 1;
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ boost::array<double> probs = { 0.990, 0.991, 0.992, 0.993, 0.994,
+ 0.995, 0.996, 0.997, 0.998, 0.999 };
+ accumulator_t acc(extended_p_square_probabilities = probs);
+ accumulator_t_weighted acc_weighted(extended_p_square_probabilities = probs);
+ accumulator_t_quadratic acc2(extended_p_square_probabilities = probs);
+ accumulator_t_weighted_quadratic acc_weighted2(extended_p_square_probabilities = probs);
+
+ for (int i=0; i<10000; ++i)
+ {
+ double sample = rng();
+ acc(sample);
+ acc2(sample);
+ acc_weighted(sample, weight = 1.);
+ acc_weighted2(sample, weight = 1.);
+ }
+
+ for (std::size_t i = 0; i < probs.size() - 1; ++i)
+ {
+ BOOST_CHECK_CLOSE(
+ quantile(acc, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ BOOST_CHECK_CLOSE(
+ quantile(acc2, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ BOOST_CHECK_CLOSE(
+ quantile(acc_weighted, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ BOOST_CHECK_CLOSE(
+ quantile(acc_weighted2, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ }
+
+[*See also]
+
+* [classref boost::accumulators::impl::extended_p_square_quantile_impl [^extended_p_square_quantile_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.extended_p_square [^extended_p_square]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_extended_p_square [^weighted_extended_p_square]]
+
+[endsect]
+
+[section:kurtosis kurtosis]
+
+The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the
+square of the 2nd central moment (the variance) of the samples, minus 3. The term [^-3] is added
+in order to ensure that the normal distribution has zero kurtosis. For more implementation
+details, see [classref boost::accumulators::impl::kurtosis_impl [^kurtosis_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, _sample_type_>::result_type
+ ``]]
+ [[Depends On] [`mean` \n `moment<2>` \n `moment<3>` \n `moment<4>`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::kurtosis > > acc;
+
+ acc(2);
+ acc(7);
+ acc(4);
+ acc(9);
+ acc(3);
+
+ BOOST_CHECK_EQUAL( mean(acc), 5 );
+ BOOST_CHECK_EQUAL( moment<2>(acc), 159./5. );
+ BOOST_CHECK_EQUAL( moment<3>(acc), 1171./5. );
+ BOOST_CHECK_EQUAL( moment<4>(acc), 1863 );
+ BOOST_CHECK_CLOSE( kurtosis(acc), -1.39965397924, 1e-6 );
+
+[*See also]
+
+* [classref boost::accumulators::impl::kurtosis_impl [^kurtosis_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.moment [^moment]]
+
+[endsect]
+
+[section:max max]
+
+Calculates the maximum value of all the samples.
+
+[variablelist
+ [[Result Type] [``
+ _sample_type_
+ ``]]
+ [[Depends On] [['none]]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::max> > acc;
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1, (max)(acc));
+
+ acc(0);
+ BOOST_CHECK_EQUAL(1, (max)(acc));
+
+ acc(2);
+ BOOST_CHECK_EQUAL(2, (max)(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::max_impl [^max_impl]]
+
+[endsect]
+
+[section:mean mean ['and variants]]
+
+Calculates the mean of samples, weights or variates. The calculation is either
+lazy (in the result extractor), or immediate (in the accumulator). The lazy implementation
+is the default. For more implementation details, see
+[classref boost::accumulators::impl::mean_impl [^mean_impl]] or.
+[classref boost::accumulators::impl::immediate_mean_impl [^immediate_mean_impl]]
+
+[variablelist
+ [[Result Type] [For samples, `numeric::functional::average<_sample_type_, std::size_t>::result_type` \n
+ For weights, `numeric::functional::average<_weight_type_, std::size_t>::result_type` \n
+ For variates, `numeric::functional::average<_variate_type_, std::size_t>::result_type`]]
+ [[Depends On] [`count` \n
+ The lazy mean of samples depends on `sum` \n
+ The lazy mean of weights depends on `sum_of_weights` \n
+ The lazy mean of variates depends on `sum_of_variates<>`]]
+ [[Variants] [`mean_of_weights` \n
+ `mean_of_variates<_variate_type_, _variate_tag_>` \n
+ `immediate_mean` \n
+ `immediate_mean_of_weights` \n
+ `immediate_mean_of_variates<_variate_type_, _variate_tag_>`]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<
+ int
+ , stats<
+ tag::mean
+ , tag::mean_of_weights
+ , tag::mean_of_variates<int, tag::covariate1>
+ >
+ , int
+ > acc;
+
+ acc(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(2, sum(acc));
+ BOOST_CHECK_CLOSE(2., mean_of_weights(acc), 1e-5);
+ BOOST_CHECK_CLOSE(3., (mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ acc(0, weight = 4, covariate1 = 4);
+ BOOST_CHECK_CLOSE(0.33333333333333333, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(2, sum(acc));
+ BOOST_CHECK_CLOSE(3., mean_of_weights(acc), 1e-5);
+ BOOST_CHECK_CLOSE(3.5, (mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ acc(2, weight = 9, covariate1 = 8);
+ BOOST_CHECK_CLOSE(1.33333333333333333, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(20, sum(acc));
+ BOOST_CHECK_CLOSE(5., mean_of_weights(acc), 1e-5);
+ BOOST_CHECK_CLOSE(5., (mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ accumulator_set<
+ int
+ , stats<
+ tag::mean(immediate)
+ , tag::mean_of_weights(immediate)
+ , tag::mean_of_variates<int, tag::covariate1>(immediate)
+ >
+ , int
+ > acc2;
+
+ acc2(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc2));
+ BOOST_CHECK_CLOSE(2., mean_of_weights(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(3., (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ acc2(0, weight = 4, covariate1 = 4);
+ BOOST_CHECK_CLOSE(0.33333333333333333, mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc2));
+ BOOST_CHECK_CLOSE(3., mean_of_weights(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(3.5, (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ acc2(2, weight = 9, covariate1 = 8);
+ BOOST_CHECK_CLOSE(1.33333333333333333, mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc2));
+ BOOST_CHECK_CLOSE(5., mean_of_weights(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(5., (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+[*See also]
+
+* [classref boost::accumulators::impl::mean_impl [^mean_impl]]
+* [classref boost::accumulators::impl::immediate_mean_impl [^immediate_mean_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+
+[endsect]
+
+[section:median median ['and variants]]
+
+Median estimation based on the [^P^2] quantile estimator, the density estimator, or
+the [^P^2] cumulative distribution estimator. For more implementation details, see
+[classref boost::accumulators::impl::median_impl [^median_impl]],
+[classref boost::accumulators::impl::with_density_median_impl [^with_density_median_impl]],
+and [classref boost::accumulators::impl::with_p_square_cumulative_distribution_median_impl [^with_p_square_cumulative_distribution_median_impl]].
+
+The three median accumulators all satisfy the `tag::median` feature, and can all be
+extracted with the `median()` extractor.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`median` depends on `p_square_quantile_for_median` \n
+ `with_density_median` depends on `count` and `density` \n
+ `with_p_square_cumulative_distribution_median` depends on `p_square_cumulative_distribution`]]
+ [[Variants] [`with_density_median` \n
+ `with_p_square_cumulative_distribution_median`]]
+ [[Initialization Parameters] [`with_density_median` requires `tag::density::cache_size` and `tag::density::num_bins` \n
+ `with_p_square_cumulative_distribution_median` requires `tag::p_square_cumulative_distribution::num_cells`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [TODO]]
+]
+
+[*Example]
+
+ // two random number generators
+ double mu = 1.;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(mu,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> >
+ normal(rng, mean_sigma);
+
+ accumulator_set<double, stats<tag::median(with_p_square_quantile) > > acc;
+ accumulator_set<double, stats<tag::median(with_density) > >
+ acc_dens( density_cache_size = 10000, density_num_bins = 1000 );
+ accumulator_set<double, stats<tag::median(with_p_square_cumulative_distribution) > >
+ acc_cdist( p_square_cumulative_distribution_num_cells = 100 );
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal();
+ acc(sample);
+ acc_dens(sample);
+ acc_cdist(sample);
+ }
+
+ BOOST_CHECK_CLOSE(1., median(acc), 1.);
+ BOOST_CHECK_CLOSE(1., median(acc_dens), 1.);
+ BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.);
+
+[*See also]
+
+* [classref boost::accumulators::impl::median_impl [^median_impl]]
+* [classref boost::accumulators::impl::with_density_median_impl [^with_density_median_impl]]
+* [classref boost::accumulators::impl::with_p_square_cumulative_distribution_median_impl [^with_p_square_cumulative_distribution_median_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.p_square_quantile [^p_square_quantile]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.p_square_cumulative_distribution [^p_square_cumulative_distribution]]
+
+[endsect]
+
+[section:min min]
+
+Calculates the minimum value of all the samples.
+
+[variablelist
+ [[Result Type] [``
+ _sample_type_
+ ``]]
+ [[Depends On] [['none]]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::min> > acc;
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1, (min)(acc));
+
+ acc(0);
+ BOOST_CHECK_EQUAL(0, (min)(acc));
+
+ acc(2);
+ BOOST_CHECK_EQUAL(0, (min)(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::min_impl [^min_impl]]
+
+[endsect]
+
+[section:moment moment]
+
+Calculates the N-th moment of the samples, which is defined as the sum of the N-th power of the
+samples over the count of samples.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`count`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::moment<2> > > acc1;
+
+ acc1(2); // 4
+ acc1(4); // 16
+ acc1(5); // + 25
+ // = 45 / 3 = 15
+
+ BOOST_CHECK_CLOSE(15., moment<2>(acc1), 1e-5);
+
+ accumulator_set<int, stats<tag::moment<5> > > acc2;
+
+ acc2(2); // 32
+ acc2(3); // 243
+ acc2(4); // 1024
+ acc2(5); // + 3125
+ // = 4424 / 4 = 1106
+
+ BOOST_CHECK_CLOSE(1106., moment<5>(acc2), 1e-5);
+
+[*See also]
+
+* [classref boost::accumulators::impl::moment_impl [^moment_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+
+[endsect]
+
+[section:p_square_cumulative_distribution p_square_cumulative_distribution]
+
+Histogram calculation of the cumulative distribution with the [^P^2] algorithm.
+For more implementation details, see
+[classref boost::accumulators::impl::p_square_cumulative_distribution_impl [^p_square_cumulative_distribution_impl]]
+
+[variablelist
+ [[Result Type] [``
+ iterator_range<
+ std::vector<
+ std::pair<
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ , numeric::functional::average<_sample_type_, std::size_t>::result_type
+ >
+ >::iterator
+ >
+ ``]]
+ [[Depends On] [`count`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::p_square_cumulative_distribution::num_cells`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(N) where N is `num_cells`]]
+]
+
+[*Example]
+
+ // tolerance in %
+ double epsilon = 3;
+
+ typedef accumulator_set<double, stats<tag::p_square_cumulative_distribution> > accumulator_t;
+
+ accumulator_t acc(tag::p_square_cumulative_distribution::num_cells = 100);
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ acc(normal());
+ }
+
+ typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
+ histogram_type histogram = p_square_cumulative_distribution(acc);
+
+ for (std::size_t i = 0; i < histogram.size(); ++i)
+ {
+ // problem with small results: epsilon is relative (in percent), not absolute!
+ if ( histogram[i].second > 0.001 )
+ BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram[i].first / sqrt(2.0) )), histogram[i].second, epsilon );
+ }
+
+[*See also]
+
+* [classref boost::accumulators::impl::p_square_cumulative_distribution_impl [^p_square_cumulative_distribution_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+
+[endsect]
+
+[section:p_square_quantile p_square_quantile ['and variants]]
+
+Single quantile estimation with the [^P^2] algorithm. For more implementation details, see
+[classref boost::accumulators::impl::p_square_quantile_impl [^p_square_quantile_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`count`]]
+ [[Variants] [`p_square_quantile_for_median`]]
+ [[Initialization Parameters] [`quantile_probability`, which defaults to `0.5`.
+ (Note: for `p_square_quantile_for_median`, the `quantile_probability`
+ parameter is ignored and is always `0.5`.)]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ typedef accumulator_set<double, stats<tag::p_square_quantile> > accumulator_t;
+
+ // tolerance in %
+ double epsilon = 1;
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ accumulator_t acc0(quantile_probability = 0.001);
+ accumulator_t acc1(quantile_probability = 0.01 );
+ accumulator_t acc2(quantile_probability = 0.1 );
+ accumulator_t acc3(quantile_probability = 0.25 );
+ accumulator_t acc4(quantile_probability = 0.5 );
+ accumulator_t acc5(quantile_probability = 0.75 );
+ accumulator_t acc6(quantile_probability = 0.9 );
+ accumulator_t acc7(quantile_probability = 0.99 );
+ accumulator_t acc8(quantile_probability = 0.999);
+
+ for (int i=0; i<100000; ++i)
+ {
+ double sample = rng();
+ acc0(sample);
+ acc1(sample);
+ acc2(sample);
+ acc3(sample);
+ acc4(sample);
+ acc5(sample);
+ acc6(sample);
+ acc7(sample);
+ acc8(sample);
+ }
+
+ BOOST_CHECK_CLOSE( p_square_quantile(acc0), 0.001, 15*epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc1), 0.01 , 5*epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc2), 0.1 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc3), 0.25 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc4), 0.5 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc5), 0.75 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc6), 0.9 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc7), 0.99 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc8), 0.999, epsilon );
+
+[*See also]
+
+* [classref boost::accumulators::impl::p_square_quantile_impl [^p_square_quantile_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+
+[endsect]
+
+[section:peaks_over_threshold peaks_over_threshold ['and variants]]
+
+Peaks Over Threshold method for quantile and tail mean estimation. For implementation
+details, see [classref boost::accumulators::impl::peaks_over_threshold_impl [^peaks_over_threshold_impl]]
+and [classref boost::accumulators::impl::peaks_over_threshold_prob_impl [^peaks_over_threshold_prob_impl]].
+
+Both `tag::peaks_over_threshold` and `tag::peaks_over_threshold_prob<>` satisfy the `tag::abstract_peaks_over_threshold`
+feature, and can be extracted with the `peaks_over_threshold()` extractor. The result is a 3-tuple representing
+the fit parameters `u_bar`, `beta_bar` and `xi_hat`.
+
+[variablelist
+ [[Result Type] [``
+ boost::tuple<
+ numeric::functional::average<_sample_type_, std::size_t>::result_type // u_bar
+ , numeric::functional::average<_sample_type_, std::size_t>::result_type // beta_bar
+ , numeric::functional::average<_sample_type_, std::size_t>::result_type // xi_hat
+ >
+ ``]]
+ [[Depends On] [`count` \n
+ In addtion, `tag::peaks_over_threshold_prob<>` depends on `tail<_left_or_right_>`]]
+ [[Variants] [`peaks_over_threshold_prob<_left_or_right_>`]]
+ [[Initialization Parameters] [ `tag::peaks_over_threshold::threshold_value` \n
+ `tag::peaks_over_threshold_prob::threshold_probability` \n
+ `tag::tail<_left_or_right_>::cache_size` ]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [TODO]]
+]
+
+[*Example]
+
+See example for [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]].
+
+[*See also]
+
+* [classref boost::accumulators::impl::peaks_over_threshold_impl [^peaks_over_threshold_impl]]
+* [classref boost::accumulators::impl::peaks_over_threshold_prob_impl [^peaks_over_threshold_prob_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_tail_mean [^pot_tail_mean]]
+
+[endsect]
+
+[section:pot_quantile pot_quantile ['and variants]]
+
+Quantile estimation based on Peaks over Threshold method (for both left and right tails). For
+implementation details, see [classref boost::accumulators::impl::pot_quantile_impl [^pot_quantile_impl]].
+
+Both `tag::pot_quantile<_left_or_right_>` and `tag::pot_quantile_prob<_left_or_right_>` satisfy the
+`tag::quantile` feature and can be extracted using the `quantile()` extractor.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`pot_quantile<_left_or_right_>` depends on `peaks_over_threshold<_left_or_right_>` \n
+ `pot_quantile_prob<_left_or_right_>` depends on `peaks_over_threshold_prob<_left_or_right_>` ]]
+ [[Variants] [`pot_quantile_prob<_left_or_right_>`]]
+ [[Initialization Parameters] [ `tag::peaks_over_threshold::threshold_value` \n
+ `tag::peaks_over_threshold_prob::threshold_probability` \n
+ `tag::tail<_left_or_right_>::cache_size` ]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [`quantile_probability`]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [TODO]]
+]
+
+[*Example]
+
+ // tolerance in %
+ double epsilon = 1.;
+
+ double alpha = 0.999;
+ double threshold_probability = 0.99;
+ double threshold = 3.;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::exponential_distribution<> lambda(1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::exponential_distribution<> > exponential(rng, lambda);
+
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc1(
+ tag::peaks_over_threshold::threshold_value = threshold
+ );
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc2(
+ tag::tail<right>::cache_size = 2000
+ , tag::peaks_over_threshold_prob::threshold_probability = threshold_probability
+ );
+
+ threshold_probability = 0.995;
+ threshold = 5.;
+
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc3(
+ tag::peaks_over_threshold::threshold_value = threshold
+ );
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc4(
+ tag::tail<right>::cache_size = 2000
+ , tag::peaks_over_threshold_prob::threshold_probability = threshold_probability
+ );
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ double sample = normal();
+ acc1(sample);
+ acc2(sample);
+ }
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ double sample = exponential();
+ acc3(sample);
+ acc4(sample);
+ }
+
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = alpha), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = alpha), 3.090232, epsilon );
+
+ BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = alpha), 6.908, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc4, quantile_probability = alpha), 6.908, epsilon );
+
+[*See also]
+
+* [classref boost::accumulators::impl::pot_quantile_impl [^pot_quantile_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.peaks_over_threshold [^peaks_over_threshold]]
+
+[endsect]
+
+[section:pot_tail_mean pot_tail_mean]
+
+Estimation of the (coherent) tail mean based on the peaks over threshold method (for both left and right tails).
+For inplementation details, see [classref boost::accumulators::impl::pot_tail_mean_impl [^pot_tail_mean_impl]].
+
+Both `tag::pot_tail_mean<_left_or_right_>` and `tag::pot_tail_mean_prob<_left_or_right_>` satisfy the
+`tag::tail_mean` feature and can be extracted using the `tail_mean()` extractor.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`pot_tail_mean<_left_or_right_>` depends on `peaks_over_threshold<_left_or_right_>`
+ and `pot_quantile<_left_or_right_>` \n
+ `pot_tail_mean_prob<_left_or_right_>` depends on `peaks_over_threshold_prob<_left_or_right_>`
+ and `pot_quantile_prob<_left_or_right_>` ]]
+ [[Variants] [`pot_tail_mean_prob<_left_or_right_>`]]
+ [[Initialization Parameters] [ `tag::peaks_over_threshold::threshold_value` \n
+ `tag::peaks_over_threshold_prob::threshold_probability` \n
+ `tag::tail<_left_or_right_>::cache_size` ]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [`quantile_probability`]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [TODO]]
+]
+
+[*Example]
+
+ // TODO
+
+[*See also]
+
+* [classref boost::accumulators::impl::pot_tail_mean_impl [^pot_tail_mean_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.peaks_over_threshold [^peaks_over_threshold]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]]
+
+[endsect]
+
+[section:skewness skewness]
+
+The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the [^3/2]-th power
+of the 2nd central moment (the variance) of the sampless 3. For implementation details, see
+[classref boost::accumulators::impl::skewness_impl [^skewness_impl]].
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, _sample_type_>::result_type
+ ``]]
+ [[Depends On] [`mean` \n `moment<2>` \n `moment<3>`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::skewness > > acc2;
+
+ acc2(2);
+ acc2(7);
+ acc2(4);
+ acc2(9);
+ acc2(3);
+
+ BOOST_CHECK_EQUAL( mean(acc2), 5 );
+ BOOST_CHECK_EQUAL( moment<2>(acc2), 159./5. );
+ BOOST_CHECK_EQUAL( moment<3>(acc2), 1171./5. );
+ BOOST_CHECK_CLOSE( skewness(acc2), 0.406040288214, 1e-6 );
+
+
+[*See also]
+
+* [classref boost::accumulators::impl::skewness_impl [^skewness_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.moment [^moment]]
+
+[endsect]
+
+[section:sum sum ['and variants]]
+
+For summing the samples, weights or variates.
+
+[variablelist
+ [[Result Type] [`_sample_type_` for summing samples \n
+ `_weight_type_` for summing weights \n
+ `_variate_type_` for summing variates]]
+ [[Depends On] [['none]]]
+ [[Variants] [`tag::sum` \n
+ `tag::sum_of_weights` \n
+ `tag::sum_of_variates<_variate_type_, _variate_tag_>`]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [`weight` for summing weights \n
+ `_variate_tag_` for summing variates]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<
+ int
+ , stats<
+ tag::sum
+ , tag::sum_of_weights
+ , tag::sum_of_variates<int, tag::covariate1>
+ >
+ , int
+ > acc;
+
+ acc(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_EQUAL(2, sum(acc)); // weighted sample = 1 * 2
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc));
+ BOOST_CHECK_EQUAL(3, sum_of_variates(acc));
+
+ acc(2, weight = 4, covariate1 = 6);
+ BOOST_CHECK_EQUAL(10, sum(acc)); // weighted sample = 2 * 4
+ BOOST_CHECK_EQUAL(6, sum_of_weights(acc));
+ BOOST_CHECK_EQUAL(9, sum_of_variates(acc));
+
+ acc(3, weight = 6, covariate1 = 9);
+ BOOST_CHECK_EQUAL(28, sum(acc)); // weighted sample = 3 * 6
+ BOOST_CHECK_EQUAL(12, sum_of_weights(acc));
+ BOOST_CHECK_EQUAL(18, sum_of_variates(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::sum_impl [^sum_impl]]
+
+[endsect]
+
+[section:tail tail]
+
+Tracks the largest or smallest [^N] values. `tag::tail<right>` tracks the largest [^N],
+and `tag::tail<left>` tracks the smallest. The parameter [^N] is specified with the
+`tag::tail<_left_or_right_>::cache_size` initialization parameter. For implementation details, see
+[classref boost::accumulators::impl::tail_impl [^tail_impl]].
+
+Both `tag::tail<left>` and `tag::tail<right>` satisfy the `tag::abstract_tail` feature and
+can be extracted with the `tail()` extractor.
+
+[variablelist
+ [[Result Type] [``
+ boost::iterator_range<
+ boost::reverse_iterator<
+ boost::permutation_iterator<
+ std::vector<_sample_type_>::const_iterator // samples
+ , std::vector<std::size_t>::iterator // indices
+ >
+ >
+ >
+ ``]]
+ [[Depends On] [['none]]]
+ [[Variants] [`abstract_tail`]]
+ [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(log N), where N is the cache size]]
+ [[Extractor Complexity] [O(N log N), where N is the cache size]]
+]
+
+[*Example]
+
+See the Example for [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_variate [^tail_variate]].
+
+[*See also]
+
+* [classref boost::accumulators::impl::tail_impl [^tail_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_variate [^tail_variate]]
+
+[endsect]
+
+[section:coherent_tail_mean coherent_tail_mean]
+
+Estimation of the coherent tail mean based on order statistics (for both left and right tails).
+The left coherent tail mean feature is `tag::coherent_tail_mean<left>`, and the right choherent
+tail mean feature is `tag::coherent_tail_mean<right>`. They both share the `tag::tail_mean` feature
+and can be extracted with the `tail_mean()` extractor. For more implementation details, see
+[classref boost::accumulators::impl::coherent_tail_mean_impl [^coherent_tail_mean_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`count` \n `quantile` \n `non_coherent_tail_mean<_left_or_right_>`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [`quantile_probability`]]
+ [[Accumulator Complexity] [O(log N), where N is the cache size]]
+ [[Extractor Complexity] [O(N log N), where N is the cache size]]
+]
+
+[*Example]
+
+See the example for
+[link accumulators.user_s_guide.the_statistical_accumulators_library.non_coherent_tail_mean [^non_coherent_tail_mean]].
+
+[*See also]
+
+* [classref boost::accumulators::impl::coherent_tail_mean_impl [^coherent_tail_mean_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.extended_p_square_quantile [^extended_p_square_quantile]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.pot_quantile [^pot_quantile]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_quantile [^tail_quantile]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.non_coherent_tail_mean [^non_coherent_tail_mean]]
+
+[endsect]
+
+[section:non_coherent_tail_mean non_coherent_tail_mean]
+
+Estimation of the (non-coherent) tail mean based on order statistics (for both left and right tails).
+The left non-coherent tail mean feature is `tag::non_coherent_tail_mean<left>`, and the right non-choherent
+tail mean feature is `tag::non_coherent_tail_mean<right>`. They both share the `tag::abstract_non_coherent_tail_mean`
+feature and can be extracted with the `non_coherent_tail_mean()` extractor. For more implementation details, see
+[classref boost::accumulators::impl::non_coherent_tail_mean_impl [^non_coherent_tail_mean_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`count` \n `tail<_left_or_right_>`]]
+ [[Variants] [`abstract_non_coherent_tail_mean`]]
+ [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [`quantile_probability`]]
+ [[Accumulator Complexity] [O(log N), where N is the cache size]]
+ [[Extractor Complexity] [O(N log N), where N is the cache size]]
+]
+
+[*Example]
+
+ // tolerance in %
+ double epsilon = 1;
+
+ std::size_t n = 100000; // number of MC steps
+ std::size_t c = 10000; // cache size
+
+ typedef accumulator_set<double, stats<tag::non_coherent_tail_mean<right>, tag::tail_quantile<right> > > accumulator_t_right1;
+ typedef accumulator_set<double, stats<tag::non_coherent_tail_mean<left>, tag::tail_quantile<left> > > accumulator_t_left1;
+ typedef accumulator_set<double, stats<tag::coherent_tail_mean<right>, tag::tail_quantile<right> > > accumulator_t_right2;
+ typedef accumulator_set<double, stats<tag::coherent_tail_mean<left>, tag::tail_quantile<left> > > accumulator_t_left2;
+
+ accumulator_t_right1 acc0( right_tail_cache_size = c );
+ accumulator_t_left1 acc1( left_tail_cache_size = c );
+ accumulator_t_right2 acc2( right_tail_cache_size = c );
+ accumulator_t_left2 acc3( left_tail_cache_size = c );
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ double sample = rng();
+ acc0(sample);
+ acc1(sample);
+ acc2(sample);
+ acc3(sample);
+ }
+
+ // check uniform distribution
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.95), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.975), 0.9875, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.99), 0.995, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.999), 0.9995, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.05), 0.025, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.025), 0.0125, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.01), 0.005, 5 );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.001), 0.0005, 10 );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.95), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.975), 0.9875, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.99), 0.995, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.999), 0.9995, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.05), 0.025, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.025), 0.0125, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.01), 0.005, 5 );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.001), 0.0005, 10 );
+
+[*See also]
+
+* [classref boost::accumulators::impl::non_coherent_tail_mean_impl [^non_coherent_tail_mean_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
+
+[endsect]
+
+[section:tail_quantile tail_quantile]
+
+Tail quantile estimation based on order statistics (for both left and right tails).
+The left tail quantile feature is `tag::tail_quantile<left>`, and the right
+tail quantile feature is `tag::tail_quantile<right>`. They both share the `tag::quantile`
+feature and can be extracted with the `quantile()` extractor. For more implementation details, see
+[classref boost::accumulators::impl::tail_quantile_impl [^tail_quantile_impl]]
+
+[variablelist
+ [[Result Type] [``
+ _sample_type_
+ ``]]
+ [[Depends On] [`count` \n `tail<_left_or_right_>`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [`quantile_probability`]]
+ [[Accumulator Complexity] [O(log N), where N is the cache size]]
+ [[Extractor Complexity] [O(N log N), where N is the cache size]]
+]
+
+[*Example]
+
+ // tolerance in %
+ double epsilon = 1;
+
+ std::size_t n = 100000; // number of MC steps
+ std::size_t c = 10000; // cache size
+
+ typedef accumulator_set<double, stats<tag::tail_quantile<right> > > accumulator_t_right;
+ typedef accumulator_set<double, stats<tag::tail_quantile<left> > > accumulator_t_left;
+
+ accumulator_t_right acc0( tag::tail<right>::cache_size = c );
+ accumulator_t_right acc1( tag::tail<right>::cache_size = c );
+ accumulator_t_left acc2( tag::tail<left>::cache_size = c );
+ accumulator_t_left acc3( tag::tail<left>::cache_size = c );
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ double sample1 = rng();
+ double sample2 = normal();
+ acc0(sample1);
+ acc1(sample2);
+ acc2(sample1);
+ acc3(sample2);
+ }
+
+ // check uniform distribution
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.95 ), 0.95, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.975), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.99 ), 0.99, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.999), 0.999, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.05 ), 0.05, 2 );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.025), 0.025, 2 );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.01 ), 0.01, 3 );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.001), 0.001, 20 );
+
+ // check standard normal distribution
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.975), 1.959963, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.025), -1.959963, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.001), -3.090232, epsilon );
+
+[*See also]
+
+* [classref boost::accumulators::impl::tail_quantile_impl [^tail_quantile_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
+
+[endsect]
+
+[section:tail_variate tail_variate]
+
+Tracks the covariates of largest or smallest [^N] samples.
+`tag::tail_variate<_variate_type_, _variate_tag_, right>` tracks the covariate associated with
+_variate_tag_ for the largest [^N], and `tag::tail_variate<_variate_type_, _variate_tag_, left>`
+for the smallest. The parameter [^N] is specified with the `tag::tail<_left_or_right_>::cache_size`
+initialization parameter. For implementation details, see
+[classref boost::accumulators::impl::tail_variate_impl [^tail_variate_impl]].
+
+Both `tag::tail_variate<_variate_type_, _variate_tag_, right>` and
+`tag::tail_variate<_variate_type_, _variate_tag_, left>` satisfy the `tag::abstract_tail_variate` feature
+and can be extracted with the `tail_variate()` extractor.
+
+[variablelist
+ [[Result Type] [``
+ boost::iterator_range<
+ boost::reverse_iterator<
+ boost::permutation_iterator<
+ std::vector<_variate_type_>::const_iterator // variates
+ , std::vector<std::size_t>::iterator // indices
+ >
+ >
+ >
+ ``]]
+ [[Depends On] [`tail<_left_or_right_>`]]
+ [[Variants] [`abstract_tail_variate`]]
+ [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(log N), where N is the cache size]]
+ [[Extractor Complexity] [O(N log N), where N is the cache size]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::tail_variate<int, tag::covariate1, right> > > acc(
+ tag::tail<right>::cache_size = 4
+ );
+
+ acc(8, covariate1 = 3);
+ CHECK_RANGE_EQUAL(tail(acc), {8});
+ CHECK_RANGE_EQUAL(tail_variate(acc), {3});
+
+ acc(16, covariate1 = 1);
+ CHECK_RANGE_EQUAL(tail(acc), {16, 8});
+ CHECK_RANGE_EQUAL(tail_variate(acc), {1, 3});
+
+ acc(12, covariate1 = 4);
+ CHECK_RANGE_EQUAL(tail(acc), {16, 12, 8});
+ CHECK_RANGE_EQUAL(tail_variate(acc), {1, 4, 3});
+
+ acc(24, covariate1 = 5);
+ CHECK_RANGE_EQUAL(tail(acc), {24, 16, 12, 8});
+ CHECK_RANGE_EQUAL(tail_variate(acc), {5, 1, 4, 3});
+
+ acc(1, covariate1 = 9);
+ CHECK_RANGE_EQUAL(tail(acc), {24, 16, 12, 8});
+ CHECK_RANGE_EQUAL(tail_variate(acc), {5, 1, 4, 3});
+
+ acc(9, covariate1 = 7);
+ CHECK_RANGE_EQUAL(tail(acc), {24, 16, 12, 9});
+ CHECK_RANGE_EQUAL(tail_variate(acc), {5, 1, 4, 7});
+
+[*See also]
+
+* [classref boost::accumulators::impl::tail_variate_impl [^tail_variate_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.tail [^tail]]
+
+[endsect]
+
+[section:tail_variate_means tail_variate_means ['and variants]]
+
+Estimation of the absolute and relative tail variate means (for both left and right tails).
+The absolute tail variate means has the feature
+`tag::absolute_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`
+and the relative tail variate mean has the feature
+`tag::relative_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`. All
+absolute tail variate mean features share the `tag::abstract_absolute_tail_variate_means`
+feature and can be extracted with the `tail_variate_means()` extractor. All the
+relative tail variate mean features share the `tag::abstract_relative_tail_variate_means`
+feature and can be extracted with the `relative_tail_variate_means()` extractor.
+
+For more implementation details, see
+[classref boost::accumulators::impl::tail_variate_means_impl [^tail_variate_means_impl]]
+
+[variablelist
+ [[Result Type] [``
+ boost::iterator_range<
+ std::vector<
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ >::iterator
+ >
+ ``]]
+ [[Depends On] [`non_coherent_tail_mean<_left_or_right_>` \n
+ `tail_variate<_variate_type_, _variate_tag_, _left_or_right_>`]]
+ [[Variants] [`tag::absolute_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>` \n
+ `tag::relative_tail_variate_means<_left_or_right_, _variate_type_, _variate_tag_>`]]
+ [[Initialization Parameters] [`tag::tail<_left_or_right_>::cache_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [`quantile_probability`]]
+ [[Accumulator Complexity] [O(log N), where N is the cache size]]
+ [[Extractor Complexity] [O(N log N), where N is the cache size]]
+]
+
+[*Example]
+
+ std::size_t c = 5; // cache size
+
+ typedef double variate_type;
+ typedef std::vector<variate_type> variate_set_type;
+
+ typedef accumulator_set<double, stats<
+ tag::tail_variate_means<right, variate_set_type, tag::covariate1>(relative)>, tag::tail<right> >
+ accumulator_t1;
+
+ typedef accumulator_set<double, stats<
+ tag::tail_variate_means<right, variate_set_type, tag::covariate1>(absolute)>, tag::tail<right> >
+ accumulator_t2;
+
+ typedef accumulator_set<double, stats<
+ tag::tail_variate_means<left, variate_set_type, tag::covariate1>(relative)>, tag::tail<left> >
+ accumulator_t3;
+
+ typedef accumulator_set<double, stats<
+ tag::tail_variate_means<left, variate_set_type, tag::covariate1>(absolute)>, tag::tail<left> >
+ accumulator_t4;
+
+ accumulator_t1 acc1( right_tail_cache_size = c );
+ accumulator_t2 acc2( right_tail_cache_size = c );
+ accumulator_t3 acc3( left_tail_cache_size = c );
+ accumulator_t4 acc4( left_tail_cache_size = c );
+
+ variate_set_type cov1, cov2, cov3, cov4, cov5;
+ double c1[] = { 10., 20., 30., 40. }; // 100
+ double c2[] = { 26., 4., 17., 3. }; // 50
+ double c3[] = { 46., 64., 40., 50. }; // 200
+ double c4[] = { 1., 3., 70., 6. }; // 80
+ double c5[] = { 2., 2., 2., 14. }; // 20
+ cov1.assign(c1, c1 + sizeof(c1)/sizeof(variate_type));
+ cov2.assign(c2, c2 + sizeof(c2)/sizeof(variate_type));
+ cov3.assign(c3, c3 + sizeof(c3)/sizeof(variate_type));
+ cov4.assign(c4, c4 + sizeof(c4)/sizeof(variate_type));
+ cov5.assign(c5, c5 + sizeof(c5)/sizeof(variate_type));
+
+ acc1(100., covariate1 = cov1);
+ acc1( 50., covariate1 = cov2);
+ acc1(200., covariate1 = cov3);
+ acc1( 80., covariate1 = cov4);
+ acc1( 20., covariate1 = cov5);
+
+ acc2(100., covariate1 = cov1);
+ acc2( 50., covariate1 = cov2);
+ acc2(200., covariate1 = cov3);
+ acc2( 80., covariate1 = cov4);
+ acc2( 20., covariate1 = cov5);
+
+ acc3(100., covariate1 = cov1);
+ acc3( 50., covariate1 = cov2);
+ acc3(200., covariate1 = cov3);
+ acc3( 80., covariate1 = cov4);
+ acc3( 20., covariate1 = cov5);
+
+ acc4(100., covariate1 = cov1);
+ acc4( 50., covariate1 = cov2);
+ acc4(200., covariate1 = cov3);
+ acc4( 80., covariate1 = cov4);
+ acc4( 20., covariate1 = cov5);
+
+ // check relative risk contributions
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() ), 14./75. ); // (10 + 46) / 300 = 14/75
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 1), 7./25. ); // (20 + 64) / 300 = 7/25
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 2), 7./30. ); // (30 + 40) / 300 = 7/30
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 3), 3./10. ); // (40 + 50) / 300 = 3/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() ), 14./35. ); // (26 + 2) / 70 = 14/35
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 1), 3./35. ); // ( 4 + 2) / 70 = 3/35
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 2), 19./70. ); // (17 + 2) / 70 = 19/70
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 3), 17./70. ); // ( 3 + 14) / 70 = 17/70
+
+ // check absolute risk contributions
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() ), 28 ); // (10 + 46) / 2 = 28
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 1), 42 ); // (20 + 64) / 2 = 42
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 2), 35 ); // (30 + 40) / 2 = 35
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 3), 45 ); // (40 + 50) / 2 = 45
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() ), 14 ); // (26 + 2) / 2 = 14
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 1), 3 ); // ( 4 + 2) / 2 = 3
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 2),9.5 ); // (17 + 2) / 2 = 9.5
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 3),8.5 ); // ( 3 + 14) / 2 = 8.5
+
+ // check relative risk contributions
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() ), 23./100. ); // 46/200 = 23/100
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 1), 8./25. ); // 64/200 = 8/25
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 2), 1./5. ); // 40/200 = 1/5
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 3), 1./4. ); // 50/200 = 1/4
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() ), 1./10. ); // 2/ 20 = 1/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 1), 1./10. ); // 2/ 20 = 1/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 2), 1./10. ); // 2/ 20 = 1/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 3), 7./10. ); // 14/ 20 = 7/10
+
+ // check absolute risk contributions
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() ), 46 ); // 46
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 1), 64 ); // 64
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 2), 40 ); // 40
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 3), 50 ); // 50
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() ), 2 ); // 2
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 1), 2 ); // 2
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 2), 2 ); // 2
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 3), 14 ); // 14
+
+[*See also]
+
+* [classref boost::accumulators::impl::tail_variate_means_impl [^tail_variate_means_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.non_coherent_tail_mean [^non_coherent_tail_mean]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.tail_variate [^tail_variate]]
+
+[endsect]
+
+[section:variance variance ['and variants]]
+
+Lazy or iterative calculation of the variance. The lazy calculation is associated with the `tag::variance`
+feature, and the iterative calculation with the `tag::immediate_variance` feature. Both can be extracted
+using the `tag::variance()` extractor. For more implementation details, see
+[classref boost::accumulators::impl::variance_impl [^variance_impl]] and
+[classref boost::accumulators::impl::immediate_variance_impl [^immediate_variance_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`tag::variance` depends on `tag::moment<2>` and `tag::mean` \n
+ `tag::immediate_variance` depends on `tag::count` and `tag::immediate_mean`]]
+ [[Variants] [`tag::variance` (a.k.a. `tag::variance(lazy))` \n
+ `tag::immediate_variance` (a.k.a. `tag::variance(immediate)`)]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ // basic lazy variance
+ accumulator_set<int, stats<tag::variance > > acc1;
+
+ acc1(1);
+ acc1(2);
+ acc1(3);
+ acc1(4);
+ acc1(5);
+
+ BOOST_CHECK_EQUAL(5u, count(acc1));
+ BOOST_CHECK_CLOSE(3., mean(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(11., moment<2>(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(2., variance(acc1), 1e-5);
+
+ // immediate variance
+ accumulator_set<int, stats<tag::variance(immediate) > > acc2;
+
+ acc2(1);
+ acc2(2);
+ acc2(3);
+ acc2(4);
+ acc2(5);
+
+ BOOST_CHECK_EQUAL(5u, count(acc2));
+ BOOST_CHECK_CLOSE(3., mean(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(2., variance(acc2), 1e-5);
+
+
+[*See also]
+
+* [classref boost::accumulators::impl::variance_impl [^variance_impl]]
+* [classref boost::accumulators::impl::immediate_variance_impl [^immediate_variance_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.mean [^mean]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.moment [^moment]]
+
+[endsect]
+
+[section:weighted_covariance weighted_covariance]
+
+An iterative Monte Carlo estimator for the weighted covariance. The feature is specified as
+`tag::weighted_covariance<_variate_type_, _variate_tag_>` and is extracted with the `weighted_variate()`
+extractor. For more implementation details, see
+[classref boost::accumulators::impl::weighted_covariance_impl [^weighted_covariance_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::outer_product<
+ numeric::functional::multiplies<
+ _weight_type_
+ , numeric::functional::average<_sample_type_, std::size_t>::result_type
+ >::result_type
+ , numeric::functional::multiplies<
+ _weight_type_
+ , numeric::functional::average<_variate_type_, std::size_t>::result_type
+ >::result_type
+ >
+ ``]]
+ [[Depends On] [`count` \n
+ `sum_of_weights` \n
+ `weighted_mean` \n
+ `weighted_mean_of_variates<_variate_type_, _variate_tag_>`]]
+ [[Variants] [`abstract_weighted_covariance`]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [`weight` \n
+ `_variate_tag_`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<double, stats<tag::weighted_covariance<double, tag::covariate1> >, double > acc;
+
+ acc(1., weight = 1.1, covariate1 = 2.);
+ acc(1., weight = 2.2, covariate1 = 4.);
+ acc(2., weight = 3.3, covariate1 = 3.);
+ acc(6., weight = 4.4, covariate1 = 1.);
+
+ double epsilon = 1e-6;
+ BOOST_CHECK_CLOSE(weighted_covariance(acc), -2.39, epsilon);
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_covariance_impl [^weighted_covariance_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
+
+[endsect]
+
+[section:weighted_density weighted_density]
+
+The `tag::weighted_density` feature returns a histogram of the weighted sample distribution. For more
+implementation details, see [classref boost::accumulators::impl::weighted_density_impl [^weighted_density_impl]].
+
+[variablelist
+ [[Result Type] [``
+ iterator_range<
+ std::vector<
+ std::pair<
+ numeric::functional::average<_weight_type_, std::size_t>::result_type
+ , numeric::functional::average<_weight_type_, std::size_t>::result_type
+ >
+ >::iterator
+ >
+ ``]]
+ [[Depends On] [`count` \n `sum_of_weights` \n `min` \n `max`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::weighted_density::cache_size` \n `tag::weighted_density::num_bins`]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(N), when N is `weighted_density::num_bins`]]
+]
+
+[/ TODO add example ]
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_density_impl [^weighted_density_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.min [^min]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.max [^max]]
+
+[endsect]
+
+[section:weighted_extended_p_square weighted_extended_p_square]
+
+Multiple quantile estimation with the extended [^P^2] algorithm for weighted samples. For further
+details, see [classref boost::accumulators::impl::weighted_extended_p_square_impl [^weighted_extended_p_square_impl]].
+
+[variablelist
+ [[Result Type] [``
+ boost::iterator_range<
+ _implementation_defined_
+ >
+ ``]]
+ [[Depends On] [`count` \n `sum_of_weights`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::weighted_extended_p_square::probabilities`]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ typedef accumulator_set<double, stats<tag::weighted_extended_p_square>, double> accumulator_t;
+
+ // tolerance in %
+ double epsilon = 1;
+
+ // some random number generators
+ double mu1 = -1.0;
+ double mu2 = 1.0;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma1(mu1, 1);
+ boost::normal_distribution<> mean_sigma2(mu2, 1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal1(rng, mean_sigma1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal2(rng, mean_sigma2);
+
+ std::vector<double> probs_uniform, probs_normal1, probs_normal2, probs_normal_exact1, probs_normal_exact2;
+
+ double p1[] = {/*0.001,*/ 0.01, 0.1, 0.5, 0.9, 0.99, 0.999};
+ probs_uniform.assign(p1, p1 + sizeof(p1) / sizeof(double));
+
+ double p2[] = {0.001, 0.025};
+ double p3[] = {0.975, 0.999};
+ probs_normal1.assign(p2, p2 + sizeof(p2) / sizeof(double));
+ probs_normal2.assign(p3, p3 + sizeof(p3) / sizeof(double));
+
+ double p4[] = {-3.090232, -1.959963};
+ double p5[] = {1.959963, 3.090232};
+ probs_normal_exact1.assign(p4, p4 + sizeof(p4) / sizeof(double));
+ probs_normal_exact2.assign(p5, p5 + sizeof(p5) / sizeof(double));
+
+ accumulator_t acc_uniform(tag::weighted_extended_p_square::probabilities = probs_uniform);
+ accumulator_t acc_normal1(tag::weighted_extended_p_square::probabilities = probs_normal1);
+ accumulator_t acc_normal2(tag::weighted_extended_p_square::probabilities = probs_normal2);
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ acc_uniform(rng(), weight = 1.);
+
+ double sample1 = normal1();
+ double sample2 = normal2();
+ acc_normal1(sample1, weight = std::exp(-mu1 * (sample1 - 0.5 * mu1)));
+ acc_normal2(sample2, weight = std::exp(-mu2 * (sample2 - 0.5 * mu2)));
+ }
+
+ // check for uniform distribution
+ for (std::size_t i = 0; i < probs_uniform.size(); ++i)
+ {
+ BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_uniform)[i], probs_uniform[i], epsilon);
+ }
+
+ // check for standard normal distribution
+ for (std::size_t i = 0; i < probs_normal1.size(); ++i)
+ {
+ BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_normal1)[i], probs_normal_exact1[i], epsilon);
+ BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_normal2)[i], probs_normal_exact2[i], epsilon);
+ }
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_extended_p_square_impl [^weighted_extended_p_square_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+
+[endsect]
+
+[section:weighted_kurtosis weighted_kurtosis]
+
+The kurtosis of a sample distribution is defined as the ratio of the 4th central moment and the
+square of the 2nd central moment (the variance) of the samples, minus 3. The term [^-3] is added
+in order to ensure that the normal distribution has zero kurtosis. For more implementation
+details, see [classref boost::accumulators::impl::weighted_kurtosis_impl [^weighted_kurtosis_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<
+ numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
+ , numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
+ >::result_type
+ ``]]
+ [[Depends On] [`weighted_mean` \n `weighted_moment<2>` \n `weighted_moment<3>` \n `weighted_moment<4>`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::weighted_kurtosis>, int > acc2;
+
+ acc2(2, weight = 4);
+ acc2(7, weight = 1);
+ acc2(4, weight = 3);
+ acc2(9, weight = 1);
+ acc2(3, weight = 2);
+
+ BOOST_CHECK_EQUAL( weighted_mean(acc2), 42./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<2>(acc2), 212./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<3>(acc2), 1350./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<4>(acc2), 9956./11. );
+ BOOST_CHECK_CLOSE( weighted_kurtosis(acc2), 0.58137026432, 1e-6 );
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_kurtosis_impl [^weighted_kurtosis_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_moment [^weighted_moment]]
+
+[endsect]
+
+[section:weighted_mean weighted_mean ['and variants]]
+
+Calculates the weighted mean of samples or variates. The calculation is either
+lazy (in the result extractor), or immediate (in the accumulator). The lazy implementation
+is the default. For more implementation details, see
+[classref boost::accumulators::impl::weighted_mean_impl [^weighted_mean_impl]] or.
+[classref boost::accumulators::impl::immediate_weighted_mean_impl [^immediate_weighted_mean_impl]]
+
+[variablelist
+ [[Result Type] [For samples, `numeric::functional::average<numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type, _weight_type_>::result_type` \n
+ For variates, `numeric::functional::average<numeric::functional::multiplies<_variate_type_, _weight_type_>::result_type, _weight_type_>::result_type`]]
+ [[Depends On] [`sum_of_weights` \n
+ The lazy mean of samples depends on `weighted_sum` \n
+ The lazy mean of variates depends on `weighted_sum_of_variates<>`]]
+ [[Variants] [`weighted_mean_of_variates<_variate_type_, _variate_tag_>` \n
+ `immediate_weighted_mean` \n
+ `immediate_weighted_mean_of_variates<_variate_type_, _variate_tag_>`]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<
+ int
+ , stats<
+ tag::weighted_mean
+ , tag::weighted_mean_of_variates<int, tag::covariate1>
+ >
+ , int
+ > acc;
+
+ acc(10, weight = 2, covariate1 = 7); // 20
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc)); //
+ //
+ acc(6, weight = 3, covariate1 = 8); // 18
+ BOOST_CHECK_EQUAL(5, sum_of_weights(acc)); //
+ //
+ acc(4, weight = 4, covariate1 = 9); // 16
+ BOOST_CHECK_EQUAL(9, sum_of_weights(acc)); //
+ //
+ acc(6, weight = 5, covariate1 = 6); //+ 30
+ BOOST_CHECK_EQUAL(14, sum_of_weights(acc)); //
+ //= 84 / 14 = 6
+
+ BOOST_CHECK_EQUAL(6., weighted_mean(acc));
+ BOOST_CHECK_EQUAL(52./7., (weighted_mean_of_variates<int, tag::covariate1>(acc)));
+
+ accumulator_set<
+ int
+ , stats<
+ tag::weighted_mean(immediate)
+ , tag::weighted_mean_of_variates<int, tag::covariate1>(immediate)
+ >
+ , int
+ > acc2;
+
+ acc2(10, weight = 2, covariate1 = 7); // 20
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc2)); //
+ //
+ acc2(6, weight = 3, covariate1 = 8); // 18
+ BOOST_CHECK_EQUAL(5, sum_of_weights(acc2)); //
+ //
+ acc2(4, weight = 4, covariate1 = 9); // 16
+ BOOST_CHECK_EQUAL(9, sum_of_weights(acc2)); //
+ //
+ acc2(6, weight = 5, covariate1 = 6); //+ 30
+ BOOST_CHECK_EQUAL(14, sum_of_weights(acc2)); //
+ //= 84 / 14 = 6
+
+ BOOST_CHECK_EQUAL(6., weighted_mean(acc2));
+ BOOST_CHECK_EQUAL(52./7., (weighted_mean_of_variates<int, tag::covariate1>(acc2)));
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_mean_impl [^weighted_mean_impl]]
+* [classref boost::accumulators::impl::immediate_weighted_mean_impl [^immediate_weighted_mean_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_sum [^weighted_sum]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+
+[endsect]
+
+[section:weighted_median weighted_median ['and variants]]
+
+Median estimation for weighted samples based on the [^P^2] quantile estimator, the density estimator, or
+the [^P^2] cumulative distribution estimator. For more implementation details, see
+[classref boost::accumulators::impl::weighted_median_impl [^weighted_median_impl]],
+[classref boost::accumulators::impl::with_weighted_density_median_impl [^with_weighted_density_median_impl]],
+and [classref boost::accumulators::impl::with_weighted_p_square_cumulative_distribution_median_impl [^with_weighted_p_square_cumulative_distribution_median_impl]].
+
+The three median accumulators all satisfy the `tag::weighted_median` feature, and can all be
+extracted with the `weighted_median()` extractor.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`weighted_median` depends on `weighted_p_square_quantile_for_median` \n
+ `with_weighted_density_median` depends on `count` and `weighted_density` \n
+ `with_weighted_p_square_cumulative_distribution_median` depends on `weighted_p_square_cumulative_distribution`]]
+ [[Variants] [`with_weighted_density_median` (a.k.a. `weighted_median(with_weighted_density)`) \n
+ `with_weighted_p_square_cumulative_distribution_median` (a.k.a. `weighted_median(with_weighted_p_square_cumulative_distribution)`)]]
+ [[Initialization Parameters] [`with_weighted_density_median` requires `tag::weighted_density::cache_size` and `tag::weighted_density::num_bins` \n
+ `with_weighted_p_square_cumulative_distribution_median` requires `tag::weighted_p_square_cumulative_distribution::num_cells`]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [TODO]]
+]
+
+[*Example]
+
+ // Median estimation of normal distribution N(1,1) using samples from a narrow normal distribution N(1,0.01)
+ // The weights equal to the likelihood ratio of the corresponding samples
+
+ // two random number generators
+ double mu = 1.;
+ double sigma_narrow = 0.01;
+ double sigma = 1.;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma_narrow(mu,sigma_narrow);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_narrow(rng, mean_sigma_narrow);
+
+ accumulator_set<double, stats<tag::weighted_median(with_weighted_p_square_quantile) >, double > acc;
+ accumulator_set<double, stats<tag::weighted_median(with_weighted_density) >, double >
+ acc_dens( tag::weighted_density::cache_size = 10000, tag::weighted_density::num_bins = 1000 );
+ accumulator_set<double, stats<tag::weighted_median(with_weighted_p_square_cumulative_distribution) >, double >
+ acc_cdist( tag::weighted_p_square_cumulative_distribution::num_cells = 100 );
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal_narrow();
+ acc(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
+ acc_dens(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
+ acc_cdist(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
+ }
+
+ BOOST_CHECK_CLOSE(1., weighted_median(acc), 1e-1);
+ BOOST_CHECK_CLOSE(1., weighted_median(acc_dens), 1e-1);
+ BOOST_CHECK_CLOSE(1., weighted_median(acc_cdist), 1e-1);
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_median_impl [^weighted_median_impl]]
+* [classref boost::accumulators::impl::with_weighted_density_median_impl [^with_weighted_density_median_impl]]
+* [classref boost::accumulators::impl::with_weighted_p_square_cumulative_distribution_median_impl [^with_weighted_p_square_cumulative_distribution_median_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_p_square_quantile [^weighted_p_square_quantile]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_p_square_cumulative_distribution [^weighted_p_square_cumulative_distribution]]
+
+[endsect]
+
+[section:weighted_moment weighted_moment]
+
+Calculates the N-th moment of the weighted samples, which is defined as the sum of the weighted N-th
+power of the samples over the sum of the weights.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<
+ numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
+ , weight_type
+ >::result_type
+ ``]]
+ [[Depends On] [`count` \n `sum_of_weights`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<double, stats<tag::weighted_moment<2> >, double> acc2;
+ accumulator_set<double, stats<tag::weighted_moment<7> >, double> acc7;
+
+ acc2(2.1, weight = 0.7);
+ acc2(2.7, weight = 1.4);
+ acc2(1.8, weight = 0.9);
+
+ acc7(2.1, weight = 0.7);
+ acc7(2.7, weight = 1.4);
+ acc7(1.8, weight = 0.9);
+
+ BOOST_CHECK_CLOSE(5.403, weighted_moment<2>(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(548.54182, weighted_moment<7>(acc7), 1e-5);
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_moment_impl [^weighted_moment_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+
+[endsect]
+
+[section:weighted_p_square_cumulative_distribution weighted_p_square_cumulative_distribution]
+
+Histogram calculation of the cumulative distribution with the [^P^2] algorithm for weighted samples.
+For more implementation details, see
+[classref boost::accumulators::impl::weighted_p_square_cumulative_distribution_impl [^weighted_p_square_cumulative_distribution_impl]]
+
+[variablelist
+ [[Result Type] [``
+ iterator_range<
+ std::vector<
+ std::pair<
+ numeric::functional::average<weighted_sample, std::size_t>::result_type
+ , numeric::functional::average<weighted_sample, std::size_t>::result_type
+ >
+ >::iterator
+ >
+ ``
+ where `weighted_sample` is `numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type`]]
+ [[Depends On] [`count` \n `sum_or_weights`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::weighted_p_square_cumulative_distribution::num_cells`]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(N) where N is `num_cells`]]
+]
+
+[*Example]
+
+ // tolerance in %
+ double epsilon = 4;
+
+ typedef accumulator_set<double, stats<tag::weighted_p_square_cumulative_distribution>, double > accumulator_t;
+
+ accumulator_t acc_upper(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
+ accumulator_t acc_lower(tag::weighted_p_square_cumulative_distribution::num_cells = 100);
+
+ // two random number generators
+ double mu_upper = 1.0;
+ double mu_lower = -1.0;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma_upper(mu_upper,1);
+ boost::normal_distribution<> mean_sigma_lower(mu_lower,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_upper(rng, mean_sigma_upper);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_lower(rng, mean_sigma_lower);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal_upper();
+ acc_upper(sample, weight = std::exp(-mu_upper * (sample - 0.5 * mu_upper)));
+ }
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal_lower();
+ acc_lower(sample, weight = std::exp(-mu_lower * (sample - 0.5 * mu_lower)));
+ }
+
+ typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
+ histogram_type histogram_upper = weighted_p_square_cumulative_distribution(acc_upper);
+ histogram_type histogram_lower = weighted_p_square_cumulative_distribution(acc_lower);
+
+ // Note that applaying importance sampling results in a region of the distribution
+ // to be estimated more accurately and another region to be estimated less accurately
+ // than without importance sampling, i.e., with unweighted samples
+
+ for (std::size_t i = 0; i < histogram_upper.size(); ++i)
+ {
+ // problem with small results: epsilon is relative (in percent), not absolute!
+
+ // check upper region of distribution
+ if ( histogram_upper[i].second > 0.1 )
+ BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram_upper[i].first / sqrt(2.0) )), histogram_upper[i].second, epsilon );
+ // check lower region of distribution
+ if ( histogram_lower[i].second < -0.1 )
+ BOOST_CHECK_CLOSE( 0.5 * (1.0 + erf( histogram_lower[i].first / sqrt(2.0) )), histogram_lower[i].second, epsilon );
+ }
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_p_square_cumulative_distribution_impl [^weighted_p_square_cumulative_distribution_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+
+[endsect]
+
+[section:weighted_p_square_quantile weighted_p_square_quantile ['and variants]]
+
+Single quantile estimation with the [^P^2] algorithm. For more implementation details, see
+[classref boost::accumulators::impl::weighted_p_square_quantile_impl [^weighted_p_square_quantile_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<
+ numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
+ , std::size_t
+ >::result_type
+ ``]]
+ [[Depends On] [`count` \n `sum_of_weights`]]
+ [[Variants] [`weighted_p_square_quantile_for_median`]]
+ [[Initialization Parameters] [`quantile_probability`, which defaults to `0.5`.
+ (Note: for `weighted_p_square_quantile_for_median`, the `quantile_probability`
+ parameter is ignored and is always `0.5`.)]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [TODO]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ typedef accumulator_set<double, stats<tag::weighted_p_square_quantile>, double> accumulator_t;
+
+ // tolerance in %
+ double epsilon = 1;
+
+ // some random number generators
+ double mu4 = -1.0;
+ double mu5 = -1.0;
+ double mu6 = 1.0;
+ double mu7 = 1.0;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma4(mu4, 1);
+ boost::normal_distribution<> mean_sigma5(mu5, 1);
+ boost::normal_distribution<> mean_sigma6(mu6, 1);
+ boost::normal_distribution<> mean_sigma7(mu7, 1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal4(rng, mean_sigma4);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal5(rng, mean_sigma5);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal6(rng, mean_sigma6);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal7(rng, mean_sigma7);
+
+ accumulator_t acc0(quantile_probability = 0.001);
+ accumulator_t acc1(quantile_probability = 0.025);
+ accumulator_t acc2(quantile_probability = 0.975);
+ accumulator_t acc3(quantile_probability = 0.999);
+
+ accumulator_t acc4(quantile_probability = 0.001);
+ accumulator_t acc5(quantile_probability = 0.025);
+ accumulator_t acc6(quantile_probability = 0.975);
+ accumulator_t acc7(quantile_probability = 0.999);
+
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = rng();
+ acc0(sample, weight = 1.);
+ acc1(sample, weight = 1.);
+ acc2(sample, weight = 1.);
+ acc3(sample, weight = 1.);
+
+ double sample4 = normal4();
+ double sample5 = normal5();
+ double sample6 = normal6();
+ double sample7 = normal7();
+ acc4(sample4, weight = std::exp(-mu4 * (sample4 - 0.5 * mu4)));
+ acc5(sample5, weight = std::exp(-mu5 * (sample5 - 0.5 * mu5)));
+ acc6(sample6, weight = std::exp(-mu6 * (sample6 - 0.5 * mu6)));
+ acc7(sample7, weight = std::exp(-mu7 * (sample7 - 0.5 * mu7)));
+ }
+
+ // check for uniform distribution with weight = 1
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc0), 0.001, 15 );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc1), 0.025, 5 );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc2), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc3), 0.999, epsilon );
+
+ // check for shifted standard normal distribution ("importance sampling")
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc4), -3.090232, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc5), -1.959963, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc6), 1.959963, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc7), 3.090232, epsilon );
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_p_square_quantile_impl [^weighted_p_square_quantile_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.sum [^sum]]
+
+[endsect]
+
+[section:weighted_skewness weighted_skewness]
+
+The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the [^3/2]-th power
+of the 2nd central moment (the variance) of the sampless 3. The skewness estimator for weighted samples
+is formally identical to the estimator for unweighted samples, except that the weighted counterparts of
+all measures it depends on are to be taken.
+
+For implementation details, see
+[classref boost::accumulators::impl::weighted_skewness_impl [^weighted_skewness_impl]].
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<
+ numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
+ , numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
+ >::result_type
+ ``]]
+ [[Depends On] [`weighted_mean` \n `weighted_moment<2>` \n `weighted_moment<3>`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::weighted_skewness>, int > acc2;
+
+ acc2(2, weight = 4);
+ acc2(7, weight = 1);
+ acc2(4, weight = 3);
+ acc2(9, weight = 1);
+ acc2(3, weight = 2);
+
+ BOOST_CHECK_EQUAL( weighted_mean(acc2), 42./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<2>(acc2), 212./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<3>(acc2), 1350./11. );
+ BOOST_CHECK_CLOSE( weighted_skewness(acc2), 1.30708406282, 1e-6 );
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_skewness_impl [^weighted_skewness_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_moment [^weighted_moment]]
+
+[endsect]
+
+[section:weighted_sum weighted_sum ['and variants]]
+
+For summing the weighted samples or variates. All of the `tag::weighted_sum_of_variates<>` features
+can be extracted with the `weighted_sum_of_variates()` extractor.
+
+[variablelist
+ [[Result Type] [`numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type` for summing weighted samples \n
+ `numeric::functional::multiplies<_variate_type_, _weight_type_>::result_type` for summing weighted variates]]
+ [[Depends On] [['none]]]
+ [[Variants] [`tag::weighted_sum` \n
+ `tag::weighted_sum_of_variates<_variate_type_, _variate_tag_>`]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [`weight` \n
+ `_variate_tag_` for summing variates]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ accumulator_set<int, stats<tag::weighted_sum, tag::weighted_sum_of_variates<int, tag::covariate1> >, int> acc;
+
+ acc(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_EQUAL(2, weighted_sum(acc));
+ BOOST_CHECK_EQUAL(6, weighted_sum_of_variates(acc));
+
+ acc(2, weight = 3, covariate1 = 6);
+ BOOST_CHECK_EQUAL(8, weighted_sum(acc));
+ BOOST_CHECK_EQUAL(24, weighted_sum_of_variates(acc));
+
+ acc(4, weight = 6, covariate1 = 9);
+ BOOST_CHECK_EQUAL(32, weighted_sum(acc));
+ BOOST_CHECK_EQUAL(78, weighted_sum_of_variates(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_sum_impl [^weighted_sum_impl]]
+
+[endsect]
+
+[section:weighted_variance weighted_variance ['and variants]]
+
+Lazy or iterative calculation of the weighted variance. The lazy calculation is associated with the `tag::weighted_variance`
+feature, and the iterative calculation with the `tag::immediate_weighted_variance` feature. Both can be extracted
+using the `tag::weighted_variance()` extractor. For more implementation details, see
+[classref boost::accumulators::impl::weighted_variance_impl [^weighted_variance_impl]] and
+[classref boost::accumulators::impl::immediate_weighted_variance_impl [^immediate_weighted_variance_impl]]
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<
+ numeric::functional::multiplies<_sample_type_, _weight_type_>::result_type
+ , std::size_t
+ >::result_type
+ ``]]
+ [[Depends On] [`tag::weighted_variance` depends on `tag::weighted_moment<2>` and `tag::weighted_mean` \n
+ `tag::immediate_weighted_variance` depends on `tag::count` and `tag::immediate_weighted_mean`]]
+ [[Variants] [`tag::weighted_variance` (a.k.a. `tag::weighted_variance(lazy))` \n
+ `tag::immediate_weighted_variance` (a.k.a. `tag::weighted_variance(immediate)`)]]
+ [[Initialization Parameters] [['none]]]
+ [[Accumulator Parameters] [`weight`]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Example]
+
+ // basic lazy weighted_variance
+ accumulator_set<int, stats<tag::weighted_variance>, int> acc1;
+
+ acc1(1, weight = 2); // 2
+ acc1(2, weight = 3); // 6
+ acc1(3, weight = 1); // 3
+ acc1(4, weight = 4); // 16
+ acc1(5, weight = 1); // 5
+
+ // weighted_mean = (2+6+3+16+5) / (2+3+1+4+1) = 32 / 11 = 2.9090909090909090909090909090909
+
+ BOOST_CHECK_EQUAL(5u, count(acc1));
+ BOOST_CHECK_CLOSE(2.9090909, weighted_mean(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(10.1818182, weighted_moment<2>(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(1.7190083, weighted_variance(acc1), 1e-5);
+
+ accumulator_set<int, stats<tag::weighted_variance(immediate)>, int> acc2;
+
+ acc2(1, weight = 2);
+ acc2(2, weight = 3);
+ acc2(3, weight = 1);
+ acc2(4, weight = 4);
+ acc2(5, weight = 1);
+
+ BOOST_CHECK_EQUAL(5u, count(acc2));
+ BOOST_CHECK_CLOSE(2.9090909, weighted_mean(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(1.7190083, weighted_variance(acc2), 1e-5);
+
+ // check lazy and immediate variance with random numbers
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ accumulator_set<double, stats<tag::weighted_variance>, double > acc_lazy;
+ accumulator_set<double, stats<tag::weighted_variance(immediate)>, double > acc_immediate;
+
+ for (std::size_t i=0; i<10000; ++i)
+ {
+ double value = normal();
+ acc_lazy(value, weight = rng());
+ acc_immediate(value, weight = rng());
+ }
+
+ BOOST_CHECK_CLOSE(1., weighted_variance(acc_lazy), 1.);
+ BOOST_CHECK_CLOSE(1., weighted_variance(acc_immediate), 1.);
+
+[*See also]
+
+* [classref boost::accumulators::impl::weighted_variance_impl [^weighted_variance_impl]]
+* [classref boost::accumulators::impl::immediate_weighted_variance_impl [^immediate_weighted_variance_impl]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.count [^count]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_mean [^weighted_mean]]
+* [link accumulators.user_s_guide.the_statistical_accumulators_library.weighted_moment [^weighted_moment]]
+
+[endsect]
+
+[endsect]
+
+[endsect]
+
+[section Acknowledgements]
+
+Boost.Accumulators represents the efforts of many individuals. I would like to thank
+Daniel Egloff of _ZKB_ for helping to conceive the library and realize its
+implementation. I would also like to thank David Abrahams and Matthias Troyer for
+their key contributions to the design of the library. Many thanks are due to Michael
+Gauckler and Olivier Gygi, who, along with Daniel Egloff, implemented many of the
+statistical accumulators.
+
+Finally, I would like to thank _ZKB_ for sponsoring the work on Boost.Accumulators
+and graciously donating it to the community.
+
+[endsect]
+
+[section Reference]
+
+[xinclude accdoc.xml]
+
+[xinclude statsdoc.xml]
+
+[xinclude opdoc.xml]
+
+[endsect]
Added: branches/release/libs/accumulators/example/Jamfile.v2
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/example/Jamfile.v2 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,11 @@
+# (C) Copyright 2004: 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)
+
+exe example
+ :
+ main.cpp
+ :
+ <include>../../..
+ <include>$(BOOST_ROOT)
+ ;
Added: branches/release/libs/accumulators/example/main.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/example/main.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,176 @@
+///////////////////////////////////////////////////////////////////////////////
+// main.hpp
+//
+// Copyright 2005 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)
+
+#include <iostream>
+#include <algorithm>
+#include <boost/ref.hpp>
+#include <boost/bind.hpp>
+#include <boost/array.hpp>
+#include <boost/foreach.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+
+using namespace boost;
+using namespace boost::accumulators;
+
+// Helper that uses BOOST_FOREACH to display a range of doubles
+template<typename Range>
+void output_range(Range const &rng)
+{
+ bool first = true;
+ BOOST_FOREACH(double d, rng)
+ {
+ if(!first) std::cout << ", ";
+ std::cout << d;
+ first = false;
+ }
+ std::cout << '\n';
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// example1
+//
+// Calculate some useful stats using accumulator_set<> and std::for_each()
+//
+void example1()
+{
+ accumulator_set<
+ double
+ , stats<tag::min, tag::mean(immediate), tag::sum, tag::moment<2> >
+ > acc;
+
+ boost::array<double, 4> data = {0., 1., -1., 3.14159};
+
+ // std::for_each pushes each sample into the accumulator one at a
+ // time, and returns a copy of the accumulator.
+ acc = std::for_each(data.begin(), data.end(), acc);
+
+ // The following would be equivalent, and could be more efficient
+ // because it doesn't pass and return the entire accumulator set
+ // by value.
+ //std::for_each(data.begin(), data.end(), bind<void>(ref(acc), _1));
+
+ std::cout << " min(acc) = " << (min)(acc) << std::endl;
+ std::cout << " mean(acc) = " << mean(acc) << std::endl;
+
+ // since mean depends on count and sum, we can get their results, too.
+ std::cout << " count(acc) = " << count(acc) << std::endl;
+ std::cout << " sum(acc) = " << sum(acc) << std::endl;
+ std::cout << " moment<2>(acc) = " << moment<2>(acc) << std::endl;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// example2
+//
+// Calculate some tail statistics. This demonstrates how to specify
+// constructor and accumulator parameters. Note that the tail statistics
+// return multiple values, which are returned in an iterator_range.
+//
+// It pushes data in and displays the intermediate results to demonstrate
+// how the tail statistics are updated.
+void example2()
+{
+ // An accumulator which tracks the right tail (largest N items) and
+ // some data that are covariate with them. N == 4.
+ accumulator_set<
+ double
+ , stats<tag::tail_variate<double, tag::covariate1, right> >
+ > acc(tag::tail<right>::cache_size = 4);
+
+ acc(2.1, covariate1 = .21);
+ acc(1.1, covariate1 = .11);
+ acc(2.1, covariate1 = .21);
+ acc(1.1, covariate1 = .11);
+
+ std::cout << " tail = "; output_range(tail(acc));
+ std::cout << " tail_variate = "; output_range(tail_variate(acc));
+ std::cout << std::endl;
+
+ acc(21.1, covariate1 = 2.11);
+ acc(11.1, covariate1 = 1.11);
+ acc(21.1, covariate1 = 2.11);
+ acc(11.1, covariate1 = 1.11);
+
+ std::cout << " tail = "; output_range(tail(acc));
+ std::cout << " tail_variate = "; output_range(tail_variate(acc));
+ std::cout << std::endl;
+
+ acc(42.1, covariate1 = 4.21);
+ acc(41.1, covariate1 = 4.11);
+ acc(42.1, covariate1 = 4.21);
+ acc(41.1, covariate1 = 4.11);
+
+ std::cout << " tail = "; output_range(tail(acc));
+ std::cout << " tail_variate = "; output_range(tail_variate(acc));
+ std::cout << std::endl;
+
+ acc(32.1, covariate1 = 3.21);
+ acc(31.1, covariate1 = 3.11);
+ acc(32.1, covariate1 = 3.21);
+ acc(31.1, covariate1 = 3.11);
+
+ std::cout << " tail = "; output_range(tail(acc));
+ std::cout << " tail_variate = "; output_range(tail_variate(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// example3
+//
+// Demonstrate how to calculate weighted statistics. This example demonstrates
+// both a simple weighted statistical calculation, and a more complicated
+// calculation where the weight statistics are calculated and stored in an
+// external weight accumulataor.
+void example3()
+{
+ // weight == double
+ double w = 1.;
+
+ // Simple weighted calculation
+ {
+ // stats that depend on the weight are made external
+ accumulator_set<double, stats<tag::mean>, double> acc;
+
+ acc(0., weight = w);
+ acc(1., weight = w);
+ acc(-1., weight = w);
+ acc(3.14159, weight = w);
+
+ std::cout << " mean(acc) = " << mean(acc) << std::endl;
+ }
+
+ // Weighted calculation with an external weight accumulator
+ {
+ // stats that depend on the weight are made external
+ accumulator_set<double, stats<tag::mean>, external<double> > acc;
+
+ // Here's an external weight accumulator
+ accumulator_set<void, stats<tag::sum_of_weights>, double> weight_acc;
+
+ weight_acc(weight = w); acc(0., weight = w);
+ weight_acc(weight = w); acc(1., weight = w);
+ weight_acc(weight = w); acc(-1., weight = w);
+ weight_acc(weight = w); acc(3.14159, weight = w);
+
+ std::cout << " mean(acc) = " << mean(acc, weights = weight_acc) << std::endl;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// main
+int main()
+{
+ std::cout << "Example 1:\n";
+ example1();
+
+ std::cout << "\nExample 2:\n";
+ example2();
+
+ std::cout << "\nExample 3:\n";
+ example3();
+
+ return 0;
+}
Added: branches/release/libs/accumulators/index.html
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/index.html 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,15 @@
+<html>
+<head>
+<meta http-equiv="refresh" content="0; URL=../../doc/html/accumulators.html">
+</head>
+<body>
+Automatic redirection failed, please go to
+../../doc/html/accumulators.html
+<p>Copyright Eric Niebler 2006</p>
+<p>Distributed under the Boost Software License, Version 1.0. (See accompanying file
+LICENSE_1_0.txt or copy at
+www.boost.org/LICENSE_1_0.txt).
+</p>
+</body>
+</html>
+
Added: branches/release/libs/accumulators/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/Jamfile.v2 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,74 @@
+# (C) Copyright 2005: 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)
+
+# bring in rules for testing
+import testing ;
+import feature ;
+
+feature.feature iterator_debugging
+ : on off
+ : composite propagated optional
+ ;
+
+feature.compose <iterator_debugging>off
+ : <define>_HAS_ITERATOR_DEBUGGING=0
+ ;
+
+project
+ : requirements
+ <library>/boost/test//boost_unit_test_framework
+ <link>static
+ <include>../../..
+ <toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
+ # MSVC's iterator debugging causes some tests to run forever.
+ <toolset>msvc:<iterator_debugging>off
+ <toolset>intel-win:<iterator_debugging>off
+ ;
+
+test-suite "accumulators"
+ : [ run count.cpp ]
+ [ run covariance.cpp ]
+ [ run droppable.cpp ]
+ [ run error_of.cpp ]
+ [ run extended_p_square.cpp ]
+ [ run extended_p_square_quantile.cpp ]
+ [ run external_accumulator.cpp ]
+ [ run external_weights.cpp ]
+ [ run kurtosis.cpp ]
+ [ run max.cpp ]
+ [ run mean.cpp ]
+ [ run median.cpp ]
+ [ run min.cpp ]
+ [ run moment.cpp ]
+ [ run pot_quantile.cpp ]
+ [ run p_square_cumulative_distribution.cpp ]
+ [ run p_square_quantile.cpp ]
+ [ run reference.cpp ]
+ [ run skewness.cpp ]
+ [ run sum.cpp ]
+ [ run tail.cpp ]
+ [ run tail_mean.cpp ]
+ [ run tail_quantile.cpp ]
+ [ run tail_variate_means.cpp ]
+ [ run valarray.cpp ]
+ [ run variance.cpp ]
+ [ run vector.cpp ]
+ [ run weighted_covariance.cpp ]
+ [ run weighted_extended_p_square.cpp ]
+ [ run weighted_kurtosis.cpp ]
+ [ run weighted_mean.cpp ]
+ [ run weighted_median.cpp ]
+ [ run weighted_moment.cpp ]
+ [ run weighted_p_square_cum_dist.cpp ]
+ [ run weighted_p_square_quantile.cpp ]
+ [ run weighted_skewness.cpp ]
+ [ run weighted_sum.cpp ]
+ [ run weighted_variance.cpp ]
+
+ [ run weighted_pot_quantile.cpp ]
+ [ run weighted_tail_mean.cpp ]
+ [ run weighted_tail_quantile.cpp ]
+ [ run weighted_tail_variate_means.cpp ]
+
+ ;
Added: branches/release/libs/accumulators/test/count.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/count.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,48 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::count> > acc;
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(4u, count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(5u, count(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("count test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/covariance.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/covariance.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,101 @@
+// (C) Copyright 2005 Daniel Egloff, Eric Niebler
+// Use, modification and distribution are subject to 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)
+
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/covariance.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ std::vector<double> dummy;
+ dummy.push_back(0);
+ dummy.push_back(0);
+
+ accumulator_set<double, stats<tag::covariance<double, tag::covariate1> > > acc;
+ accumulator_set<std::vector<double>, stats<tag::covariance<double, tag::covariate1> > > acc2(sample = dummy);
+ accumulator_set<double, stats<tag::covariance<std::vector<double>, tag::covariate1> > > acc3(covariate1 = dummy);
+ accumulator_set<std::vector<double>, stats<tag::covariance<std::vector<double>, tag::covariate1> > > acc4(sample = dummy, covariate1 = dummy);
+
+ std::vector<double> a;
+ a.push_back(1.);
+ a.push_back(2.);
+ std::vector<double> b;
+ b.push_back(3.);
+ b.push_back(4.);
+ std::vector<double> c;
+ c.push_back(2.);
+ c.push_back(5.);
+ std::vector<double> d;
+ d.push_back(4.);
+ d.push_back(2.);
+
+ // double - double
+ {
+ acc(1., covariate1 = 2.);
+ acc(1., covariate1 = 4.);
+ acc(2., covariate1 = 3.);
+ acc(6., covariate1 = 1.);
+ }
+
+ // vector - double
+ {
+ acc2(a, covariate1 = 1.);
+ acc2(b, covariate1 = 1.);
+ acc2(c, covariate1 = 2.);
+ acc2(d, covariate1 = 6.);
+ }
+
+ // double - vector
+ {
+ acc3(1., covariate1 = a);
+ acc3(1., covariate1 = b);
+ acc3(2., covariate1 = c);
+ acc3(6., covariate1 = d);
+ }
+
+ // vector - vector
+ {
+ acc4(a, covariate1 = b);
+ acc4(b, covariate1 = c);
+ acc4(a, covariate1 = c);
+ acc4(d, covariate1 = b);
+ }
+
+ double epsilon = 1e-6;
+
+ BOOST_CHECK_CLOSE((covariance(acc)), -1.75, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc2))[0], 1.75, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc2))[1], -1.125, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc3))[0], 1.75, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc3))[1], -1.125, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc4))(0,0), 0.125, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc4))(0,1), -0.25, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc4))(1,0), -0.125, epsilon);
+ BOOST_CHECK_CLOSE((covariance(acc4))(1,1), 0.25, epsilon);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("covariance test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/droppable.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/droppable.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,142 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+template<typename T>
+void assert_is_double(T const &)
+{
+ BOOST_MPL_ASSERT((is_same<T, double>));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<droppable<tag::mean> > > acc, test_acc(sample = 0);
+
+ acc(1);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc(0);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc.drop<tag::mean>();
+
+ acc(2);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ assert_is_double(mean(acc));
+
+
+ accumulator_set<int, stats<droppable<tag::mean(immediate)> > > acc2, test_acc2(sample = 0);
+
+ acc2(1);
+ BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc2));
+
+ acc2(0);
+ BOOST_CHECK_CLOSE(0.5, mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc2));
+
+ acc2.drop<tag::mean>();
+
+ acc2(2);
+ BOOST_CHECK_CLOSE(0.5, mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc2));
+
+ assert_is_double(mean(acc2));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat2
+//
+void test_stat2()
+{
+ accumulator_set<int, stats<droppable<tag::sum>, droppable<tag::mean> > > acc, test_acc(sample = 0);
+
+ acc(1);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc(0);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc.drop<tag::mean>();
+ acc.drop<tag::sum>();
+
+ acc(2);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ assert_is_double(mean(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat3
+//
+void test_stat3()
+{
+ accumulator_set<int, stats<droppable<tag::sum>, droppable<tag::count>, droppable<tag::mean> > > acc, test_acc(sample = 0);
+
+ acc(1);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc(0);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc.drop<tag::mean>();
+ acc.drop<tag::sum>();
+
+ acc(2);
+ BOOST_CHECK_CLOSE(1./3., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc.drop<tag::count>();
+ acc(3);
+ BOOST_CHECK_CLOSE(1./3., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ assert_is_double(mean(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("droppable test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+ test->add(BOOST_TEST_CASE(&test_stat2));
+ test->add(BOOST_TEST_CASE(&test_stat3));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/error_of.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/error_of.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,57 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/with_error.hpp>
+#include <boost/accumulators/statistics/error_of_mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<double, stats<tag::error_of<tag::mean(lazy)> > > acc;
+ acc(1.1);
+ acc(1.2);
+ acc(1.3);
+ BOOST_CHECK_CLOSE(0.057735, error_of<tag::mean(lazy)>(acc), 1e-4);
+
+ accumulator_set<double, stats<tag::error_of<tag::mean(immediate)> > > acc2;
+ acc2(1.1);
+ acc2(1.2);
+ acc2(1.3);
+ BOOST_CHECK_CLOSE(0.057735, error_of<tag::mean(immediate)>(acc2), 1e-4);
+
+ accumulator_set<double, stats<with_error<tag::mean(lazy)> > > acc3;
+ acc3(1.1);
+ acc3(1.2);
+ acc3(1.3);
+ BOOST_CHECK_CLOSE(0.057735, error_of<tag::mean(lazy)>(acc3), 1e-4);
+
+ accumulator_set<double, stats<with_error<tag::mean(immediate)> > > acc4;
+ acc4(1.1);
+ acc4(1.2);
+ acc4(1.3);
+ BOOST_CHECK_CLOSE(0.057735, error_of<tag::mean(immediate)>(acc4), 1e-4);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("mean test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/extended_p_square.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/extended_p_square.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,74 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for extended_p_square.hpp
+
+#include <iostream>
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/extended_p_square.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef accumulator_set<double, stats<tag::extended_p_square> > accumulator_t;
+
+ // tolerance
+ double epsilon = 2;
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ std::vector<double> probs;
+
+ probs.push_back(0.001);
+ probs.push_back(0.01 );
+ probs.push_back(0.1 );
+ probs.push_back(0.25 );
+ probs.push_back(0.5 );
+ probs.push_back(0.75 );
+ probs.push_back(0.9 );
+ probs.push_back(0.99 );
+ probs.push_back(0.999);
+
+ accumulator_t acc(extended_p_square_probabilities = probs);
+
+ for (int i=0; i<10000; ++i)
+ acc(rng());
+
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[0], probs[0], 25);
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[1], probs[1], 10);
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[2], probs[2], 5);
+
+ for (std::size_t i=3; i<probs.size(); ++i)
+ {
+ BOOST_CHECK_CLOSE(extended_p_square(acc)[i], probs[i], epsilon);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("extended_p_square test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/extended_p_square_quantile.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/extended_p_square_quantile.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,102 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for extended_p_square_quantile.hpp
+
+#include <iostream>
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/extended_p_square_quantile.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef accumulator_set<double, stats<tag::extended_p_square_quantile> > accumulator_t;
+ typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile>, double > accumulator_t_weighted;
+ typedef accumulator_set<double, stats<tag::extended_p_square_quantile(quadratic)> > accumulator_t_quadratic;
+ typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile(quadratic)>, double > accumulator_t_weighted_quadratic;
+
+ // tolerance
+ double epsilon = 1;
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ std::vector<double> probs;
+
+ probs.push_back(0.990);
+ probs.push_back(0.991);
+ probs.push_back(0.992);
+ probs.push_back(0.993);
+ probs.push_back(0.994);
+ probs.push_back(0.995);
+ probs.push_back(0.996);
+ probs.push_back(0.997);
+ probs.push_back(0.998);
+ probs.push_back(0.999);
+
+ accumulator_t acc(extended_p_square_probabilities = probs);
+ accumulator_t_weighted acc_weighted(extended_p_square_probabilities = probs);
+ accumulator_t_quadratic acc2(extended_p_square_probabilities = probs);
+ accumulator_t_weighted_quadratic acc_weighted2(extended_p_square_probabilities = probs);
+
+ for (int i=0; i<10000; ++i)
+ {
+ double sample = rng();
+ acc(sample);
+ acc2(sample);
+ acc_weighted(sample, weight = 1.);
+ acc_weighted2(sample, weight = 1.);
+ }
+
+ for (std::size_t i = 0; i < probs.size() - 1; ++i)
+ {
+ BOOST_CHECK_CLOSE(
+ quantile(acc, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ BOOST_CHECK_CLOSE(
+ quantile(acc2, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ BOOST_CHECK_CLOSE(
+ quantile(acc_weighted, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ BOOST_CHECK_CLOSE(
+ quantile(acc_weighted2, quantile_probability = 0.99025 + i*0.001)
+ , 0.99025 + i*0.001
+ , epsilon
+ );
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("extended_p_square_quantile test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/external_accumulator.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/external_accumulator.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,129 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+namespace my
+{
+ BOOST_PARAMETER_KEYWORD(tag, sum_acc)
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::mean, tag::external<tag::sum, my::tag::sum_acc> > > acc;
+ accumulator_set<int, stats<tag::sum> > sum_acc;
+
+ acc(1);
+ sum_acc(1);
+ BOOST_CHECK_CLOSE(1., mean(acc, my::sum_acc = sum_acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(sum_acc));
+
+ acc(0);
+ sum_acc(0);
+ BOOST_CHECK_CLOSE(0.5, mean(acc, my::sum_acc = sum_acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc, my::sum_acc = sum_acc));
+
+ acc(2);
+ sum_acc(2);
+ BOOST_CHECK_CLOSE(1., mean(acc, my::sum_acc = sum_acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(3, sum(acc, my::sum_acc = sum_acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_reference
+//
+void test_reference()
+{
+ typedef accumulator_set<int, stats<tag::sum> > sum_acc_type;
+ sum_acc_type sum_acc;
+ accumulator_set<
+ int
+ , stats<
+ tag::mean
+ , tag::external<tag::sum, my::tag::sum_acc>
+ , tag::reference<sum_acc_type, my::tag::sum_acc>
+ >
+ > acc(my::sum_acc = sum_acc);
+
+ acc(1);
+ sum_acc(1);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(sum_acc));
+
+ acc(0);
+ sum_acc(0);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc(2);
+ sum_acc(2);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(3, sum(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_reference2
+//
+void test_reference2()
+{
+ typedef accumulator_set<int, stats<tag::sum> > sum_acc_type;
+ sum_acc_type sum_acc;
+ accumulator_set<
+ int
+ , stats<
+ tag::mean
+ , tag::external<tag::sum, my::tag::sum_acc, sum_acc_type>
+ >
+ > acc(my::sum_acc = sum_acc);
+
+ acc(1);
+ sum_acc(1);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(sum_acc));
+
+ acc(0);
+ sum_acc(0);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+
+ acc(2);
+ sum_acc(2);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(3, sum(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("external_accumulator test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+ test->add(BOOST_TEST_CASE(&test_reference));
+ test->add(BOOST_TEST_CASE(&test_reference2));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/external_weights.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/external_weights.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,54 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::weighted_mean>, external<int> > acc;
+ accumulator_set<void, stats<tag::sum_of_weights>, int> weight_acc;
+
+ acc(10, weight = 2); // 20
+ weight_acc(weight = 2); //
+ BOOST_CHECK_EQUAL(2, sum_of_weights(weight_acc)); //
+ //
+ acc(6, weight = 3); // 18
+ weight_acc(weight = 3); //
+ BOOST_CHECK_EQUAL(5, sum_of_weights(weight_acc)); //
+ //
+ acc(4, weight = 4); // 16
+ weight_acc(weight = 4); //
+ BOOST_CHECK_EQUAL(9, sum_of_weights(weight_acc)); //
+ //
+ acc(6, weight = 5); //+ 30
+ weight_acc(weight = 5); //
+ BOOST_CHECK_EQUAL(14, sum_of_weights(weight_acc)); //
+ //= 84 / 14 = 6
+
+ BOOST_CHECK_CLOSE(6., weighted_mean(acc, weights = weight_acc), 1e-5);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("external_weights test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/kurtosis.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/kurtosis.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,70 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for kurtosis.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/kurtosis.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ // double epsilon = 1;
+
+ accumulator_set<double, stats<tag::kurtosis > > acc1;
+ accumulator_set<int, stats<tag::kurtosis > > acc2;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ acc1(normal());
+ }
+
+ // This check fails because epsilon is relative and not absolute
+ // BOOST_CHECK_CLOSE( kurtosis(acc1), 0., epsilon );
+
+ acc2(2);
+ acc2(7);
+ acc2(4);
+ acc2(9);
+ acc2(3);
+
+ BOOST_CHECK_EQUAL( mean(acc2), 5 );
+ BOOST_CHECK_EQUAL( moment<2>(acc2), 159./5. );
+ BOOST_CHECK_EQUAL( moment<3>(acc2), 1171./5. );
+ BOOST_CHECK_EQUAL( moment<4>(acc2), 1863 );
+ BOOST_CHECK_CLOSE( kurtosis(acc2), -1.39965397924, 1e-6 );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("kurtosis test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/max.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/max.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,42 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::max> > acc;
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1, (max)(acc));
+
+ acc(0);
+ BOOST_CHECK_EQUAL(1, (max)(acc));
+
+ acc(2);
+ BOOST_CHECK_EQUAL(2, (max)(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("max test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/mean.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/mean.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,92 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+template<typename T>
+void assert_is_double(T const &)
+{
+ BOOST_MPL_ASSERT((is_same<T, double>));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<
+ int
+ , stats<
+ tag::mean
+ , tag::mean_of_variates<int, tag::covariate1>
+ >
+ > acc, test_acc(sample = 0);
+
+ acc(1, covariate1 = 3);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+ BOOST_CHECK_CLOSE(3., (mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ acc(0, covariate1 = 4);
+ BOOST_CHECK_CLOSE(0.5, mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(1, sum(acc));
+ BOOST_CHECK_CLOSE(3.5, (mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ acc(2, covariate1 = 8);
+ BOOST_CHECK_CLOSE(1., mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(3, sum(acc));
+ BOOST_CHECK_CLOSE(5., (mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ assert_is_double(mean(acc));
+
+ accumulator_set<
+ int
+ , stats<
+ tag::mean(immediate)
+ , tag::mean_of_variates<int, tag::covariate1>(immediate)
+ >
+ > acc2, test_acc2(sample = 0);
+
+ acc2(1, covariate1 = 3);
+ BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc2));
+ BOOST_CHECK_CLOSE(3., (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ acc2(0, covariate1 = 4);
+ BOOST_CHECK_CLOSE(0.5, mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc2));
+ BOOST_CHECK_CLOSE(3.5, (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ acc2(2, covariate1 = 8);
+ BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc2));
+ BOOST_CHECK_CLOSE(5., (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ assert_is_double(mean(acc2));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("mean test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/median.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/median.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,57 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/random.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/median.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // two random number generators
+ double mu = 1.;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(mu,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ accumulator_set<double, stats<tag::median(with_p_square_quantile) > > acc;
+ accumulator_set<double, stats<tag::median(with_density) > >
+ acc_dens( density_cache_size = 10000, density_num_bins = 1000 );
+ accumulator_set<double, stats<tag::median(with_p_square_cumulative_distribution) > >
+ acc_cdist( p_square_cumulative_distribution_num_cells = 100 );
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal();
+ acc(sample);
+ acc_dens(sample);
+ acc_cdist(sample);
+ }
+
+ BOOST_CHECK_CLOSE(1., median(acc), 1.);
+ BOOST_CHECK_CLOSE(1., median(acc_dens), 1.);
+ BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("median test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/min.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/min.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,42 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::min> > acc;
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1, (min)(acc));
+
+ acc(0);
+ BOOST_CHECK_EQUAL(0, (min)(acc));
+
+ acc(2);
+ BOOST_CHECK_EQUAL(0, (min)(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("min test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/moment.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/moment.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,52 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/moment.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::moment<2> > > acc1;
+
+ acc1(2); // 4
+ acc1(4); // 16
+ acc1(5); // + 25
+ // = 45 / 3 = 15
+
+ BOOST_CHECK_CLOSE(15., moment<2>(acc1), 1e-5);
+
+ accumulator_set<int, stats<tag::moment<5> > > acc2;
+
+ acc2(2); // 32
+ acc2(3); // 243
+ acc2(4); // 1024
+ acc2(5); // + 3125
+ // = 4424 / 4 = 1106
+
+ BOOST_CHECK_CLOSE(1106., moment<5>(acc2), 1e-5);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("moment test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/p_square_cumulative_distribution.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/p_square_cumulative_distribution.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,81 @@
+// (C) Copyright Eric Niebler, Olivier Gygi 2006.
+// Use, modification and distribution are subject to 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)
+
+// Test case for p_square_cumulative_distribution.hpp
+
+#include <cmath>
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/p_square_cumulative_distribution.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// erf() not known by VC++ compiler!
+// my_erf() computes error function by numerically integrating with trapezoidal rule
+//
+double my_erf(double const& x, int const& n = 1000)
+{
+ double sum = 0.;
+ double delta = x/n;
+ for (int i = 1; i < n; ++i)
+ sum += std::exp(-i*i*delta*delta) * delta;
+ sum += 0.5 * delta * (1. + std::exp(-x*x));
+ return sum * 2. / std::sqrt(3.141592653);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 3;
+
+ typedef accumulator_set<double, stats<tag::p_square_cumulative_distribution> > accumulator_t;
+
+ accumulator_t acc(p_square_cumulative_distribution_num_cells = 100);
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ acc(normal());
+ }
+
+ typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
+ histogram_type histogram = p_square_cumulative_distribution(acc);
+
+ for (std::size_t i = 0; i < histogram.size(); ++i)
+ {
+ // problem with small results: epsilon is relative (in percent), not absolute!
+ if ( histogram[i].second > 0.001 )
+ BOOST_CHECK_CLOSE( 0.5 * (1.0 + my_erf( histogram[i].first / sqrt(2.0) )), histogram[i].second, epsilon );
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("p_square_cumulative_distribution test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/p_square_quantile.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/p_square_quantile.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,81 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for p_square_quantile.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/p_square_quantile.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef accumulator_set<double, stats<tag::p_square_quantile> > accumulator_t;
+
+ // tolerance in %
+ double epsilon = 1;
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ accumulator_t acc0(quantile_probability = 0.001);
+ accumulator_t acc1(quantile_probability = 0.01 );
+ accumulator_t acc2(quantile_probability = 0.1 );
+ accumulator_t acc3(quantile_probability = 0.25 );
+ accumulator_t acc4(quantile_probability = 0.5 );
+ accumulator_t acc5(quantile_probability = 0.75 );
+ accumulator_t acc6(quantile_probability = 0.9 );
+ accumulator_t acc7(quantile_probability = 0.99 );
+ accumulator_t acc8(quantile_probability = 0.999);
+
+ for (int i=0; i<100000; ++i)
+ {
+ double sample = rng();
+ acc0(sample);
+ acc1(sample);
+ acc2(sample);
+ acc3(sample);
+ acc4(sample);
+ acc5(sample);
+ acc6(sample);
+ acc7(sample);
+ acc8(sample);
+ }
+
+ BOOST_CHECK_CLOSE( p_square_quantile(acc0), 0.001, 15*epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc1), 0.01 , 5*epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc2), 0.1 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc3), 0.25 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc4), 0.5 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc5), 0.75 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc6), 0.9 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc7), 0.99 , epsilon );
+ BOOST_CHECK_CLOSE( p_square_quantile(acc8), 0.999, epsilon );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("p_square_quantile test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/p_square_quantile_extended.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/p_square_quantile_extended.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,70 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for p_square_quantile_extended.hpp
+
+#include <iostream>
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/p_square_quantile_extended.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef accumulator_set<double, stats<tag::p_square_quantile_extended> > accumulator_t;
+
+ // tolerance
+ double epsilon = 1e-6;
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ std::vector<double> probs;
+
+ probs.push_back(0.001);
+ probs.push_back(0.01 );
+ probs.push_back(0.1 );
+ probs.push_back(0.25 );
+ probs.push_back(0.5 );
+ probs.push_back(0.75 );
+ probs.push_back(0.9 );
+ probs.push_back(0.99 );
+ probs.push_back(0.999);
+
+ accumulator_t acc(tag::p_square_quantile_extended::probabilities = probs);
+
+ for (int i=0; i<10000; ++i)
+ acc(rng());
+
+ for (std::size_t i=0; i<probs.size(); ++i)
+ {
+ BOOST_CHECK_CLOSE(p_square_quantile_extended(acc)[i], probs[i], epsilon);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("p_square_quantile_extended test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/pot_quantile.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/pot_quantile.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,97 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for pot_quantile.hpp
+
+#define BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+#include <boost/accumulators/statistics/peaks_over_threshold.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 1.;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::exponential_distribution<> lambda(1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::exponential_distribution<> > exponential(rng, lambda);
+
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc1(
+ pot_threshold_value = 3.
+ );
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc2(
+ right_tail_cache_size = 2000
+ , pot_threshold_probability = 0.99
+ );
+ accumulator_set<double, stats<tag::pot_quantile<left>(with_threshold_value)> > acc3(
+ pot_threshold_value = -3.
+ );
+ accumulator_set<double, stats<tag::pot_quantile<left>(with_threshold_probability)> > acc4(
+ left_tail_cache_size = 2000
+ , pot_threshold_probability = 0.01
+ );
+
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_value)> > acc5(
+ pot_threshold_value = 5.
+ );
+ accumulator_set<double, stats<tag::pot_quantile<right>(with_threshold_probability)> > acc6(
+ right_tail_cache_size = 2000
+ , pot_threshold_probability = 0.995
+ );
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ double sample = normal();
+ acc1(sample);
+ acc2(sample);
+ acc3(sample);
+ acc4(sample);
+ }
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ double sample = exponential();
+ acc5(sample);
+ acc6(sample);
+ }
+
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.999), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.001), -3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc4, quantile_probability = 0.001), -3.090232, epsilon );
+
+ BOOST_CHECK_CLOSE( quantile(acc5, quantile_probability = 0.999), 6.908, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc6, quantile_probability = 0.999), 6.908, epsilon );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("pot_quantile test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/reference.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/reference.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,95 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+namespace my
+{
+ BOOST_PARAMETER_KEYWORD(tag, int_ref)
+ BOOST_PARAMETER_KEYWORD(tag, sum_acc)
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ int i = 0;
+ accumulator_set<double, stats<tag::reference<int, my::tag::int_ref> > > acc(
+ my::int_ref = i);
+
+ int &ref1 = reference<int, my::tag::int_ref>(acc);
+ int &ref2 = reference_tag<my::tag::int_ref>(acc);
+
+ BOOST_CHECK_EQUAL(&i, &ref1);
+ BOOST_CHECK_EQUAL(&i, &ref2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_external
+//
+void test_external()
+{
+ typedef accumulator_set<int, stats<tag::sum> > sum_acc_type;
+ sum_acc_type sum_acc; // the sum accumulator
+ accumulator_set<
+ int
+ , stats<
+ tag::mean
+ , tag::external<tag::sum, my::tag::sum_acc> // make sum external
+ , tag::reference<sum_acc_type, my::tag::sum_acc> // and hold a reference to it
+ >
+ > acc_with_ref(my::sum_acc = sum_acc); // initialize the reference sum
+
+ sum_acc(1);
+ sum_acc(2); // sum is now 3 for both
+
+ BOOST_CHECK_EQUAL(sum(acc_with_ref), sum(sum_acc));
+ BOOST_CHECK_EQUAL(sum(acc_with_ref), 3);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_external2
+//
+void test_external2()
+{
+ typedef accumulator_set<int, stats<tag::sum> > sum_acc_type;
+ sum_acc_type sum_acc; // the sum accumulator
+ accumulator_set<
+ int
+ , stats<
+ tag::mean
+ // make sum external and hold a reference to it
+ , tag::external<tag::sum, my::tag::sum_acc, sum_acc_type>
+ >
+ > acc_with_ref(my::sum_acc = sum_acc); // initialize the reference sum
+
+ sum_acc(1);
+ sum_acc(2); // sum is now 3 for both
+
+ BOOST_CHECK_EQUAL(sum(acc_with_ref), sum(sum_acc));
+ BOOST_CHECK_EQUAL(sum(acc_with_ref), 3);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("reference_accumulator test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+ test->add(BOOST_TEST_CASE(&test_external));
+ test->add(BOOST_TEST_CASE(&test_external2));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/skewness.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/skewness.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,69 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for skewness.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/skewness.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ // double epsilon = 1;
+
+ accumulator_set<double, stats<tag::skewness > > acc1;
+ accumulator_set<int, stats<tag::skewness > > acc2;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ acc1(normal());
+ }
+
+ // This check fails because epsilon is relative and not absolute
+ // BOOST_CHECK_CLOSE( skewness(acc1), 0., epsilon );
+
+ acc2(2);
+ acc2(7);
+ acc2(4);
+ acc2(9);
+ acc2(3);
+
+ BOOST_CHECK_EQUAL( mean(acc2), 5 );
+ BOOST_CHECK_EQUAL( moment<2>(acc2), 159./5. );
+ BOOST_CHECK_EQUAL( moment<3>(acc2), 1171./5. );
+ BOOST_CHECK_CLOSE( skewness(acc2), 0.406040288214, 1e-6 );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("skewness test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/sum.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/sum.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,50 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/weighted_sum.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::sum, tag::sum_of_weights, tag::sum_of_variates<int, tag::covariate1> >, int> acc;
+
+ acc(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_EQUAL(2, sum(acc));
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc));
+ BOOST_CHECK_EQUAL(3, sum_of_variates(acc));
+
+ acc(2, weight = 4, covariate1 = 6);
+ BOOST_CHECK_EQUAL(10, sum(acc));
+ BOOST_CHECK_EQUAL(6, sum_of_weights(acc));
+ BOOST_CHECK_EQUAL(9, sum_of_variates(acc));
+
+ acc(3, weight = 6, covariate1 = 9);
+ BOOST_CHECK_EQUAL(28, sum(acc));
+ BOOST_CHECK_EQUAL(12, sum_of_weights(acc));
+ BOOST_CHECK_EQUAL(18, sum_of_variates(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("sum test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/tail.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/tail.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,126 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/foreach.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/tail.hpp>
+#include <boost/accumulators/statistics/tail_variate.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+template<typename Range>
+void check_tail(Range const &rng, char const *expected)
+{
+ BOOST_FOREACH(int i, rng)
+ {
+ if(!*expected)
+ {
+ BOOST_CHECK(false);
+ return;
+ }
+ BOOST_CHECK_EQUAL(i, *expected++);
+ }
+ BOOST_CHECK(!*expected);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_right_tail
+//
+void test_right_tail()
+{
+ accumulator_set<int, stats<tag::tail_weights<right>, tag::tail_variate<int, tag::covariate1, right> >, int > acc(
+ right_tail_cache_size = 4
+ );
+
+ acc(010, weight = 2, covariate1 = 3);
+ check_tail(tail(acc), "\10");
+ check_tail(tail_variate(acc), "\3");
+ check_tail(tail_weights(acc), "\2");
+
+ acc(020, weight = 7, covariate1 = 1);
+ check_tail(tail(acc), "\20\10");
+ check_tail(tail_variate(acc), "\1\3");
+ check_tail(tail_weights(acc), "\7\2");
+
+ acc(014, weight = 6, covariate1 = 4);
+ check_tail(tail(acc), "\20\14\10");
+ check_tail(tail_variate(acc), "\1\4\3");
+ check_tail(tail_weights(acc), "\7\6\2");
+
+ acc(030, weight = 4, covariate1 = 5);
+ check_tail(tail(acc), "\30\20\14\10");
+ check_tail(tail_variate(acc), "\5\1\4\3");
+ check_tail(tail_weights(acc), "\4\7\6\2");
+
+ acc(001, weight = 1, covariate1 = 9);
+ check_tail(tail(acc), "\30\20\14\10");
+ check_tail(tail_variate(acc), "\5\1\4\3");
+ check_tail(tail_weights(acc), "\4\7\6\2");
+
+ acc(011, weight = 3, covariate1 = 7);
+ check_tail(tail(acc), "\30\20\14\11");
+ check_tail(tail_variate(acc), "\5\1\4\7");
+ check_tail(tail_weights(acc), "\4\7\6\3");
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_left_tail
+//
+void test_left_tail()
+{
+ accumulator_set<int, stats<tag::tail_weights<left>, tag::tail_variate<int, tag::covariate1, left> >, int > acc(
+ left_tail_cache_size = 4
+ );
+
+ acc(010, weight = 2, covariate1 = 3);
+ check_tail(tail(acc), "\10");
+ check_tail(tail_variate(acc), "\3");
+ check_tail(tail_weights(acc), "\2");
+
+ acc(020, weight = 7, covariate1 = 1);
+ check_tail(tail(acc), "\10\20");
+ check_tail(tail_variate(acc), "\3\1");
+ check_tail(tail_weights(acc), "\2\7");
+
+ acc(014, weight = 6, covariate1 = 4);
+ check_tail(tail(acc), "\10\14\20");
+ check_tail(tail_variate(acc), "\3\4\1");
+ check_tail(tail_weights(acc), "\2\6\7");
+
+ acc(030, weight = 4, covariate1 = 5);
+ check_tail(tail(acc), "\10\14\20\30");
+ check_tail(tail_variate(acc), "\3\4\1\5");
+ check_tail(tail_weights(acc), "\2\6\7\4");
+
+ acc(001, weight = 1, covariate1 = 9);
+ check_tail(tail(acc), "\1\10\14\20");
+ check_tail(tail_variate(acc), "\x9\3\4\1");
+ check_tail(tail_weights(acc), "\1\2\6\7");
+
+ acc(011, weight = 3, covariate1 = 7);
+ check_tail(tail(acc), "\1\10\11\14");
+ check_tail(tail_variate(acc), "\x9\3\7\4");
+ check_tail(tail_weights(acc), "\1\2\3\6");
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("tail test");
+
+ test->add(BOOST_TEST_CASE(&test_right_tail));
+ test->add(BOOST_TEST_CASE(&test_left_tail));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/tail_mean.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/tail_mean.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,86 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for tail_mean.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/tail_mean.hpp>
+#include <boost/accumulators/statistics/tail_quantile.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 1;
+
+ std::size_t n = 100000; // number of MC steps
+ std::size_t c = 10000; // cache size
+
+ typedef accumulator_set<double, stats<tag::non_coherent_tail_mean<right>, tag::tail_quantile<right> > > accumulator_t_right1;
+ typedef accumulator_set<double, stats<tag::non_coherent_tail_mean<left>, tag::tail_quantile<left> > > accumulator_t_left1;
+ typedef accumulator_set<double, stats<tag::coherent_tail_mean<right>, tag::tail_quantile<right> > > accumulator_t_right2;
+ typedef accumulator_set<double, stats<tag::coherent_tail_mean<left>, tag::tail_quantile<left> > > accumulator_t_left2;
+
+ accumulator_t_right1 acc0( right_tail_cache_size = c );
+ accumulator_t_left1 acc1( left_tail_cache_size = c );
+ accumulator_t_right2 acc2( right_tail_cache_size = c );
+ accumulator_t_left2 acc3( left_tail_cache_size = c );
+
+ // a random number generator
+ boost::lagged_fibonacci607 rng;
+
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ double sample = rng();
+ acc0(sample);
+ acc1(sample);
+ acc2(sample);
+ acc3(sample);
+ }
+
+ // check uniform distribution
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.95), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.975), 0.9875, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.99), 0.995, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc0, quantile_probability = 0.999), 0.9995, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.05), 0.025, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.025), 0.0125, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.01), 0.005, 5 );
+ BOOST_CHECK_CLOSE( non_coherent_tail_mean(acc1, quantile_probability = 0.001), 0.0005, 10 );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.95), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.975), 0.9875, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.99), 0.995, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc2, quantile_probability = 0.999), 0.9995, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.05), 0.025, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.025), 0.0125, epsilon );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.01), 0.005, 5 );
+ BOOST_CHECK_CLOSE( tail_mean(acc3, quantile_probability = 0.001), 0.0005, 10 );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("tail_mean test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/tail_quantile.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/tail_quantile.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,85 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for tail_quantile.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/tail_quantile.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 1;
+
+ std::size_t n = 100000; // number of MC steps
+ std::size_t c = 10000; // cache size
+
+ typedef accumulator_set<double, stats<tag::tail_quantile<right> > > accumulator_t_right;
+ typedef accumulator_set<double, stats<tag::tail_quantile<left> > > accumulator_t_left;
+
+ accumulator_t_right acc0( right_tail_cache_size = c );
+ accumulator_t_right acc1( right_tail_cache_size = c );
+ accumulator_t_left acc2( left_tail_cache_size = c );
+ accumulator_t_left acc3( left_tail_cache_size = c );
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ double sample1 = rng();
+ double sample2 = normal();
+ acc0(sample1);
+ acc1(sample2);
+ acc2(sample1);
+ acc3(sample2);
+ }
+
+ // check uniform distribution
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.95 ), 0.95, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.975), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.99 ), 0.99, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc0, quantile_probability = 0.999), 0.999, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.05 ), 0.05, 2 );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.025), 0.025, 2 );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.01 ), 0.01, 3 );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.001), 0.001, 20 );
+
+ // check standard normal distribution
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.975), 1.959963, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.025), -1.959963, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.001), -3.090232, epsilon );
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("tail_quantile test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/tail_variate_means.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/tail_variate_means.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,131 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for tail_variate_means.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/tail_variate_means.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ std::size_t c = 5; // cache size
+
+ typedef double variate_type;
+ typedef std::vector<variate_type> variate_set_type;
+
+ typedef accumulator_set<double, stats<tag::tail_variate_means<right, variate_set_type, tag::covariate1>(relative)> > accumulator_t1;
+ typedef accumulator_set<double, stats<tag::tail_variate_means<right, variate_set_type, tag::covariate1>(absolute)> > accumulator_t2;
+ typedef accumulator_set<double, stats<tag::tail_variate_means<left, variate_set_type, tag::covariate1>(relative)> > accumulator_t3;
+ typedef accumulator_set<double, stats<tag::tail_variate_means<left, variate_set_type, tag::covariate1>(absolute)> > accumulator_t4;
+
+ accumulator_t1 acc1( right_tail_cache_size = c );
+ accumulator_t2 acc2( right_tail_cache_size = c );
+ accumulator_t3 acc3( left_tail_cache_size = c );
+ accumulator_t4 acc4( left_tail_cache_size = c );
+
+ variate_set_type cov1, cov2, cov3, cov4, cov5;
+ double c1[] = { 10., 20., 30., 40. }; // 100
+ double c2[] = { 26., 4., 17., 3. }; // 50
+ double c3[] = { 46., 64., 40., 50. }; // 200
+ double c4[] = { 1., 3., 70., 6. }; // 80
+ double c5[] = { 2., 2., 2., 14. }; // 20
+ cov1.assign(c1, c1 + sizeof(c1)/sizeof(variate_type));
+ cov2.assign(c2, c2 + sizeof(c2)/sizeof(variate_type));
+ cov3.assign(c3, c3 + sizeof(c3)/sizeof(variate_type));
+ cov4.assign(c4, c4 + sizeof(c4)/sizeof(variate_type));
+ cov5.assign(c5, c5 + sizeof(c5)/sizeof(variate_type));
+
+ acc1(100., covariate1 = cov1);
+ acc1( 50., covariate1 = cov2);
+ acc1(200., covariate1 = cov3);
+ acc1( 80., covariate1 = cov4);
+ acc1( 20., covariate1 = cov5);
+
+ acc2(100., covariate1 = cov1);
+ acc2( 50., covariate1 = cov2);
+ acc2(200., covariate1 = cov3);
+ acc2( 80., covariate1 = cov4);
+ acc2( 20., covariate1 = cov5);
+
+ acc3(100., covariate1 = cov1);
+ acc3( 50., covariate1 = cov2);
+ acc3(200., covariate1 = cov3);
+ acc3( 80., covariate1 = cov4);
+ acc3( 20., covariate1 = cov5);
+
+ acc4(100., covariate1 = cov1);
+ acc4( 50., covariate1 = cov2);
+ acc4(200., covariate1 = cov3);
+ acc4( 80., covariate1 = cov4);
+ acc4( 20., covariate1 = cov5);
+
+ // check relative risk contributions
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() ), 14./75. ); // (10 + 46) / 300 = 14/75
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 1), 7./25. ); // (20 + 64) / 300 = 7/25
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 2), 7./30. ); // (30 + 40) / 300 = 7/30
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 3), 3./10. ); // (40 + 50) / 300 = 3/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() ), 14./35. ); // (26 + 2) / 70 = 14/35
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 1), 3./35. ); // ( 4 + 2) / 70 = 3/35
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 2), 19./70. ); // (17 + 2) / 70 = 19/70
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 3), 17./70. ); // ( 3 + 14) / 70 = 17/70
+
+ // check absolute risk contributions
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() ), 28 ); // (10 + 46) / 2 = 28
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 1), 42 ); // (20 + 64) / 2 = 42
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 2), 35 ); // (30 + 40) / 2 = 35
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.7).begin() + 3), 45 ); // (40 + 50) / 2 = 45
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() ), 14 ); // (26 + 2) / 2 = 14
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 1), 3 ); // ( 4 + 2) / 2 = 3
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 2),9.5 ); // (17 + 2) / 2 = 9.5
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.3).begin() + 3),8.5 ); // ( 3 + 14) / 2 = 8.5
+
+ // check relative risk contributions
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() ), 23./100. ); // 46/200 = 23/100
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 1), 8./25. ); // 64/200 = 8/25
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 2), 1./5. ); // 40/200 = 1/5
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 3), 1./4. ); // 50/200 = 1/4
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() ), 1./10. ); // 2/ 20 = 1/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 1), 1./10. ); // 2/ 20 = 1/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 2), 1./10. ); // 2/ 20 = 1/10
+ BOOST_CHECK_EQUAL( *(relative_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 3), 7./10. ); // 14/ 20 = 7/10
+
+ // check absolute risk contributions
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() ), 46 ); // 46
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 1), 64 ); // 64
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 2), 40 ); // 40
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc2, quantile_probability = 0.9).begin() + 3), 50 ); // 50
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() ), 2 ); // 2
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 1), 2 ); // 2
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 2), 2 ); // 2
+ BOOST_CHECK_EQUAL( *(tail_variate_means(acc4, quantile_probability = 0.1).begin() + 3), 14 ); // 14
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("tail_variate_means test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/valarray.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/valarray.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,180 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <iostream>
+#include <valarray>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_floating_point.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+template<typename T>
+typename enable_if<is_floating_point<T> >::type is_equal_or_close(T const &left, T const &right)
+{
+ BOOST_CHECK_CLOSE(left, right, 1e-5);
+}
+
+template<typename T>
+typename disable_if<is_floating_point<T> >::type is_equal_or_close(T const &left, T const &right)
+{
+ BOOST_CHECK_EQUAL(left, right);
+}
+
+template<typename T>
+void is_equal(std::valarray<T> const &left, std::valarray<T> const &right)
+{
+ BOOST_CHECK_EQUAL(left.size(), right.size());
+ if(left.size() == right.size())
+ {
+ for(std::size_t i = 0; i < left.size(); ++i)
+ {
+ is_equal_or_close(left[i], right[i]);
+ }
+ }
+}
+
+namespace std
+{
+ template<typename T>
+ inline std::ostream &operator <<(std::ostream &sout, std::valarray<T> const &arr)
+ {
+ sout << '(';
+ for(std::size_t i = 0; i < arr.size(); ++i)
+ {
+ sout << arr[i] << ',';
+ }
+ sout << ')' << std::endl;
+ return sout;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef std::valarray<int> sample_t;
+
+ // test sum
+ {
+ accumulator_set<sample_t, stats<tag::sum> > acc(sample = sample_t(0,3));
+
+ acc(sample_t(1,3));
+ acc(sample_t(2,3));
+ acc(sample_t(3,3));
+
+ is_equal(sample_t(6,3), sum(acc));
+ }
+
+ // test min and max
+ {
+ int s1[] = {1,2,3}, s2[] = {0,3,4}, s3[] = {2,1,4}, min_res[] = {0,1,3}, max_res[] = {2,3,4};
+ accumulator_set<sample_t, stats<tag::min, tag::max> > acc(sample = sample_t(0,3));
+
+ acc(sample_t(s1,3));
+ acc(sample_t(s2,3));
+ acc(sample_t(s3,3));
+
+ is_equal(sample_t(min_res,3), (min)(acc));
+ is_equal(sample_t(max_res,3), (max)(acc));
+ }
+
+ // test mean(lazy) and mean(immediate)
+ {
+ accumulator_set<sample_t, stats<tag::mean> > acc(sample = sample_t(0,3));
+
+ acc(sample_t(1,3));
+ is_equal(std::valarray<double>(1., 3), mean(acc));
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ is_equal(sample_t(1, 3), sum(acc));
+
+ acc(sample_t(0,3));
+ is_equal(std::valarray<double>(0.5, 3), mean(acc));
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ is_equal(sample_t(1, 3), sum(acc));
+
+ acc(sample_t(2,3));
+ is_equal(std::valarray<double>(1., 3), mean(acc));
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ is_equal(sample_t(3, 3), sum(acc));
+
+
+ accumulator_set<sample_t, stats<tag::mean(immediate)> > acc2(sample = sample_t(0,3));
+
+ acc2(sample_t(1,3));
+ is_equal(std::valarray<double>(1., 3), mean(acc2));
+ BOOST_CHECK_EQUAL(1u, count(acc2));
+
+ acc2(sample_t(0,3));
+ is_equal(std::valarray<double>(0.5, 3), mean(acc2));
+ BOOST_CHECK_EQUAL(2u, count(acc2));
+
+ acc2(sample_t(2,3));
+ is_equal(std::valarray<double>(1., 3), mean(acc2));
+ BOOST_CHECK_EQUAL(3u, count(acc2));
+ }
+
+ // test weighted_mean
+ {
+ accumulator_set<sample_t, stats<tag::weighted_mean>, int> acc(sample = sample_t(0,3));
+
+ acc(sample_t(10,3), weight = 2); // 20
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc)); //
+ //
+ acc(sample_t(6,3), weight = 3); // 18
+ BOOST_CHECK_EQUAL(5, sum_of_weights(acc)); //
+ //
+ acc(sample_t(4,3), weight = 4); // 16
+ BOOST_CHECK_EQUAL(9, sum_of_weights(acc)); //
+ //
+ acc(sample_t(6,3), weight = 5); //+ 30
+ BOOST_CHECK_EQUAL(14, sum_of_weights(acc)); //
+ //= 84 / 14 = 6
+
+ is_equal(std::valarray<double>(6.,3), weighted_mean(acc));
+
+
+ accumulator_set<sample_t, stats<tag::weighted_mean(immediate)>, int> acc2(sample = sample_t(0,3));
+
+ acc2(sample_t(10,3), weight = 2); // 20
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc2)); //
+ //
+ acc2(sample_t(6,3), weight = 3); // 18
+ BOOST_CHECK_EQUAL(5, sum_of_weights(acc2)); //
+ //
+ acc2(sample_t(4,3), weight = 4); // 16
+ BOOST_CHECK_EQUAL(9, sum_of_weights(acc2)); //
+ //
+ acc2(sample_t(6,3), weight = 5); //+ 30
+ BOOST_CHECK_EQUAL(14, sum_of_weights(acc2));//
+ //= 84 / 14 = 6
+
+ is_equal(std::valarray<double>(6.,3), weighted_mean(acc2));
+
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("valarray test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/value.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/value.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,45 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+namespace my
+{
+ BOOST_PARAMETER_KEYWORD(tag, int_val)
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ int i = 42;
+ accumulator_set<double, stats<tag::value<int, my::tag::int_val> > > acc2(
+ my::int_val = i);
+
+ int val1 = value<int, my::tag::int_val>(acc2);
+ int val2 = value_tag<my::tag::int_val>(acc2);
+
+ BOOST_CHECK_EQUAL(i, val1);
+ BOOST_CHECK_EQUAL(i, val2);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("value_accumulator test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/variance.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/variance.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,68 @@
+// (C) Copyright 2005 Daniel Egloff, Eric Niebler
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/variance.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // matlab
+ // >> samples = [1:5];
+ // >> mean(samples)
+ // ans = 3
+ // >> sum(samples .* samples) / length(samples)
+ // ans = 11
+ // >> sum(samples .* samples) / length(samples) - mean(samples)^2
+ // ans = 2
+
+ // basic lazy variance
+ accumulator_set<int, stats<tag::variance > > acc1;
+
+ acc1(1);
+ acc1(2);
+ acc1(3);
+ acc1(4);
+ acc1(5);
+
+ BOOST_CHECK_EQUAL(5u, count(acc1));
+ BOOST_CHECK_CLOSE(3., mean(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(11., moment<2>(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(2., variance(acc1), 1e-5);
+
+ // immediate variance, now immediate with syntactic sugar, thanks to Eric
+ accumulator_set<int, stats<tag::variance(immediate) > > acc2;
+
+ acc2(1);
+ acc2(2);
+ acc2(3);
+ acc2(4);
+ acc2(5);
+
+ BOOST_CHECK_EQUAL(5u, count(acc2));
+ BOOST_CHECK_CLOSE(3., mean(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(2., variance(acc2), 1e-5);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("variance test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/vector.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/vector.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,180 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <iostream>
+#include <vector>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_floating_point.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+template<typename T>
+typename enable_if<is_floating_point<T> >::type is_equal_or_close(T const &left, T const &right)
+{
+ BOOST_CHECK_CLOSE(left, right, 1e-5);
+}
+
+template<typename T>
+typename disable_if<is_floating_point<T> >::type is_equal_or_close(T const &left, T const &right)
+{
+ BOOST_CHECK_EQUAL(left, right);
+}
+
+template<typename T>
+void is_equal(std::vector<T> const &left, std::vector<T> const &right)
+{
+ BOOST_CHECK_EQUAL(left.size(), right.size());
+ if(left.size() == right.size())
+ {
+ for(std::size_t i = 0; i < left.size(); ++i)
+ {
+ is_equal_or_close(left[i], right[i]);
+ }
+ }
+}
+
+namespace std
+{
+ template<typename T>
+ inline std::ostream &operator <<(std::ostream &sout, std::vector<T> const &arr)
+ {
+ sout << '(';
+ for(std::size_t i = 0; i < arr.size(); ++i)
+ {
+ sout << arr[i] << ',';
+ }
+ sout << ')' << std::endl;
+ return sout;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef std::vector<int> sample_t;
+
+ // test sum
+ {
+ accumulator_set<sample_t, stats<tag::sum> > acc(sample = sample_t(3,0));
+
+ acc(sample_t(3,1));
+ acc(sample_t(3,2));
+ acc(sample_t(3,3));
+
+ is_equal(sample_t(3,6), sum(acc));
+ }
+
+ // test min and max
+ {
+ int s1[] = {1,2,3}, s2[] = {0,3,4}, s3[] = {2,1,4}, min_res[] = {0,1,3}, max_res[] = {2,3,4};
+ accumulator_set<sample_t, stats<tag::min, tag::max> > acc(sample = sample_t(3,0));
+
+ acc(sample_t(s1,s1+3));
+ acc(sample_t(s2,s2+3));
+ acc(sample_t(s3,s3+3));
+
+ is_equal(sample_t(min_res,min_res+3), (min)(acc));
+ is_equal(sample_t(max_res,max_res+3), (max)(acc));
+ }
+
+ // test mean(lazy) and mean(immediate)
+ {
+ accumulator_set<sample_t, stats<tag::mean> > acc(sample = sample_t(3,0));
+
+ acc(sample_t(3,1));
+ is_equal(std::vector<double>(3, 1.), mean(acc));
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ is_equal(sample_t(3,1), sum(acc));
+
+ acc(sample_t(3,0));
+ is_equal(std::vector<double>(3, 0.5), mean(acc));
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ is_equal(sample_t(3,1), sum(acc));
+
+ acc(sample_t(3,2));
+ is_equal(std::vector<double>(3, 1.), mean(acc));
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ is_equal(sample_t(3,3), sum(acc));
+
+
+ accumulator_set<sample_t, stats<tag::mean(immediate)> > acc2(sample = sample_t(3,0));
+
+ acc2(sample_t(3,1));
+ is_equal(std::vector<double>(3,1.), mean(acc2));
+ BOOST_CHECK_EQUAL(1u, count(acc2));
+
+ acc2(sample_t(3,0));
+ is_equal(std::vector<double>(3,0.5), mean(acc2));
+ BOOST_CHECK_EQUAL(2u, count(acc2));
+
+ acc2(sample_t(3,2));
+ is_equal(std::vector<double>(3,1.), mean(acc2));
+ BOOST_CHECK_EQUAL(3u, count(acc2));
+ }
+
+ // test weighted_mean
+ {
+ accumulator_set<sample_t, stats<tag::weighted_mean>, int> acc(sample = sample_t(3,0));
+
+ acc(sample_t(3,10), weight = 2); // 20
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc)); //
+ //
+ acc(sample_t(3,6), weight = 3); // 18
+ BOOST_CHECK_EQUAL(5, sum_of_weights(acc)); //
+ //
+ acc(sample_t(3,4), weight = 4); // 16
+ BOOST_CHECK_EQUAL(9, sum_of_weights(acc)); //
+ //
+ acc(sample_t(3,6), weight = 5); //+ 30
+ BOOST_CHECK_EQUAL(14, sum_of_weights(acc)); //
+ //= 84 / 14 = 6
+
+ is_equal(std::vector<double>(3,6.), weighted_mean(acc));
+
+
+ accumulator_set<sample_t, stats<tag::weighted_mean(immediate)>, int> acc2(sample = sample_t(3,0));
+
+ acc2(sample_t(3,10), weight = 2); // 20
+ BOOST_CHECK_EQUAL(2, sum_of_weights(acc2)); //
+ //
+ acc2(sample_t(3,6), weight = 3); // 18
+ BOOST_CHECK_EQUAL(5, sum_of_weights(acc2)); //
+ //
+ acc2(sample_t(3,4), weight = 4); // 16
+ BOOST_CHECK_EQUAL(9, sum_of_weights(acc2)); //
+ //
+ acc2(sample_t(3,6), weight = 5); //+ 30
+ BOOST_CHECK_EQUAL(14, sum_of_weights(acc2));//
+ //= 84 / 14 = 6
+
+ is_equal(std::vector<double>(3,6.), weighted_mean(acc2));
+
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("vector test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/weighted_covariance.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_covariance.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,101 @@
+// (C) Copyright 2005 Daniel Egloff, Eric Niebler
+// Use, modification and distribution are subject to 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)
+
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_covariance.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ std::vector<double> dummy;
+ dummy.push_back(0);
+ dummy.push_back(0);
+
+ accumulator_set<double, stats<tag::weighted_covariance<double, tag::covariate1> >, double > acc;
+ accumulator_set<std::vector<double>, stats<tag::weighted_covariance<double, tag::covariate1> >, double > acc2(sample = dummy);
+ accumulator_set<double, stats<tag::weighted_covariance<std::vector<double>, tag::covariate1> >, double > acc3(covariate1 = dummy);
+ accumulator_set<std::vector<double>, stats<tag::weighted_covariance<std::vector<double>, tag::covariate1> >, double > acc4(sample = dummy, covariate1 = dummy);
+
+ std::vector<double> a;
+ a.push_back(1.);
+ a.push_back(2.);
+ std::vector<double> b;
+ b.push_back(3.);
+ b.push_back(4.);
+ std::vector<double> c;
+ c.push_back(2.);
+ c.push_back(5.);
+ std::vector<double> d;
+ d.push_back(4.);
+ d.push_back(2.);
+
+ // double - double
+ {
+ acc(1., weight = 1.1, covariate1 = 2.);
+ acc(1., weight = 2.2, covariate1 = 4.);
+ acc(2., weight = 3.3, covariate1 = 3.);
+ acc(6., weight = 4.4, covariate1 = 1.);
+ }
+
+ // vector - double
+ {
+ acc2(a, weight = 1.1, covariate1 = 1.);
+ acc2(b, weight = 2.2, covariate1 = 1.);
+ acc2(c, weight = 3.3, covariate1 = 2.);
+ acc2(d, weight = 4.4, covariate1 = 6.);
+ }
+
+ // double - vector
+ {
+ acc3(1., weight = 1.1, covariate1 = a);
+ acc3(1., weight = 2.2, covariate1 = b);
+ acc3(2., weight = 3.3, covariate1 = c);
+ acc3(6., weight = 4.4, covariate1 = d);
+ }
+
+ // vector - vector
+ {
+ acc4(a, weight = 1.1, covariate1 = b);
+ acc4(b, weight = 2.2, covariate1 = c);
+ acc4(a, weight = 3.3, covariate1 = c);
+ acc4(d, weight = 4.4, covariate1 = b);
+ }
+
+ double epsilon = 1e-6;
+
+ BOOST_CHECK_CLOSE((weighted_covariance(acc)), -2.39, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc2))[0], 1.93, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc2))[1], -2.09, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc3))[0], 1.93, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc3))[1], -2.09, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc4))(0,0), 0.4, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc4))(0,1), -0.2, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc4))(1,0), -0.4, epsilon);
+ BOOST_CHECK_CLOSE((weighted_covariance(acc4))(1,1), 0.2, epsilon);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_covariance test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/weighted_extended_p_square.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_extended_p_square.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,98 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_extended_p_square.hpp
+
+#include <iostream>
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_extended_p_square.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef accumulator_set<double, stats<tag::weighted_extended_p_square>, double> accumulator_t;
+
+ // problem with small results: epsilon is relative (in percent), not absolute
+
+ // tolerance in %
+ double epsilon = 1;
+
+ // some random number generators
+ double mu1 = -1.0;
+ double mu2 = 1.0;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma1(mu1, 1);
+ boost::normal_distribution<> mean_sigma2(mu2, 1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal1(rng, mean_sigma1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal2(rng, mean_sigma2);
+
+ std::vector<double> probs_uniform, probs_normal1, probs_normal2, probs_normal_exact1, probs_normal_exact2;
+
+ double p1[] = {/*0.001,*/ 0.01, 0.1, 0.5, 0.9, 0.99, 0.999};
+ probs_uniform.assign(p1, p1 + sizeof(p1) / sizeof(double));
+
+ double p2[] = {0.001, 0.025};
+ double p3[] = {0.975, 0.999};
+ probs_normal1.assign(p2, p2 + sizeof(p2) / sizeof(double));
+ probs_normal2.assign(p3, p3 + sizeof(p3) / sizeof(double));
+
+ double p4[] = {-3.090232, -1.959963};
+ double p5[] = {1.959963, 3.090232};
+ probs_normal_exact1.assign(p4, p4 + sizeof(p4) / sizeof(double));
+ probs_normal_exact2.assign(p5, p5 + sizeof(p5) / sizeof(double));
+
+ accumulator_t acc_uniform(extended_p_square_probabilities = probs_uniform);
+ accumulator_t acc_normal1(extended_p_square_probabilities = probs_normal1);
+ accumulator_t acc_normal2(extended_p_square_probabilities = probs_normal2);
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ acc_uniform(rng(), weight = 1.);
+
+ double sample1 = normal1();
+ double sample2 = normal2();
+ acc_normal1(sample1, weight = std::exp(-mu1 * (sample1 - 0.5 * mu1)));
+ acc_normal2(sample2, weight = std::exp(-mu2 * (sample2 - 0.5 * mu2)));
+ }
+
+ // check for uniform distribution
+ for (std::size_t i = 0; i < probs_uniform.size(); ++i)
+ {
+ BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_uniform)[i], probs_uniform[i], epsilon);
+ }
+
+ // check for standard normal distribution
+ for (std::size_t i = 0; i < probs_normal1.size(); ++i)
+ {
+ BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_normal1)[i], probs_normal_exact1[i], epsilon);
+ BOOST_CHECK_CLOSE(weighted_extended_p_square(acc_normal2)[i], probs_normal_exact2[i], epsilon);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_extended_p_square test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_kurtosis.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_kurtosis.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,70 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_kurtosis.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_kurtosis.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ // double epsilon = 1;
+
+ accumulator_set<double, stats<tag::weighted_kurtosis>, double > acc1;
+ accumulator_set<int, stats<tag::weighted_kurtosis>, int > acc2;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ acc1(normal(), weight = rng());
+ }
+
+ // This check fails because epsilon is relative and not absolute
+ // BOOST_CHECK_CLOSE( weighted_kurtosis(acc1), 0., epsilon );
+
+ acc2(2, weight = 4);
+ acc2(7, weight = 1);
+ acc2(4, weight = 3);
+ acc2(9, weight = 1);
+ acc2(3, weight = 2);
+
+ BOOST_CHECK_EQUAL( weighted_mean(acc2), 42./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<2>(acc2), 212./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<3>(acc2), 1350./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<4>(acc2), 9956./11. );
+ BOOST_CHECK_CLOSE( weighted_kurtosis(acc2), 0.58137026432, 1e-6 );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_kurtosis test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_mean.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_mean.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,102 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_mean.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+template<typename T>
+void assert_is_double(T const &)
+{
+ BOOST_MPL_ASSERT((is_same<T, double>));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<
+ int
+ , stats<
+ tag::weighted_mean
+ , tag::mean_of_weights
+ , tag::weighted_mean_of_variates<int, tag::covariate1>
+ >
+ , int
+ > acc, test_acc(sample = 0);
+
+ acc(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_CLOSE(1., weighted_mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc));
+ BOOST_CHECK_EQUAL(2, sum(acc));
+ BOOST_CHECK_CLOSE(2., mean_of_weights(acc), 1e-5);
+ BOOST_CHECK_CLOSE(3., (weighted_mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ acc(0, weight = 4, covariate1 = 4);
+ BOOST_CHECK_CLOSE(1./3., weighted_mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc));
+ BOOST_CHECK_EQUAL(2, sum(acc));
+ BOOST_CHECK_CLOSE(3., mean_of_weights(acc), 1e-5);
+ BOOST_CHECK_CLOSE(11./3., (weighted_mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ acc(2, weight = 9, covariate1 = 8);
+ BOOST_CHECK_CLOSE(4./3., weighted_mean(acc), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc));
+ BOOST_CHECK_EQUAL(20, sum(acc));
+ BOOST_CHECK_CLOSE(5., mean_of_weights(acc), 1e-5);
+ BOOST_CHECK_CLOSE(94./15., (weighted_mean_of_variates<int, tag::covariate1>(acc)), 1e-5);
+
+ assert_is_double(mean(acc));
+
+ accumulator_set<
+ int
+ , stats<
+ tag::weighted_mean(immediate)
+ , tag::mean_of_weights(immediate)
+ , tag::weighted_mean_of_variates<int, tag::covariate1>(immediate)
+ >
+ , int
+ > acc2, test_acc2(sample = 0);
+
+ acc2(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_CLOSE(1., weighted_mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(1u, count(acc2));
+ BOOST_CHECK_CLOSE(2., mean_of_weights(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(3., (weighted_mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ acc2(0, weight = 4, covariate1 = 4);
+ BOOST_CHECK_CLOSE(1./3., weighted_mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(2u, count(acc2));
+ BOOST_CHECK_CLOSE(3., mean_of_weights(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(11./3., (weighted_mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ acc2(2, weight = 9, covariate1 = 8);
+ BOOST_CHECK_CLOSE(4./3., weighted_mean(acc2), 1e-5);
+ BOOST_CHECK_EQUAL(3u, count(acc2));
+ BOOST_CHECK_CLOSE(5., mean_of_weights(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(94./15., (mean_of_variates<int, tag::covariate1>(acc2)), 1e-5);
+
+ assert_is_double(mean(acc2));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_mean test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/weighted_median.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_median.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,64 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/random.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_median.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // Median estimation of normal distribution N(1,1) using samples from a narrow normal distribution N(1,0.01)
+ // The weights equal to the likelihood ratio of the corresponding samples
+
+ // two random number generators
+ double mu = 1.;
+ double sigma_narrow = 0.01;
+ double sigma = 1.;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma_narrow(mu,sigma_narrow);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_narrow(rng, mean_sigma_narrow);
+
+ accumulator_set<double, stats<tag::weighted_median(with_p_square_quantile) >, double > acc;
+ accumulator_set<double, stats<tag::weighted_median(with_density) >, double >
+ acc_dens( density_cache_size = 10000, density_num_bins = 1000 );
+ accumulator_set<double, stats<tag::weighted_median(with_p_square_cumulative_distribution) >, double >
+ acc_cdist( p_square_cumulative_distribution_num_cells = 100 );
+
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal_narrow();
+ acc(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
+ acc_dens(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
+ acc_cdist(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma )));
+ }
+
+ BOOST_CHECK_CLOSE(1., weighted_median(acc), 1e-1);
+ BOOST_CHECK_CLOSE(1., weighted_median(acc_dens), 1e-1);
+ BOOST_CHECK_CLOSE(1., weighted_median(acc_cdist), 1e-1);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_median test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/weighted_moment.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_moment.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,47 @@
+// (C) Copyright Eric Niebler, Olivier Gygi 2006.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_moment.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<double, stats<tag::weighted_moment<2> >, double> acc2;
+ accumulator_set<double, stats<tag::weighted_moment<7> >, double> acc7;
+
+ acc2(2.1, weight = 0.7);
+ acc2(2.7, weight = 1.4);
+ acc2(1.8, weight = 0.9);
+
+ acc7(2.1, weight = 0.7);
+ acc7(2.7, weight = 1.4);
+ acc7(1.8, weight = 0.9);
+
+ BOOST_CHECK_CLOSE(5.403, weighted_moment<2>(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(548.54182, weighted_moment<7>(acc7), 1e-5);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_moment test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_p_square_cum_dist.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_p_square_cum_dist.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,103 @@
+// (C) Copyright Eric Niebler, Olivier Gygi 2006.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_p_square_cumulative_distribution.hpp
+
+#include <cmath>
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_p_square_cumulative_distribution.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// erf() not known by VC++ compiler!
+// my_erf() computes error function by numerically integrating with trapezoidal rule
+//
+double my_erf(double const& x, int const& n = 1000)
+{
+ double sum = 0.;
+ double delta = x/n;
+ for (int i = 1; i < n; ++i)
+ sum += std::exp(-i*i*delta*delta) * delta;
+ sum += 0.5 * delta * (1. + std::exp(-x*x));
+ return sum * 2. / std::sqrt(3.141592653);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 4;
+
+ typedef accumulator_set<double, stats<tag::weighted_p_square_cumulative_distribution>, double > accumulator_t;
+
+ accumulator_t acc_upper(p_square_cumulative_distribution_num_cells = 100);
+ accumulator_t acc_lower(p_square_cumulative_distribution_num_cells = 100);
+
+ // two random number generators
+ double mu_upper = 1.0;
+ double mu_lower = -1.0;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma_upper(mu_upper,1);
+ boost::normal_distribution<> mean_sigma_lower(mu_lower,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_upper(rng, mean_sigma_upper);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal_lower(rng, mean_sigma_lower);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal_upper();
+ acc_upper(sample, weight = std::exp(-mu_upper * (sample - 0.5 * mu_upper)));
+ }
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = normal_lower();
+ acc_lower(sample, weight = std::exp(-mu_lower * (sample - 0.5 * mu_lower)));
+ }
+
+ typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;
+ histogram_type histogram_upper = weighted_p_square_cumulative_distribution(acc_upper);
+ histogram_type histogram_lower = weighted_p_square_cumulative_distribution(acc_lower);
+
+ // Note that applaying importance sampling results in a region of the distribution
+ // to be estimated more accurately and another region to be estimated less accurately
+ // than without importance sampling, i.e., with unweighted samples
+
+ for (std::size_t i = 0; i < histogram_upper.size(); ++i)
+ {
+ // problem with small results: epsilon is relative (in percent), not absolute!
+
+ // check upper region of distribution
+ if ( histogram_upper[i].second > 0.1 )
+ BOOST_CHECK_CLOSE( 0.5 * (1.0 + my_erf( histogram_upper[i].first / sqrt(2.0) )), histogram_upper[i].second, epsilon );
+ // check lower region of distribution
+ if ( histogram_lower[i].second < -0.1 )
+ BOOST_CHECK_CLOSE( 0.5 * (1.0 + my_erf( histogram_lower[i].first / sqrt(2.0) )), histogram_lower[i].second, epsilon );
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_p_square_cumulative_distribution test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_p_square_quantile.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_p_square_quantile.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,100 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_p_square_quantile.hpp
+
+#include <cmath> // for std::exp()
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_p_square_quantile.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ typedef accumulator_set<double, stats<tag::weighted_p_square_quantile>, double> accumulator_t;
+
+ // tolerance in %
+ double epsilon = 1;
+
+ // some random number generators
+ double mu4 = -1.0;
+ double mu5 = -1.0;
+ double mu6 = 1.0;
+ double mu7 = 1.0;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma4(mu4, 1);
+ boost::normal_distribution<> mean_sigma5(mu5, 1);
+ boost::normal_distribution<> mean_sigma6(mu6, 1);
+ boost::normal_distribution<> mean_sigma7(mu7, 1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal4(rng, mean_sigma4);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal5(rng, mean_sigma5);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal6(rng, mean_sigma6);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal7(rng, mean_sigma7);
+
+ accumulator_t acc0(quantile_probability = 0.001);
+ accumulator_t acc1(quantile_probability = 0.025);
+ accumulator_t acc2(quantile_probability = 0.975);
+ accumulator_t acc3(quantile_probability = 0.999);
+
+ accumulator_t acc4(quantile_probability = 0.001);
+ accumulator_t acc5(quantile_probability = 0.025);
+ accumulator_t acc6(quantile_probability = 0.975);
+ accumulator_t acc7(quantile_probability = 0.999);
+
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ double sample = rng();
+ acc0(sample, weight = 1.);
+ acc1(sample, weight = 1.);
+ acc2(sample, weight = 1.);
+ acc3(sample, weight = 1.);
+
+ double sample4 = normal4();
+ double sample5 = normal5();
+ double sample6 = normal6();
+ double sample7 = normal7();
+ acc4(sample4, weight = std::exp(-mu4 * (sample4 - 0.5 * mu4)));
+ acc5(sample5, weight = std::exp(-mu5 * (sample5 - 0.5 * mu5)));
+ acc6(sample6, weight = std::exp(-mu6 * (sample6 - 0.5 * mu6)));
+ acc7(sample7, weight = std::exp(-mu7 * (sample7 - 0.5 * mu7)));
+ }
+ // check for uniform distribution with weight = 1
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc0), 0.001, 15 );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc1), 0.025, 5 );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc2), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc3), 0.999, epsilon );
+
+ // check for shifted standard normal distribution ("importance sampling")
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc4), -3.090232, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc5), -1.959963, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc6), 1.959963, epsilon );
+ BOOST_CHECK_CLOSE( weighted_p_square_quantile(acc7), 3.090232, epsilon );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_p_square_quantile test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_pot_quantile.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_pot_quantile.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,104 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to 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)
+
+// Test case for pot_quantile.hpp (weighted feature)
+
+#define BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 1.;
+
+ double mu1, mu2, l;
+
+ mu1 = 1.;
+ mu2 = -1.;
+ l = 0.5;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma1(mu1,1);
+ boost::normal_distribution<> mean_sigma2(mu2,1);
+ boost::exponential_distribution<> lambda(l);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal1(rng, mean_sigma1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal2(rng, mean_sigma2);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::exponential_distribution<> > exponential(rng, lambda);
+
+ accumulator_set<double, stats<tag::weighted_pot_quantile<right>(with_threshold_value)>, double > acc1(
+ pot_threshold_value = 3.
+ );
+ accumulator_set<double, stats<tag::weighted_pot_quantile<right>(with_threshold_probability)>, double > acc2(
+ right_tail_cache_size = 10000
+ , pot_threshold_probability = 0.99
+ );
+ accumulator_set<double, stats<tag::weighted_pot_quantile<left>(with_threshold_value)>, double > acc3(
+ pot_threshold_value = -3.
+ );
+ accumulator_set<double, stats<tag::weighted_pot_quantile<left>(with_threshold_probability)>, double > acc4(
+ left_tail_cache_size = 10000
+ , pot_threshold_probability = 0.01
+ );
+
+ accumulator_set<double, stats<tag::weighted_pot_quantile<right>(with_threshold_value)>, double > acc5(
+ pot_threshold_value = 5.
+ );
+ accumulator_set<double, stats<tag::weighted_pot_quantile<right>(with_threshold_probability)>, double > acc6(
+ right_tail_cache_size = 10000
+ , pot_threshold_probability = 0.995
+ );
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ double sample1 = normal1();
+ double sample2 = normal2();
+ acc1(sample1, weight = std::exp(-mu1 * (sample1 - 0.5 * mu1)));
+ acc2(sample1, weight = std::exp(-mu1 * (sample1 - 0.5 * mu1)));
+ acc3(sample2, weight = std::exp(-mu2 * (sample2 - 0.5 * mu2)));
+ acc4(sample2, weight = std::exp(-mu2 * (sample2 - 0.5 * mu2)));
+ }
+
+ for (std::size_t i = 0; i < 100000; ++i)
+ {
+ double sample = exponential();
+ acc5(sample, weight = 1./l * std::exp(-sample * (1. - l)));
+ acc6(sample, weight = 1./l * std::exp(-sample * (1. - l)));
+ }
+
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.999), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc3, quantile_probability = 0.001), -3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc4, quantile_probability = 0.001), -3.090232, epsilon );
+
+ BOOST_CHECK_CLOSE( quantile(acc5, quantile_probability = 0.999), 6.908, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc6, quantile_probability = 0.999), 6.908, epsilon );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_pot_quantile test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/weighted_skewness.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_skewness.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,69 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_skewness.hpp
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/numeric/functional/vector.hpp>
+#include <boost/accumulators/numeric/functional/complex.hpp>
+#include <boost/accumulators/numeric/functional/valarray.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_skewness.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ // double epsilon = 1;
+
+ accumulator_set<double, stats<tag::weighted_skewness>, double > acc1;
+ accumulator_set<int, stats<tag::weighted_skewness>, int > acc2;
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ for (std::size_t i=0; i<100000; ++i)
+ {
+ acc1(normal(), weight = rng());
+ }
+
+ // This check fails because epsilon is relative and not absolute
+ // BOOST_CHECK_CLOSE( weighted_skewness(acc1), 0., epsilon );
+
+ acc2(2, weight = 4);
+ acc2(7, weight = 1);
+ acc2(4, weight = 3);
+ acc2(9, weight = 1);
+ acc2(3, weight = 2);
+
+ BOOST_CHECK_EQUAL( weighted_mean(acc2), 42./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<2>(acc2), 212./11. );
+ BOOST_CHECK_EQUAL( weighted_moment<3>(acc2), 1350./11. );
+ BOOST_CHECK_CLOSE( weighted_skewness(acc2), 1.30708406282, 1e-6 );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_skewness test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_sum.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_sum.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,46 @@
+// (C) Copyright Eric Niebler, Olivier Gygi 2006.
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_sum.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::weighted_sum, tag::weighted_sum_of_variates<int, tag::covariate1> >, int> acc;
+
+ acc(1, weight = 2, covariate1 = 3);
+ BOOST_CHECK_EQUAL(2, weighted_sum(acc));
+ BOOST_CHECK_EQUAL(6, weighted_sum_of_variates(acc));
+
+ acc(2, weight = 3, covariate1 = 6);
+ BOOST_CHECK_EQUAL(8, weighted_sum(acc));
+ BOOST_CHECK_EQUAL(24, weighted_sum_of_variates(acc));
+
+ acc(4, weight = 6, covariate1 = 9);
+ BOOST_CHECK_EQUAL(32, weighted_sum(acc));
+ BOOST_CHECK_EQUAL(78, weighted_sum_of_variates(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_sum test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Added: branches/release/libs/accumulators/test/weighted_tail_mean.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_tail_mean.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,77 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_tail_mean.hpp
+
+#define BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+#include <boost/accumulators/statistics/weighted_tail_mean.hpp>
+#include <boost/accumulators/statistics/weighted_tail_quantile.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 1;
+
+ std::size_t n = 100000; // number of MC steps
+ std::size_t c = 25000; // cache size
+
+ accumulator_set<double, stats<tag::non_coherent_weighted_tail_mean<right> >, double >
+ acc0( right_tail_cache_size = c );
+ accumulator_set<double, stats<tag::non_coherent_weighted_tail_mean<left> >, double >
+ acc1( left_tail_cache_size = c );
+
+ // random number generators
+ boost::lagged_fibonacci607 rng;
+
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ double smpl = std::sqrt(rng());
+ acc0(smpl, weight = 1./smpl);
+ }
+
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ double smpl = rng();
+ acc1(smpl*smpl, weight = smpl);
+ }
+
+ // check uniform distribution
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.95), 0.975, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.975), 0.9875, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.99), 0.995, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc0, quantile_probability = 0.999), 0.9995, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.05), 0.025, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.025), 0.0125, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.01), 0.005, epsilon );
+ BOOST_CHECK_CLOSE( non_coherent_weighted_tail_mean(acc1, quantile_probability = 0.001), 0.0005, 5*epsilon );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_tail_mean test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_tail_quantile.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_tail_quantile.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,75 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_tail_quantile.hpp
+
+#define BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+#include <boost/accumulators/statistics/weighted_tail_quantile.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // tolerance in %
+ double epsilon = 1;
+
+ std::size_t n = 100000; // number of MC steps
+ std::size_t c = 20000; // cache size
+
+ double mu1 = 1.0;
+ double mu2 = -1.0;
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma1(mu1,1);
+ boost::normal_distribution<> mean_sigma2(mu2,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal1(rng, mean_sigma1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal2(rng, mean_sigma2);
+
+ accumulator_set<double, stats<tag::weighted_tail_quantile<right> >, double>
+ acc1(right_tail_cache_size = c);
+
+ accumulator_set<double, stats<tag::weighted_tail_quantile<left> >, double>
+ acc2(left_tail_cache_size = c);
+
+ for (std::size_t i = 0; i < n; ++i)
+ {
+ double sample1 = normal1();
+ double sample2 = normal2();
+ acc1(sample1, weight = std::exp(-mu1 * (sample1 - 0.5 * mu1)));
+ acc2(sample2, weight = std::exp(-mu2 * (sample2 - 0.5 * mu2)));
+ }
+
+ // check standard normal distribution
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.975), 1.959963, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc1, quantile_probability = 0.999), 3.090232, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.025), -1.959963, epsilon );
+ BOOST_CHECK_CLOSE( quantile(acc2, quantile_probability = 0.001), -3.090232, epsilon );
+
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_tail_quantile test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_tail_variate_means.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_tail_variate_means.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,131 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi.
+// Use, modification and distribution are subject to 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)
+
+// Test case for weighted_tail_variate_means.hpp
+
+#define BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
+#define BOOST_NUMERIC_FUNCTIONAL_STD_VECTOR_SUPPORT
+
+#include <boost/random.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/variates/covariate.hpp>
+#include <boost/accumulators/statistics.hpp>
+#include <boost/accumulators/statistics/weighted_tail_variate_means.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace boost::accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ std::size_t c = 5; // cache size
+
+ typedef double variate_type;
+ typedef std::vector<variate_type> variate_set_type;
+
+ accumulator_set<double, stats<tag::weighted_tail_variate_means<right, variate_set_type, tag::covariate1>(relative)>, double >
+ acc1( right_tail_cache_size = c );
+ accumulator_set<double, stats<tag::weighted_tail_variate_means<right, variate_set_type, tag::covariate1>(absolute)>, double >
+ acc2( right_tail_cache_size = c );
+ accumulator_set<double, stats<tag::weighted_tail_variate_means<left, variate_set_type, tag::covariate1>(relative)>, double >
+ acc3( left_tail_cache_size = c );
+ accumulator_set<double, stats<tag::weighted_tail_variate_means<left, variate_set_type, tag::covariate1>(absolute)>, double >
+ acc4( left_tail_cache_size = c );
+
+ variate_set_type cov1, cov2, cov3, cov4, cov5;
+ double c1[] = { 10., 20., 30., 40. }; // 100
+ double c2[] = { 26., 4., 17., 3. }; // 50
+ double c3[] = { 46., 64., 40., 50. }; // 200
+ double c4[] = { 1., 3., 70., 6. }; // 80
+ double c5[] = { 2., 2., 2., 14. }; // 20
+ cov1.assign(c1, c1 + sizeof(c1)/sizeof(variate_type));
+ cov2.assign(c2, c2 + sizeof(c2)/sizeof(variate_type));
+ cov3.assign(c3, c3 + sizeof(c3)/sizeof(variate_type));
+ cov4.assign(c4, c4 + sizeof(c4)/sizeof(variate_type));
+ cov5.assign(c5, c5 + sizeof(c5)/sizeof(variate_type));
+
+ acc1(100., weight = 0.8, covariate1 = cov1);
+ acc1( 50., weight = 0.9, covariate1 = cov2);
+ acc1(200., weight = 1.0, covariate1 = cov3);
+ acc1( 80., weight = 1.1, covariate1 = cov4);
+ acc1( 20., weight = 1.2, covariate1 = cov5);
+
+ acc2(100., weight = 0.8, covariate1 = cov1);
+ acc2( 50., weight = 0.9, covariate1 = cov2);
+ acc2(200., weight = 1.0, covariate1 = cov3);
+ acc2( 80., weight = 1.1, covariate1 = cov4);
+ acc2( 20., weight = 1.2, covariate1 = cov5);
+
+ acc3(100., weight = 0.8, covariate1 = cov1);
+ acc3( 50., weight = 0.9, covariate1 = cov2);
+ acc3(200., weight = 1.0, covariate1 = cov3);
+ acc3( 80., weight = 1.1, covariate1 = cov4);
+ acc3( 20., weight = 1.2, covariate1 = cov5);
+
+ acc4(100., weight = 0.8, covariate1 = cov1);
+ acc4( 50., weight = 0.9, covariate1 = cov2);
+ acc4(200., weight = 1.0, covariate1 = cov3);
+ acc4( 80., weight = 1.1, covariate1 = cov4);
+ acc4( 20., weight = 1.2, covariate1 = cov5);
+
+ // check relative risk contributions
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() ), (0.8*10 + 1.0*46)/(0.8*100 + 1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 1), (0.8*20 + 1.0*64)/(0.8*100 + 1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 2), (0.8*30 + 1.0*40)/(0.8*100 + 1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.7).begin() + 3), (0.8*40 + 1.0*50)/(0.8*100 + 1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() ), (0.9*26 + 1.2*2)/(0.9*50 + 1.2*20) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 1), (0.9*4 + 1.2*2)/(0.9*50 + 1.2*20) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 2), (0.9*17 + 1.2*2)/(0.9*50 + 1.2*20) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.3).begin() + 3), (0.9*3 + 1.2*14)/(0.9*50 + 1.2*20) );
+
+ // check absolute risk contributions
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() ), (0.8*10 + 1.0*46)/1.8 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() + 1), (0.8*20 + 1.0*64)/1.8 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() + 2), (0.8*30 + 1.0*40)/1.8 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.7).begin() + 3), (0.8*40 + 1.0*50)/1.8 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() ), (0.9*26 + 1.2*2)/2.1 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() + 1), (0.9*4 + 1.2*2)/2.1 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() + 2), (0.9*17 + 1.2*2)/2.1 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.3).begin() + 3), (0.9*3 + 1.2*14)/2.1 );
+
+ // check relative risk contributions
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() ), 1.0*46/(1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 1), 1.0*64/(1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 2), 1.0*40/(1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc1, quantile_probability = 0.9).begin() + 3), 1.0*50/(1.0*200) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() ), 1.2*2/(1.2*20) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 1), 1.2*2/(1.2*20) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 2), 1.2*2/(1.2*20) );
+ BOOST_CHECK_EQUAL( *(relative_weighted_tail_variate_means(acc3, quantile_probability = 0.1).begin() + 3), 1.2*14/(1.2*20) );
+
+ // check absolute risk contributions
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() ), 1.0*46/1.0 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() + 1), 1.0*64/1.0 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() + 2), 1.0*40/1.0 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc2, quantile_probability = 0.9).begin() + 3), 1.0*50/1.0 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() ), 1.2*2/1.2 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() + 1), 1.2*2/1.2 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() + 2), 1.2*2/1.2 );
+ BOOST_CHECK_EQUAL( *(weighted_tail_variate_means(acc4, quantile_probability = 0.1).begin() + 3), 1.2*14/1.2 );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_tail_variate_means test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
+
Added: branches/release/libs/accumulators/test/weighted_variance.cpp
==============================================================================
--- (empty file)
+++ branches/release/libs/accumulators/test/weighted_variance.cpp 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -0,0 +1,81 @@
+// (C) Copyright 2006 Eric Niebler, Olivier Gygi
+// Use, modification and distribution are subject to 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)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/random.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/weighted_variance.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ // basic lazy weighted_variance
+ accumulator_set<int, stats<tag::weighted_variance>, int> acc1;
+
+ acc1(1, weight = 2); // 2
+ acc1(2, weight = 3); // 6
+ acc1(3, weight = 1); // 3
+ acc1(4, weight = 4); // 16
+ acc1(5, weight = 1); // 5
+
+ // weighted_mean = (2+6+3+16+5) / (2+3+1+4+1) = 32 / 11 = 2.9090909090909090909090909090909
+
+ BOOST_CHECK_EQUAL(5u, count(acc1));
+ BOOST_CHECK_CLOSE(2.9090909, weighted_mean(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(10.1818182, weighted_moment<2>(acc1), 1e-5);
+ BOOST_CHECK_CLOSE(1.7190083, weighted_variance(acc1), 1e-5);
+
+ accumulator_set<int, stats<tag::weighted_variance(immediate)>, int> acc2;
+
+ acc2(1, weight = 2);
+ acc2(2, weight = 3);
+ acc2(3, weight = 1);
+ acc2(4, weight = 4);
+ acc2(5, weight = 1);
+
+ BOOST_CHECK_EQUAL(5u, count(acc2));
+ BOOST_CHECK_CLOSE(2.9090909, weighted_mean(acc2), 1e-5);
+ BOOST_CHECK_CLOSE(1.7190083, weighted_variance(acc2), 1e-5);
+
+ // check lazy and immediate variance with random numbers
+
+ // two random number generators
+ boost::lagged_fibonacci607 rng;
+ boost::normal_distribution<> mean_sigma(0,1);
+ boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
+
+ accumulator_set<double, stats<tag::weighted_variance>, double > acc_lazy;
+ accumulator_set<double, stats<tag::weighted_variance(immediate)>, double > acc_immediate;
+
+ for (std::size_t i=0; i<10000; ++i)
+ {
+ double value = normal();
+ acc_lazy(value, weight = rng());
+ acc_immediate(value, weight = rng());
+ }
+
+ BOOST_CHECK_CLOSE(1., weighted_variance(acc_lazy), 1.);
+ BOOST_CHECK_CLOSE(1., weighted_variance(acc_immediate), 1.);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+test_suite* init_unit_test_suite( int argc, char* argv[] )
+{
+ test_suite *test = BOOST_TEST_SUITE("weighted_variance test");
+
+ test->add(BOOST_TEST_CASE(&test_stat));
+
+ return test;
+}
Modified: branches/release/status/Jamfile.v2
==============================================================================
--- branches/release/status/Jamfile.v2 (original)
+++ branches/release/status/Jamfile.v2 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -24,6 +24,7 @@
# Tests from Jamfiles in individual library test subdirectories
# Please keep these in alphabetic order by test-suite name
+build-project ../libs/accumulators/test ; # test-suite accumulators
build-project ../libs/algorithm/minmax/test ; # test-suite algorith/minmax
build-project ../libs/algorithm/string/test ; # test-suite algorithm/string
build-project ../libs/asio/test ; # test-suite asio
Modified: branches/release/status/explicit-failures-markup.xml
==============================================================================
--- branches/release/status/explicit-failures-markup.xml (original)
+++ branches/release/status/explicit-failures-markup.xml 2008-06-19 23:47:42 EDT (Thu, 19 Jun 2008)
@@ -37,6 +37,35 @@
<!-- /////////////// Libraries /////////////// -->
+ <!-- accumulators -->
+ <library name="accumulators">
+ <mark-unusable>
+ <toolset name="sun-5.7"/>
+ <toolset name="sun-5.8"/>
+ <toolset name="sun-5.9"/>
+ <toolset name="borland-*"/>
+ </mark-unusable>
+ <mark-expected-failures>
+ <test name="tail_variate_means"/>
+ <test name="weighted_tail_variate_means"/>
+ <toolset name="gcc-4.2.1*"/>
+ <note author="Boris Gubenko" refid="42"/>
+ </mark-expected-failures>
+ <mark-expected-failures>
+ <test name="weighted_kurtosis"/>
+ <toolset name="acc"/>
+ <note author="Boris Gubenko" refid="38"/>
+ </mark-expected-failures>
+ <mark-expected-failures>
+ <test name="weighted_tail_variate_means"/>
+ <toolset name="hp_cxx-71*"/>
+ <note author="Markus Schoepflin">
+ This failure is caused by a timeout when compiling the test. It
+ passes when the timeout value is increased.
+ </note>
+ </mark-expected-failures>
+ </library>
+
<!-- minmax -->
<library name="algorithm/minmax">
<mark-unusable>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk