@@ -71,7 +71,7 @@ See doc/MINING.txt for detailed instructions on running /ecoin-miner/ on differe
listen=1
server=1
daemon=1
- addnode = 46.163.118.220 # ecoin.03c8.net (turina.space)
+ addnode=46.163.118.220 # ecoin.03c8.net (turina.space)
./ecoind -conf=/home/$USER/.ecoin/ecoin.conf
@@ -29,12 +29,11 @@ All of the commands should be executed in a shell.
(0.) Version libraries:
- - Libboost -> 1.74.0.3 (https://www.boost.org/users/history/version_1_74_0.html)
- - LibSSL -> 3.0.15 (https://debian.pkgs.org/12/debian-main-amd64/libssl3_3.0.15-1~deb12u1_amd64.deb.html)
+ - Libboost -> source code 1.68 provided at: src/boost_1_68_0
(1.) Install dependencies:
- sudo apt-get install build-essential libssl-dev libssl3 libdb5.3-dev libdb5.3++-dev libleveldb-dev miniupnpc libminiupnpc-dev libboost-all-dev
+ sudo apt-get install build-essential libssl-dev libssl3 libdb5.3-dev libdb5.3++-dev libleveldb-dev miniupnpc libminiupnpc-dev
+ Optionally install qrencode (and set USE_QRCODE=1):
@@ -58,12 +57,11 @@ All of the commands should be executed in a shell.
(1.) First, make sure that the required packages for Qt5 development (an the others required for building the daemon) are installed:
- sudo apt-get install qt5-qmake qtbase5-dev build-essential libssl-dev libssl3 libdb5.3-dev libdb5.3++-dev libleveldb-dev miniupnpc libminiupnpc-dev libboost-all-dev
+ sudo apt-get install qt5-qmake qtbase5-dev build-essential libssl-dev libssl3 libdb5.3-dev libdb5.3++-dev libleveldb-dev miniupnpc libminiupnpc-dev
@@ -1,4 +1,4 @@
-# ECOin - Copyright (c) - 2014/2024 - GPLv3 - epsylon@riseup.net (https://03c8.net)
+# ECOin - Copyright (c) - 2014/2025 - GPLv3 - epsylon@riseup.net (https://ecoin.03c8.net)
TEMPLATE = app
TARGET = ecoin-qt
@@ -0,0 +1,8 @@
+See ./index.html for information about this release. The "Getting Started"
+section is a useful starting place.
+
+---------------------------
+Copyright Beman Dawes, 2008
+Distributed under the Boost Software License, Version 1.0.
+See ./LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt
@@ -0,0 +1,340 @@
+# Copyright Vladimir Prus 2002-2006.
+# Copyright Dave Abrahams 2005-2006.
+# Copyright Rene Rivera 2005-2007.
+# Copyright Douglas Gregor 2005.
+#
+# 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)
+# Usage:
+# b2 [options] [properties] [install|stage]
+# Builds and installs Boost.
+# Targets and Related Options:
+# install Install headers and compiled library files to the
+# ======= configured locations (below).
+# --prefix=<PREFIX> Install architecture independent files here.
+# Default; C:\Boost on Win32
+# Default; /usr/local on Unix. Linux, etc.
+# --exec-prefix=<EPREFIX> Install architecture dependent files here.
+# Default; <PREFIX>
+# --libdir=<DIR> Install library files here.
+# Default; <EPREFIX>/lib
+# --includedir=<HDRDIR> Install header files here.
+# Default; <PREFIX>/include
+# stage Build and install only compiled library files to the
+# ===== stage directory.
+# --stagedir=<STAGEDIR> Install library files here
+# Default; ./stage
+# Other Options:
+# --build-type=<type> Build the specified pre-defined set of variations of
+# the libraries. Note, that which variants get built
+# depends on what each library supports.
+# -- minimal -- (default) Builds a minimal set of
+# variants. On Windows, these are static
+# multithreaded libraries in debug and release
+# modes, using shared runtime. On Linux, these are
+# static and shared multithreaded libraries in
+# release mode.
+# -- complete -- Build all possible variations.
+# --build-dir=DIR Build in this location instead of building within
+# the distribution tree. Recommended!
+# --show-libraries Display the list of Boost libraries that require
+# build and installation steps, and then exit.
+# --layout=<layout> Determine whether to choose library names and header
+# locations such that multiple versions of Boost or
+# multiple compilers can be used on the same system.
+# -- versioned -- Names of boost binaries include
+# the Boost version number, name and version of
+# the compiler and encoded build properties. Boost
+# headers are installed in a subdirectory of
+# <HDRDIR> whose name contains the Boost version
+# number.
+# -- tagged -- Names of boost binaries include the
+# encoded build properties such as variant and
+# threading, but do not including compiler name
+# and version, or Boost version. This option is
+# useful if you build several variants of Boost,
+# using the same compiler.
+# -- system -- Binaries names do not include the
+# Boost version number or the name and version
+# number of the compiler. Boost headers are
+# installed directly into <HDRDIR>. This option is
+# intended for system integrators building
+# distribution packages.
+# The default value is 'versioned' on Windows, and
+# 'system' on Unix.
+# --buildid=ID Add the specified ID to the name of built libraries.
+# The default is to not add anything.
+# --python-buildid=ID Add the specified ID to the name of built libraries
+# that depend on Python. The default is to not add
+# anything. This ID is added in addition to --buildid.
+# --help This message.
+# --with-<library> Build and install the specified <library>. If this
+# option is used, only libraries specified using this
+# option will be built.
+# --without-<library> Do not build, stage, or install the specified
+# <library>. By default, all libraries are built.
+# Properties:
+# toolset=toolset Indicate the toolset to build with.
+# variant=debug|release Select the build variant
+# link=static|shared Whether to build static or shared libraries
+# threading=single|multi Whether to build single or multithreaded binaries
+# runtime-link=static|shared
+# Whether to link to static or shared C and C++
+# runtime.
+# TODO:
+# - handle boost version
+# - handle python options such as pydebug
+import boostcpp ;
+import package ;
+import sequence ;
+import xsltproc ;
+import set ;
+import path ;
+import link ;
+import notfile ;
+import virtual-target ;
+import "class" : new ;
+import property-set ;
+import threadapi-feature ;
+import option ;
+path-constant BOOST_ROOT : . ;
+constant BOOST_VERSION : 1.68.0 ;
+constant BOOST_JAMROOT_MODULE : $(__name__) ;
+boostcpp.set-version $(BOOST_VERSION) ;
+use-project /boost/architecture : libs/config/checks/architecture ;
+local all-headers =
+ [ MATCH .*libs/(.*)/include/boost : [ glob libs/*/include/boost libs/*/*/include/boost ] ] ;
+for dir in $(all-headers)
+{
+ link-directory $(dir)-headers : libs/$(dir)/include/boost : <location>. ;
+ explicit $(dir)-headers ;
+}
+if $(all-headers)
+ constant BOOST_MODULARLAYOUT : $(all-headers) ;
+project boost
+ : requirements <include>.
+ [ boostcpp.architecture ]
+ [ boostcpp.address-model ]
+ # Disable auto-linking for all targets here, primarily because it caused
+ # troubles with V2.
+ <define>BOOST_ALL_NO_LIB=1
+ # Used to encode variant in target name. See the 'tag' rule below.
+ <tag>@$(__name__).tag
+ <conditional>@handle-static-runtime
+ # Comeau does not support shared lib
+ <toolset>como:<link>static
+ <toolset>como-linux:<define>_GNU_SOURCE=1
+ # When building docs within Boost, we want the standard Boost style
+ <xsl:param>boost.defaults=Boost
+ <conditional>@threadapi-feature.detect
+ : usage-requirements <include>.
+ : build-dir bin.v2
+ ;
+# This rule is called by Boost.Build to determine the name of target. We use it
+# to encode the build variant, compiler name and boost version in the target
+# name.
+rule tag ( name : type ? : property-set )
+ return [ boostcpp.tag $(name) : $(type) : $(property-set) ] ;
+rule python-tag ( name : type ? : property-set )
+ return [ boostcpp.python-tag $(name) : $(type) : $(property-set) ] ;
+rule handle-static-runtime ( properties * )
+ # Using static runtime with shared libraries is impossible on Linux, and
+ # dangerous on Windows. Therefore, we disallow it. This might be drastic,
+ # but it was disabled for a while without anybody complaining.
+ # For CW, static runtime is needed so that std::locale works.
+ if <link>shared in $(properties) && <runtime-link>static in $(properties) &&
+ ! ( <toolset>cw in $(properties) )
+ {
+ if ! $(.shared-static-warning-emitted)
+ ECHO "warning: skipping configuration link=shared, runtime-link=static" ;
+ ECHO "warning: this combination is either impossible or too dangerous" ;
+ ECHO "warning: to be of any use" ;
+ .shared-static-warning-emitted = 1 ;
+ }
+ return <build>no ;
+all-libraries = [ MATCH .*libs/(.*)/build/.* : [ glob libs/*/build/Jamfile.v2 ]
+ [ glob libs/*/build/Jamfile ] ] ;
+all-libraries = [ sequence.unique $(all-libraries) ] ;
+# The function_types library has a Jamfile, but it's used for maintenance
+# purposes, there's no library to build and install.
+all-libraries = [ set.difference $(all-libraries) : function_types ] ;
+# Setup convenient aliases for all libraries.
+local rule explicit-alias ( id : targets + )
+ alias $(id) : $(targets) ;
+ explicit $(id) ;
+# First, the complicated libraries: where the target name in Jamfile is
+# different from its directory name.
+explicit-alias prg_exec_monitor : libs/test/build//boost_prg_exec_monitor ;
+explicit-alias test_exec_monitor : libs/test/build//boost_test_exec_monitor ;
+explicit-alias unit_test_framework : libs/test/build//boost_unit_test_framework ;
+explicit-alias bgl-vis : libs/graps/build//bgl-vis ;
+explicit-alias serialization : libs/serialization/build//boost_serialization ;
+explicit-alias wserialization : libs/serialization/build//boost_wserialization ;
+for local l in $(all-libraries)
+ if ! $(l) in test graph serialization
+ explicit-alias $(l) : libs/$(l)/build//boost_$(l) ;
+# Log has an additional target
+explicit-alias log_setup : libs/log/build//boost_log_setup ;
+rule do-nothing { }
+rule generate-alias ( project name : property-set : sources * )
+ local action-name = [ $(property-set).get <action> ] ;
+ local m = [ MATCH ^@(.*) : $(action-name) ] ;
+ property-set = [ property-set.empty ] ;
+ local action = [ new action $(sources) : $(m[1]) : $(property-set) ] ;
+ local t = [ new notfile-target $(name) : $(project) : $(action) ] ;
+ return [ virtual-target.register $(t) ] ;
+generate headers : $(all-headers)-headers : <generating-rule>@generate-alias <action>@do-nothing : : <include>. ;
+#alias headers : $(all-headers)-headers : : : <include>. ;
+explicit headers ;
+# Make project ids of all libraries known.
+ use-project /boost/$(l) : libs/$(l)/build ;
+if [ path.exists $(BOOST_ROOT)/tools/inspect/build ]
+ use-project /boost/tools/inspect : tools/inspect/build ;
+if [ path.exists $(BOOST_ROOT)/libs/wave/tool/build ]
+ use-project /boost/libs/wave/tool : libs/wave/tool/build ;
+# This rule should be called from libraries' Jamfiles and will create two
+# targets, "install" and "stage", that will install or stage that library. The
+# --prefix option is respected, but --with and --without options, naturally, are
+# ignored.
+# - libraries -- list of library targets to install.
+rule boost-install ( libraries * )
+ package.install install
+ : <dependency>/boost//install-proper-headers $(install-requirements)
+ : # No binaries
+ : $(libraries)
+ : # No headers, it is handled by the dependency.
+ local stage-locate = [ option.get stagedir : $(BOOST_ROOT)/stage ] ;
+ install stage : $(libraries) : <location>$(stage-locate)/lib ;
+ module [ CALLER_MODULE ]
+ explicit stage ;
+ explicit install ;
+# Creates a library target, adding autolink support and also creates
+# stage and install targets via boost-install, above.
+rule boost-lib ( name : sources * : requirements * : default-build * : usage-requirements * )
+ name = boost_$(name) ;
+ autolink = <link>shared:<define>$(name:U)_DYN_LINK=1 ;
+ lib $(name)
+ : $(sources)
+ : $(requirements) $(autolink)
+ : $(default-build)
+ : $(usage-requirements) $(autolink)
+ boost-install $(name) ;
+headers =
+ # The .SUNWCCh files are present in tr1 include directory and have to be
+ # installed (see http://lists.boost.org/Archives/boost/2007/05/121430.php).
+ [ path.glob-tree $(BOOST_ROOT)/boost : *.hpp *.ipp *.h *.inc *.SUNWCCh : CVS .svn ]
+ [ path.glob-tree $(BOOST_ROOT)/boost/compatibility/cpp_c_headers : c* : CVS .svn ]
+ [ path.glob $(BOOST_ROOT)/boost/tr1/tr1 : * : bcc32 sun CVS .svn ]
+# Declare special top-level targets that build and install the desired variants
+# of the libraries.
+boostcpp.declare-targets $(all-libraries) : $(headers) : $(all-headers) ;
@@ -0,0 +1,23 @@
+Boost Software License - Version 1.0 - August 17th, 2003
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
+# Copyright (C) 2002-2003 David Abrahams.
+# Copyright (C) 2002-2003 Vladimir Prus.
+# Copyright (C) 2003,2007 Rene Rivera.
+# 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)
+# This is the initial file loaded by Boost Jam when run from any Boost library
+# folder. It allows us to choose which Boost Build installation to use for
+# building Boost libraries. Unless explicitly selected using a command-line
+# option, the version included with the Boost library distribution is used (as
+# opposed to any other Boost Build version installed on the user's sytem).
+BOOST_ROOT = $(.boost-build-file:D) ;
+BOOST_BUILD = [ MATCH --boost-build=(.*) : $(ARGV) ] ;
+BOOST_BUILD ?= tools/build/src ;
+boost-build $(BOOST_BUILD) ;
@@ -0,0 +1,66 @@
+/*=============================================================================
+ Copyright 2002 William E. Kempf
+ Distributed under the Boost Software License, Version 1.0. (See accompany-
+ ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+H1
+ FONT-SIZE: 200%;
+ COLOR: #00008B;
+H2
+ FONT-SIZE: 150%;
+H3
+ FONT-SIZE: 125%;
+H4
+ FONT-SIZE: 108%;
+BODY
+ FONT-SIZE: 100%;
+ BACKGROUND-COLOR: #ffffff;
+ COLOR: #000000;
+PRE
+ MARGIN-LEFT: 2em;
+ FONT-FAMILY: Courier,
+ monospace;
+CODE
+CODE.as_pre
+ white-space: pre;
+.index
+ TEXT-ALIGN: left;
+.page-index
+.definition
+.footnote
+ FONT-SIZE: 66%;
+ VERTICAL-ALIGN: super;
+ TEXT-DECORATION: none;
+.function-semantics
+ CLEAR: left;
@@ -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
@@ -0,0 +1,230 @@
+// accumulators_fwd.hpp
+#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/cat.hpp>
+#include <boost/preprocessor/arithmetic/inc.hpp>
+#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
+#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
+#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
+#if BOOST_ACCUMULATORS_MAX_FEATURES > BOOST_MPL_LIMIT_VECTOR_SIZE
+# error BOOST_ACCUMULATORS_MAX_FEATURES cannot be larger than BOOST_MPL_LIMIT_VECTOR_SIZE
+#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
+#if BOOST_WORKAROUND(__GNUC__, == 3) \
+ || BOOST_WORKAROUND(__EDG_VERSION__, BOOST_TESTED_AT(306))
+# define BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS
+#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)
+#define BOOST_ACCUMULATORS_GCC_VERSION \
+ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+namespace boost { namespace accumulators
+// Named parameters tags
+namespace tag
+ struct sample;
+ struct weight;
+ struct accumulator;
+ struct weights;
+// User-level features
+ template<typename ValueType, typename Tag>
+ struct value;
+ template<typename Tag>
+ struct value_tag;
+ template<typename Referent, typename Tag>
+ struct reference;
+ 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;
+struct droppable_accumulator;
+struct with_cached_result;
+template<typename Sample, typename Features, typename Weight = void>
+struct accumulator_set;
+template<typename Feature>
+struct extractor;
+struct feature_of;
+struct as_feature;
+struct as_weighted_feature;
+template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature, mpl::na)>
+struct depends_on;
+struct features;
+template<typename Feature, typename AccumulatorSet>
+typename mpl::apply<AccumulatorSet, Feature>::type const &
+find_accumulator(AccumulatorSet const &acc);
+typename mpl::apply<AccumulatorSet, Feature>::type::result_type
+extract_result(AccumulatorSet const &acc);
+template<typename Feature, typename AccumulatorSet, typename A1>
+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) \
+ );
+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 ...>
+extract_result(AccumulatorSet const &acc, A1 const &a1, A2 const &a2 ...);
+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;
+ inline void ignore_variable(void const *) {}
+#define BOOST_ACCUMULATORS_IGNORE_GLOBAL(X) \
+ namespace detail \
+ { \
+ struct BOOST_PP_CAT(ignore_, X) \
+ void ignore() \
+ boost::accumulators::detail::ignore_variable(&X); \
+ } \
+ }; \
+ /**/
+}} // namespace boost::accumulators
+// 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(); \
@@ -0,0 +1,65 @@
+// accumulator_base.hpp
+#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>
+ 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)
@@ -0,0 +1,29 @@
+// accumulator_concept.hpp
+#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>
+template<typename Stat>
+struct accumulator_concept
+ void constraints()
+ // TODO: define the stat concept
+ Stat stat;
@@ -0,0 +1,401 @@
+// accumulator_set.hpp
+#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/enum_binary_params.hpp>
+#include <boost/accumulators/accumulators_fwd.hpp>
+#include <boost/accumulators/framework/depends_on.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>
+ ///////////////////////////////////////////////////////////////////////////////
+ // accumulator_visitor
+ // wrap a boost::parameter argument pack in a Fusion extractor object
+ struct accumulator_visitor
+ explicit accumulator_visitor(Args const &a)
+ : args(a)
+ void operator ()(Accumulator &accumulator) const
+ accumulator(this->args);
+ private:
+ accumulator_visitor &operator =(accumulator_visitor const &);
+ Args const &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
+ 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
+/// \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
+ ///
+ typename detail::make_accumulator_tuple<
+ Features
+ , Sample
+ , Weight
+ >::type
+ accumulators_mpl_vector;
+ // generate a fusion::list of accumulators
+ typename detail::meta::make_acc_list<
+ accumulators_mpl_vector
+ accumulators_type;
+ //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)
+ , detail::accumulator_params()(*this, a1)
+ // ... other overloads generated by Boost.Preprocessor:
+#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)) \
+ ); \
+ BOOST_PP_REPEAT_FROM_TO(
+ , BOOST_ACCUMULATORS_ACCUMULATOR_SET_CTOR
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ 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);
+ /// The return type of the operator() overloads is void.
+ typedef void result_type;
+ /// Accumulation
+ void operator ()()
+ this->visit(
+ detail::make_accumulator_visitor(
+ detail::accumulator_params()(*this)
+ void operator ()(A1 const &a1)
+ detail::accumulator_params()(*this, a1)
+#define BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP(z, n, _) \
+ void operator ()(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a)) \
+ this->visit( \
+ detail::make_accumulator_visitor( \
+ detail::accumulator_params()( \
+ , BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP
+ void operator ()(A1 const &a1, A2 const &a2, ...);
+ /// Extraction
+ struct apply
+ : fusion::result_of::value_of<
+ typename fusion::result_of::find_if<
+ accumulators_type
+ , detail::matches_feature<Feature>
+ typename apply<Feature>::type &extract()
+ return *fusion::find_if<detail::matches_feature<Feature> >(this->accumulators);
+ typename apply<Feature>::type const &extract() const
+ /// Drop
+ 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>));
+ 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;
+#pragma warning(pop)
+// find_accumulator
+// find an accumulator in an accumulator_set corresponding to a feature
+typename mpl::apply<AccumulatorSet, Feature>::type &
+find_accumulator(AccumulatorSet &acc BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(AccumulatorSet))
+ return acc.template extract<Feature>();
+/// \overload
+find_accumulator(AccumulatorSet const &acc)
+// extract_result
+// extract a result from an accumulator set
+#define BOOST_ACCUMULATORS_EXTRACT_RESULT_FUN(z, n, _) \
+ return find_accumulator<Feature>(acc).result( \
+ 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
@@ -0,0 +1,328 @@
+// droppable_accumulator.hpp
+#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/aligned_storage.hpp>
+#include <boost/accumulators/framework/depends_on.hpp> // for feature_of
+#include <boost/accumulators/framework/parameters/accumulator.hpp> // for accumulator
+ struct droppable_accumulator;
+ namespace detail
+ // add_ref_visitor
+ // a fusion function object for add_ref'ing accumulators
+ struct add_ref_visitor
+ explicit add_ref_visitor(Args const &args)
+ : args_(args)
+ 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
+ add_ref_visitor &operator =(add_ref_visitor const &);
+ Args const &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
+ struct drop_visitor
+ explicit drop_visitor(Args const &args)
+ if(typename Accumulator::is_droppable())
+ acc.drop(this->args_);
+ drop_visitor &operator =(drop_visitor const &);
+ drop_visitor<Args> make_drop_visitor(Args const &args)
+ return drop_visitor<Args>(args);
+ //////////////////////////////////////////////////////////////////////////
+ // droppable_accumulator_base
+ struct droppable_accumulator_base
+ : Accumulator
+ typedef droppable_accumulator_base base;
+ typedef mpl::true_ is_droppable;
+ typedef typename Accumulator::result_type result_type;
+ droppable_accumulator_base(Args const &args)
+ : Accumulator(args)
+ , ref_count_(0)
+ droppable_accumulator_base(droppable_accumulator_base const &that)
+ : Accumulator(*static_cast<Accumulator const *>(&that))
+ , ref_count_(that.ref_count_)
+ void operator ()(Args const &args)
+ if(!this->is_dropped())
+ this->Accumulator::operator ()(args);
+ void add_ref(Args const &)
+ ++this->ref_count_;
+ 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_;
+ int ref_count_;
+ // droppable_accumulator
+ // this can be specialized for any type that needs special handling
+ struct droppable_accumulator
+ : droppable_accumulator_base<Accumulator>
+ droppable_accumulator(Args const &args)
+ : droppable_accumulator::base(args)
+ droppable_accumulator(droppable_accumulator const &that)
+ : droppable_accumulator::base(*static_cast<typename droppable_accumulator::base const *>(&that))
+ // with_cached_result
+ struct with_cached_result
+ with_cached_result(Args const &args)
+ , cache()
+ with_cached_result(with_cached_result const &that)
+ 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();
+ void on_drop(Args const &args)
+ // cache the result at the point this calculation was dropped
+ BOOST_ASSERT(!this->has_result());
+ this->set(this->Accumulator::result(args));
+ result_type result(Args const &args) const
+ return this->has_result() ? this->get() : this->Accumulator::result(args);
+ with_cached_result &operator =(with_cached_result const &);
+ void set(result_type const &r)
+ ::new(this->cache.address()) result_type(r);
+ 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
+ struct as_droppable
+ typedef droppable<Feature> type;
+ struct as_droppable<droppable<Feature> >
+ // droppable
+ struct droppable
+ : as_feature<Feature>::type
+ typedef typename as_feature<Feature>::type feature_type;
+ typedef typename feature_type::dependencies tmp_dependencies_;
+ typename mpl::transform<
+ typename feature_type::dependencies
+ , as_droppable<mpl::_1>
+ dependencies;
+ struct impl
+ template<typename Sample, typename Weight>
+ droppable_accumulator<
+ typename mpl::apply2<typename feature_type::impl, Sample, Weight>::type
+ type;
+ // make droppable<tag::feature(modifier)> work
+ 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>
+ 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
+ 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;
@@ -0,0 +1,108 @@
+// external_accumulator.hpp
+#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/parameter/keyword.hpp>
+#include <boost/accumulators/framework/depends_on.hpp> // for feature_tag
+namespace boost { namespace accumulators { namespace impl
+ // external_impl
+ struct external_impl
+ : accumulator_base
+ typedef typename detail::feature_tag<Accumulator>::type feature_tag;
+ external_impl(dont_care) {}
+ return this->extract_(args, args[parameter::keyword<Tag>::get() | 0]);
+ 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(accumulators::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.
+ return extract(acc);
+} // namespace impl
+ // external
+ template<typename Feature, typename Tag, typename AccumulatorSet>
+ struct external
+ : depends_on<reference<AccumulatorSet, Tag> >
+ 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<>
+// 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> >
+// 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;
@@ -0,0 +1,89 @@
+// reference_accumulator.hpp
+#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>
+ // reference_accumulator_impl
+ //
+ struct reference_accumulator_impl
+ typedef Referent &result_type;
+ reference_accumulator_impl(Args const &args)
+ : ref(args[parameter::keyword<Tag>::get()])
+ result_type result(dont_care) const
+ return this->ref;
+ reference_wrapper<Referent> ref;
+ // reference_tag
+ struct reference_tag
+ // reference
+ struct reference
+ 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> >
+// value_accumulator.hpp
+// Copyright 2005 Eric Niebler, Daniel Egloff. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
+#define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATORS_VALUE_ACCUMULATOR_HPP_EAN_03_23_2006
+ // value_accumulator_impl
+ struct value_accumulator_impl
+ typedef ValueType result_type;
+ value_accumulator_impl(Args const &args)
+ : val(args[parameter::keyword<Tag>::get()])
+ return this->val;
+ ValueType val;
+ // value_tag
+ struct value_tag
+ // value
+ struct value
+ typedef mpl::always<accumulators::impl::value_accumulator_impl<ValueType, Tag> > impl;
+ 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.
+struct feature_of<tag::value<ValueType, Tag> >
+ : feature_of<tag::value_tag<Tag> >
@@ -0,0 +1,448 @@
+// depends_on.hpp
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_DEPENDS_ON_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_DEPENDS_ON_HPP_EAN_28_10_2005
+#include <boost/mpl/end.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/set.hpp>
+#include <boost/mpl/copy.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/sort.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/remove.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/inherit.hpp>
+#include <boost/mpl/equal_to.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/insert_range.hpp>
+#include <boost/mpl/back_inserter.hpp>
+#include <boost/mpl/transform_view.hpp>
+#include <boost/mpl/inherit_linearly.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/facilities/intercept.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>
+ ///////////////////////////////////////////////////////////////////////////
+ // as_feature
+ struct as_feature
+ typedef Feature type;
+ // weighted_feature
+ struct as_weighted_feature
+ // feature_of
+ struct feature_of
+ // feature_tag
+ struct feature_tag
+ typedef typename Accumulator::feature_tag type;
+ struct undroppable
+ struct undroppable<tag::droppable<Feature> >
+ // 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 feature_of<typename undroppable<B>::type>::type
+ , typename undroppable<A>::type
+ {};
+ struct dependencies_of
+ typedef typename Feature::dependencies type;
+ // Should use mpl::insert_range, but doesn't seem to work with mpl sets
+ template<typename Set, typename Range>
+ struct set_insert_range
+ : mpl::fold<
+ Range
+ , Set
+ , mpl::insert<mpl::_1, mpl::_2>
+ template<typename Features>
+ struct collect_abstract_features
+ , mpl::set0<>
+ , set_insert_range<
+ mpl::insert<mpl::_1, feature_of<mpl::_2> >
+ , collect_abstract_features<dependencies_of<mpl::_2> >
+ struct depends_on_base
+ : mpl::inherit_linearly<
+ typename mpl::sort<
+ typename mpl::copy<
+ typename collect_abstract_features<Features>::type
+ , mpl::back_inserter<mpl::vector0<> >
+ , is_dependent_on<mpl::_1, mpl::_2>
+ // Don't inherit multiply from a feature
+ , mpl::if_<
+ is_dependent_on<mpl::_1, mpl::_2>
+ , mpl::_1
+ , mpl::inherit<mpl::_1, mpl::_2>
+ /// depends_on
+ template<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, typename Feature)>
+ struct depends_on
+ : detail::depends_on_base<
+ mpl::vector<BOOST_PP_ENUM_PARAMS(BOOST_ACCUMULATORS_MAX_FEATURES, Feature)>
+ , as_feature<mpl::_1>
+ typedef mpl::false_ is_weight_accumulator;
+ struct matches_feature
+ : is_same<
+ , typename feature_of<typename as_feature<typename feature_tag<Accumulator>::type>::type>::type
+ template<typename Features, typename Accumulator>
+ struct contains_feature_of
+ mpl::transform_view<Features, feature_of<as_feature<mpl::_> > >
+ features_list;
+ typename feature_of<typename feature_tag<Accumulator>::type>::type
+ typename mpl::contains<features_list, the_feature>::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
+ struct contains_feature_of_
+ : 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;
+ static fusion::nil_
+ call(Args const &, First const&, Last const&)
+ return fusion::nil_();
+ struct build_acc_list<First, Last, false>
+ 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>
+ 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
+ struct checked_as_weighted_feature
+ 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> >
+ struct as_feature_list<Features, void>
+ : mpl::transform_view<Features, as_feature<mpl::_1> >
+ // accumulator_wrapper
+ template<typename Accumulator, typename Feature>
+ struct accumulator_wrapper
+ typedef Feature feature_tag;
+ accumulator_wrapper(accumulator_wrapper const &that)
+ accumulator_wrapper(Args const &args)
+ // to_accumulator
+ struct to_accumulator
+ accumulator_wrapper<
+ typename mpl::apply2<typename Feature::impl, Sample, Weight>::type
+ , Feature
+ 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>));
+ accumulator_type;
+ typename mpl::if_<
+ typename Feature::is_weight_accumulator
+ , accumulator_wrapper<impl::external_impl<accumulator_type, tag::weights>, Feature>
+ , accumulator_type
+ // BUGBUG work around an 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
+ as_feature_list<typename Feature::dependencies, Weight>
+ , FeatureMap
+ , insert_dependencies<
+ insert_feature<mpl::_1, mpl::_2>
+ , mpl::_2
+ 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>
+ , insert_feature<mpl::_1, mpl::_2>
+ template<typename Features, typename Sample, typename Weight>
+ struct make_accumulator_tuple
+ typename mpl::fold<
+ , mpl::map0<>
+ mpl::is_sequence<mpl::_2>
+ , insert_sequence<mpl::_1, mpl::_2, Weight>
+ feature_map;
+ // for each element in the map, add its dependencies also
+ feature_map
+ , feature_map
+ , insert_dependencies<mpl::_1, mpl::second<mpl::_2>, Weight>
+ feature_map_with_dependencies;
+ // turn the map into a vector so we can sort it
+ typename mpl::insert_range<
+ mpl::vector<>
+ , mpl::end<mpl::vector<> >::type
+ , mpl::transform_view<feature_map_with_dependencies, mpl::second<mpl::_1> >
+ feature_vector_with_dependencies;
+ // sort the features according to which is derived from which
+ feature_vector_with_dependencies
+ , is_dependent_on<mpl::_2, mpl::_1>
+ sorted_feature_vector;
+ // From the vector of features, construct a vector of accumulators
+ sorted_feature_vector
+ , to_accumulator<mpl::_1, Sample, Weight>
+ } // namespace detail
+// external.hpp
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_EXTERNAL_HPP_EAN_01_12_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_EXTERNAL_HPP_EAN_01_12_2005
+//namespace boost { namespace accumulators
+//{
+/////////////////////////////////////////////////////////////////////////////////
+//// external
+////
+//template<typename Type>
+//struct external
+//};
+//}} // namespace boost::accumulators
@@ -0,0 +1,229 @@
+// extractor.hpp
+#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/parameter/binding.hpp>
+#include <boost/mpl/eval_if.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+ template<typename AccumulatorSet, typename Feature>
+ struct accumulator_set_result
+ 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
+ template<typename A, typename Feature>
+ struct extractor_result
+ 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_)
+ return extract_result<feature_type>(acc);
+ template<typename Feature, typename Args>
+ typename extractor_result<Args, Feature>::type
+ do_extract(Args const &args, mpl::false_)
+ return find_accumulator<feature_type>(args[accumulator]).result(args);
+/// Extracts the result associated with Feature from the specified accumulator_set.
+struct extractor
+ typedef extractor<Feature> this_type;
+ /// The result meta-function for determining the return type of the extractor
+ template<typename F>
+ struct result;
+ 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>());
+ /// \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>));
+ return extract_result<feature_type>(acc, a1);
+#define BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP(z, n, _) \
+ struct result<this_type(BOOST_PP_ENUM_PARAMS_Z(z, n, A))> \
+ : detail::extractor_result<A1, Feature> \
+ {}; \
+ typename AccumulatorSet \
+ typename detail::extractor_result<AccumulatorSet, Feature>::type \
+ operator ()( \
+ ) 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_ACCUMULATORS_EXTRACTOR_FUN_OP
+ template<typename AccumulatorSet, typename A1, typename A2, ...>
+ operator ()(AccumulatorSet const &acc, A1 const &a1, A2 const &a2, ...);
+#define BOOST_ACCUMULATORS_ARRAY_REM(Array) \
+ BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_ARRAY_SIZE(Array), BOOST_PP_ARRAY_DATA(Array))
+#define BOOST_ACCUMULATORS_SEQ_REM(Seq) \
+ BOOST_ACCUMULATORS_ARRAY_REM(BOOST_PP_SEQ_TO_ARRAY(Seq))
+#define BOOST_ACCUMULATORS_ARGS_OP(s, data, elem) \
+ T ## s
+#define BOOST_ACCUMULATORS_PARAMS_OP(s, data, elem) \
+ elem T ## s
+#define BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) \
+ Tag::Feature< \
+ BOOST_ACCUMULATORS_SEQ_REM( \
+ BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_ARGS_OP, ~, ParamsSeq) \
+#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN_IMPL(z, n, Tag, Feature, ParamsSeq) \
+ BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_PARAMS_OP, ~, ParamsSeq) \
+ , typename Arg1 \
+ 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)); \
+#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)) \
+// features.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_08_12_2005
+#define BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_08_12_2005
+// 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)>
@@ -0,0 +1,22 @@
+// accumulator.hpp
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005
+BOOST_PARAMETER_KEYWORD(tag, accumulator)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(accumulator)
+// sample.hpp
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005
+BOOST_PARAMETER_KEYWORD(tag, sample)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(sample)
+// weight.hpp
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005
+// The weight of a single sample
+BOOST_PARAMETER_KEYWORD(tag, weight)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(weight)
+// weights.hpp
+#ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005
+// The weight accumulator
+BOOST_PARAMETER_KEYWORD(tag, weights)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(weights)
@@ -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
+ 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;
+}} // namespace boost::detail
+#endif // BOOST_DETAIL_FUNCTION1_DWA200655_HPP
@@ -0,0 +1,10 @@
+#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
+#ifndef BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
+# define BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
+# define args (3)
+#endif // BOOST_DETAIL_FUNCTION3_DWA2006514_HPP
+#ifndef BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
+# define BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
+# define args (4)
+#endif // BOOST_DETAIL_FUNCTION4_DWA2006514_HPP
@@ -0,0 +1,148 @@
+// #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/preprocessor/control/if.hpp>
+#include <boost/preprocessor/punctuation/comma_if.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>
+# 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) \
+struct function_name
+ BOOST_PP_REPEAT(
+ BOOST_MPL_LIMIT_METAFUNCTION_ARITY
+ , BOOST_DETAIL_default_arg
+ , ~
+ 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 \
+ 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
+//#endif // BOOST_DETAIL_FUNCTION_N_DWA2006514_HPP
@@ -0,0 +1,20 @@
+#ifndef BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
+# define BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
+template<typename T>
+struct pod_singleton
+ static T instance;
+T pod_singleton<T>::instance;
+#endif // BOOST_DETAIL_POD_SINGLETON_DWA200655_HPP
@@ -0,0 +1,537 @@
+/// \file functional.hpp
+#ifndef BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_HPP_EAN_08_12_2005
+#include <limits>
+#include <functional>
+#include <boost/static_assert.hpp>
+#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/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>
+#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_VALARRAY_SUPPORT
+# include <boost/accumulators/numeric/functional/valarray.hpp>
+#ifdef BOOST_NUMERIC_FUNCTIONAL_STD_COMPLEX_SUPPORT
+# include <boost/accumulators/numeric/functional/complex.hpp>
+#define BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
+#ifdef BOOST_NUMERIC_FUNCTIONAL_DOXYGEN_INVOKED
+// Hack to make Doxygen show the inheritance relationships
+namespace std
+ template<class Arg, class Ret> struct unary_function {};
+ template<class Left, class Right, class Ret> struct binary_function {};
+namespace boost { namespace numeric
+ namespace functional
+ 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;
+ T &lvalue_of();
+ // TODO: handle complex weight, valarray, MTL vectors
+#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 \
+ typedef typename remove_const<Arg>::type argument_type; \
+ typedef typename result_of_ ## Name<Arg>::type result_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 \
+ : boost::detail::function1<functional::Name<_, functional::tag<_> > > \
+ op::Name const &Name = boost::detail::pod_singleton<op::Name>::instance; \
+#define BOOST_NUMERIC_FUNCTIONAL_DEFINE_BINARY_OP(Name, Op, RetType) \
+ template<typename Left, typename Right, typename EnableIf> \
+ RetType(Left, Op, Right) \
+ typedef typename remove_const<Left>::type first_argument_type; \
+ typedef typename remove_const<Right>::type second_argument_type; \
+ typedef typename result_of_ ## Name<Left, Right>::type result_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> \
+ : Name ## _base<Left, Right, void> \
+ : boost::detail::function2< \
+ functional::Name<_1, _2, functional::tag<_1>, functional::tag<_2> > \
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(Name) \
+#define BOOST_NUMERIC_FUNCTIONAL_DEDUCED(Left, Op, Right) \
+ , boost::numeric::functional::detail::lvalue_of<Left>() Op \
+ boost::numeric::functional::detail::lvalue_of<Right>() \
+#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
+ template<typename Left, typename Right, typename EnableIf>
+ struct min_assign_base
+ typedef Left first_argument_type;
+ typedef Right second_argument_type;
+ void operator ()(Left &left, Right &right) const
+ if(numeric::less(right, left))
+ left = right;
+ struct max_assign_base
+ if(numeric::greater(right, left))
+ struct fdiv_base
+ : functional::divides<Left, Right>
+ // partial specialization that promotes the arguments to double for
+ // integral division.
+ struct fdiv_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
+ typedef From argument_type;
+ typedef To result_type;
+ To operator ()(From &from) const
+ return from;
+ template<typename ToFrom>
+ struct promote_base<ToFrom, ToFrom, void>
+ typedef ToFrom argument_type;
+ typedef ToFrom result_type;
+ ToFrom &operator ()(ToFrom &tofrom)
+ return tofrom;
+ template<typename Arg, typename EnableIf>
+ struct as_min_base
+ BOOST_STATIC_ASSERT(std::numeric_limits<typename remove_const<Arg>::type>::is_specialized);
+ typedef Arg argument_type;
+ typedef typename remove_const<Arg>::type result_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>
+ return -(std::numeric_limits<typename remove_const<Arg>::type>::max)();
+ struct as_max_base
+ return (std::numeric_limits<typename remove_const<Arg>::type>::max)();
+ struct as_zero_base
+ return numeric::zero<typename remove_const<Arg>::type>::value;
+ struct as_one_base
+ 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>
+ struct max_assign
+ : max_assign_base<Left, Right, void>
+ struct fdiv
+ : fdiv_base<Left, Right, void>
+ /// For back-compat only. Use fdiv.
+ struct average
+ : fdiv<Left, Right, LeftTag, RightTag>
+ template<typename Arg, typename Tag>
+ struct as_min
+ : as_min_base<Arg, void>
+ struct as_max
+ : as_max_base<Arg, void>
+ struct as_zero
+ : as_zero_base<Arg, void>
+ struct as_one
+ : as_one_base<Arg, void>
+ namespace op
+ template<typename To>
+ : boost::detail::function1<functional::promote<To, _, typename functional::tag<To>::type, functional::tag<_> > >
+ : boost::detail::function2<functional::min_assign<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ : boost::detail::function2<functional::max_assign<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ : boost::detail::function2<functional::fdiv<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ : boost::detail::function1<functional::as_min<_, functional::tag<_> > >
+ : boost::detail::function1<functional::as_max<_, functional::tag<_> > >
+ : boost::detail::function1<functional::as_zero<_, functional::tag<_> > >
+ : 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::fdiv const &fdiv = boost::detail::pod_singleton<op::fdiv>::instance;
+ op::fdiv const &average = boost::detail::pod_singleton<op::fdiv>::instance; ///< INTERNAL ONLY
+ op::as_min const &as_min = boost::detail::pod_singleton<op::as_min>::instance;
+ op::as_max const &as_max = boost::detail::pod_singleton<op::as_max>::instance;
+ op::as_zero const &as_zero = boost::detail::pod_singleton<op::as_zero>::instance;
+ op::as_one const &as_one = boost::detail::pod_singleton<op::as_one>::instance;
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(min_assign)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(max_assign)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(fdiv)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(average)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_min)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_max)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_zero)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(as_one)
+ // 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);
+ 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);
+ struct default_
+ typedef default_ type;
+ typedef T value_type;
+ static T const value;
+ operator T const & () const
+ return default_::value;
+ T const default_<T>::value = T();
+ struct one
+ typedef one type;
+ return one::value;
+ T const one<T>::value = T(1);
+ struct zero
+ typedef zero type;
+ return zero::value;
+ T const zero<T>::value = T();
+ struct one_or_default
+ : mpl::if_<is_empty<T>, default_<T>, one<T> >::type
+ struct zero_or_default
+ : mpl::if_<is_empty<T>, default_<T>, zero<T> >::type
+}} // namespace boost::numeric
@@ -0,0 +1,82 @@
+/// \file complex.hpp
+#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
+#include <complex>
+#include <boost/mpl/or.hpp>
+#include <boost/typeof/std/complex.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>
+ operator *(std::complex<T> ri, U const &u)
+ // BUGBUG promote result to typeof(T()*u) ?
+ return ri *= static_cast<T>(u);
+ operator /(std::complex<T> ri, U const &u)
+ return ri /= static_cast<T>(u);
+}}} // namespace boost::numeric::operators
+ struct one_complex
+ static std::complex<T> const value;
+ std::complex<T> const one_complex<T>::value
+ = std::complex<T>(numeric::one<T>::value, numeric::one<T>::value);
+ struct one<std::complex<T> >
+ : detail::one_complex<T>
+ typedef std::complex<T> value_type;
+ operator value_type const & () const
+ return detail::one_complex<T>::value;
@@ -0,0 +1,362 @@
+/// \file valarray.hpp
+#ifndef BOOST_NUMERIC_FUNCTIONAL_VALARRAY_HPP_EAN_12_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_VALARRAY_HPP_EAN_12_12_2005
+#include <valarray>
+#include <boost/mpl/not.hpp>
+#include <boost/type_traits/is_scalar.hpp>
+#include <boost/typeof/std/valarray.hpp>
+ namespace operators
+ namespace acc_detail
+ template<typename Fun>
+ struct make_valarray
+ typedef std::valarray<typename Fun::result_type> type;
+ // Handle valarray<Left> / Right where Right is a scalar and Right != Left.
+ typename lazy_enable_if<
+ mpl::and_<is_scalar<Right>, mpl::not_<is_same<Left, Right> > >
+ , acc_detail::make_valarray<functional::divides<Left, Right> >
+ 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.
+ , acc_detail::make_valarray<functional::multiplies<Left, Right> >
+ operator *(std::valarray<Left> const &left, Right const &right)
+ typedef typename functional::multiplies<Left, Right>::result_type value_type;
+ result[i] = numeric::multiplies(left[i], right);
+ // Handle valarray<Left> + valarray<Right> where Right != Left.
+ typename lazy_disable_if<
+ is_same<Left, Right>
+ , acc_detail::make_valarray<functional::plus<Left, Right> >
+ operator +(std::valarray<Left> const &left, std::valarray<Right> const &right)
+ typedef typename functional::plus<Left, Right>::result_type value_type;
+ result[i] = numeric::plus(left[i], right[i]);
+ struct std_valarray_tag;
+ struct tag<std::valarray<T> >
+ typedef std_valarray_tag type;
+ #ifdef __GLIBCXX__
+ struct tag<std::_Expr<T, U> >
+ // 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> \
+ typedef Left first_argument_type; \
+ typedef Right second_argument_type; \
+ typedef typename Left::value_type left_value_type; \
+ typedef typename Right::value_type right_value_type; \
+ std::valarray< \
+ typename Name<left_value_type, right_value_type>::result_type \
+ result_type; \
+ result_type \
+ return numeric::promote<std::valarray<left_value_type> >(left) \
+ Op numeric::promote<std::valarray<right_value_type> >(right); \
+ struct Name<Left, Right, std_valarray_tag, void> \
+ typename Name<left_value_type, Right>::result_type \
+ return numeric::promote<std::valarray<left_value_type> >(left) Op right;\
+ struct Name<Left, Right, void, std_valarray_tag> \
+ typename Name<Left, right_value_type>::result_type \
+ 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
+ struct min_assign<Left, Right, std_valarray_tag, std_valarray_tag>
+ 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
+ struct max_assign<Left, Right, std_valarray_tag, std_valarray_tag>
+ if(numeric::greater(right[i], left[i]))
+ // partial specialization of numeric::fdiv<> for std::valarray.
+ template<typename Left, typename Right, typename RightTag>
+ struct fdiv<Left, Right, std_valarray_tag, RightTag>
+ : mpl::if_<
+ are_integral<typename Left::value_type, Right>
+ , divides<Left, double const>
+ , divides<Left, Right>
+ struct promote<To, From, std_valarray_tag, std_valarray_tag>
+ 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;
+ struct promote<ToFrom, ToFrom, std_valarray_tag, std_valarray_tag>
+ ToFrom &operator ()(ToFrom &tofrom) const
+ // 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>
+ typedef bool result_type;
+ bool operator ()(From &arr) const
+ BOOST_MPL_ASSERT((is_same<bool, typename From::value_type>));
+ if(!arr[i])
+ return false;
+ return true;
+ struct promote<bool const, From, void, std_valarray_tag>
+ : promote<bool, From, void, std_valarray_tag>
+ // functional::as_min
+ struct as_min<T, std_valarray_tag>
+ typedef T argument_type;
+ typedef typename remove_const<T>::type result_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
+ struct as_max<T, std_valarray_tag>
+ : T(numeric::as_max(arr[0]), arr.size());
+ // functional::as_zero
+ struct as_zero<T, std_valarray_tag>
+ : T(numeric::as_zero(arr[0]), arr.size());
+ // functional::as_one
+ struct as_one<T, std_valarray_tag>
+ : T(numeric::as_one(arr[0]), arr.size());
+ } // namespace functional
@@ -0,0 +1,347 @@
+/// \file vector.hpp
+#ifndef BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_VECTOR_HPP_EAN_12_12_2005
+#include <vector>
+#include <boost/typeof/std/vector.hpp>
+ struct make_vector
+ typedef std::vector<typename Fun::result_type> type;
+ // Handle vector<Left> / Right where Right is a scalar.
+ is_scalar<Right>
+ , acc_detail::make_vector<functional::divides<Left, Right> >
+ operator /(std::vector<Left> const &left, Right const &right)
+ std::vector<value_type> result(left.size());
+ // Handle vector<Left> / vector<Right>.
+ std::vector<typename functional::divides<Left, Right>::result_type>
+ operator /(std::vector<Left> const &left, std::vector<Right> const &right)
+ result[i] = numeric::divides(left[i], right[i]);
+ // Handle vector<Left> * Right where Right is a scalar.
+ , acc_detail::make_vector<functional::multiplies<Left, Right> >
+ operator *(std::vector<Left> const &left, Right const &right)
+ // Handle Left * vector<Right> where Left is a scalar.
+ is_scalar<Left>
+ operator *(Left const &left, std::vector<Right> const &right)
+ std::vector<value_type> result(right.size());
+ result[i] = numeric::multiplies(left, right[i]);
+ // Handle vector<Left> * vector<Right>
+ std::vector<typename functional::multiplies<Left, Right>::result_type>
+ operator *(std::vector<Left> const &left, std::vector<Right> const &right)
+ result[i] = numeric::multiplies(left[i], right[i]);
+ // Handle vector<Left> + vector<Right>
+ std::vector<typename functional::plus<Left, Right>::result_type>
+ operator +(std::vector<Left> const &left, std::vector<Right> const &right)
+ // Handle vector<Left> - vector<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;
+ result[i] = numeric::minus(left[i], right[i]);
+ // Handle vector<Left> += vector<Left>
+ template<typename Left>
+ std::vector<Left> &
+ operator +=(std::vector<Left> &left, std::vector<Left> const &right)
+ numeric::plus_assign(left[i], right[i]);
+ return left;
+ // Handle -vector<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());
+ result[i] = numeric::unary_minus(arg[i]);
+ 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
+ struct min_assign<Left, Right, std_vector_tag, std_vector_tag>
+ // element-wise max of std::vector
+ struct max_assign<Left, Right, std_vector_tag, std_vector_tag>
+ // partial specialization for std::vector.
+ struct fdiv<Left, Right, std_vector_tag, void>
+ struct promote<To, From, std_vector_tag, std_vector_tag>
+ struct promote<ToFrom, ToFrom, std_vector_tag, std_vector_tag>
+ struct as_min<T, std_vector_tag>
+ : T(arr.size(), numeric::as_min(arr[0]));
+ struct as_max<T, std_vector_tag>
+ : T(arr.size(), numeric::as_max(arr[0]));
+ struct as_zero<T, std_vector_tag>
+ : T(arr.size(), numeric::as_zero(arr[0]));
+ struct as_one<T, std_vector_tag>
+ : T(arr.size(), numeric::as_one(arr[0]));
@@ -0,0 +1,221 @@
+/// \file functional_fwd.hpp
+#ifndef BOOST_NUMERIC_FUNCTIONAL_FWD_HPP_EAN_08_12_2005
+#define BOOST_NUMERIC_FUNCTIONAL_FWD_HPP_EAN_08_12_2005
+#include <boost/type_traits/is_const.hpp>
+ // For using directives -- this namespace may be re-opened elsewhere
+ {}
+ using mpl::_;
+ using mpl::_1;
+ using mpl::_2;
+ using namespace operators;
+ struct tag
+ typedef void type;
+ struct tag<T const>
+ : tag<T>
+ struct tag<T volatile>
+ struct tag<T const volatile>
+ struct static_;
+ struct are_integral;
+#define BOOST_NUMERIC_FUNCTIONAL_DECLARE_UNARY_OP(Name, Op) \
+ template<typename Arg, typename EnableIf = void> \
+ struct Name ## _base; \
+ template<typename Arg, typename ArgTag = typename tag<Arg>::type> \
+ struct Name; \
+ extern op::Name const &Name; \
+#define BOOST_NUMERIC_FUNCTIONAL_DECLARE_BINARY_OP(Name) \
+ template<typename Left, typename Right, typename EnableIf = void> \
+ struct result_of_ ## Name; \
+ typename Left \
+ , typename Right \
+ , typename LeftTag = typename tag<Left>::type \
+ , typename RightTag = typename tag<Right>::type \
+ 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
+ template<typename To, typename From, typename EnableIf = void>
+ struct promote_base;
+ template<typename Left, typename Right, typename EnableIf = void>
+ struct min_assign_base;
+ struct max_assign_base;
+ struct fdiv_base;
+ template<typename Arg, typename EnableIf = void>
+ struct as_min_base;
+ struct as_max_base;
+ struct as_zero_base;
+ 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;
+ struct max_assign;
+ struct fdiv;
+ template<typename Arg, typename Tag = typename tag<Arg>::type>
+ struct as_min;
+ struct as_max;
+ struct as_zero;
+ struct as_one;
+ extern op::min_assign const &min_assign;
+ extern op::max_assign const &max_assign;
+ extern op::fdiv const &fdiv;
+ extern op::as_min const &as_min;
+ extern op::as_max const &as_max;
+ extern op::as_zero const &as_zero;
+ extern op::as_one const &as_one;
+ promote(From &from);
+ promote(From const &from);
+ struct default_;
+ struct one;
+ struct zero;
+ struct one_or_default;
+ struct zero_or_default;
@@ -0,0 +1,61 @@
+/// \file statistics.hpp
+/// Includes all of the Statistical Accumulators Library
+#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_cumul_dist.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/sum_kahan.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_cumul_dist.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_sum_kahan.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>
@@ -0,0 +1,80 @@
+// count.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_COUNT_HPP_EAN_28_10_2005
+#include <boost/accumulators/statistics_fwd.hpp>
+ // count_impl
+ struct count_impl
+ // for boost::result_of
+ typedef std::size_t result_type;
+ count_impl(dont_care)
+ : cnt(0)
+ void operator ()(dont_care)
+ ++this->cnt;
+ return this->cnt;
+ std::size_t cnt;
+// tag::count
+ struct count
+ typedef mpl::always<accumulators::impl::count_impl> impl;
+// extract::count
+ extractor<tag::count> const count = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(count)
+using extract::count;
@@ -0,0 +1,212 @@
+// covariance.hpp
+// Copyright 2006 Daniel Egloff, Olivier Gygi. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_COVARIANCE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_COVARIANCE_HPP_DE_01_01_2006
+#include <numeric>
+#include <boost/mpl/bool.hpp>
+#include <boost/range.hpp>
+#include <boost/numeric/ublas/io.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+ // functional::outer_product
+ struct outer_product_base
+ : functional::multiplies<Left, Right>
+ struct outer_product
+ : outer_product_base<Left, Right, void>
+ struct outer_product<Left, Right, std_vector_tag, std_vector_tag>
+ 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]);
+ : boost::detail::function2<functional::outer_product<_1, _2, functional::tag<_1>, functional::tag<_2> > >
+ op::outer_product const &outer_product = boost::detail::pod_singleton<op::outer_product>::instance;
+}}
+ // 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
+ typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type sample_type;
+ typedef typename numeric::functional::fdiv<VariateType, std::size_t>::result_type variate_type;
+ typedef typename numeric::functional::outer_product<sample_type, variate_type>::result_type result_type;
+ covariance_impl(Args const &args)
+ : cov_(
+ numeric::outer_product(
+ numeric::fdiv(args[sample | Sample()], (std::size_t)1)
+ , numeric::fdiv(args[parameter::keyword<VariateTag>::get() | VariateType()], (std::size_t)1)
+ 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.);
+ return this->cov_;
+ result_type cov_;
+// tag::covariance
+ 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
+// extract::covariance
+ extractor<tag::abstract_covariance> const covariance = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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.
+struct as_weighted_feature<tag::covariance<VariateType, VariateTag> >
+ typedef tag::weighted_covariance<VariateType, VariateTag> type;
+struct feature_of<tag::weighted_covariance<VariateType, VariateTag> >
+ : feature_of<tag::covariance<VariateType, VariateTag> >
+{};
@@ -0,0 +1,250 @@
+// density.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_DENSITY_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_DENSITY_HPP_DE_01_01_2006
+// 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)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(density_cache_size)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(density_num_bins)
+ // 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
+ typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type float_type;
+ typedef std::vector<std::pair<float_type, float_type> > histogram_type;
+ typedef std::vector<float_type> array_type;
+ typedef iterator_range<typename histogram_type::iterator> result_type;
+ 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::fdiv(args[sample | Sample()],(std::size_t)1)
+ , numeric::fdiv(args[sample | Sample()],(std::size_t)1)
+ , is_dirty(true)
+ this->is_dirty = true;
+ // 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 under and overflow bins.
+ // Store their lower bounds (bin_positions) and fill the bins with the cached samples (samples_in_bin).
+ if (cnt == this->cache_size)
+ float_type minimum = numeric::fdiv((min)(args), (std::size_t)1);
+ float_type maximum = numeric::fdiv((max)(args), (std::size_t)1);
+ float_type bin_size = numeric::fdiv(maximum - minimum, this->num_bins );
+ // determine bin positions (their lower bounds)
+ for (std::size_t i = 0; i < this->num_bins + 2; ++i)
+ 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])
+ else if (args[sample] >= this->bin_positions[this->num_bins + 1])
+ , args[sample]
+ @pre The number of samples must meet or exceed the cache size
+ 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).
+ this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::fdiv(this->samples_in_bin[i], count(args)));
+ // returns a range of pairs
+ return make_iterator_range(this->histogram);
+ 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;
+// tag::density
+ struct density
+ : depends_on<count, min, max>
+ , density_cache_size
+ , density_num_bins
+ typedef accumulators::impl::density_impl<mpl::_1> impl;
+ /// 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;
+// extract::density
+ extractor<tag::density> const density = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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;
+struct feature_of<tag::weighted_density>
+ : feature_of<tag::density>
@@ -0,0 +1,99 @@
+// error_of.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_HPP_EAN_29_11_2005
+ struct this_feature_has_no_error_calculation
+ : mpl::false_
+ // error_of_impl
+ template<typename Sample, typename Feature>
+ struct error_of_impl
+ // TODO: specialize this on the specific features that have errors we're
+ // interested in.
+ BOOST_MPL_ASSERT((this_feature_has_no_error_calculation<Feature>));
+ typedef int result_type;
+ error_of_impl(dont_care)
+ return 0;
+// tag::error_of
+ struct error_of
+ : depends_on<Feature>
+ typedef accumulators::impl::error_of_impl<mpl::_1, Feature> impl;
+// extract::error_of
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, error_of, (typename))
+using extract::error_of;
+// make tag::error_of<tag::feature(modifier)> work
+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>
+struct as_weighted_feature<tag::error_of<Feature> >
+ typedef tag::error_of<typename as_weighted_feature<Feature>::type> type;
@@ -0,0 +1,73 @@
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
+#define BOOST_ACCUMULATORS_STATISTICS_ERROR_OF_MEAN_HPP_EAN_27_03_2006
+ // error_of_mean_impl
+ template<typename Sample, typename Variance>
+ struct error_of_mean_impl
+ typedef typename numeric::functional::fdiv<Sample, std::size_t>::result_type result_type;
+ error_of_mean_impl(dont_care) {}
+ using namespace std;
+ extractor<Variance> const variance = {};
+ return sqrt(numeric::fdiv(variance(args), count(args) - 1));
+ template<>
+ struct error_of<mean>
+ : depends_on<lazy_variance, count>
+ typedef accumulators::impl::error_of_mean_impl<mpl::_1, lazy_variance> impl;
+ struct error_of<immediate_mean>
+ : depends_on<variance, count>
+ typedef accumulators::impl::error_of_mean_impl<mpl::_1, variance> impl;
@@ -0,0 +1,295 @@
+// extended_p_square.hpp
+// Copyright 2005 Daniel Egloff. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_EXTENDED_SINGLE_HPP_DE_01_01_2006
+#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/accumulators/statistics/times2_iterator.hpp>
+// probabilities named parameter
+BOOST_PARAMETER_NESTED_KEYWORD(tag, extended_p_square_probabilities, probabilities)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(extended_p_square_probabilities)
+ // 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 generalizes the \f$ P^2 \f$ algorithm of
+ R. Jain and I. Chlamtac, The P^2 algorithm for dynamic calculation of quantiles and
+ histograms without storing observations, Communications of the ACM,
+ Volume 28 (October), Number 10, 1985, p. 1076-1085.
+ @param extended_p_square_probabilities A vector of quantile probabilities.
+ struct extended_p_square_impl
+ typedef iterator_range<
+ detail::lvalue_index_iterator<
+ permutation_iterator<
+ typename array_type::const_iterator
+ , detail::times2_iterator
+ > result_type;
+ 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]);
+ this->desired_positions[i] = 1. + 2. * (num_quantiles + 1.) * this->positions_increments[i];
+ // 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());
+ 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;
+ typedef typename array_type::iterator iterator;
+ iterator it = std::upper_bound(
+ this->heights.begin()
+ , this->heights.end()
+ 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
+ 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;
+ // use linear formula
+ if(d > 0)
+ this->heights[i] += hp;
+ if(d < 0)
+ this->heights[i] -= hm;
+ this->actual_positions[i] += sign_d;
+ // 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)
+ 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
+// tag::extended_p_square
+ struct extended_p_square
+ : depends_on<count>
+ , extended_p_square_probabilities
+ typedef accumulators::impl::extended_p_square_impl<mpl::_1> impl;
+ /// tag::extended_p_square::probabilities named parameter
+ static boost::parameter::keyword<tag::probabilities> const probabilities;
+// extract::extended_p_square
+ extractor<tag::extended_p_square> const extended_p_square = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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
+struct as_weighted_feature<tag::extended_p_square>
+ typedef tag::weighted_extended_p_square type;
+struct feature_of<tag::weighted_extended_p_square>
+ : feature_of<tag::extended_p_square>
@@ -0,0 +1,320 @@
+// extended_p_square_quantile.hpp
+#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 <boost/throw_exception.hpp>
+# pragma warning(push)
+# pragma warning(disable: 4127) // conditional expression is constant
+ // 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
+ > range_type;
+ typedef float_type result_type;
+ extended_p_square_quantile_impl(Args const &args)
+ is_same<Impl1, weighted>
+ , tag::weighted_extended_p_square
+ , tag::extended_p_square
+ 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();
+ 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];
+ result_type res;
+ 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::fdiv(h1 - h0, p1 - p0);
+ float_type b = h1 - p1 * a;
+ res = a * this->probability + b;
+ // 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);
+ 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::fdiv(h2 - h1, p2 - p1);
+ float_type hp10 = numeric::fdiv(h1 - h0, p1 - p0);
+ float_type p21 = numeric::fdiv(p2 * p2 - p1 * p1, p2 - p1);
+ float_type p10 = numeric::fdiv(p1 * p1 - p0 * p0, p1 - p0);
+ float_type a = numeric::fdiv(hp21 - hp10, p21 - p10);
+ float_type b = hp21 - a * p21;
+ float_type c = h2 - a * p2 * p2 - b * p2;
+ res = a * this->probability * this-> probability + b * this->probability + c;
+ array_type probabilities;
+ mutable float_type probability;
+// tag::extended_p_square_quantile
+ 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
+ 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
+ typedef accumulators::impl::extended_p_square_quantile_impl<mpl::_1, weighted, quadratic> impl;
+// extract::extended_p_square_quantile
+// extract::weighted_extended_p_square_quantile
+ 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 = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(extended_p_square_quantile)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(extended_p_square_quantile_quadratic)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_extended_p_square_quantile)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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
+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
+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
+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
+struct as_feature<tag::weighted_extended_p_square_quantile(quadratic)>
+ typedef tag::weighted_extended_p_square_quantile_quadratic type;
+// extended_p_square_quantile and weighted_extended_p_square_quantile
+// provide the same feature as quantile
+struct feature_of<tag::extended_p_square_quantile>
+ : feature_of<tag::quantile>
+struct feature_of<tag::extended_p_square_quantile_quadratic>
+// So that extended_p_square_quantile can be automatically substituted with
+// weighted_extended_p_square_quantile when the weight parameter is non-void
+struct as_weighted_feature<tag::extended_p_square_quantile>
+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
+struct as_weighted_feature<tag::extended_p_square_quantile_quadratic>
+struct feature_of<tag::weighted_extended_p_square_quantile_quadratic>
+ : feature_of<tag::extended_p_square_quantile_quadratic>
+# pragma warning(pop)
@@ -0,0 +1,112 @@
+// kurtosis.hpp
+// Copyright 2006 Olivier Gygi, Daniel Egloff. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_KURTOSIS_HPP_EAN_28_10_2005
+ // 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:
+ \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,
+ 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.
+ struct kurtosis_impl
+ typedef typename numeric::functional::fdiv<Sample, Sample>::result_type result_type;
+ kurtosis_impl(dont_care) {}
+ return numeric::fdiv(
+ accumulators::moment<4>(args)
+ - 4. * accumulators::moment<3>(args) * mean(args)
+ + 6. * accumulators::moment<2>(args) * mean(args) * mean(args)
+ - 3. * mean(args) * mean(args) * mean(args) * mean(args)
+ , ( accumulators::moment<2>(args) - mean(args) * mean(args) )
+ * ( accumulators::moment<2>(args) - mean(args) * mean(args) )
+ ) - 3.;
+// tag::kurtosis
+ struct kurtosis
+ : depends_on<mean, moment<2>, moment<3>, moment<4> >
+ typedef accumulators::impl::kurtosis_impl<mpl::_1> impl;
+// extract::kurtosis
+ extractor<tag::kurtosis> const kurtosis = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(kurtosis)
+using extract::kurtosis;
+// So that kurtosis can be automatically substituted with
+// weighted_kurtosis when the weight parameter is non-void
+struct as_weighted_feature<tag::kurtosis>
+ typedef tag::weighted_kurtosis type;
+struct feature_of<tag::weighted_kurtosis>
+ : feature_of<tag::kurtosis>
@@ -0,0 +1,85 @@
+// max.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MAX_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MAX_HPP_EAN_28_10_2005
+ // max_impl
+ struct max_impl
+ typedef Sample result_type;
+ max_impl(Args const &args)
+ : max_(numeric::as_min(args[sample | Sample()]))
+ numeric::max_assign(this->max_, args[sample]);
+ return this->max_;
+ Sample max_;
+// tag::max
+ struct max
+ typedef accumulators::impl::max_impl<mpl::_1> impl;
+// extract::max
+ extractor<tag::max> const max = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(max)
+using extract::max;
@@ -0,0 +1,298 @@
+// mean.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MEAN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MEAN_HPP_EAN_28_10_2005
+ // mean_impl
+ // lazy, by default
+ template<typename Sample, typename SumFeature>
+ struct mean_impl
+ mean_impl(dont_care) {}
+ extractor<SumFeature> sum;
+ return numeric::fdiv(sum(args), count(args));
+ template<typename Sample, typename Tag>
+ struct immediate_mean_impl
+ immediate_mean_impl(Args const &args)
+ : mean(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value))
+ this->mean = numeric::fdiv(
+ (this->mean * (cnt - 1)) + args[parameter::keyword<Tag>::get()]
+ , cnt
+ return this->mean;
+ result_type mean;
+// tag::mean
+// tag::immediate_mean
+// tag::mean_of_weights
+// tag::immediate_mean_of_weights
+// tag::mean_of_variates
+// tag::immediate_mean_of_variates
+ struct mean
+ : depends_on<count, sum>
+ typedef accumulators::impl::mean_impl<mpl::_1, sum> impl;
+ struct immediate_mean
+ 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;
+ typedef accumulators::impl::mean_impl<mpl::_2, sum_of_weights> impl;
+ struct immediate_mean_of_weights
+ typedef accumulators::impl::immediate_mean_impl<mpl::_2, tag::weight> impl;
+ struct mean_of_variates
+ : depends_on<count, sum_of_variates<VariateType, VariateTag> >
+ typedef mpl::always<accumulators::impl::mean_impl<VariateType, sum_of_variates<VariateType, VariateTag> > > impl;
+ struct immediate_mean_of_variates
+ typedef mpl::always<accumulators::impl::immediate_mean_impl<VariateType, VariateTag> > impl;
+// extract::mean
+// extract::mean_of_weights
+// extract::mean_of_variates
+ extractor<tag::mean> const mean = {};
+ extractor<tag::mean_of_weights> const mean_of_weights = {};
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, mean_of_variates, (typename)(typename))
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(mean)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(mean_of_weights)
+using extract::mean;
+using extract::mean_of_weights;
+using extract::mean_of_variates;
+// mean(lazy) -> mean
+struct as_feature<tag::mean(lazy)>
+ typedef tag::mean type;
+// mean(immediate) -> immediate_mean
+struct as_feature<tag::mean(immediate)>
+ typedef tag::immediate_mean type;
+// mean_of_weights(lazy) -> mean_of_weights
+struct as_feature<tag::mean_of_weights(lazy)>
+ typedef tag::mean_of_weights type;
+// mean_of_weights(immediate) -> immediate_mean_of_weights
+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>
+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>
+struct as_feature<tag::mean_of_variates<VariateType, VariateTag>(immediate)>
+ typedef tag::immediate_mean_of_variates<VariateType, VariateTag> type;
+// immediate_mean provides the same feature as mean
+struct feature_of<tag::immediate_mean>
+ : feature_of<tag::mean>
+struct feature_of<tag::immediate_mean_of_weights>
+ : feature_of<tag::mean_of_weights>
+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.
+struct as_weighted_feature<tag::mean>
+ typedef tag::weighted_mean type;
+struct feature_of<tag::weighted_mean>
+// So that immediate_mean can be automatically substituted with
+// immediate_weighted_mean when the weight parameter is non-void.
+struct as_weighted_feature<tag::immediate_mean>
+ typedef tag::immediate_weighted_mean type;
+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.
+struct as_weighted_feature<tag::mean_of_variates<VariateType, VariateTag> >
+ typedef tag::weighted_mean_of_variates<VariateType, VariateTag> type;
+struct feature_of<tag::weighted_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.
+struct as_weighted_feature<tag::immediate_mean_of_variates<VariateType, VariateTag> >
+ typedef tag::immediate_weighted_mean_of_variates<VariateType, VariateTag> type;
+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)
+// {
+// }
@@ -0,0 +1,301 @@
+// median.hpp
+// Copyright 2006 Eric Niebler, Olivier Gygi. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MEDIAN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MEDIAN_HPP_EAN_28_10_2005
+ // 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.
+ struct median_impl
+ median_impl(dont_care) {}
+ 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.
+ struct with_density_median_impl
+ typedef iterator_range<typename histogram_type::iterator> range_type;
+ with_density_median_impl(Args const &args)
+ : sum(numeric::fdiv(args[sample | Sample()], (std::size_t)1))
+ 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::fdiv(this->sum - 0.5 * cnt, it->second * cnt);
+ this->median = it->first * over + (it + 1)->first * (1. - over);
+ return this->median;
+ mutable float_type sum;
+ 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.
+ struct with_p_square_cumulative_distribution_median_impl
+ with_p_square_cumulative_distribution_median_impl(dont_care)
+ : is_dirty(true)
+ range_type histogram = p_square_cumulative_distribution(args);
+ while (it->second < 0.5)
+ float_type over = numeric::fdiv(it->second - 0.5, it->second - (it - 1)->second);
+ this->median = it->first * over + (it + 1)->first * ( 1. - over );
+// tag::median
+// tag::with_densisty_median
+// tag::with_p_square_cumulative_distribution_median
+ struct median
+ : depends_on<p_square_quantile_for_median>
+ typedef accumulators::impl::median_impl<mpl::_1> impl;
+ struct with_density_median
+ : depends_on<count, density>
+ typedef accumulators::impl::with_density_median_impl<mpl::_1> impl;
+ struct with_p_square_cumulative_distribution_median
+ : depends_on<p_square_cumulative_distribution>
+ 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
+ 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 = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(median)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(with_density_median)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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
+struct as_feature<tag::median(with_p_square_quantile)>
+ typedef tag::median type;
+// median(with_density) -> with_density_median
+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
+struct as_feature<tag::median(with_p_square_cumulative_distribution)>
+ typedef tag::with_p_square_cumulative_distribution_median type;
+// with_density_median and with_p_square_cumulative_distribution_median
+// provide the same feature as median
+struct feature_of<tag::with_density_median>
+ : feature_of<tag::median>
+struct feature_of<tag::with_p_square_cumulative_distribution_median>
+// So that median can be automatically substituted with
+// weighted_median when the weight parameter is non-void.
+struct as_weighted_feature<tag::median>
+ typedef tag::weighted_median type;
+struct feature_of<tag::weighted_median>
+// So that with_density_median can be automatically substituted with
+// with_density_weighted_median when the weight parameter is non-void.
+struct as_weighted_feature<tag::with_density_median>
+ typedef tag::with_density_weighted_median type;
+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.
+struct as_weighted_feature<tag::with_p_square_cumulative_distribution_median>
+ typedef tag::with_p_square_cumulative_distribution_weighted_median type;
+struct feature_of<tag::with_p_square_cumulative_distribution_weighted_median>
+ : feature_of<tag::with_p_square_cumulative_distribution_median>
+// min.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MIN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MIN_HPP_EAN_28_10_2005
+ // min_impl
+ struct min_impl
+ min_impl(Args const &args)
+ : min_(numeric::as_max(args[sample | Sample()]))
+ numeric::min_assign(this->min_, args[sample]);
+ return this->min_;
+ Sample min_;
+// tag::min
+ struct min
+ typedef accumulators::impl::min_impl<mpl::_1> impl;
+// extract::min
+ extractor<tag::min> const min = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(min)
+using extract::min;
@@ -0,0 +1,125 @@
+// moment.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_MOMENT_HPP_EAN_15_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_MOMENT_HPP_EAN_15_11_2005
+#include <boost/config/no_tr1/cmath.hpp>
+#include <boost/mpl/int.hpp>
+ T const &pow(T const &x, mpl::int_<1>)
+ return x;
+ template<typename T, int N>
+ T pow(T const &x, mpl::int_<N>)
+ T y = numeric::pow(x, mpl::int_<N/2>());
+ T z = y * y;
+ return (N % 2) ? (z * x) : z;
+ // 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);
+ moment_impl(Args const &args)
+ : sum(args[sample | Sample()])
+ this->sum += numeric::pow(args[sample], N());
+ return numeric::fdiv(this->sum, count(args));
+ Sample sum;
+// tag::moment
+ template<int N>
+ struct moment
+ typedef accumulators::impl::moment_impl<mpl::int_<N>, mpl::_1> impl;
+// extract::moment
+ 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;
+struct feature_of<tag::weighted_moment<N> >
+ : feature_of<tag::moment<N> >
@@ -0,0 +1,263 @@
+// p_square_cumulative_distribution.hpp
+// Copyright 2005 Daniel Egloff, Olivier Gygi. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_P_SQUARE_CUMUL_DIST_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_P_SQUARE_CUMUL_DIST_HPP_DE_01_01_2006
+// num_cells named parameter
+BOOST_PARAMETER_NESTED_KEYWORD(tag, p_square_cumulative_distribution_num_cells, num_cells)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(p_square_cumulative_distribution_num_cells)
+ // 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.
+ @param p_square_cumulative_distribution_num_cells.
+ struct p_square_cumulative_distribution_impl
+ 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)
+ 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::fdiv(i, b);
+ std::size_t sample_cell = 1; // k
+ // accumulate num_cells + 1 first samples
+ if (cnt <= b + 1)
+ if (cnt == b + 1)
+ // find cell k such that heights[k-1] <= args[sample] < heights[k] and adjust extreme values
+ if (args[sample] < this->heights[0])
+ else if (this->heights[b] <= args[sample])
+ this->heights[b] = args[sample];
+ sample_cell = b;
+ typename array_type::iterator it;
+ it = std::upper_bound(
+ // increment positions of markers above sample_cell
+ for (std::size_t i = sample_cell; i < b + 1; ++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)
+ // 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 dp = this->actual_positions[i + 1] - this->actual_positions[i];
+ float_type dm = this->actual_positions[i - 1] - this->actual_positions[i];
+ 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. ) )
+ 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] )
+ if (d>0)
+ if (d<0)
+ // the values heights[i] (x-axis of histogram) and
+ // actual_positions[i] / cnt (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::fdiv(this->actual_positions[i], cnt));
+ //return histogram;
+ std::size_t num_cells; // number of cells b
+ array_type desired_positions; // n'_i
+ array_type positions_increments; // dn'_i
+// tag::p_square_cumulative_distribution
+ struct p_square_cumulative_distribution
+ , p_square_cumulative_distribution_num_cells
+ typedef accumulators::impl::p_square_cumulative_distribution_impl<mpl::_1> impl;
+// extract::p_square_cumulative_distribution
+ extractor<tag::p_square_cumulative_distribution> const p_square_cumulative_distribution = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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
+struct as_weighted_feature<tag::p_square_cumulative_distribution>
+ typedef tag::weighted_p_square_cumulative_distribution type;
+struct feature_of<tag::weighted_p_square_cumulative_distribution>
+ : feature_of<tag::p_square_cumulative_distribution>
@@ -0,0 +1,19 @@
+// Copyright 2012 Eric Niebler. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_03_19_2012
+#define BOOST_ACCUMULATORS_STATISTICS_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_03_19_2012
+#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__DMC__)
+# pragma message ("Warning: This header is deprecated. Please use: boost/accumulators/statistics/p_square_cumul_dist.hpp")
+#elif defined(__GNUC__) || defined(__HP_aCC) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
+# warning "This header is deprecated. Please use: boost/accumulators/statistics/p_square_cumul_dist.hpp"
@@ -0,0 +1,257 @@
+// p_square_quantile.hpp
+#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 <cmath>
+#include <boost/array.hpp>
+ // p_square_quantile_impl
+ @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.
+ @param quantile_probability
+ template<typename Sample, typename Impl>
+ struct p_square_quantile_impl
+ typedef array<float_type, 5> array_type;
+ 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->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[1] = this->p / 2.;
+ this->positions_increments[2] = this->p;
+ this->positions_increments[3] = (1. + this->p) / 2.;
+ this->positions_increments[4] = 1.;
+ // accumulate 5 first samples
+ if(cnt <= 5)
+ if(cnt == 5)
+ else if (this->heights[4] <= args[sample])
+ this->heights[4] = args[sample];
+ sample_cell = 4;
+ // update positions of markers above sample_cell
+ for(std::size_t i = sample_cell; i < 5; ++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
+ if((d >= 1. && dp > 1.) || (d <= -1. && dm < -1.))
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ((sign_d - dm) * hp
+ return this->heights[2];
+ float_type p; // the quantile probability p
+// tag::p_square_quantile
+ struct p_square_quantile
+ typedef accumulators::impl::p_square_quantile_impl<mpl::_1, regular> impl;
+ struct p_square_quantile_for_median
+ typedef accumulators::impl::p_square_quantile_impl<mpl::_1, for_median> impl;
+// extract::p_square_quantile
+// extract::p_square_quantile_for_median
+ extractor<tag::p_square_quantile> const p_square_quantile = {};
+ extractor<tag::p_square_quantile_for_median> const p_square_quantile_for_median = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(p_square_quantile)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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
+struct as_weighted_feature<tag::p_square_quantile>
+ typedef tag::weighted_p_square_quantile type;
+struct feature_of<tag::weighted_p_square_quantile>
+ : feature_of<tag::p_square_quantile>
+// quantile_probability.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_PARAMETERS_QUANTILE_PROBABILITY_HPP_EAN_03_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_PARAMETERS_QUANTILE_PROBABILITY_HPP_EAN_03_11_2005
+BOOST_PARAMETER_KEYWORD(tag, quantile_probability)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(quantile_probability)
@@ -0,0 +1,405 @@
+// peaks_over_threshold.hpp
+#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 <boost/config/no_tr1/cmath.hpp> // pow
+#include <sstream> // stringstream
+#include <stdexcept> // runtime_error
+#include <boost/tuple/tuple.hpp>
+// 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)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(pot_threshold_value)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(pot_threshold_probability)
+ // 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
+ 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.
+ 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),
+ \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],
+ \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(x) = [1 - \P(X \leq u)]F_u(x - u) + \P(X \leq u)
+ 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
+ \widehat{F}(x) = [1 - F_n(u)]G_{\xi,\beta,u}(x) + F_n(u).
+ 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,
+ \hat{q}_{\alpha} = \bar{u} + \frac{\bar{\beta}}{\xi}\left[(1-\alpha)^{-\xi}-1\right],
+ and similarly an estimator for the (coherent) tail mean,
+ \widehat{CTM}_{\alpha} = \hat{q}_{\alpha} - \frac{\bar{\beta}}{\xi-1}(1-\alpha)^{-\xi},
+ 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.
+ 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 pot_threshold_value
+ template<typename Sample, typename LeftRight>
+ struct peaks_over_threshold_impl
+ 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;
+ peaks_over_threshold_impl(Args const &args)
+ : Nu_(0)
+ , mu_(sign::value * numeric::fdiv(args[sample | Sample()], (std::size_t)1))
+ , sigma2_(numeric::fdiv(args[sample | Sample()], (std::size_t)1))
+ , threshold_(sign::value * args[pot_threshold_value])
+ , fit_parameters_(boost::make_tuple(0., 0., 0.))
+ , is_dirty_(true)
+ this->is_dirty_ = true;
+ if (sign::value * args[sample] > this->threshold_)
+ this->mu_ += args[sample];
+ this->sigma2_ += args[sample] * args[sample];
+ ++this->Nu_;
+ if (this->is_dirty_)
+ this->is_dirty_ = false;
+ this->mu_ = sign::value * numeric::fdiv(this->mu_, this->Nu_);
+ this->sigma2_ = numeric::fdiv(this->sigma2_, this->Nu_);
+ this->sigma2_ -= this->mu_ * this->mu_;
+ float_type threshold_probability = numeric::fdiv(cnt - this->Nu_, cnt);
+ float_type tmp = numeric::fdiv(( this->mu_ - this->threshold_ )*( this->mu_ - this->threshold_ ), this->sigma2_);
+ float_type xi_hat = 0.5 * ( 1. - tmp );
+ float_type beta_hat = 0.5 * ( this->mu_ - this->threshold_ ) * ( 1. + tmp );
+ float_type beta_bar = beta_hat * std::pow(1. - threshold_probability, xi_hat);
+ 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_;
+ 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
+ @sa peaks_over_threshold_impl
+ @param pot_threshold_probability
+ struct peaks_over_threshold_prob_impl
+ peaks_over_threshold_prob_impl(Args const &args)
+ : mu_(sign::value * numeric::fdiv(args[sample | Sample()], (std::size_t)1))
+ , threshold_probability_(args[pot_threshold_probability])
+ // 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()
+ msg << "index n = " << n << " is not in valid range [0, " << tail(args).size() << ")";
+ return boost::make_tuple(Sample(0), Sample(0), Sample(0));
+ 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::fdiv(this->mu_, n);
+ this->sigma2_ = numeric::fdiv(this->sigma2_, n);
+ if (is_same<LeftRight, left>::value)
+ this->threshold_probability_ = 1. - this->threshold_probability_;
+ float_type tmp = numeric::fdiv(( this->mu_ - u )*( this->mu_ - u ), this->sigma2_);
+ 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;
+ 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_;
+// tag::peaks_over_threshold
+ template<typename LeftRight>
+ struct peaks_over_threshold
+ , pot_threshold_value
+ typedef accumulators::impl::peaks_over_threshold_impl<mpl::_1, LeftRight> impl;
+ struct peaks_over_threshold_prob
+ : depends_on<count, tail<LeftRight> >
+ , pot_threshold_probability
+ typedef accumulators::impl::peaks_over_threshold_prob_impl<mpl::_1, LeftRight> impl;
+ struct abstract_peaks_over_threshold
+// extract::peaks_over_threshold
+ extractor<tag::abstract_peaks_over_threshold> const peaks_over_threshold = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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>
+struct as_feature<tag::peaks_over_threshold<LeftRight>(with_threshold_probability)>
+ typedef tag::peaks_over_threshold_prob<LeftRight> type;
+struct feature_of<tag::peaks_over_threshold<LeftRight> >
+ : feature_of<tag::abstract_peaks_over_threshold>
+struct feature_of<tag::peaks_over_threshold_prob<LeftRight> >
+// So that peaks_over_threshold can be automatically substituted
+// with weighted_peaks_over_threshold when the weight parameter is non-void.
+struct as_weighted_feature<tag::peaks_over_threshold<LeftRight> >
+ typedef tag::weighted_peaks_over_threshold<LeftRight> type;
+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.
+struct as_weighted_feature<tag::peaks_over_threshold_prob<LeftRight> >
+ typedef tag::weighted_peaks_over_threshold_prob<LeftRight> type;
+struct feature_of<tag::weighted_peaks_over_threshold_prob<LeftRight> >
+ : feature_of<tag::peaks_over_threshold_prob<LeftRight> >
@@ -0,0 +1,205 @@
+// pot_quantile.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_POT_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_POT_QUANTILE_HPP_DE_01_01_2006
+ // pot_quantile_impl
+ @brief Quantile Estimation based on Peaks over Threshold Method (for both left and right tails)
+ Computes an estimate
+ \hat{q}_{\alpha} = \bar{u} + \frac{\bar{\beta}}{\xi}\left[(1-\alpha)^{-\xi}-1\right]
+ 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
+ pot_quantile_impl(dont_care)
+ : sign_((is_same<LeftRight, left>::value) ? -1 : 1)
+ is_same<Impl, weighted>
+ , tag::weighted_peaks_over_threshold<LeftRight>
+ , tag::peaks_over_threshold<LeftRight>
+ 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.));
+ short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result
+// tag::pot_quantile<>
+// tag::pot_quantile_prob<>
+// tag::weighted_pot_quantile<>
+// tag::weighted_pot_quantile_prob<>
+ struct pot_quantile
+ : depends_on<peaks_over_threshold<LeftRight> >
+ typedef accumulators::impl::pot_quantile_impl<mpl::_1, unweighted, LeftRight> impl;
+ struct pot_quantile_prob
+ : depends_on<peaks_over_threshold_prob<LeftRight> >
+ struct weighted_pot_quantile
+ : depends_on<weighted_peaks_over_threshold<LeftRight> >
+ typedef accumulators::impl::pot_quantile_impl<mpl::_1, weighted, LeftRight> impl;
+ struct weighted_pot_quantile_prob
+ : depends_on<weighted_peaks_over_threshold_prob<LeftRight> >
+// pot_quantile<LeftRight>(with_threshold_value) -> pot_quantile<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>
+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>
+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>
+struct as_feature<tag::weighted_pot_quantile<LeftRight>(with_threshold_probability)>
+ typedef tag::weighted_pot_quantile_prob<LeftRight> type;
+// pot_quantile<LeftRight> and pot_quantile_prob<LeftRight> provide
+// the same feature as quantile
+struct feature_of<tag::pot_quantile<LeftRight> >
+struct feature_of<tag::pot_quantile_prob<LeftRight> >
+// So that pot_quantile can be automatically substituted
+// with weighted_pot_quantile when the weight parameter is non-void.
+struct as_weighted_feature<tag::pot_quantile<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.
+struct as_weighted_feature<tag::pot_quantile_prob<LeftRight> >
+struct feature_of<tag::weighted_pot_quantile_prob<LeftRight> >
+ : feature_of<tag::pot_quantile_prob<LeftRight> >
@@ -0,0 +1,211 @@
+// pot_tail_mean.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_POT_TAIL_MEAN_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_POT_TAIL_MEAN_HPP_DE_01_01_2006
+ // 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
+ 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.
+ struct pot_tail_mean_impl
+ pot_tail_mean_impl(dont_care)
+ , tag::weighted_pot_quantile<LeftRight>
+ , tag::pot_quantile<LeftRight>
+ pot_quantile_tag;
+ extractor<pot_quantile_tag> const some_pot_quantile = {};
+ return some_pot_quantile(args) - this->sign_ * beta_bar/( xi_hat - 1. ) * std::pow(
+ , -xi_hat);
+// tag::pot_tail_mean
+// tag::pot_tail_mean_prob
+ struct pot_tail_mean
+ : depends_on<peaks_over_threshold<LeftRight>, pot_quantile<LeftRight> >
+ typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, unweighted, LeftRight> impl;
+ struct pot_tail_mean_prob
+ : depends_on<peaks_over_threshold_prob<LeftRight>, pot_quantile_prob<LeftRight> >
+ struct weighted_pot_tail_mean
+ : depends_on<weighted_peaks_over_threshold<LeftRight>, weighted_pot_quantile<LeftRight> >
+ typedef accumulators::impl::pot_tail_mean_impl<mpl::_1, weighted, LeftRight> impl;
+ struct weighted_pot_tail_mean_prob
+ : depends_on<weighted_peaks_over_threshold_prob<LeftRight>, weighted_pot_quantile_prob<LeftRight> >
+// pot_tail_mean<LeftRight>(with_threshold_value) -> pot_tail_mean<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>
+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>
+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>
+struct as_feature<tag::weighted_pot_tail_mean<LeftRight>(with_threshold_probability)>
+ typedef tag::weighted_pot_tail_mean_prob<LeftRight> type;
+// pot_tail_mean<LeftRight> and pot_tail_mean_prob<LeftRight> provide
+// the same feature as tail_mean
+struct feature_of<tag::pot_tail_mean<LeftRight> >
+ : feature_of<tag::tail_mean>
+struct feature_of<tag::pot_tail_mean_prob<LeftRight> >
+// So that pot_tail_mean can be automatically substituted
+// with weighted_pot_tail_mean when the weight parameter is non-void.
+struct as_weighted_feature<tag::pot_tail_mean<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.
+struct as_weighted_feature<tag::pot_tail_mean_prob<LeftRight> >
+struct feature_of<tag::weighted_pot_tail_mean_prob<LeftRight> >
+ : feature_of<tag::pot_tail_mean_prob<LeftRight> >
+// rolling_count.hpp
+// Copyright 2008 Eric Niebler. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_COUNT_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_COUNT_HPP_EAN_26_12_2008
+#include <boost/accumulators/statistics/rolling_window.hpp>
+ // rolling_count_impl
+ // returns the count of elements in the rolling window
+ struct rolling_count_impl
+ rolling_count_impl(dont_care)
+ return static_cast<std::size_t>(rolling_window_plus1(args).size()) - is_rolling_window_plus1_full(args);
+// tag::rolling_count
+ struct rolling_count
+ : depends_on< rolling_window_plus1 >
+ typedef accumulators::impl::rolling_count_impl< mpl::_1 > impl;
+ /// tag::rolling_window::window_size named parameter
+ static boost::parameter::keyword<tag::rolling_window_size> const window_size;
+} // namespace tag
+// extract::rolling_count
+ extractor<tag::rolling_count> const rolling_count = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_count)
+using extract::rolling_count;
@@ -0,0 +1,179 @@
+// rolling_mean.hpp
+// Copyright (C) 2008 Eric Niebler.
+// Copyright (C) 2012 Pieter Bastiaan Ober (Integricom).
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MEAN_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MEAN_HPP_EAN_26_12_2008
+#include <boost/accumulators/statistics/rolling_sum.hpp>
+#include <boost/accumulators/statistics/rolling_count.hpp>
+ namespace impl
+ // lazy_rolling_mean_impl
+ // returns the mean over the rolling window and is calculated only
+ // when the result is requested
+ struct lazy_rolling_mean_impl
+ typedef typename numeric::functional::fdiv<Sample, std::size_t, void, void>::result_type result_type;
+ lazy_rolling_mean_impl(dont_care)
+ return numeric::fdiv(rolling_sum(args), rolling_count(args));
+ // immediate_rolling_mean_impl
+ // The non-lazy version computes the rolling mean recursively when a new
+ // sample is added
+ struct immediate_rolling_mean_impl
+ immediate_rolling_mean_impl(Args const &args)
+ : mean_(numeric::fdiv(args[sample | Sample()],numeric::one<std::size_t>::value))
+ void operator()(Args const &args)
+ if(is_rolling_window_plus1_full(args))
+ mean_ += numeric::fdiv(args[sample]-rolling_window_plus1(args).front(),rolling_count(args));
+ result_type prev_mean = mean_;
+ mean_ += numeric::fdiv(args[sample]-prev_mean,rolling_count(args));
+ result_type result(Args const &) const
+ return mean_;
+ result_type mean_;
+ } // namespace impl
+ // tag::lazy_rolling_mean
+ // tag::immediate_rolling_mean
+ // tag::rolling_mean
+ struct lazy_rolling_mean
+ : depends_on< rolling_sum, rolling_count >
+ typedef accumulators::impl::lazy_rolling_mean_impl< mpl::_1 > impl;
+ struct immediate_rolling_mean
+ : depends_on< rolling_window_plus1, rolling_count>
+ typedef accumulators::impl::immediate_rolling_mean_impl< mpl::_1> impl;
+ // make immediate_rolling_mean the default implementation
+ struct rolling_mean : immediate_rolling_mean {};
+ } // namespace tag
+ // extract::lazy_rolling_mean
+ // extract::immediate_rolling_mean
+ // extract::rolling_mean
+ namespace extract
+ extractor<tag::lazy_rolling_mean> const lazy_rolling_mean = {};
+ extractor<tag::immediate_rolling_mean> const immediate_rolling_mean = {};
+ extractor<tag::rolling_mean> const rolling_mean = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(lazy_rolling_mean)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(immediate_rolling_mean)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_mean)
+ using extract::lazy_rolling_mean;
+ using extract::immediate_rolling_mean;
+ using extract::rolling_mean;
+ // rolling_mean(lazy) -> lazy_rolling_mean
+ struct as_feature<tag::rolling_mean(lazy)>
+ typedef tag::lazy_rolling_mean type;
+ // rolling_mean(immediate) -> immediate_rolling_mean
+ struct as_feature<tag::rolling_mean(immediate)>
+ typedef tag::immediate_rolling_mean type;
+ // immediate_rolling_mean provides the same feature as rolling_mean
+ struct feature_of<tag::immediate_rolling_mean>
+ : feature_of<tag::rolling_mean>
+ // lazy_rolling_mean provides the same feature as rolling_mean
+ struct feature_of<tag::lazy_rolling_mean>
@@ -0,0 +1,113 @@
+// rolling_moment.hpp
+// Copyright 2005 Eric Niebler.
+// Copyright (C) 2014 Pieter Bastiaan Ober (Integricom).
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
+ // rolling_moment_impl
+ struct rolling_moment_impl
+ typedef typename numeric::functional::fdiv<Sample, std::size_t,void,void>::result_type result_type;
+ rolling_moment_impl(Args const &args)
+ : sum_(args[sample | Sample()])
+ this->sum_ -= numeric::pow(rolling_window_plus1(args).front(), N());
+ this->sum_ += numeric::pow(args[sample], N());
+ return numeric::fdiv(this->sum_, rolling_count(args));
+ result_type sum_;
+// tag::rolling_moment
+ struct rolling_moment
+ typedef accumulators::impl::rolling_moment_impl<mpl::int_<N>, mpl::_1> impl;
+// extract::rolling_moment
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, rolling_moment, (int))
+using extract::rolling_moment;
+// There is no weighted_rolling_moment (yet)...
+//// So that rolling_moment<N> can be automatically substituted with
+//// weighted_rolling_moment<N> when the weight parameter is non-void
+//template<int N>
+//struct as_weighted_feature<tag::rolling_moment<N> >
+// typedef tag::weighted_rolling_moment<N> type;
+//struct feature_of<tag::weighted_rolling_moment<N> >
+// : feature_of<tag::rolling_moment<N> >
@@ -0,0 +1,91 @@
+// rolling_sum.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
+ // rolling_sum_impl
+ // returns the sum of the samples in the rolling window
+ struct rolling_sum_impl
+ rolling_sum_impl(Args const &args)
+ this->sum_ -= rolling_window_plus1(args).front();
+ this->sum_ += args[sample];
+ result_type result(Args const & /*args*/) const
+ return this->sum_;
+ Sample sum_;
+// tag::rolling_sum
+ struct rolling_sum
+ typedef accumulators::impl::rolling_sum_impl< mpl::_1 > impl;
+// extract::rolling_sum
+ extractor<tag::rolling_sum> const rolling_sum = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_sum)
+using extract::rolling_sum;
@@ -0,0 +1,247 @@
+// rolling_variance.hpp
+// Copyright (C) 2005 Eric Niebler
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_VARIANCE_HPP_EAN_15_11_2011
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_VARIANCE_HPP_EAN_15_11_2011
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/rolling_mean.hpp>
+#include <boost/accumulators/statistics/rolling_moment.hpp>
+#include <boost/type_traits/is_arithmetic.hpp>
+ //! Immediate (lazy) calculation of the rolling variance.
+ /*!
+ Calculation of sample variance \f$\sigma_n^2\f$ is done as follows, see also
+ http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance.
+ For a rolling window of size \f$N\f$, when \f$n <= N\f$, the variance is computed according to the formula
+ \sigma_n^2 = \frac{1}{n-1} \sum_{i = 1}^n (x_i - \mu_n)^2.
+ When \f$n > N\f$, the sample variance over the window becomes:
+ \sigma_n^2 = \frac{1}{N-1} \sum_{i = n-N+1}^n (x_i - \mu_n)^2.
+ // lazy_rolling_variance_impl
+ struct lazy_rolling_variance_impl
+ lazy_rolling_variance_impl(dont_care) {}
+ result_type mean = rolling_mean(args);
+ size_t nr_samples = rolling_count(args);
+ if (nr_samples < 2) return result_type();
+ return nr_samples*(rolling_moment<2>(args) - mean*mean)/(nr_samples-1);
+ //! Iterative calculation of the rolling variance.
+ Iterative calculation of sample variance \f$\sigma_n^2\f$ is done as follows, see also
+ For a rolling window of size \f$N\f$, for the first \f$N\f$ samples, the variance is computed according to the formula
+ \sigma_n^2 = \frac{1}{n-1} \sum_{i = 1}^n (x_i - \mu_n)^2 = \frac{1}{n-1}M_{2,n},
+ where the sum of squares \f$M_{2,n}\f$ can be recursively computed as:
+ M_{2,n} = \sum_{i = 1}^n (x_i - \mu_n)^2 = M_{2,n-1} + (x_n - \mu_n)(x_n - \mu_{n-1}),
+ and the estimate of the sample mean as:
+ \mu_n = \frac{1}{n} \sum_{i = 1}^n x_i = \mu_{n-1} + \frac{1}{n}(x_n - \mu_{n-1}).
+ For further samples, when the rolling window is fully filled with data, one has to take into account that the oldest
+ sample \f$x_{n-N}\f$ is dropped from the window. The sample variance over the window now becomes:
+ \sigma_n^2 = \frac{1}{N-1} \sum_{i = n-N+1}^n (x_i - \mu_n)^2 = \frac{1}{n-1}M_{2,n},
+ where the sum of squares \f$M_{2,n}\f$ now equals:
+ M_{2,n} = \sum_{i = n-N+1}^n (x_i - \mu_n)^2 = M_{2,n-1} + (x_n - \mu_n)(x_n - \mu_{n-1}) - (x_{n-N} - \mu_n)(x_{n-N} - \mu_{n-1}),
+ and the estimated mean is:
+ \mu_n = \frac{1}{N} \sum_{i = n-N+1}^n x_i = \mu_{n-1} + \frac{1}{n}(x_n - x_{n-N}).
+ Note that the sample variance is not defined for \f$n <= 1\f$.
+ // immediate_rolling_variance_impl
+ struct immediate_rolling_variance_impl
+ immediate_rolling_variance_impl(Args const &args)
+ : previous_mean_(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value))
+ , sum_of_squares_(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value))
+ Sample added_sample = args[sample];
+ result_type mean = immediate_rolling_mean(args);
+ sum_of_squares_ += (added_sample-mean)*(added_sample-previous_mean_);
+ Sample removed_sample = rolling_window_plus1(args).front();
+ sum_of_squares_ -= (removed_sample-mean)*(removed_sample-previous_mean_);
+ prevent_underflow(sum_of_squares_);
+ previous_mean_ = mean;
+ return numeric::fdiv(sum_of_squares_,(nr_samples-1));
+ result_type previous_mean_;
+ result_type sum_of_squares_;
+ void prevent_underflow(T &non_negative_number,typename boost::enable_if<boost::is_arithmetic<T>,T>::type* = 0)
+ if (non_negative_number < T(0)) non_negative_number = T(0);
+ void prevent_underflow(T &non_arithmetic_quantity,typename boost::disable_if<boost::is_arithmetic<T>,T>::type* = 0)
+// tag:: lazy_rolling_variance
+// tag:: immediate_rolling_variance
+// tag:: rolling_variance
+ struct lazy_rolling_variance
+ : depends_on< rolling_count, rolling_mean, rolling_moment<2> >
+ typedef accumulators::impl::lazy_rolling_variance_impl< mpl::_1 > impl;
+ struct immediate_rolling_variance
+ : depends_on< rolling_window_plus1, rolling_count, immediate_rolling_mean>
+ typedef accumulators::impl::immediate_rolling_variance_impl< mpl::_1> impl;
+ // make immediate_rolling_variance the default implementation
+ struct rolling_variance : immediate_rolling_variance {};
+// extract::lazy_rolling_variance
+// extract::immediate_rolling_variance
+// extract::rolling_variance
+ extractor<tag::lazy_rolling_variance> const lazy_rolling_variance = {};
+ extractor<tag::immediate_rolling_variance> const immediate_rolling_variance = {};
+ extractor<tag::rolling_variance> const rolling_variance = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(lazy_rolling_variance)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(immediate_rolling_variance)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_variance)
+using extract::lazy_rolling_variance;
+using extract::immediate_rolling_variance;
+using extract::rolling_variance;
+// rolling_variance(lazy) -> lazy_rolling_variance
+struct as_feature<tag::rolling_variance(lazy)>
+ typedef tag::lazy_rolling_variance type;
+// rolling_variance(immediate) -> immediate_rolling_variance
+struct as_feature<tag::rolling_variance(immediate)>
+ typedef tag::immediate_rolling_variance type;
+// lazy_rolling_variance provides the same feature as rolling_variance
+struct feature_of<tag::lazy_rolling_variance>
+ : feature_of<tag::rolling_variance>
+// immediate_rolling_variance provides the same feature as rolling_variance
+struct feature_of<tag::immediate_rolling_variance>
@@ -0,0 +1,172 @@
+// rolling_window.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_WINDOW_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_WINDOW_HPP_EAN_26_12_2008
+#include <cstddef>
+#include <boost/circular_buffer.hpp>
+// tag::rolling_window::size named parameter
+BOOST_PARAMETER_NESTED_KEYWORD(tag, rolling_window_size, window_size)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_window_size)
+ // rolling_window_plus1_impl
+ // stores the latest N+1 samples, where N is specified at construction time
+ // with the rolling_window_size named parameter
+ struct rolling_window_plus1_impl
+ typedef typename circular_buffer<Sample>::const_iterator const_iterator;
+ typedef iterator_range<const_iterator> result_type;
+ rolling_window_plus1_impl(Args const & args)
+ : buffer_(args[rolling_window_size] + 1)
+ #if BOOST_VERSION < 103600
+ // Before Boost 1.36, copying a circular buffer didn't copy
+ // it's capacity, and we need that behavior.
+ rolling_window_plus1_impl(rolling_window_plus1_impl const &that)
+ : buffer_(that.buffer_)
+ this->buffer_.set_capacity(that.buffer_.capacity());
+ rolling_window_plus1_impl &operator =(rolling_window_plus1_impl const &that)
+ this->buffer_ = that.buffer_;
+ this->buffer_.push_back(args[sample]);
+ bool full() const
+ return this->buffer_.full();
+ // The result of a shifted rolling window is the range including
+ // everything except the most recently added element.
+ return result_type(this->buffer_.begin(), this->buffer_.end());
+ circular_buffer<Sample> buffer_;
+ bool is_rolling_window_plus1_full(Args const &args)
+ return find_accumulator<tag::rolling_window_plus1>(args[accumulator]).full();
+ // rolling_window_impl
+ // stores the latest N samples, where N is specified at construction type
+ struct rolling_window_impl
+ rolling_window_impl(dont_care)
+ return rolling_window_plus1(args).advance_begin(is_rolling_window_plus1_full(args));
+// tag::rolling_window_plus1
+// tag::rolling_window
+ struct rolling_window_plus1
+ , tag::rolling_window_size
+ typedef accumulators::impl::rolling_window_plus1_impl< mpl::_1 > impl;
+ /// tag::rolling_window::size named parameter
+ struct rolling_window
+ typedef accumulators::impl::rolling_window_impl< mpl::_1 > impl;
+// extract::rolling_window_plus1
+// extract::rolling_window
+ extractor<tag::rolling_window_plus1> const rolling_window_plus1 = {};
+ extractor<tag::rolling_window> const rolling_window = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_window_plus1)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_window)
+using extract::rolling_window_plus1;
+using extract::rolling_window;
@@ -0,0 +1,114 @@
+// skewness.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_SKEWNESS_HPP_EAN_28_10_2005
+ // 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 samples 3. The skewness can also be expressed by the simple moments:
+ \hat{g}_1 =
+ {\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}}
+ struct skewness_impl
+ skewness_impl(dont_care)
+ accumulators::moment<3>(args)
+ - 3. * accumulators::moment<2>(args) * mean(args)
+ + 2. * mean(args) * mean(args) * mean(args)
+ * std::sqrt( accumulators::moment<2>(args) - mean(args) * mean(args) )
+// tag::skewness
+ struct skewness
+ : depends_on<mean, moment<2>, moment<3> >
+ typedef accumulators::impl::skewness_impl<mpl::_1> impl;
+// extract::skewness
+ extractor<tag::skewness> const skewness = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(skewness)
+using extract::skewness;
+// So that skewness can be automatically substituted with
+// weighted_skewness when the weight parameter is non-void
+struct as_weighted_feature<tag::skewness>
+ typedef tag::weighted_skewness type;
+struct feature_of<tag::weighted_skewness>
+ : feature_of<tag::skewness>
+/// \file stats.hpp
+/// Contains the stats<> template.
+#ifndef BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_STATS_HPP_EAN_28_10_2005
+/// 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)>
@@ -0,0 +1,141 @@
+// sum.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_SUM_HPP_EAN_28_10_2005
+ // sum_impl
+ struct sum_impl
+ sum_impl(Args const &args)
+ : sum(args[parameter::keyword<Tag>::get() | Sample()])
+ // what about overflow?
+ this->sum += args[parameter::keyword<Tag>::get()];
+ return this->sum;
+// tag::sum
+// tag::sum_of_weights
+// tag::sum_of_variates
+ struct sum
+ typedef accumulators::impl::sum_impl<mpl::_1, tag::sample> impl;
+ struct sum_of_weights
+ typedef accumulators::impl::sum_impl<mpl::_2, tag::weight> impl;
+ struct sum_of_variates
+ typedef mpl::always<accumulators::impl::sum_impl<VariateType, VariateTag> > impl;
+ struct abstract_sum_of_variates
+// extract::sum
+// extract::sum_of_weights
+// extract::sum_of_variates
+ extractor<tag::sum> const sum = {};
+ extractor<tag::sum_of_weights> const sum_of_weights = {};
+ extractor<tag::abstract_sum_of_variates> const sum_of_variates = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_weights)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_variates)
+using extract::sum;
+using extract::sum_of_weights;
+using extract::sum_of_variates;
+struct as_weighted_feature<tag::sum>
+ typedef tag::weighted_sum type;
+struct feature_of<tag::weighted_sum>
+ : feature_of<tag::sum>
+struct feature_of<tag::sum_of_variates<VariateType, VariateTag> >
+ : feature_of<tag::abstract_sum_of_variates>
@@ -0,0 +1,188 @@
+// sum_kahan.hpp
+// Copyright 2010 Gaetano Mendola, 2011 Simon West. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_SUM_KAHAN_HPP_EAN_26_07_2010
+#define BOOST_ACCUMULATORS_STATISTICS_SUM_KAHAN_HPP_EAN_26_07_2010
+#include <boost/numeric/conversion/cast.hpp>
+#if _MSC_VER > 1400
+# pragma float_control(push)
+# pragma float_control(precise, on)
+template<typename Sample, typename Tag>
+struct sum_kahan_impl
+ ////////////////////////////////////////////////////////////////////////////
+ // sum_kahan_impl
+ @brief Kahan summation algorithm
+ The Kahan summation algorithm reduces the numerical error obtained with standard
+ sequential sum.
+ sum_kahan_impl(Args const & args)
+ : sum(args[parameter::keyword<Tag>::get() | Sample()]),
+ compensation(boost::numeric_cast<Sample>(0.0))
+ void
+#if BOOST_ACCUMULATORS_GCC_VERSION > 40305
+ __attribute__((__optimize__("no-associative-math")))
+ operator ()(Args const & args)
+ const Sample myTmp1 = args[parameter::keyword<Tag>::get()] - this->compensation;
+ const Sample myTmp2 = this->sum + myTmp1;
+ this->compensation = (myTmp2 - this->sum) - myTmp1;
+ this->sum = myTmp2;
+ Sample compensation;
+# pragma float_control(pop)
+// tag::sum_kahan
+// tag::sum_of_weights_kahan
+// tag::sum_of_variates_kahan
+ struct sum_kahan
+ typedef impl::sum_kahan_impl< mpl::_1, tag::sample > impl;
+ struct sum_of_weights_kahan
+ typedef accumulators::impl::sum_kahan_impl<mpl::_2, tag::weight> impl;
+ struct sum_of_variates_kahan
+ typedef mpl::always<accumulators::impl::sum_kahan_impl<VariateType, VariateTag> > impl;
+// extract::sum_kahan
+// extract::sum_of_weights_kahan
+// extract::sum_of_variates_kahan
+ extractor<tag::sum_kahan> const sum_kahan = {};
+ extractor<tag::sum_of_weights_kahan> const sum_of_weights_kahan = {};
+ extractor<tag::abstract_sum_of_variates> const sum_of_variates_kahan = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_kahan)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_weights_kahan)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(sum_of_variates_kahan)
+} // namespace extract
+using extract::sum_kahan;
+using extract::sum_of_weights_kahan;
+using extract::sum_of_variates_kahan;
+// sum(kahan) -> sum_kahan
+struct as_feature<tag::sum(kahan)>
+ typedef tag::sum_kahan type;
+// sum_of_weights(kahan) -> sum_of_weights_kahan
+struct as_feature<tag::sum_of_weights(kahan)>
+ typedef tag::sum_of_weights_kahan type;
+// So that sum_kahan can be automatically substituted with
+// weighted_sum_kahan when the weight parameter is non-void.
+struct as_weighted_feature<tag::sum_kahan>
+ typedef tag::weighted_sum_kahan type;
+struct feature_of<tag::weighted_sum_kahan>
+// sum_kahan provides the same feature as sum
+struct feature_of<tag::sum_kahan>
+// sum_of_weights_kahan provides the same feature as sum_of_weights
+struct feature_of<tag::sum_of_weights_kahan>
+ : feature_of<tag::sum_of_weights>
+struct feature_of<tag::sum_of_variates_kahan<VariateType, VariateTag> >
@@ -0,0 +1,341 @@
+// tail.hpp
+// Copyright 2005 Eric Niebler, Michael Gauckler. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_TAIL_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_HPP_EAN_28_10_2005
+#include <boost/iterator/reverse_iterator.hpp>
+// 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)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(right_tail_cache_size)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(left_tail_cache_size)
+ // tail_range
+ template<typename ElementIterator, typename IndexIterator>
+ struct tail_range
+ typedef boost::iterator_range<
+ boost::reverse_iterator<boost::permutation_iterator<ElementIterator, IndexIterator> >
+ > type;
+ // make_tail_range
+ 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
+ struct stat_assign_visitor
+ stat_assign_visitor(Args const &a, std::size_t i)
+ , index(i)
+ template<typename Stat>
+ void operator ()(Stat &stat) const
+ stat.assign(this->args, this->index);
+ stat_assign_visitor &operator =(stat_assign_visitor const &);
+ std::size_t index;
+ // stat_assign
+ 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
+ template<typename Stat, typename LeftRight>
+ struct is_tail_variate_feature
+ template<typename VariateType, typename VariateTag, typename LeftRight>
+ struct is_tail_variate_feature<tag::tail_variate<VariateType, VariateTag, LeftRight>, LeftRight>
+ : mpl::true_
+ struct is_tail_variate_feature<tag::tail_weights<LeftRight>, LeftRight>
+ // tail_impl
+ struct tail_impl
+ // LeftRight must be either right or left
+ mpl::or_<is_same<LeftRight, right>, is_same<LeftRight, left> >
+ is_same<LeftRight, right>
+ , numeric::functional::greater<Sample const, Sample const>
+ , numeric::functional::less<Sample const, Sample const>
+ predicate_type;
+ typedef typename detail::tail_range<
+ typename std::vector<Sample>::const_iterator
+ , std::vector<std::size_t>::iterator
+ >::type result_type;
+ 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 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.
+ if(this->indices.size() < this->samples.size())
+ 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));
+ 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()
+ struct is_tail_variate
+ : detail::is_tail_variate_feature<
+ typename detail::feature_tag<T>::type
+ , LeftRight
+ void assign(Args const &args, std::size_t index)
+ BOOST_ASSERT(index < this->samples.size());
+ 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
+ typedef std::size_t first_argument_type;
+ typedef std::size_t second_argument_type;
+ indirect_cmp(std::vector<Sample> const &s)
+ : samples(s)
+ bool operator ()(std::size_t left, std::size_t right) const
+ return predicate_type()(this->samples[left], this->samples[right]);
+ 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;
+// 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.
+struct tail_cache_size_named_arg
+struct tail_cache_size_named_arg<left>
+ : tag::left_tail_cache_size
+struct tail_cache_size_named_arg<right>
+ : tag::right_tail_cache_size
+// tag::tail<>
+ struct tail
+ , tail_cache_size_named_arg<LeftRight>
+ typedef accumulators::impl::tail_impl<mpl::_1, LeftRight> impl;
+ /// tag::tail<LeftRight>::cache_size named parameter
+ static boost::parameter::keyword<tail_cache_size_named_arg<LeftRight> > const cache_size;
+ struct abstract_tail
+// extract::tail
+ extractor<tag::abstract_tail> const tail = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(tail)
+using extract::tail;
+struct feature_of<tag::tail<LeftRight> >
+ : feature_of<tag::abstract_tail>
@@ -0,0 +1,246 @@
+// tail_mean.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_TAIL_MEAN_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_MEAN_HPP_DE_01_01_2006
+#include <sstream>
+#include <stdexcept>
+ // 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.
+ \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)
+ \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)
+ struct coherent_tail_mean_impl
+ coherent_tail_mean_impl(dont_care) {}
+ 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::fdiv(quantile(args), n)
+ * (
+ ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability]
+ - numeric::fdiv(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:
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X) = \frac{1}{\lceil n(1-\alpha)\rceil} \sum_{i=\lceil \alpha n \rceil}^n X_{i:n}
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X) = \frac{1}{\lceil n\alpha\rceil} \sum_{i=1}^{\lceil \alpha n \rceil} X_{i:n}
+ 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.
+ struct non_coherent_tail_mean_impl
+ non_coherent_tail_mean_impl(dont_care) {}
+ if (n <= static_cast<std::size_t>(tail(args).size()))
+ std::accumulate(
+ tail(args).begin()
+ , tail(args).begin() + n
+ , Sample(0)
+ , n
+// tag::coherent_tail_mean<>
+// tag::non_coherent_tail_mean<>
+ struct coherent_tail_mean
+ : depends_on<count, quantile, non_coherent_tail_mean<LeftRight> >
+ typedef accumulators::impl::coherent_tail_mean_impl<mpl::_1, LeftRight> impl;
+ struct non_coherent_tail_mean
+ typedef accumulators::impl::non_coherent_tail_mean_impl<mpl::_1, LeftRight> impl;
+ struct abstract_non_coherent_tail_mean
+// extract::non_coherent_tail_mean;
+// extract::coherent_tail_mean;
+ extractor<tag::abstract_non_coherent_tail_mean> const non_coherent_tail_mean = {};
+ extractor<tag::tail_mean> const coherent_tail_mean = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(non_coherent_tail_mean)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(coherent_tail_mean)
+using extract::non_coherent_tail_mean;
+using extract::coherent_tail_mean;
+// coherent_tail_mean<LeftRight> provides the same feature as tail_mean
+struct feature_of<tag::coherent_tail_mean<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.
+struct as_weighted_feature<tag::non_coherent_tail_mean<LeftRight> >
+ typedef tag::non_coherent_weighted_tail_mean<LeftRight> type;
+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!
@@ -0,0 +1,158 @@
+// tail_quantile.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_TAIL_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_QUANTILE_HPP_DE_01_01_2006
+#include <boost/config/no_tr1/cmath.hpp> // For ceil
+ // 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
+ caching of at least the \f$\lceil n\alpha\rceil\f$ smallest or the \f$\lceil n(1-\alpha)\rceil\f$ largest samples,
+ \f$n\f$ being the total number of samples. The largest of the \f$\lceil n\alpha\rceil\f$ smallest samples or the
+ smallest of the \f$\lceil n(1-\alpha)\rceil\f$ largest samples provides an estimate for the quantile:
+ \hat{q}_{n,\alpha} = X_{\lceil \alpha n \rceil:n}
+ struct tail_quantile_impl
+ tail_quantile_impl(dont_care) {}
+ 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);
+// tag::tail_quantile<>
+ struct tail_quantile
+ typedef accumulators::impl::tail_quantile_impl<mpl::_1, LeftRight> impl;
+// extract::tail_quantile
+ extractor<tag::quantile> const tail_quantile = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(tail_quantile)
+using extract::tail_quantile;
+// tail_quantile<LeftRight> provide the same feature as quantile
+struct feature_of<tag::tail_quantile<LeftRight> >
+// So that tail_quantile can be automatically substituted with
+// weighted_tail_quantile when the weight parameter is non-void.
+struct as_weighted_feature<tag::tail_quantile<LeftRight> >
+ typedef tag::weighted_tail_quantile<LeftRight> type;
+struct feature_of<tag::weighted_tail_quantile<LeftRight> >
+ : feature_of<tag::tail_quantile<LeftRight> >
+// tail_variate.hpp
+#ifndef BOOST_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
+#define BOOST_STAT_STATISTICS_TAIL_VARIATE_HPP_EAN_28_10_2005
+ // tail_variate_impl
+ struct tail_variate_impl
+ typename detail::tail_range<
+ typename std::vector<VariateType>::const_iterator
+ tail_variate_impl(Args const &args)
+ : variates(args[tag::tail<LeftRight>::cache_size], args[parameter::keyword<VariateTag>::get() | VariateType()])
+ this->variates[index] = args[parameter::keyword<VariateTag>::get()];
+ // 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));
+ template<typename TailRng>
+ result_type do_result(TailRng const &rng) const
+ 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;
+// tag::tail_variate<>
+ struct tail_variate
+ : depends_on<tail<LeftRight> >
+ typedef mpl::always<accumulators::impl::tail_variate_impl<VariateType, VariateTag, LeftRight> > impl;
+ struct abstract_tail_variate
+ struct tail_weights
+ typedef accumulators::impl::tail_variate_impl<mpl::_2, tag::weight, LeftRight> impl;
+ struct abstract_tail_weights
+// extract::tail_variate
+// extract::tail_weights
+ extractor<tag::abstract_tail_variate> const tail_variate = {};
+ extractor<tag::abstract_tail_weights> const tail_weights = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(tail_variate)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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>
+struct feature_of<tag::tail_weights<LeftRight> >
+ typedef tag::abstract_tail_weights type;
@@ -0,0 +1,262 @@
+// tail_variate_means.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_TAIL_VARIATE_MEANS_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TAIL_VARIATE_MEANS_HPP_DE_01_01_2006
+ @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$.
+ \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}
+ \widehat{ATM}_{n,\alpha}^{\mathrm{left}}(X, j) =
+ \frac{1}{\lceil n\alpha \rceil}
+ \sum_{i=1}^{\lceil n\alpha \rceil} \xi_{j,i}
+ \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)}
+ \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)}
+ // tail_variate_means_impl
+ // by default: absolute tail_variate_means
+ template<typename Sample, typename Impl, typename LeftRight, typename VariateTag>
+ struct tail_variate_means_impl
+ typedef iterator_range<typename array_type::iterator> result_type;
+ tail_variate_means_impl(dont_care) {}
+ std::size_t num_variates = tail_variate(args).begin()->size();
+ this->tail_means_.clear();
+ this->tail_means_.resize(num_variates, Sample(0));
+ 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()
+#ifdef BOOST_NO_CXX98_BINDERS
+ , std::bind(std::divides<float_type>(), std::placeholders::_1, factor)
+ , std::bind2nd(std::divides<float_type>(), factor)
+ std::fill(
+ return make_iterator_range(this->tail_means_);
+ mutable array_type tail_means_;
+// tag::absolute_tail_variate_means
+// tag::relative_tail_variate_means
+ 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;
+ struct relative_tail_variate_means
+ typedef accumulators::impl::tail_variate_means_impl<mpl::_1, relative, LeftRight, VariateTag> impl;
+ struct abstract_absolute_tail_variate_means
+ struct abstract_relative_tail_variate_means
+// extract::tail_variate_means
+// extract::relative_tail_variate_means
+ extractor<tag::abstract_absolute_tail_variate_means> const tail_variate_means = {};
+ extractor<tag::abstract_relative_tail_variate_means> const relative_tail_variate_means = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(tail_variate_means)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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>
+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
+struct feature_of<tag::absolute_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ : feature_of<tag::abstract_absolute_tail_variate_means>
+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.
+struct as_weighted_feature<tag::absolute_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ typedef tag::absolute_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+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.
+struct as_weighted_feature<tag::relative_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ typedef tag::relative_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> type;
+struct feature_of<tag::relative_weighted_tail_variate_means<LeftRight, VariateType, VariateTag> >
+ : feature_of<tag::relative_tail_variate_means<LeftRight, VariateType, VariateTag> >
@@ -0,0 +1,70 @@
+// times2_iterator.hpp
+// Copyright 2006 Eric Niebler. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_TIMES2_ITERATOR_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_TIMES2_ITERATOR_HPP_DE_01_01_2006
+#include <boost/detail/workaround.hpp>
+ typedef transform_iterator<
+ decltype(std::bind(std::multiplies<std::size_t>(), 2, std::placeholders::_1))
+ 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::bind(std::multiplies<std::size_t>(), 2, std::placeholders::_1)
+ , std::bind1st(std::multiplies<std::size_t>(), 2)
+ // lvalue_index_iterator
+ template<typename Base>
+ struct lvalue_index_iterator
+ : Base
+ lvalue_index_iterator()
+ : Base()
+ lvalue_index_iterator(Base base)
+ : Base(base)
+ typename Base::reference operator [](typename Base::difference_type n) const
+ return *(*this + n);
@@ -0,0 +1,236 @@
+// variance.hpp
+// Copyright 2005 Daniel Egloff, Eric Niebler. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_VARIANCE_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_VARIANCE_HPP_EAN_28_10_2005
+ //! Lazy calculation of variance.
+ Default sample variance implementation based on the second moment \f$ M_n^{(2)} \f$ moment<2>, mean and count.
+ \sigma_n^2 = M_n^{(2)} - \mu_n^2.
+ where
+ \mu_n = \frac{1}{n} \sum_{i = 1}^n x_i.
+ is the estimate of the sample mean and \f$n\f$ is the number of samples.
+ template<typename Sample, typename MeanFeature>
+ struct lazy_variance_impl
+ lazy_variance_impl(dont_care) {}
+ extractor<MeanFeature> mean;
+ result_type tmp = mean(args);
+ return accumulators::moment<2>(args) - tmp * tmp;
+ //! Iterative calculation of variance.
+ Iterative calculation of sample variance \f$\sigma_n^2\f$ according to the formula
+ \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.
+ A simplification can be obtained by the approximate recursion
+ \sigma_n^2 \approx \frac{n-1}{n} \sigma_{n-1}^2 + \frac{1}{n}(x_n - \mu_n)^2.
+ because the difference
+ \left(\frac{1}{n-1} - \frac{1}{n}\right)(x_n - \mu_n)^2 = \frac{1}{n(n-1)}(x_n - \mu_n)^2.
+ 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 variance_impl
+ variance_impl(Args const &args)
+ : variance(numeric::fdiv(args[sample | Sample()], numeric::one<std::size_t>::value))
+ if(cnt > 1)
+ result_type tmp = args[parameter::keyword<Tag>::get()] - mean(args);
+ this->variance =
+ numeric::fdiv(this->variance * (cnt - 1), cnt)
+ + numeric::fdiv(tmp * tmp, cnt - 1);
+ return this->variance;
+ result_type variance;
+// tag::variance
+// tag::immediate_variance
+ struct lazy_variance
+ : depends_on<moment<2>, mean>
+ typedef accumulators::impl::lazy_variance_impl<mpl::_1, mean> impl;
+ struct variance
+ : depends_on<count, immediate_mean>
+ typedef accumulators::impl::variance_impl<mpl::_1, mean, sample> impl;
+// extract::lazy_variance
+// extract::variance
+ extractor<tag::lazy_variance> const lazy_variance = {};
+ extractor<tag::variance> const variance = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(lazy_variance)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(variance)
+using extract::lazy_variance;
+using extract::variance;
+// variance(lazy) -> lazy_variance
+struct as_feature<tag::variance(lazy)>
+ typedef tag::lazy_variance type;
+// variance(immediate) -> variance
+struct as_feature<tag::variance(immediate)>
+ typedef tag::variance type;
+// immediate_variance provides the same feature as variance
+struct feature_of<tag::lazy_variance>
+ : feature_of<tag::variance>
+// So that variance can be automatically substituted with
+// weighted_variance when the weight parameter is non-void.
+struct as_weighted_feature<tag::variance>
+ typedef tag::weighted_variance type;
+// weighted_variance provides the same feature as variance
+struct feature_of<tag::weighted_variance>
+// So that immediate_variance can be automatically substituted with
+// immediate_weighted_variance when the weight parameter is non-void.
+struct as_weighted_feature<tag::lazy_variance>
+ typedef tag::lazy_weighted_variance type;
+// immediate_weighted_variance provides the same feature as immediate_variance
+struct feature_of<tag::lazy_weighted_variance>
+ : feature_of<tag::lazy_variance>
+//// droppable_accumulator<variance_impl>
+//// need to specialize droppable lazy variance to cache the result at the
+//template<typename Sample, typename MeanFeature>
+//struct droppable_accumulator<impl::variance_impl<Sample, MeanFeature> >
+// with_cached_result<impl::variance_impl<Sample, MeanFeature> >
@@ -0,0 +1,25 @@
+#ifndef BOOST_ACCUMULATORS_STATISTICS_VARIATES_COVARIATE_HPP_EAN_03_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_VARIATES_COVARIATE_HPP_EAN_03_11_2005
+BOOST_PARAMETER_KEYWORD(tag, covariate1)
+BOOST_PARAMETER_KEYWORD(tag, covariate2)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(covariate1)
+BOOST_ACCUMULATORS_IGNORE_GLOBAL(covariate2)
@@ -0,0 +1,133 @@
+// weighted_covariance.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_COVARIANCE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_COVARIANCE_HPP_DE_01_01_2006
+#include <boost/accumulators/statistics/covariance.hpp> // for numeric::outer_product() and type traits
+ // 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:
+ \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$\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
+ typedef typename numeric::functional::multiplies<Weight, typename numeric::functional::fdiv<Sample, std::size_t>::result_type>::result_type weighted_sample_type;
+ typedef typename numeric::functional::multiplies<Weight, typename numeric::functional::fdiv<VariateType, std::size_t>::result_type>::result_type weighted_variate_type;
+ typedef typename numeric::functional::outer_product<weighted_sample_type, weighted_variate_type>::result_type result_type;
+ weighted_covariance_impl(Args const &args)
+ * numeric::one<Weight>::value
+ 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)
+ some_weighted_mean_of_variates(args) - args[parameter::keyword<VariateTag>::get()]
+ , weighted_mean(args) - args[sample]
+ ) * args[weight] / (sum_of_weights(args) - args[weight]);
+// tag::weighted_covariance
+ 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
+ extractor<tag::abstract_covariance> const weighted_covariance = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_covariance)
+using extract::weighted_covariance;
+// weighted_density.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_DENSITY_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_DENSITY_HPP_DE_01_01_2006
+#include <boost/accumulators/statistics/density.hpp> // for named parameters density_cache_size and density_num_bins
+ // weighted_density_impl
+ // density histogram for weighted samples
+ @brief Histogram density estimator for weighted samples
+ 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).
+ struct weighted_density_impl
+ typedef typename numeric::functional::fdiv<Weight, std::size_t>::result_type float_type;
+ weighted_density_impl(Args const &args)
+ this->cache[cnt - 1] = std::make_pair(args[sample], args[weight]);
+ // the minimum and maximum of the cached samples as well as an under- and an overflow bin.
+ float_type minimum = numeric::fdiv((min)(args),(std::size_t)1);
+ float_type maximum = numeric::fdiv((max)(args),(std::size_t)1);
+ float_type bin_size = numeric::fdiv(maximum - minimum, this->num_bins);
+ 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;
+ , iter->first
+ this->samples_in_bin[d - 1] += iter->second;
+ this->samples_in_bin[0] += args[weight];
+ this->samples_in_bin[this->num_bins + 1] += args[weight];
+ this->samples_in_bin[d - 1] += args[weight];
+ this->histogram[i] = std::make_pair(this->bin_positions[i], numeric::fdiv(this->samples_in_bin[i], sum_of_weights(args)));
+ histogram_type cache; // cache to store the first cache_size samples with their weights as std::pair
+// tag::weighted_density
+ struct weighted_density
+ : depends_on<count, sum_of_weights, min, max>
+ typedef accumulators::impl::weighted_density_impl<mpl::_1, mpl::_2> impl;
+// extract::weighted_density
+ extractor<tag::density> const weighted_density = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_density)
+using extract::weighted_density;
@@ -0,0 +1,290 @@
+// weighted_extended_p_square.hpp
+#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
+ // 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.
+ struct weighted_extended_p_square_impl
+ typedef typename numeric::functional::multiplies<Sample, Weight>::result_type weighted_sample;
+ typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type float_type;
+ weighted_extended_p_square_impl(Args const &args)
+ std::size_t num_markers = 2 * num_quantiles + 3;
+ this->actual_positions[cnt - 1] = args[weight];
+ // complete the initialization of heights (and actual_positions) by sorting
+ // 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];
+ this->actual_positions[0] = args[weight];
+ // update actual position of all markers above sample_cell
+ 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.)
+ 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])
+ // 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)
+ float_type h = this->heights[i] + sign_d / (dp - dm) * ((sign_d - dm)*hp + (dp - sign_d) * hm);
+// tag::weighted_extended_p_square
+ struct weighted_extended_p_square
+ typedef accumulators::impl::weighted_extended_p_square_impl<mpl::_1, mpl::_2> impl;
+// extract::weighted_extended_p_square
+ extractor<tag::weighted_extended_p_square> const weighted_extended_p_square = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_extended_p_square)
+using extract::weighted_extended_p_square;
@@ -0,0 +1,105 @@
+// weighted_kurtosis.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_KURTOSIS_HPP_EAN_28_10_2005
+ // weighted_kurtosis_impl
+ @brief Kurtosis estimation for weighted 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.
+ struct weighted_kurtosis_impl
+ typedef typename numeric::functional::fdiv<weighted_sample, weighted_sample>::result_type result_type;
+ weighted_kurtosis_impl(dont_care)
+ accumulators::weighted_moment<4>(args)
+ - 4. * accumulators::weighted_moment<3>(args) * weighted_mean(args)
+ + 6. * accumulators::weighted_moment<2>(args) * weighted_mean(args) * weighted_mean(args)
+ - 3. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args) * weighted_mean(args)
+ , ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
+ * ( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
+// tag::weighted_kurtosis
+ struct weighted_kurtosis
+ : depends_on<weighted_mean, weighted_moment<2>, weighted_moment<3>, weighted_moment<4> >
+ typedef accumulators::impl::weighted_kurtosis_impl<mpl::_1, mpl::_2> impl;
+// extract::weighted_kurtosis
+ extractor<tag::weighted_kurtosis> const weighted_kurtosis = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_kurtosis)
+using extract::weighted_kurtosis;
@@ -0,0 +1,189 @@
+// weighted_mean.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MEAN_HPP_EAN_03_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MEAN_HPP_EAN_03_11_2005
+ // weighted_mean_impl
+ template<typename Sample, typename Weight, typename Tag>
+ struct weighted_mean_impl
+ typedef typename numeric::functional::fdiv<weighted_sample, Weight>::result_type result_type;
+ weighted_mean_impl(dont_care) {}
+ is_same<Tag, tag::sample>
+ , tag::weighted_sum
+ , tag::weighted_sum_of_variates<Sample, Tag>
+ weighted_sum_tag;
+ extractor<weighted_sum_tag> const some_weighted_sum = {};
+ return numeric::fdiv(some_weighted_sum(args), sum_of_weights(args));
+ // immediate_weighted_mean_impl
+ // immediate
+ struct immediate_weighted_mean_impl
+ immediate_weighted_mean_impl(Args const &args)
+ : mean(
+ numeric::fdiv(
+ args[parameter::keyword<Tag>::get() | Sample()]
+ , numeric::one<Weight>::value
+ // 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::fdiv(this->mean * (w_sum - w) + s, w_sum);
+// tag::weighted_mean
+// tag::immediate_weighted_mean
+ struct weighted_mean
+ : depends_on<sum_of_weights, weighted_sum>
+ typedef accumulators::impl::weighted_mean_impl<mpl::_1, mpl::_2, tag::sample> impl;
+ struct immediate_weighted_mean
+ : depends_on<sum_of_weights>
+ typedef accumulators::impl::immediate_weighted_mean_impl<mpl::_1, mpl::_2, tag::sample> impl;
+ struct weighted_mean_of_variates
+ : depends_on<sum_of_weights, weighted_sum_of_variates<VariateType, VariateTag> >
+ typedef accumulators::impl::weighted_mean_impl<VariateType, mpl::_2, VariateTag> impl;
+ struct immediate_weighted_mean_of_variates
+ typedef accumulators::impl::immediate_weighted_mean_impl<VariateType, mpl::_2, VariateTag> impl;
+// extract::weighted_mean
+// extract::weighted_mean_of_variates
+ extractor<tag::mean> const weighted_mean = {};
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, weighted_mean_of_variates, (typename)(typename))
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_mean)
+using extract::weighted_mean;
+using extract::weighted_mean_of_variates;
+// weighted_mean(lazy) -> weighted_mean
+struct as_feature<tag::weighted_mean(lazy)>
+// weighted_mean(immediate) -> immediate_weighted_mean
+struct as_feature<tag::weighted_mean(immediate)>
+// weighted_mean_of_variates<VariateType, VariateTag>(lazy) -> weighted_mean_of_variates<VariateType, VariateTag>
+struct as_feature<tag::weighted_mean_of_variates<VariateType, VariateTag>(lazy)>
+// weighted_mean_of_variates<VariateType, VariateTag>(immediate) -> immediate_weighted_mean_of_variates<VariateType, VariateTag>
+struct as_feature<tag::weighted_mean_of_variates<VariateType, VariateTag>(immediate)>
@@ -0,0 +1,237 @@
+// weighted_median.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MEDIAN_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MEDIAN_HPP_EAN_28_10_2005
+ // 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.
+ struct weighted_median_impl
+ weighted_median_impl(dont_care) {}
+ return weighted_p_square_quantile_for_median(args);
+ // with_density_weighted_median_impl
+ @brief Median estimation for weighted samples based on the density estimator
+ struct with_density_weighted_median_impl
+ with_density_weighted_median_impl(Args const &args)
+ range_type histogram = weighted_density(args);
+ // with_p_square_cumulative_distribution_weighted_median_impl
+ @brief Median estimation for weighted samples based on the \f$P^2\f$ cumulative distribution estimator
+ struct with_p_square_cumulative_distribution_weighted_median_impl
+ with_p_square_cumulative_distribution_weighted_median_impl(dont_care)
+ range_type histogram = weighted_p_square_cumulative_distribution(args);
+// tag::weighted_median
+// tag::with_density_weighted_median
+// tag::with_p_square_cumulative_distribution_weighted_median
+ struct weighted_median
+ : depends_on<weighted_p_square_quantile_for_median>
+ typedef accumulators::impl::weighted_median_impl<mpl::_1> impl;
+ struct with_density_weighted_median
+ : depends_on<count, weighted_density>
+ 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>
+ typedef accumulators::impl::with_p_square_cumulative_distribution_weighted_median_impl<mpl::_1, mpl::_2> impl;
+// extract::weighted_median
+ extractor<tag::median> const weighted_median = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_median)
+using extract::weighted_median;
+// weighted_median(with_p_square_quantile) -> weighted_median
+struct as_feature<tag::weighted_median(with_p_square_quantile)>
+// weighted_median(with_density) -> with_density_weighted_median
+struct as_feature<tag::weighted_median(with_density)>
+// weighted_median(with_p_square_cumulative_distribution) -> with_p_square_cumulative_distribution_weighted_median
+struct as_feature<tag::weighted_median(with_p_square_cumulative_distribution)>
@@ -0,0 +1,96 @@
+// weighted_moment.hpp
+// Copyright 2006, Eric Niebler, Olivier Gygi. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MOMENT_HPP_EAN_15_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_MOMENT_HPP_EAN_15_11_2005
+#include <boost/accumulators/statistics/moment.hpp> // for pow()
+ // weighted_moment_impl
+ template<typename N, typename Sample, typename Weight>
+ struct weighted_moment_impl
+ weighted_moment_impl(Args const &args)
+ : sum(args[sample | Sample()] * numeric::one<Weight>::value)
+ this->sum += args[weight] * numeric::pow(args[sample], N());
+ return numeric::fdiv(this->sum, sum_of_weights(args));
+ weighted_sample sum;
+// tag::weighted_moment
+ struct weighted_moment
+ typedef accumulators::impl::weighted_moment_impl<mpl::int_<N>, mpl::_1, mpl::_2> impl;
+// extract::weighted_moment
+ BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, weighted_moment, (int))
+using extract::weighted_moment;
+// weighted_p_square_cumul_dist.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_P_SQUARE_CUMUL_DIST_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_P_SQUARE_CUMUL_DIST_HPP_DE_01_01_2006
+#include <boost/accumulators/statistics/p_square_cumul_dist.hpp> // for named parameter p_square_cumulative_distribution_num_cells
+ // 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
+ 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.
+ @param p_square_cumulative_distribution_num_cells
+ struct weighted_p_square_cumulative_distribution_impl
+ weighted_p_square_cumulative_distribution_impl(Args const &args)
+ //std::sort(this->heights.begin(), this->heights.end());
+ this->actual_positions[i] += this->actual_positions[i - 1];
+ // determine desired marker positions
+ this->desired_positions[i] = this->actual_positions[0]
+ + numeric::fdiv((i-1) * (sum_of_weights(args) - this->actual_positions[0]), b);
+ // actual_positions[i] / sum_of_weights (y-axis of histogram)
+ this->histogram[i] = std::make_pair(this->heights[i], numeric::fdiv(this->actual_positions[i], sum_of_weights(args)));
+// tag::weighted_p_square_cumulative_distribution
+ struct weighted_p_square_cumulative_distribution
+ typedef accumulators::impl::weighted_p_square_cumulative_distribution_impl<mpl::_1, mpl::_2> impl;
+// extract::weighted_p_square_cumulative_distribution
+ extractor<tag::weighted_p_square_cumulative_distribution> const weighted_p_square_cumulative_distribution = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_p_square_cumulative_distribution)
+using extract::weighted_p_square_cumulative_distribution;
+// weighted_p_square_cumulative_distribution.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_03_19_2012
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_P_SQUARE_CUMULATIVE_DISTRIBUTION_HPP_03_19_2012
+# pragma message ("Warning: This header is deprecated. Please use: boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp")
+# warning "This header is deprecated. Please use: boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp"
@@ -0,0 +1,255 @@
+// weighted_p_square_quantile.hpp
+#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
+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.
+ \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
+ template<typename Sample, typename Weight, typename Impl>
+ struct weighted_p_square_quantile_impl
+ weighted_p_square_quantile_impl(Args const &args)
+ if (cnt <= 5)
+ // In this initialization phase, actual_positions stores the weights of the
+ // initial samples that are needed at the end of the initialization phase to
+ // compute the correct initial positions of the markers.
+ // complete the initialization of heights and actual_positions by sorting
+ if (cnt == 5)
+ for (std::size_t i = 1; i < 5; ++i)
+ for (std::size_t i = sample_cell; i < 5; ++i)
+ // update desired positions for all markers
+ 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)
+// tag::weighted_p_square_quantile
+ struct weighted_p_square_quantile
+ typedef accumulators::impl::weighted_p_square_quantile_impl<mpl::_1, mpl::_2, regular> impl;
+ struct weighted_p_square_quantile_for_median
+ 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
+ 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 = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_p_square_quantile)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_p_square_quantile_for_median)
+using extract::weighted_p_square_quantile;
+using extract::weighted_p_square_quantile_for_median;
@@ -0,0 +1,289 @@
+// weighted_peaks_over_threshold.hpp
+#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 <boost/accumulators/statistics/peaks_over_threshold.hpp> // for named parameters pot_threshold_value and pot_threshold_probability
+ // 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
+ template<typename Sample, typename Weight, typename LeftRight>
+ struct weighted_peaks_over_threshold_impl
+ typedef typename numeric::functional::multiplies<Weight, Sample>::result_type weighted_sample;
+ weighted_peaks_over_threshold_impl(Args const &args)
+ , mu_(sign_ * numeric::fdiv(args[sample | Sample()], (std::size_t)1))
+ , w_sum_(numeric::fdiv(args[weight | Weight()], (std::size_t)1))
+ , threshold_(sign_ * args[pot_threshold_value])
+ 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];
+ this->mu_ = this->sign_ * numeric::fdiv(this->mu_, this->w_sum_);
+ this->sigma2_ = numeric::fdiv(this->sigma2_, this->w_sum_);
+ float_type threshold_probability = numeric::fdiv(sum_of_weights(args) - this->w_sum_, sum_of_weights(args));
+ 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
+ // weighted_peaks_over_threshold_prob_impl
+ @sa weighted_peaks_over_threshold_impl
+ struct weighted_peaks_over_threshold_prob_impl
+ weighted_peaks_over_threshold_prob_impl(Args const &args)
+ 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++;
+ float_type u = *(tail(args).begin() + n - 1) * this->sign_;
+ this->mu_ = this->sign_ * numeric::fdiv(this->mu_, sum);
+ this->sigma2_ = numeric::fdiv(this->sigma2_, sum);
+// tag::weighted_peaks_over_threshold
+ struct weighted_peaks_over_threshold
+ typedef accumulators::impl::weighted_peaks_over_threshold_impl<mpl::_1, mpl::_2, LeftRight> impl;
+ struct weighted_peaks_over_threshold_prob
+ : depends_on<sum_of_weights, tail_weights<LeftRight> >
+ typedef accumulators::impl::weighted_peaks_over_threshold_prob_impl<mpl::_1, mpl::_2, LeftRight> impl;
+// extract::weighted_peaks_over_threshold
+ extractor<tag::abstract_peaks_over_threshold> const weighted_peaks_over_threshold = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_peaks_over_threshold)
+using extract::weighted_peaks_over_threshold;
+// weighted_peaks_over_threshold<LeftRight>(with_threshold_value) -> weighted_peaks_over_threshold<LeftRight>
+struct as_feature<tag::weighted_peaks_over_threshold<LeftRight>(with_threshold_value)>
+// weighted_peaks_over_threshold<LeftRight>(with_threshold_probability) -> weighted_peaks_over_threshold_prob<LeftRight>
+struct as_feature<tag::weighted_peaks_over_threshold<LeftRight>(with_threshold_probability)>
@@ -0,0 +1,101 @@
+// weighted_skewness.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SKEWNESS_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SKEWNESS_HPP_EAN_28_10_2005
+ // 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:
+ The skewness estimator for weighted samples is formally identical to the estimator for unweighted samples, except that
+ struct weighted_skewness_impl
+ weighted_skewness_impl(dont_care) {}
+ accumulators::weighted_moment<3>(args)
+ - 3. * accumulators::weighted_moment<2>(args) * weighted_mean(args)
+ + 2. * weighted_mean(args) * weighted_mean(args) * weighted_mean(args)
+ * std::sqrt( accumulators::weighted_moment<2>(args) - weighted_mean(args) * weighted_mean(args) )
+// tag::weighted_skewness
+ struct weighted_skewness
+ : depends_on<weighted_mean, weighted_moment<2>, weighted_moment<3> >
+ typedef accumulators::impl::weighted_skewness_impl<mpl::_1, mpl::_2> impl;
+// extract::weighted_skewness
+ extractor<tag::weighted_skewness> const weighted_skewness = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_skewness)
+using extract::weighted_skewness;
@@ -0,0 +1,116 @@
+// weighted_sum.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SUM_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SUM_HPP_EAN_28_10_2005
+ // weighted_sum_impl
+ struct weighted_sum_impl
+ typedef weighted_sample result_type;
+ weighted_sum_impl(Args const &args)
+ : weighted_sum_(
+ this->weighted_sum_ += args[parameter::keyword<Tag>::get()] * args[weight];
+ return this->weighted_sum_;
+ weighted_sample weighted_sum_;
+// tag::weighted_sum
+ struct weighted_sum
+ typedef accumulators::impl::weighted_sum_impl<mpl::_1, mpl::_2, tag::sample> impl;
+ struct weighted_sum_of_variates
+ typedef accumulators::impl::weighted_sum_impl<VariateType, mpl::_2, VariateTag> impl;
+ struct abstract_weighted_sum_of_variates
+// extract::weighted_sum
+ extractor<tag::weighted_sum> const weighted_sum = {};
+ extractor<tag::abstract_weighted_sum_of_variates> const weighted_sum_of_variates = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_sum)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_sum_of_variates)
+using extract::weighted_sum;
+using extract::weighted_sum_of_variates;
+struct feature_of<tag::weighted_sum_of_variates<VariateType, VariateTag> >
+ : feature_of<tag::abstract_weighted_sum_of_variates>
@@ -0,0 +1,138 @@
+// weighted_sum_kahan.hpp
+// Copyright 2011 Simon West. Distributed under the Boost
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SUM_KAHAN_HPP_EAN_11_05_2011
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_SUM_KAHAN_HPP_EAN_11_05_2011
+ // weighted_sum_kahan_impl
+ struct weighted_sum_kahan_impl
+ weighted_sum_kahan_impl(Args const &args)
+ args[parameter::keyword<Tag>::get() | Sample()] * numeric::one<Weight>::value),
+ compensation(boost::numeric_cast<weighted_sample>(0.0))
+ operator ()(Args const &args)
+ const weighted_sample myTmp1 = args[parameter::keyword<Tag>::get()] * args[weight] - this->compensation;
+ const weighted_sample myTmp2 = this->weighted_sum_ + myTmp1;
+ this->compensation = (myTmp2 - this->weighted_sum_) - myTmp1;
+ this->weighted_sum_ = myTmp2;
+ weighted_sample compensation;
+// tag::weighted_sum_kahan
+// tag::weighted_sum_of_variates_kahan
+ struct weighted_sum_kahan
+ typedef accumulators::impl::weighted_sum_kahan_impl<mpl::_1, mpl::_2, tag::sample> impl;
+ struct weighted_sum_of_variates_kahan
+ typedef accumulators::impl::weighted_sum_kahan_impl<VariateType, mpl::_2, VariateTag> impl;
+// extract::weighted_sum_kahan
+// extract::weighted_sum_of_variates_kahan
+ extractor<tag::weighted_sum_kahan> const weighted_sum_kahan = {};
+ extractor<tag::abstract_weighted_sum_of_variates> const weighted_sum_of_variates_kahan = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_sum_kahan)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_sum_of_variates_kahan)
+using extract::weighted_sum_kahan;
+using extract::weighted_sum_of_variates_kahan;
+// weighted_sum(kahan) -> weighted_sum_kahan
+struct as_feature<tag::weighted_sum(kahan)>
+struct feature_of<tag::weighted_sum_of_variates_kahan<VariateType, VariateTag> >
@@ -0,0 +1,169 @@
+// weighted_tail_mean.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_TAIL_MEAN_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_TAIL_MEAN_HPP_DE_01_01_2006
+ // 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
+ \lambda = \inf\left\{ l \left| \frac{1}{\bar{w}_n}\sum_{i=1}^{l} w_i \geq \alpha \right. \right\}
+ smallest samples (left tail) or the weighted mean of the
+ 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\}
+ 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:
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X) = \frac{\sum_{i=1}^{\lambda} w_i X_{i:n}}{\sum_{i=1}^{\lambda} w_i},
+ \widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X) = \frac{\sum_{i=\rho}^n w_i X_{i:n}}{\sum_{i=\rho}^n w_i}.
+ struct non_coherent_weighted_tail_mean_impl
+ typedef typename numeric::functional::fdiv<weighted_sample, std::size_t>::result_type result_type;
+ non_coherent_weighted_tail_mean_impl(dont_care) {}
+ * ( ( is_same<LeftRight, left>::value ) ? args[quantile_probability] : 1. - args[quantile_probability] );
+ return result_type(0);
+ std::inner_product(
+ , tail_weights(args).begin()
+ , weighted_sample(0)
+ , sum
+// tag::non_coherent_weighted_tail_mean<>
+ struct non_coherent_weighted_tail_mean
+ typedef accumulators::impl::non_coherent_weighted_tail_mean_impl<mpl::_1, mpl::_2, LeftRight> impl;
+// extract::non_coherent_weighted_tail_mean;
+ extractor<tag::abstract_non_coherent_tail_mean> const non_coherent_weighted_tail_mean = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(non_coherent_weighted_tail_mean)
+using extract::non_coherent_weighted_tail_mean;
@@ -0,0 +1,146 @@
+// weighted_tail_quantile.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_TAIL_QUANTILE_HPP_DE_01_01_2006
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_TAIL_QUANTILE_HPP_DE_01_01_2006
+ // 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
+ and
+ \rho = \sup\left\{ r \left| \frac{1}{\bar{w}_n}\sum_{i=r}^{n} w_i \geq (1 - \alpha) \right. \right\},
+ \f$n\f$ being the number of samples and \f$\bar{w}_n\f$ the sum of all weights.
+ struct weighted_tail_quantile_impl
+ weighted_tail_quantile_impl(dont_care) {}
+// tag::weighted_tail_quantile<>
+ struct weighted_tail_quantile
+ typedef accumulators::impl::weighted_tail_quantile_impl<mpl::_1, mpl::_2, LeftRight> impl;
+// extract::weighted_tail_quantile
+ extractor<tag::quantile> const weighted_tail_quantile = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_tail_quantile)
+using extract::weighted_tail_quantile;
+// weighted_tail_variate_means.hpp
+#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
+namespace boost
+ // for _BinaryOperatrion2 in std::inner_product below
+ // multiplies two values and promotes the result to double
+ namespace numeric { namespace functional
+ // numeric::functional::multiply_and_promote_to_double
+ struct multiply_and_promote_to_double
+ : multiplies<T, double const>
+ }}
+ @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
+ 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$.
+ \frac{1}{\sum_{i=\rho}^n w_i}
+ \sum_{i=\rho}^n w_i \xi_{j,i}
+ \frac{1}{\sum_{i=1}^{\lambda}}
+ \sum_{i=1}^{\lambda} w_i \xi_{j,i}
+ \frac{\sum_{i=\rho}^n w_i \xi_{j,i}}
+ {\sum_{i=\rho}^n w_i \widehat{NCTM}_{n,\alpha}^{\mathrm{right}}(X)}
+ \frac{\sum_{i=1}^{\lambda} w_i \xi_{j,i}}
+ {\sum_{i=1}^{\lambda} w_i \widehat{NCTM}_{n,\alpha}^{\mathrm{left}}(X)}
+ // 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
+ typedef typename numeric::functional::fdiv<Weight, Weight>::result_type float_type;
+ typedef typename numeric::functional::fdiv<typename numeric::functional::multiplies<VariateType, Weight>::result_type, Weight>::result_type array_type;
+ weighted_tail_variate_means_impl(dont_care) {}
+ this->tail_means_ = std::inner_product(
+ , 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::bind(numeric::functional::divides<typename array_type::value_type const, float_type const>(), std::placeholders::_1, factor)
+ , std::bind2nd(numeric::functional::divides<typename array_type::value_type const, float_type const>(), factor)
+// tag::absolute_weighted_tail_variate_means
+// tag::relative_weighted_tail_variate_means
+ 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;
+ struct relative_weighted_tail_variate_means
+ 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
+ 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 = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_tail_variate_means)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(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>
+struct as_feature<tag::weighted_tail_variate_means<LeftRight, VariateType, VariateTag>(absolute)>
+// weighted_tail_variate_means<LeftRight, VariateType, VariateTag>(relative) -> relative_weighted_tail_variate_means<LeftRight, VariateType, VariateTag>
+struct as_feature<tag::weighted_tail_variate_means<LeftRight, VariateType, VariateTag>(relative)>
@@ -0,0 +1,186 @@
+// weighted_variance.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_VARIANCE_HPP_EAN_28_10_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WEIGHTED_VARIANCE_HPP_EAN_28_10_2005
+ //! 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):
+ \hat{\sigma}_n^2 = \widehat{m}_n^{(2)}-\hat{\mu}_n^2,
+ where \f$n\f$ is the number of samples.
+ template<typename Sample, typename Weight, typename MeanFeature>
+ struct lazy_weighted_variance_impl
+ lazy_weighted_variance_impl(dont_care) {}
+ extractor<MeanFeature> const some_mean = {};
+ result_type tmp = some_mean(args);
+ return accumulators::weighted_moment<2>(args) - tmp * tmp;
+ //! Iterative calculation of variance of weighted samples.
+ Iterative calculation of variance of weighted samples:
+ \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.
+ 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 samples. Note that the sample variance is not defined for
+ \f$n <= 1\f$.
+ template<typename Sample, typename Weight, typename MeanFeature, typename Tag>
+ struct weighted_variance_impl
+ weighted_variance_impl(Args const &args)
+ : weighted_variance(numeric::fdiv(args[sample | Sample()], numeric::one<Weight>::value))
+ result_type tmp = args[parameter::keyword<Tag>::get()] - some_mean(args);
+ this->weighted_variance =
+ numeric::fdiv(this->weighted_variance * (sum_of_weights(args) - args[weight]), sum_of_weights(args))
+ + numeric::fdiv(tmp * tmp * args[weight], sum_of_weights(args) - args[weight] );
+ return this->weighted_variance;
+ result_type weighted_variance;
+// tag::weighted_variance
+// tag::immediate_weighted_variance
+ struct lazy_weighted_variance
+ : depends_on<weighted_moment<2>, weighted_mean>
+ typedef accumulators::impl::lazy_weighted_variance_impl<mpl::_1, mpl::_2, weighted_mean> impl;
+ struct weighted_variance
+ : depends_on<count, immediate_weighted_mean>
+ typedef accumulators::impl::weighted_variance_impl<mpl::_1, mpl::_2, immediate_weighted_mean, sample> impl;
+// extract::weighted_variance
+// extract::immediate_weighted_variance
+ extractor<tag::lazy_weighted_variance> const lazy_weighted_variance = {};
+ extractor<tag::weighted_variance> const weighted_variance = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(lazy_weighted_variance)
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(weighted_variance)
+using extract::lazy_weighted_variance;
+using extract::weighted_variance;
+// weighted_variance(lazy) -> lazy_weighted_variance
+struct as_feature<tag::weighted_variance(lazy)>
+// weighted_variance(immediate) -> weighted_variance
+struct as_feature<tag::weighted_variance(immediate)>
+//// droppable_accumulator<weighted_variance_impl>
+//// need to specialize droppable lazy weighted_variance to cache the result at the
+//template<typename Sample, typename Weight, typename MeanFeature>
+//struct droppable_accumulator<impl::weighted_variance_impl<Sample, Weight, MeanFeature> >
+// with_cached_result<impl::weighted_variance_impl<Sample, Weight, MeanFeature> >
@@ -0,0 +1,44 @@
+// with_error.hpp
+#ifndef BOOST_ACCUMULATORS_STATISTICS_WITH_ERROR_HPP_EAN_01_11_2005
+#define BOOST_ACCUMULATORS_STATISTICS_WITH_ERROR_HPP_EAN_01_11_2005
+ struct error_of_tag
+ typedef tag::error_of<Feature> type;
+// with_error
+struct with_error
+ : mpl::transform_view<
+ , detail::error_of_tag<mpl::_1>
@@ -0,0 +1,432 @@
+// statistics_fwd.hpp
+#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/print.hpp>
+// base struct and base extractor for quantiles
+ struct quantile
+ typedef mpl::print<class ____MISSING_SPECIFIC_QUANTILE_FEATURE_IN_ACCUMULATOR_SET____ > impl;
+ extractor<tag::quantile> const quantile = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(quantile)
+using extract::quantile;
+// base struct and base extractor for *coherent* tail means
+ struct tail_mean
+ typedef mpl::print<class ____MISSING_SPECIFIC_TAIL_MEAN_FEATURE_IN_ACCUMULATOR_SET____ > impl;
+ extractor<tag::tail_mean> const tail_mean = {};
+ BOOST_ACCUMULATORS_IGNORE_GLOBAL(tail_mean)
+using extract::tail_mean;
+ // Variates tags
+ struct covariate1;
+ struct covariate2;
+ // Statistic tags
+ struct count;
+ struct covariance;
+ struct density;
+ 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;
+ struct mean_of_variates;
+ struct immediate_mean_of_variates;
+ struct median;
+ struct with_density_median;
+ struct with_p_square_cumulative_distribution_median;
+ struct min;
+ struct moment;
+ struct peaks_over_threshold;
+ struct peaks_over_threshold_prob;
+ struct pot_tail_mean;
+ struct pot_tail_mean_prob;
+ struct pot_quantile;
+ 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;
+ struct sum_of_variates;
+ struct sum_kahan;
+ struct sum_of_weights_kahan;
+ struct sum_of_variates_kahan;
+ struct tail;
+ struct coherent_tail_mean;
+ struct non_coherent_tail_mean;
+ struct tail_quantile;
+ struct tail_variate;
+ struct tail_weights;
+ struct right_tail_variate;
+ struct left_tail_variate;
+ struct tail_variate_means;
+ struct absolute_tail_variate_means;
+ struct relative_tail_variate_means;
+ struct lazy_variance;
+ struct variance;
+ struct weighted_covariance;
+ struct weighted_density;
+ struct weighted_kurtosis;
+ struct weighted_mean;
+ struct immediate_weighted_mean;
+ struct weighted_mean_of_variates;
+ 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;
+ struct weighted_moment;
+ struct weighted_peaks_over_threshold;
+ struct weighted_peaks_over_threshold_prob;
+ struct weighted_pot_quantile;
+ struct weighted_pot_quantile_prob;
+ struct weighted_pot_tail_mean;
+ 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;
+ struct weighted_tail_quantile;
+ struct non_coherent_weighted_tail_mean;
+ struct weighted_tail_variate_means;
+ struct absolute_weighted_tail_variate_means;
+ struct relative_weighted_tail_variate_means;
+ struct lazy_weighted_variance;
+ struct weighted_variance;
+ struct weighted_sum;
+ struct weighted_sum_of_variates;
+ struct rolling_window_plus1;
+ struct rolling_window;
+ struct rolling_sum;
+ struct rolling_count;
+ struct rolling_mean;
+ // Statistics impls
+ struct count_impl;
+ struct covariance_impl;
+ struct density_impl;
+ struct error_of_impl;
+ struct error_of_mean_impl;
+ struct extended_p_square_impl;
+ template<typename Sample, typename Impl1, typename Impl2>
+ struct extended_p_square_quantile_impl;
+ struct kurtosis_impl;
+ struct max_impl;
+ struct median_impl;
+ struct with_density_median_impl;
+ struct with_p_square_cumulative_distribution_median_impl;
+ struct min_impl;
+ template<typename Sample, typename SumFeature = tag::sum>
+ struct mean_impl;
+ template<typename Sample, typename Tag = tag::sample>
+ struct immediate_mean_impl;
+ struct moment_impl;
+ struct peaks_over_threshold_prob_impl;
+ struct pot_quantile_impl;
+ struct pot_tail_mean_impl;
+ struct p_square_cumulative_distribution_impl;
+ struct p_square_quantile_impl;
+ struct skewness_impl;
+ struct sum_impl;
+ struct sum_kahan_impl;
+ struct tail_impl;
+ struct coherent_tail_mean_impl;
+ struct non_coherent_tail_mean_impl;
+ struct tail_quantile_impl;
+ struct tail_variate_impl;
+ struct tail_variate_means_impl;
+ struct lazy_variance_impl;
+ struct variance_impl;
+ struct weighted_covariance_impl;
+ struct weighted_density_impl;
+ struct weighted_kurtosis_impl;
+ struct weighted_median_impl;
+ struct with_density_weighted_median_impl;
+ struct with_p_square_cumulative_distribution_weighted_median_impl;
+ struct weighted_mean_impl;
+ struct immediate_weighted_mean_impl;
+ struct weighted_peaks_over_threshold_impl;
+ struct weighted_peaks_over_threshold_prob_impl;
+ struct weighted_extended_p_square_impl;
+ struct weighted_moment_impl;
+ struct weighted_p_square_cumulative_distribution_impl;
+ struct weighted_p_square_quantile_impl;
+ struct weighted_skewness_impl;
+ struct weighted_sum_impl;
+ struct weighted_sum_kahan_impl;
+ struct non_coherent_weighted_tail_mean_impl;
+ struct weighted_tail_quantile_impl;
+ struct weighted_tail_variate_means_impl;
+ struct lazy_weighted_variance_impl;
+ struct weighted_variance_impl;
+ struct rolling_window_plus1_impl;
+ struct rolling_window_impl;
+ struct rolling_sum_impl;
+ struct rolling_count_impl;
+ struct rolling_mean_impl;
+// stats
+// A more descriptive name for an MPL sequence of statistics.
+struct stats;
+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 {};
+// modifier for sum_kahan, sum_of_weights_kahan, sum_of_variates_kahan, weighted_sum_kahan
+struct kahan {};
@@ -0,0 +1,88 @@
+/*
+ Copyright (c) Marshall Clow 2014.
+ 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)
+ Revision history:
+ 2 Dec 2014 mtc First version; power
+*/
+/// \file algorithm.hpp
+/// \brief Misc Algorithms
+/// \author Marshall Clow
+#ifndef BOOST_ALGORITHM_HPP
+#define BOOST_ALGORITHM_HPP
+#include <functional> // for plus and multiplies
+#include <boost/utility/enable_if.hpp> // for boost::disable_if
+namespace boost { namespace algorithm {
+template <typename T>
+BOOST_CXX14_CONSTEXPR T identity_operation ( std::multiplies<T> ) { return T(1); }
+BOOST_CXX14_CONSTEXPR T identity_operation ( std::plus<T> ) { return T(0); }
+/// \fn power ( T x, Integer n )
+/// \return the value "x" raised to the power "n"
+/// \param x The value to be exponentiated
+/// \param n The exponent (must be >= 0)
+// \remark Taken from Knuth, The Art of Computer Programming, Volume 2:
+// Seminumerical Algorithms, Section 4.6.3
+template <typename T, typename Integer>
+BOOST_CXX14_CONSTEXPR typename boost::enable_if<boost::is_integral<Integer>, T>::type
+power (T x, Integer n) {
+ T y = 1; // Should be "T y{1};"
+ if (n == 0) return y;
+ while (true) {
+ if (n % 2 == 1) {
+ y = x * y;
+ if (n == 1)
+ return y;
+ n = n / 2;
+ x = x * x;
+/// \fn power ( T x, Integer n, Operation op )
+/// using the operation "op".
+/// \param op The operation used
+template <typename T, typename Integer, typename Operation>
+power (T x, Integer n, Operation op) {
+ T y = identity_operation(op);
+ y = op(x, y);
+ x = op(x, x);
+#endif // BOOST_ALGORITHM_HPP
+ Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 2017
+ 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)
+ See http://www.boost.org/ for latest version.
+ Based on https://blogs.msdn.microsoft.com/oldnewthing/20170104-00/?p=95115
+/// \file apply_permutation.hpp
+/// \brief Apply permutation to a sequence.
+/// \author Alexander Zaitsev
+#ifndef BOOST_ALGORITHM_APPLY_PERMUTATION_HPP
+#define BOOST_ALGORITHM_APPLY_PERMUTATION_HPP
+#include <algorithm>
+#include <type_traits>
+namespace boost { namespace algorithm
+/// \fn apply_permutation ( RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, RandomAccessIterator2 ind_begin )
+/// \brief Reorder item sequence with index sequence order
+/// \param item_begin The start of the item sequence
+/// \param item_end One past the end of the item sequence
+/// \param ind_begin The start of the index sequence.
+/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined.
+/// Complexity: O(N).
+template<typename RandomAccessIterator1, typename RandomAccessIterator2>
+void
+apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
+ RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end)
+ using Diff = typename std::iterator_traits<RandomAccessIterator1>::difference_type;
+ using std::swap;
+ Diff size = std::distance(item_begin, item_end);
+ for (Diff i = 0; i < size; i++)
+ auto current = i;
+ while (i != ind_begin[current])
+ auto next = ind_begin[current];
+ swap(item_begin[current], item_begin[next]);
+ ind_begin[current] = current;
+ current = next;
+/// \fn apply_reverse_permutation ( RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, RandomAccessIterator2 ind_begin )
+apply_reverse_permutation(
+ RandomAccessIterator1 item_begin,
+ RandomAccessIterator1 item_end,
+ RandomAccessIterator2 ind_begin,
+ RandomAccessIterator2 ind_end)
+ using Diff = typename std::iterator_traits<RandomAccessIterator2>::difference_type;
+ Diff length = std::distance(item_begin, item_end);
+ for (Diff i = 0; i < length; i++)
+ while (i != ind_begin[i])
+ Diff next = ind_begin[i];
+ swap(item_begin[i], item_begin[next]);
+ swap(ind_begin[i], ind_begin[next]);
+/// \fn apply_permutation ( Range1 item_range, Range2 ind_range )
+/// \param item_range The item sequence
+/// \param ind_range The index sequence
+template<typename Range1, typename Range2>
+apply_permutation(Range1& item_range, Range2& ind_range)
+ apply_permutation(boost::begin(item_range), boost::end(item_range),
+ boost::begin(ind_range), boost::end(ind_range));
+/// \fn apply_reverse_permutation ( Range1 item_range, Range2 ind_range )
+apply_reverse_permutation(Range1& item_range, Range2& ind_range)
+ apply_reverse_permutation(boost::begin(item_range), boost::end(item_range),
+#endif //BOOST_ALGORITHM_APPLY_PERMUTATION_HPP
@@ -0,0 +1,175 @@
+ Copyright (c) Marshall Clow 2008-2012.
+ 27 June 2009 mtc First version
+ 23 Oct 2010 mtc Added predicate version
+/// \file clamp.hpp
+/// \brief Clamp algorithm
+/// Suggested by olafvdspek in https://svn.boost.org/trac/boost/ticket/3215
+#ifndef BOOST_ALGORITHM_CLAMP_HPP
+#define BOOST_ALGORITHM_CLAMP_HPP
+#include <functional> // For std::less
+#include <iterator> // For std::iterator_traits
+#include <cassert>
+#include <boost/mpl/identity.hpp> // for identity
+/// \fn clamp ( T const& val,
+/// typename boost::mpl::identity<T>::type const & lo,
+/// typename boost::mpl::identity<T>::type const & hi, Pred p )
+/// \return the value "val" brought into the range [ lo, hi ]
+/// using the comparison predicate p.
+/// If p ( val, lo ) return lo.
+/// If p ( hi, val ) return hi.
+/// Otherwise, return the original value.
+/// \param val The value to be clamped
+/// \param lo The lower bound of the range to be clamped to
+/// \param hi The upper bound of the range to be clamped to
+/// \param p A predicate to use to compare the values.
+/// p ( a, b ) returns a boolean.
+ template<typename T, typename Pred>
+ BOOST_CXX14_CONSTEXPR T const & clamp ( T const& val,
+ typename boost::mpl::identity<T>::type const & lo,
+ typename boost::mpl::identity<T>::type const & hi, Pred p )
+// assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they might be equal
+ return p ( val, lo ) ? lo : p ( hi, val ) ? hi : val;
+/// typename boost::mpl::identity<T>::type const & hi )
+/// \return the value "val" brought into the range [ lo, hi ].
+/// If the value is less than lo, return lo.
+/// If the value is greater than "hi", return hi.
+ BOOST_CXX14_CONSTEXPR T const& clamp ( const T& val,
+ typename boost::mpl::identity<T>::type const & hi )
+ return boost::algorithm::clamp ( val, lo, hi, std::less<T>());
+/// \fn clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
+/// std::iterator_traits<InputIterator>::value_type const & lo,
+/// std::iterator_traits<InputIterator>::value_type const & hi )
+/// \return clamp the sequence of values [first, last) into [ lo, hi ]
+/// \param first The start of the range of values
+/// \param last One past the end of the range of input values
+/// \param out An output iterator to write the clamped values into
+ template<typename InputIterator, typename OutputIterator>
+ BOOST_CXX14_CONSTEXPR OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
+ typename std::iterator_traits<InputIterator>::value_type const & lo,
+ typename std::iterator_traits<InputIterator>::value_type const & hi )
+ // this could also be written with bind and std::transform
+ while ( first != last )
+ *out++ = boost::algorithm::clamp ( *first++, lo, hi );
+ return out;
+/// \fn clamp_range ( const Range &r, OutputIterator out,
+/// typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & lo,
+/// typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & hi )
+/// \param r The range of values to be clamped
+ template<typename Range, typename OutputIterator>
+ BOOST_CXX14_CONSTEXPR typename boost::disable_if_c<boost::is_same<Range, OutputIterator>::value, OutputIterator>::type
+ clamp_range ( const Range &r, OutputIterator out,
+ typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & lo,
+ typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & hi )
+ return boost::algorithm::clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi );
+/// std::iterator_traits<InputIterator>::value_type const & hi, Pred p )
+ template<typename InputIterator, typename OutputIterator, typename Pred>
+ typename std::iterator_traits<InputIterator>::value_type const & hi, Pred p )
+ *out++ = boost::algorithm::clamp ( *first++, lo, hi, p );
+/// typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & hi,
+/// Pred p )
+// Disable this template if the first two parameters are the same type;
+// In that case, the user will get the two iterator version.
+ template<typename Range, typename OutputIterator, typename Pred>
+ typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & hi,
+ Pred p )
+ return boost::algorithm::clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi, p );
+#endif // BOOST_ALGORITHM_CLAMP_HPP