diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..2eae862 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,272 @@ +# Copyright 2018 Cromwell D. Enage +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://boost.org/LICENSE_1_0.txt) + +language: cpp + +python: "2.7" + +branches: + only: + - master + - develop + - /feature\/.*/ + +env: + matrix: + - BOGUS_JOB=true + +matrix: + + exclude: + - env: BOGUS_JOB=true + + include: + - os: linux + compiler: g++-4.4 + env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x + addons: + apt: + packages: + - g++-4.4 + sources: + - ubuntu-toolchain-r-test + + - os: linux + compiler: g++-4.6 + env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x + addons: + apt: + packages: + - g++-4.6 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11 + addons: + apt: + packages: + - g++-4.7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11 + addons: + apt: + packages: + - g++-4.8 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11 + addons: + apt: + packages: + - g++-4.9 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14 + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z CXXSTD_DIALECT=cxxstd-dialect=gnu + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test + + - os: linux + dist: trusty + compiler: g++-7 + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + dist: trusty + compiler: g++-7 + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 CXXSTD_DIALECT=cxxstd-dialect=gnu + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + compiler: g++-8 + env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17 + addons: + apt: + packages: + - g++-8 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03,11 + addons: + apt: + packages: + - clang-3.5 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.5 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03,11 + addons: + apt: + packages: + - clang-3.6 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.6 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11 + addons: + apt: + packages: + - clang-3.7 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.7 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03,11,14,1z + addons: + apt: + packages: + - clang-3.8 + - libstdc++-4.9-dev + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 + + - os: linux + env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03,11,14,1z + addons: + apt: + packages: + - clang-3.9 + - libstdc++-4.9-dev + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.9 + + - os: linux + compiler: clang++-4.0 + env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z + addons: + apt: + packages: + - clang-4.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-4.0 + + - os: linux + compiler: clang++-5.0 + env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z + addons: + apt: + packages: + - clang-5.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-5.0 + + - os: linux + compiler: clang++-6.0 + env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,1z + addons: + apt: + packages: + - clang-6.0 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-trusty-6.0 + + - os: linux + compiler: clang++ + env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z + addons: + apt: + packages: + - libstdc++-5-dev + sources: + - ubuntu-toolchain-r-test + + - os: linux + compiler: clang++-libc++ + env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z + addons: + apt: + packages: + - libc++-dev + + - os: osx + env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z + osx_image: xcode7.3 + + - os: osx + env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z + osx_image: xcode8.3 + + - os: osx + env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z + osx_image: xcode9.4.1 + +install: + - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true + - cd .. + - git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root + - cd boost-root + - git submodule update --init tools/boost_install + - git submodule update --init libs/headers + - git submodule update --init tools/build + - git submodule update --init libs/config + - git submodule update --init tools/boostdep + - cp -r $TRAVIS_BUILD_DIR/* libs/accumulators + - python tools/boostdep/depinst/depinst.py accumulators + - ./bootstrap.sh + - ./b2 headers + +script: + - |- + echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam + - ./b2 --verbose-test libs/config/test//config_info toolset=$TOOLSET cxxstd=$CXXSTD || true + - cd libs/accumulators/test + - ../../../b2 -j`(nproc || sysctl -n hw.ncpu) 2> /dev/null` toolset=$TOOLSET cxxstd=$CXXSTD $CXXSTD_DIALECT + - cd ../../.. + +notifications: + email: + on_success: always diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..71fc5e4 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,67 @@ +# Copyright 2018 Cromwell D. Enage +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://boost.org/LICENSE_1_0.txt) + +version: 1.0.{build}-{branch} + +shallow_clone: true + +branches: + only: + - master + - develop + +environment: + matrix: + - ARGS: --toolset=gcc address-model=32 + PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH% + - ARGS: --toolset=gcc address-model=32 linkflags=-Wl,-allow-multiple-definition + PATH: C:\MinGW\bin;%PATH% + - ARGS: --toolset=gcc address-model=64 + PATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH% + - ARGS: --toolset=gcc address-model=64 cxxflags=-std=gnu++1z + PATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH% + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ARGS: --toolset=msvc-9.0 address-model=32 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ARGS: --toolset=msvc-10.0 address-model=32 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ARGS: --toolset=msvc-11.0 address-model=32 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ARGS: --toolset=msvc-12.0 address-model=32 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + ARGS: --toolset=msvc-12.0 address-model=64 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + ARGS: --toolset=msvc-14.0 address-model=32 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + ARGS: --toolset=msvc-14.0 address-model=64 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + ARGS: --toolset=msvc-14.0 address-model=64 cxxflags=-std:c++latest + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + ARGS: --toolset=msvc-14.1 address-model=32 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + ARGS: --toolset=msvc-14.1 address-model=64 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + ARGS: --toolset=msvc-14.1 address-model=64 cxxflags=-std:c++latest + +install: + - cd .. + - git clone -b %APPVEYOR_REPO_BRANCH% https://github.com/boostorg/boost.git boost-root + - cd boost-root + - git submodule update --init tools/boost_install + - git submodule update --init libs/headers + - git submodule update --init tools/build + - git submodule update --init libs/config + - git submodule update --init tools/boostdep + - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\accumulators + - python tools/boostdep/depinst/depinst.py accumulators + - bootstrap + - b2 headers + +build: off + +test_script: + - cd libs\accumulators\test + - ..\..\..\b2 -j%NUMBER_OF_PROCESSORS% --hash %ARGS% + - cd ..\..\.. diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index ad050d3..eff105b 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -8,4 +8,6 @@ exe example : ../../.. $(BOOST_ROOT) + /boost/serialization + "-Wno-deprecated-declarations" ; diff --git a/example/main.cpp b/example/main.cpp index 8541dba..2c525b2 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -6,6 +6,7 @@ // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include +#include // needed for de/serialization example (4) #include #include #include @@ -13,6 +14,9 @@ #include #include #include +// needed for de/serialization example (4) +#include +#include using namespace boost; using namespace boost::accumulators; @@ -159,6 +163,85 @@ void example3() } } +/////////////////////////////////////////////////////////////////////////////// +// example4 +// +// Show how accumulators could be persisted into a file, and then continued +// from where they were left of +// +void example4() +{ + accumulator_set< + double + , stats, tag::p_square_quantile, tag::kurtosis > + > acc(quantile_probability = 0.9); + + { + // accumulate values from array + boost::array data = {-10., -8., -7., -6., -5., -4., -3., -2., -1., 0.}; + + acc = std::for_each(data.begin(), data.end(), acc); + } + + std::cout << " min = " << (min)(acc) << std::endl; + std::cout << " mean = " << mean(acc) << std::endl; + std::cout << " count = " << count(acc) << std::endl; + std::cout << " sum = " << sum(acc) << std::endl; + std::cout << " moment<2> = " << accumulators::moment<2>(acc) << std::endl; + std::cout << " p_square_quantile = " << accumulators::p_square_quantile(acc) << std::endl; + std::cout << " kurtosis = " << accumulators::kurtosis(acc) << std::endl; + + // save accumulator list into a file called "saved-stats" + const unsigned ACC_VER = 0; + const char* file_name = "saved-stats"; + { + std::ofstream ofs(file_name); + boost::archive::text_oarchive oa(ofs); + acc.serialize(oa, ACC_VER); + } + + // create a new accumulator set and initialize from data saved into the file + accumulator_set< + double + , stats, tag::p_square_quantile, tag::kurtosis > + > restored_acc(quantile_probability = 0.9); + + { + std::ifstream ifs(file_name); + boost::archive::text_iarchive ia(ifs); + restored_acc.serialize(ia, ACC_VER); + } + + // continue accumulating into both sets + { + // accumulate values from array + boost::array data = {10., 8., 7., 6., 5., 4., 3., 2., 1., 0.}; + + acc = std::for_each(data.begin(), data.end(), acc); + restored_acc = std::for_each(data.begin(), data.end(), restored_acc); + } + + // validate that both return th same values + std::cout << std::endl << "Values in original set:" << std::endl; + std::cout << " min""(acc) = " << (min)(acc) << std::endl; + std::cout << " mean(acc) = " << mean(acc) << std::endl; + std::cout << " count(acc) = " << count(acc) << std::endl; + std::cout << " sum(acc) = " << sum(acc) << std::endl; + std::cout << " moment<2>(acc) = " << accumulators::moment<2>(acc) << std::endl; + std::cout << " p_square_quantile(acc) = " << accumulators::p_square_quantile(acc) << std::endl; + std::cout << " kurtosis(acc) = " << accumulators::kurtosis(acc) << std::endl; + + std::cout << std::endl << "Values in restored set:" << std::endl; + std::cout << " min""(acc) = " << (min)(restored_acc) << std::endl; + std::cout << " mean(acc) = " << mean(restored_acc) << std::endl; + std::cout << " count(acc) = " << count(restored_acc) << std::endl; + std::cout << " sum(acc) = " << sum(restored_acc) << std::endl; + std::cout << " moment<2>(acc) = " << accumulators::moment<2>(restored_acc) << std::endl; + std::cout << " p_square_quantile(acc) = " << accumulators::p_square_quantile(restored_acc) << std::endl; + std::cout << " kurtosis(acc) = " << accumulators::kurtosis(restored_acc) << std::endl; + +} + /////////////////////////////////////////////////////////////////////////////// // main int main() @@ -172,5 +255,8 @@ int main() std::cout << "\nExample 3:\n"; example3(); + std::cout << "\nExample 4:\n"; + example4(); + return 0; } diff --git a/include/boost/accumulators/accumulators_fwd.hpp b/include/boost/accumulators/accumulators_fwd.hpp index 4c0370e..fabc4e8 100644 --- a/include/boost/accumulators/accumulators_fwd.hpp +++ b/include/boost/accumulators/accumulators_fwd.hpp @@ -9,6 +9,8 @@ #define BOOST_ACCUMULATORS_ACCUMULATORS_FWD_HPP_EAN_28_10_2005 #include +#include +#include #include // for mpl::na #include #include @@ -41,7 +43,6 @@ #endif #ifdef BOOST_ACCUMULATORS_BROKEN_CONST_OVERLOADS -# include # include # define BOOST_ACCUMULATORS_PROTO_DISABLE_IF_IS_CONST(T)\ , typename boost::disable_if >::type * = 0 @@ -128,9 +129,12 @@ template typename mpl::apply::type::result_type extract_result(AccumulatorSet const &acc); -template -typename mpl::apply::type::result_type -extract_result(AccumulatorSet const &acc, A1 const &a1); +namespace detail +{ + struct _enabler + { + }; +} // ... other overloads generated by Boost.Preprocessor: @@ -146,17 +150,37 @@ extract_result(AccumulatorSet const &acc, A1 const &a1); extract_result( \ AccumulatorSet const &acc \ BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::enable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type = detail::_enabler() \ + ); \ + template< \ + typename Feature \ + , typename AccumulatorSet \ + BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \ + > \ + typename mpl::apply::type::result_type \ + extract_result( \ + AccumulatorSet const &acc \ + BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::disable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type = detail::_enabler() \ ); /// INTERNAL ONLY /// BOOST_PP_REPEAT_FROM_TO( - 2 + 1 , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS) , BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD , _ ) +#undef BOOST_ACCUMULATORS_EXTRACT_RESULT_FWD + #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED template typename mpl::apply::type::result_type @@ -185,6 +209,9 @@ namespace detail struct is_accumulator_set; inline void ignore_variable(void const *) {} +} + +}} // namespace boost::accumulators #define BOOST_ACCUMULATORS_IGNORE_GLOBAL(X) \ namespace detail \ @@ -198,33 +225,8 @@ namespace detail }; \ } \ /**/ -} -}} // namespace boost::accumulators +#include -// 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 \ - struct name ## _ \ - { \ - static char const* keyword_name() \ - { \ - return #name; \ - } \ - static ::boost::parameter::keyword > &alias; \ - }; \ - template \ - ::boost::parameter::keyword > &name ## _::alias = \ - ::boost::parameter::keyword >::get(); \ - typedef name ## _ <> name; \ - } \ - namespace \ - { \ - ::boost::parameter::keyword &name = \ - ::boost::parameter::keyword::get(); \ - } +#endif // include guard -#endif diff --git a/include/boost/accumulators/framework/accumulator_set.hpp b/include/boost/accumulators/framework/accumulator_set.hpp index ed1ceb1..0b4f4ad 100644 --- a/include/boost/accumulators/framework/accumulator_set.hpp +++ b/include/boost/accumulators/framework/accumulator_set.hpp @@ -9,16 +9,23 @@ #define BOOST_ACCUMULATORS_FRAMEWORK_ACCUMULATOR_SET_HPP_EAN_28_10_2005 #include +#include +#include #include #include #include #include #include #include -#include -#include +#include +#include +#include +#include +#include #include +#include #include +#include #include #include #include @@ -64,14 +71,6 @@ namespace detail return accumulator_visitor(args); } - typedef - parameter::parameters< - parameter::required - , parameter::optional - // ... and others which are not specified here... - > - accumulator_params; - /////////////////////////////////////////////////////////////////////////////// // accumulator_set_base struct accumulator_set_base @@ -82,10 +81,38 @@ namespace detail // is_accumulator_set template struct is_accumulator_set - : is_base_and_derived + : mpl::if_< + boost::is_base_of< + accumulator_set_base + , typename boost::remove_const< + typename boost::remove_reference::type + >::type + > + , mpl::true_ + , mpl::false_ + >::type { }; + // function object that serialize an accumulator + template + struct serialize_accumulator + { + serialize_accumulator(Archive & _ar, const unsigned int _file_version) : + ar(_ar), file_version(_file_version) + {} + + template + void operator ()(Accumulator &accumulator) + { + accumulator.serialize(ar, file_version); + } + + private: + Archive& ar; + const unsigned int file_version; + }; + } // namespace detail #ifdef _MSC_VER @@ -140,13 +167,13 @@ struct accumulator_set : accumulators( detail::make_acc_list( accumulators_mpl_vector() - , detail::accumulator_params()(*this) + , (boost::accumulators::accumulator = *this) ) ) { // Add-ref the Features that the user has specified this->template visit_if >( - detail::make_add_ref_visitor(detail::accumulator_params()(*this)) + detail::make_add_ref_visitor(boost::accumulators::accumulator = *this) ); } @@ -154,17 +181,48 @@ struct accumulator_set /// /// \param a1 Optional named parameter to be passed to all the accumulators template - explicit accumulator_set(A1 const &a1) - : accumulators( + explicit accumulator_set( + A1 const &a1 + , typename boost::enable_if< + parameter::is_argument_pack + , detail::_enabler + >::type = detail::_enabler() + ) : accumulators( + detail::make_acc_list( + accumulators_mpl_vector() + , (boost::accumulators::accumulator = *this, a1) + ) + ) + { + // Add-ref the Features that the user has specified + this->template visit_if >( + detail::make_add_ref_visitor(boost::accumulators::accumulator = *this) + ); + } + + /// \overload + /// + /// \param a1 Optional sample parameter to be passed to all the accumulators + template + explicit accumulator_set( + A1 const &a1 + , typename boost::disable_if< + parameter::is_argument_pack + , detail::_enabler + >::type = detail::_enabler() + ) : accumulators( detail::make_acc_list( accumulators_mpl_vector() - , detail::accumulator_params()(*this, a1) + , ( + boost::accumulators::accumulator = *this + , boost::accumulators::sample = a1 + ) ) ) { // Add-ref the Features that the user has specified this->template visit_if >( - detail::make_add_ref_visitor(detail::accumulator_params()(*this)) + detail::make_add_ref_visitor(boost::accumulators::accumulator = *this) ); } @@ -174,19 +232,47 @@ struct accumulator_set /// #define BOOST_ACCUMULATORS_ACCUMULATOR_SET_CTOR(z, n, _) \ template \ - accumulator_set(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a)) \ - : accumulators( \ + accumulator_set( \ + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::enable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type = detail::_enabler() \ + ) : accumulators( \ detail::make_acc_list( \ accumulators_mpl_vector() \ - , detail::accumulator_params()( \ - *this BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \ + , ( \ + boost::accumulators::accumulator = *this \ + BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \ ) \ ) \ ) \ { \ /* Add-ref the Features that the user has specified */ \ this->template visit_if >( \ - detail::make_add_ref_visitor(detail::accumulator_params()(*this)) \ + detail::make_add_ref_visitor(boost::accumulators::accumulator = *this) \ + ); \ + } \ + template \ + accumulator_set( \ + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::disable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type = detail::_enabler() \ + ) : accumulators( \ + detail::make_acc_list( \ + accumulators_mpl_vector() \ + , ( \ + boost::accumulators::accumulator = *this \ + , boost::accumulators::sample = BOOST_PP_ENUM_PARAMS_Z(z, n, a) \ + ) \ + ) \ + ) \ + { \ + /* Add-ref the Features that the user has specified */ \ + this->template visit_if >( \ + detail::make_add_ref_visitor(boost::accumulators::accumulator = *this) \ ); \ } @@ -239,17 +325,7 @@ struct accumulator_set { this->visit( detail::make_accumulator_visitor( - detail::accumulator_params()(*this) - ) - ); - } - - template - void operator ()(A1 const &a1) - { - this->visit( - detail::make_accumulator_visitor( - detail::accumulator_params()(*this, a1) + boost::accumulators::accumulator = *this ) ); } @@ -260,12 +336,37 @@ struct accumulator_set /// #define BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP(z, n, _) \ template \ - void operator ()(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a)) \ + void operator ()( \ + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::enable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type = detail::_enabler() \ + ) \ { \ this->visit( \ detail::make_accumulator_visitor( \ - detail::accumulator_params()( \ - *this BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \ + ( \ + boost::accumulators::accumulator = *this \ + BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \ + ) \ + ) \ + ); \ + } \ + template \ + void operator ()( \ + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::disable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type = detail::_enabler() \ + ) \ + { \ + this->visit( \ + detail::make_accumulator_visitor( \ + ( \ + boost::accumulators::accumulator = *this \ + , boost::accumulators::sample = BOOST_PP_ENUM_PARAMS_Z(z, n, a) \ ) \ ) \ ); \ @@ -274,7 +375,7 @@ struct accumulator_set /// INTERNAL ONLY /// BOOST_PP_REPEAT_FROM_TO( - 2 + 1 , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS) , BOOST_ACCUMULATORS_ACCUMULATOR_SET_FUN_OP , _ @@ -329,15 +430,23 @@ struct accumulator_set the_feature; (*fusion::find_if >(this->accumulators)) - .drop(detail::accumulator_params()(*this)); + .drop(boost::accumulators::accumulator = *this); // Also drop accumulators that this feature depends on typedef typename the_feature::dependencies dependencies; this->template visit_if >( - detail::make_drop_visitor(detail::accumulator_params()(*this)) + detail::make_drop_visitor(boost::accumulators::accumulator = *this) ); } + // make the accumulator set serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + detail::serialize_accumulator serializer(ar, file_version); + fusion::for_each(this->accumulators, serializer); + } + private: accumulators_type accumulators; @@ -365,6 +474,15 @@ find_accumulator(AccumulatorSet const &acc) return acc.template extract(); } +template +typename mpl::apply::type::result_type +extract_result(AccumulatorSet const &acc) +{ + return find_accumulator(acc).result( + boost::accumulators::accumulator = acc + ); +} + /////////////////////////////////////////////////////////////////////////////// // extract_result // extract a result from an accumulator set @@ -380,18 +498,43 @@ find_accumulator(AccumulatorSet const &acc) extract_result( \ AccumulatorSet const &acc \ BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::enable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type \ ) \ { \ return find_accumulator(acc).result( \ - detail::accumulator_params()( \ - acc \ + ( \ + boost::accumulators::accumulator = acc \ BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a) \ ) \ ); \ + } \ + template< \ + typename Feature \ + , typename AccumulatorSet \ + BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A) \ + > \ + typename mpl::apply::type::result_type \ + extract_result( \ + AccumulatorSet const &acc \ + BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) \ + , typename boost::disable_if< \ + parameter::is_argument_pack \ + , detail::_enabler \ + >::type \ + ) \ + { \ + return find_accumulator(acc).result(( \ + boost::accumulators::accumulator = acc \ + , boost::accumulators::sample = BOOST_PP_ENUM_PARAMS_Z(z, n, a) \ + )); \ } -BOOST_PP_REPEAT( - BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS) +BOOST_PP_REPEAT_FROM_TO( + 1 + , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS) , BOOST_ACCUMULATORS_EXTRACT_RESULT_FUN , _ ) diff --git a/include/boost/accumulators/framework/accumulators/external_accumulator.hpp b/include/boost/accumulators/framework/accumulators/external_accumulator.hpp index 71dce42..eb6965c 100644 --- a/include/boost/accumulators/framework/accumulators/external_accumulator.hpp +++ b/include/boost/accumulators/framework/accumulators/external_accumulator.hpp @@ -34,7 +34,7 @@ namespace boost { namespace accumulators { namespace impl template result_type result(Args const &args) const { - return this->extract_(args, args[parameter::keyword::get() | 0]); + return this->extract_(args, args[parameter::keyword::instance | 0]); } private: diff --git a/include/boost/accumulators/framework/accumulators/reference_accumulator.hpp b/include/boost/accumulators/framework/accumulators/reference_accumulator.hpp index bf4252c..e50a751 100644 --- a/include/boost/accumulators/framework/accumulators/reference_accumulator.hpp +++ b/include/boost/accumulators/framework/accumulators/reference_accumulator.hpp @@ -31,7 +31,7 @@ namespace impl template reference_accumulator_impl(Args const &args) - : ref(args[parameter::keyword::get()]) + : ref(args[parameter::keyword::instance]) { } diff --git a/include/boost/accumulators/framework/accumulators/value_accumulator.hpp b/include/boost/accumulators/framework/accumulators/value_accumulator.hpp index 02bf7f3..148549b 100644 --- a/include/boost/accumulators/framework/accumulators/value_accumulator.hpp +++ b/include/boost/accumulators/framework/accumulators/value_accumulator.hpp @@ -30,7 +30,7 @@ namespace impl template value_accumulator_impl(Args const &args) - : val(args[parameter::keyword::get()]) + : val(args[parameter::keyword::instance]) { } diff --git a/include/boost/accumulators/framework/depends_on.hpp b/include/boost/accumulators/framework/depends_on.hpp index 008f121..dd2b637 100644 --- a/include/boost/accumulators/framework/depends_on.hpp +++ b/include/boost/accumulators/framework/depends_on.hpp @@ -266,11 +266,18 @@ namespace boost { namespace accumulators template typename meta::make_acc_list::type - make_acc_list(Sequence const &seq, Args const &args) + make_acc_list(Sequence &seq, Args const &args) { return meta::make_acc_list::call(args, fusion::begin(seq), fusion::end(seq)); } + template + typename meta::make_acc_list::type + make_acc_list(Sequence const &seq, Args const &args) + { + return meta::make_acc_list::call(args, fusion::begin(seq), fusion::end(seq)); + } + /////////////////////////////////////////////////////////////////////////// // checked_as_weighted_feature template diff --git a/include/boost/accumulators/framework/extractor.hpp b/include/boost/accumulators/framework/extractor.hpp index 98281ce..1697944 100644 --- a/include/boost/accumulators/framework/extractor.hpp +++ b/include/boost/accumulators/framework/extractor.hpp @@ -8,6 +8,7 @@ #ifndef BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005 #define BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005 +#include #include #include #include @@ -15,11 +16,17 @@ #include #include #include +#include #include #include +#include +#include #include -#include +#include +#include #include +#include +#include #include #include #include @@ -33,14 +40,24 @@ namespace detail struct accumulator_set_result { typedef typename as_feature::type feature_type; - typedef typename mpl::apply::type::result_type type; + typedef typename mpl::apply< + typename boost::remove_const< + typename boost::remove_reference::type + >::type + , feature_type + >::type::result_type type; }; template struct argument_pack_result : accumulator_set_result< - typename remove_reference< - typename parameter::binding::type + typename boost::remove_reference< + typename parameter::binding< + typename boost::remove_const< + typename boost::remove_reference::type + >::type + , tag::accumulator + >::type >::type , Feature > @@ -147,6 +164,8 @@ struct extractor , _ ) +#undef BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP + #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED /// \overload /// @@ -156,6 +175,8 @@ struct extractor #endif }; +}} // namespace boost::accumulators + /// INTERNAL ONLY /// #define BOOST_ACCUMULATORS_ARRAY_REM(Array) \ @@ -224,6 +245,4 @@ struct extractor , (3, (Tag, Feature, ParamSeq)) \ ) -}} // namespace boost::accumulators - #endif diff --git a/include/boost/accumulators/framework/parameters/accumulator.hpp b/include/boost/accumulators/framework/parameters/accumulator.hpp index 525ebb3..675a3a3 100644 --- a/include/boost/accumulators/framework/parameters/accumulator.hpp +++ b/include/boost/accumulators/framework/parameters/accumulator.hpp @@ -8,13 +8,13 @@ #ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005 #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_ACCUMULATOR_HPP_EAN_31_10_2005 -#include +#include #include namespace boost { namespace accumulators { -BOOST_PARAMETER_KEYWORD(tag, accumulator) +BOOST_PARAMETER_NAME((accumulator, tag) accumulator) BOOST_ACCUMULATORS_IGNORE_GLOBAL(accumulator) }} // namespace boost::accumulators diff --git a/include/boost/accumulators/framework/parameters/sample.hpp b/include/boost/accumulators/framework/parameters/sample.hpp index 8b227eb..39afe2b 100644 --- a/include/boost/accumulators/framework/parameters/sample.hpp +++ b/include/boost/accumulators/framework/parameters/sample.hpp @@ -8,13 +8,13 @@ #ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005 #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_SAMPLE_HPP_EAN_31_10_2005 -#include +#include #include namespace boost { namespace accumulators { -BOOST_PARAMETER_KEYWORD(tag, sample) +BOOST_PARAMETER_NAME((sample, tag) sample) BOOST_ACCUMULATORS_IGNORE_GLOBAL(sample) }} // namespace boost::accumulators diff --git a/include/boost/accumulators/framework/parameters/weight.hpp b/include/boost/accumulators/framework/parameters/weight.hpp index f36016f..e9c26bf 100644 --- a/include/boost/accumulators/framework/parameters/weight.hpp +++ b/include/boost/accumulators/framework/parameters/weight.hpp @@ -8,14 +8,14 @@ #ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005 #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHT_HPP_EAN_31_10_2005 -#include +#include #include namespace boost { namespace accumulators { // The weight of a single sample -BOOST_PARAMETER_KEYWORD(tag, weight) +BOOST_PARAMETER_NAME((weight, tag) weight) BOOST_ACCUMULATORS_IGNORE_GLOBAL(weight) }} // namespace boost::accumulators diff --git a/include/boost/accumulators/framework/parameters/weights.hpp b/include/boost/accumulators/framework/parameters/weights.hpp index 6beae61..ab1948a 100644 --- a/include/boost/accumulators/framework/parameters/weights.hpp +++ b/include/boost/accumulators/framework/parameters/weights.hpp @@ -8,14 +8,14 @@ #ifndef BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005 #define BOOST_ACCUMULATORS_FRAMEWORK_PARAMETERS_WEIGHTS_HPP_EAN_28_10_2005 -#include +#include #include namespace boost { namespace accumulators { // The weight accumulator -BOOST_PARAMETER_KEYWORD(tag, weights) +BOOST_PARAMETER_NAME((weights, tag) weights) BOOST_ACCUMULATORS_IGNORE_GLOBAL(weights) }} // namespace boost::accumulators diff --git a/include/boost/accumulators/statistics/count.hpp b/include/boost/accumulators/statistics/count.hpp index 6d30b41..b83435a 100644 --- a/include/boost/accumulators/statistics/count.hpp +++ b/include/boost/accumulators/statistics/count.hpp @@ -43,6 +43,13 @@ namespace impl return this->cnt; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & cnt; + } + private: std::size_t cnt; }; diff --git a/include/boost/accumulators/statistics/covariance.hpp b/include/boost/accumulators/statistics/covariance.hpp index b3030b9..d80a85e 100644 --- a/include/boost/accumulators/statistics/covariance.hpp +++ b/include/boost/accumulators/statistics/covariance.hpp @@ -152,6 +152,13 @@ namespace impl return this->cov_; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & cov_; + } + private: result_type cov_; }; diff --git a/include/boost/accumulators/statistics/density.hpp b/include/boost/accumulators/statistics/density.hpp index 88ca17d..32b4806 100644 --- a/include/boost/accumulators/statistics/density.hpp +++ b/include/boost/accumulators/statistics/density.hpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include namespace boost { namespace accumulators { @@ -184,6 +186,20 @@ namespace impl return make_iterator_range(this->histogram); } + // make this accumulator serializeable + // TODO split to save/load and check on parameters provided in ctor + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & cache_size; + ar & cache; + ar & num_bins; + ar & samples_in_bin; + ar & bin_positions; + ar & histogram; + ar & is_dirty; + } + private: std::size_t cache_size; // number of cached samples array_type cache; // cache to store the first cache_size samples diff --git a/include/boost/accumulators/statistics/extended_p_square.hpp b/include/boost/accumulators/statistics/extended_p_square.hpp index e6cc8dc..6990050 100644 --- a/include/boost/accumulators/statistics/extended_p_square.hpp +++ b/include/boost/accumulators/statistics/extended_p_square.hpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace boost { namespace accumulators { @@ -236,6 +237,19 @@ namespace impl ); } + public: + // make this accumulator serializeable + // TODO: do we need to split to load/save and verify that the parameters did not change? + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & probabilities; + ar & heights; + ar & actual_positions; + ar & desired_positions; + ar & positions_increments; + } + private: array_type probabilities; // the quantile probabilities array_type heights; // q_i diff --git a/include/boost/accumulators/statistics/extended_p_square_quantile.hpp b/include/boost/accumulators/statistics/extended_p_square_quantile.hpp index a17843d..f57304c 100644 --- a/include/boost/accumulators/statistics/extended_p_square_quantile.hpp +++ b/include/boost/accumulators/statistics/extended_p_square_quantile.hpp @@ -185,6 +185,17 @@ namespace impl } } + + public: + // make this accumulator serializeable + // TODO: do we need to split to load/save and verify that the parameters did not change? + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & probabilities; + ar & probability; + } + private: array_type probabilities; diff --git a/include/boost/accumulators/statistics/kurtosis.hpp b/include/boost/accumulators/statistics/kurtosis.hpp index 76c93d3..9ff9ecd 100644 --- a/include/boost/accumulators/statistics/kurtosis.hpp +++ b/include/boost/accumulators/statistics/kurtosis.hpp @@ -63,6 +63,10 @@ namespace impl * ( accumulators::moment<2>(args) - mean(args) * mean(args) ) ) - 3.; } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; } // namespace impl diff --git a/include/boost/accumulators/statistics/max.hpp b/include/boost/accumulators/statistics/max.hpp index 820f659..15033e6 100644 --- a/include/boost/accumulators/statistics/max.hpp +++ b/include/boost/accumulators/statistics/max.hpp @@ -48,6 +48,13 @@ namespace impl return this->max_; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & max_; + } + private: Sample max_; }; diff --git a/include/boost/accumulators/statistics/mean.hpp b/include/boost/accumulators/statistics/mean.hpp index 4788837..c6df176 100644 --- a/include/boost/accumulators/statistics/mean.hpp +++ b/include/boost/accumulators/statistics/mean.hpp @@ -41,6 +41,10 @@ namespace impl extractor sum; return numeric::fdiv(sum(args), count(args)); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; template @@ -71,6 +75,12 @@ namespace impl return this->mean; } + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & mean; + } + private: result_type mean; }; diff --git a/include/boost/accumulators/statistics/median.hpp b/include/boost/accumulators/statistics/median.hpp index d361c6d..4d4118d 100644 --- a/include/boost/accumulators/statistics/median.hpp +++ b/include/boost/accumulators/statistics/median.hpp @@ -48,6 +48,10 @@ namespace impl { return p_square_quantile_for_median(args); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; /////////////////////////////////////////////////////////////////////////////// // with_density_median_impl @@ -105,6 +109,16 @@ namespace impl return this->median; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum; + ar & is_dirty; + ar & median; + } + + private: mutable float_type sum; mutable bool is_dirty; @@ -160,6 +174,15 @@ namespace impl return this->median; } + + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & is_dirty; + ar & median; + } + private: mutable bool is_dirty; diff --git a/include/boost/accumulators/statistics/min.hpp b/include/boost/accumulators/statistics/min.hpp index 83943bd..bf30b79 100644 --- a/include/boost/accumulators/statistics/min.hpp +++ b/include/boost/accumulators/statistics/min.hpp @@ -48,6 +48,13 @@ namespace impl return this->min_; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & min_; + } + private: Sample min_; }; diff --git a/include/boost/accumulators/statistics/moment.hpp b/include/boost/accumulators/statistics/moment.hpp index 3dabd47..9ba1e4c 100644 --- a/include/boost/accumulators/statistics/moment.hpp +++ b/include/boost/accumulators/statistics/moment.hpp @@ -75,6 +75,13 @@ namespace impl return numeric::fdiv(this->sum, count(args)); } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum; + } + private: Sample sum; }; diff --git a/include/boost/accumulators/statistics/p_square_cumul_dist.hpp b/include/boost/accumulators/statistics/p_square_cumul_dist.hpp index 5069283..daa66f9 100644 --- a/include/boost/accumulators/statistics/p_square_cumul_dist.hpp +++ b/include/boost/accumulators/statistics/p_square_cumul_dist.hpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include namespace boost { namespace accumulators { @@ -204,6 +206,20 @@ namespace impl //return histogram; return make_iterator_range(this->histogram); } + + // make this accumulator serializeable + // TODO split to save/load and check on parameters provided in ctor + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & num_cells; + ar & heights; + ar & actual_positions; + ar & desired_positions; + ar & positions_increments; + ar & histogram; + ar & is_dirty; + } private: std::size_t num_cells; // number of cells b diff --git a/include/boost/accumulators/statistics/p_square_quantile.hpp b/include/boost/accumulators/statistics/p_square_quantile.hpp index 636fea7..d87c1b3 100644 --- a/include/boost/accumulators/statistics/p_square_quantile.hpp +++ b/include/boost/accumulators/statistics/p_square_quantile.hpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace boost { namespace accumulators { @@ -61,7 +62,7 @@ namespace impl template p_square_quantile_impl(Args const &args) - : p(is_same::value ? 0.5 : args[quantile_probability | 0.5]) + : p(is_same::value ? float_type(0.5) : args[quantile_probability | float_type(0.5)]) , heights() , actual_positions() , desired_positions() @@ -69,20 +70,21 @@ namespace impl { for(std::size_t i = 0; i < 5; ++i) { - this->actual_positions[i] = i + 1.; + this->actual_positions[i] = i + float_type(1.); } - this->desired_positions[0] = 1.; - this->desired_positions[1] = 1. + 2. * this->p; - this->desired_positions[2] = 1. + 4. * this->p; - this->desired_positions[3] = 3. + 2. * this->p; - this->desired_positions[4] = 5.; + this->desired_positions[0] = float_type(1.); + this->desired_positions[1] = float_type(1.) + float_type(2.) * this->p; + this->desired_positions[2] = float_type(1.) + float_type(4.) * this->p; + this->desired_positions[3] = float_type(3.) + float_type(2.) * this->p; + this->desired_positions[4] = float_type(5.); - this->positions_increments[0] = 0.; - this->positions_increments[1] = this->p / 2.; + + this->positions_increments[0] = float_type(0.); + this->positions_increments[1] = this->p / float_type(2.); this->positions_increments[2] = this->p; - this->positions_increments[3] = (1. + this->p) / 2.; - this->positions_increments[4] = 1.; + this->positions_increments[3] = (float_type(1.) + this->p) / float_type(2.); + this->positions_increments[4] = float_type(1.); } template @@ -156,7 +158,7 @@ namespace impl 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.)) + if((d >= float_type(1.) && dp > float_type(1.)) || (d <= float_type(-1.) && dm < float_type(-1.))) { short sign_d = static_cast(d / std::abs(d)); @@ -171,11 +173,11 @@ namespace impl else { // use linear formula - if(d > 0) + if(d > float_type(0)) { this->heights[i] += hp; } - if(d < 0) + if(d < float_type(0)) { this->heights[i] -= hm; } @@ -191,6 +193,18 @@ namespace impl return this->heights[2]; } + // make this accumulator serializeable + // TODO: do we need to split to load/save and verify that P did not change? + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & p; + ar & heights; + ar & actual_positions; + ar & desired_positions; + ar & positions_increments; + } + private: float_type p; // the quantile probability p array_type heights; // q_i diff --git a/include/boost/accumulators/statistics/peaks_over_threshold.hpp b/include/boost/accumulators/statistics/peaks_over_threshold.hpp index f04f743..de73c65 100644 --- a/include/boost/accumulators/statistics/peaks_over_threshold.hpp +++ b/include/boost/accumulators/statistics/peaks_over_threshold.hpp @@ -181,6 +181,21 @@ namespace impl return this->fit_parameters_; } + // make this accumulator serializeable + // TODO: do we need to split to load/save and verify that threshold did not change? + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & Nu_; + ar & mu_; + ar & sigma2_; + ar & threshold_; + ar & get<0>(fit_parameters_); + ar & get<1>(fit_parameters_); + ar & get<2>(fit_parameters_); + ar & is_dirty_; + } + private: std::size_t Nu_; // number of samples larger than threshold mutable float_type mu_; // mean of Nu_ largest samples @@ -291,6 +306,20 @@ namespace impl return this->fit_parameters_; } + // make this accumulator serializeable + // TODO: do we need to split to load/save and verify that threshold did not change? + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & mu_; + ar & sigma2_; + ar & threshold_probability_; + ar & get<0>(fit_parameters_); + ar & get<1>(fit_parameters_); + ar & get<2>(fit_parameters_); + ar & is_dirty_; + } + private: mutable float_type mu_; // mean of samples above threshold u mutable float_type sigma2_; // variance of samples above threshold u diff --git a/include/boost/accumulators/statistics/pot_quantile.hpp b/include/boost/accumulators/statistics/pot_quantile.hpp index 470bdba..ecd49f2 100644 --- a/include/boost/accumulators/statistics/pot_quantile.hpp +++ b/include/boost/accumulators/statistics/pot_quantile.hpp @@ -80,6 +80,13 @@ namespace impl , -xi_hat ) - 1.)); } + + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sign_; + } private: short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result diff --git a/include/boost/accumulators/statistics/pot_tail_mean.hpp b/include/boost/accumulators/statistics/pot_tail_mean.hpp index a78043f..96f4dc1 100644 --- a/include/boost/accumulators/statistics/pot_tail_mean.hpp +++ b/include/boost/accumulators/statistics/pot_tail_mean.hpp @@ -90,6 +90,14 @@ namespace impl is_same::value ? args[quantile_probability] : 1. - args[quantile_probability] , -xi_hat); } + + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sign_; + } + private: short sign_; // if the fit parameters from the mirrored left tail extreme values are used, mirror back the result }; diff --git a/include/boost/accumulators/statistics/rolling_count.hpp b/include/boost/accumulators/statistics/rolling_count.hpp index 1e34f76..803f1b7 100644 --- a/include/boost/accumulators/statistics/rolling_count.hpp +++ b/include/boost/accumulators/statistics/rolling_count.hpp @@ -40,6 +40,10 @@ namespace impl { return static_cast(rolling_window_plus1(args).size()) - is_rolling_window_plus1_full(args); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; } // namespace impl diff --git a/include/boost/accumulators/statistics/rolling_mean.hpp b/include/boost/accumulators/statistics/rolling_mean.hpp index 1439da1..bd5494c 100644 --- a/include/boost/accumulators/statistics/rolling_mean.hpp +++ b/include/boost/accumulators/statistics/rolling_mean.hpp @@ -43,6 +43,10 @@ namespace boost { namespace accumulators { return numeric::fdiv(rolling_sum(args), rolling_count(args)); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; /////////////////////////////////////////////////////////////////////////////// @@ -67,12 +71,18 @@ namespace boost { namespace accumulators { if(is_rolling_window_plus1_full(args)) { - mean_ += numeric::fdiv(args[sample]-rolling_window_plus1(args).front(),rolling_count(args)); + if (rolling_window_plus1(args).front() > args[sample]) + mean_ -= numeric::fdiv(rolling_window_plus1(args).front()-args[sample],rolling_count(args)); + else if (rolling_window_plus1(args).front() < args[sample]) + mean_ += numeric::fdiv(args[sample]-rolling_window_plus1(args).front(),rolling_count(args)); } else { result_type prev_mean = mean_; - mean_ += numeric::fdiv(args[sample]-prev_mean,rolling_count(args)); + if (prev_mean > args[sample]) + mean_ -= numeric::fdiv(prev_mean-args[sample],rolling_count(args)); + else if (prev_mean < args[sample]) + mean_ += numeric::fdiv(args[sample]-prev_mean,rolling_count(args)); } } @@ -81,6 +91,13 @@ namespace boost { namespace accumulators { return mean_; } + + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & mean_; + } private: @@ -176,4 +193,4 @@ namespace boost { namespace accumulators }; }} // namespace boost::accumulators -#endif \ No newline at end of file +#endif diff --git a/include/boost/accumulators/statistics/rolling_moment.hpp b/include/boost/accumulators/statistics/rolling_moment.hpp index f172cee..28ea5b5 100644 --- a/include/boost/accumulators/statistics/rolling_moment.hpp +++ b/include/boost/accumulators/statistics/rolling_moment.hpp @@ -58,6 +58,13 @@ namespace impl return numeric::fdiv(this->sum_, rolling_count(args)); } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum_; + } + private: result_type sum_; }; diff --git a/include/boost/accumulators/statistics/rolling_sum.hpp b/include/boost/accumulators/statistics/rolling_sum.hpp index bbb7a8e..c511460 100644 --- a/include/boost/accumulators/statistics/rolling_sum.hpp +++ b/include/boost/accumulators/statistics/rolling_sum.hpp @@ -51,6 +51,13 @@ namespace impl return this->sum_; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum_; + } + private: Sample sum_; }; diff --git a/include/boost/accumulators/statistics/rolling_variance.hpp b/include/boost/accumulators/statistics/rolling_variance.hpp index 33b3922..249d5c1 100644 --- a/include/boost/accumulators/statistics/rolling_variance.hpp +++ b/include/boost/accumulators/statistics/rolling_variance.hpp @@ -62,6 +62,10 @@ namespace impl if (nr_samples < 2) return result_type(); return nr_samples*(rolling_moment<2>(args) - mean*mean)/(nr_samples-1); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; //! Iterative calculation of the rolling variance. @@ -138,6 +142,14 @@ namespace impl if (nr_samples < 2) return result_type(); return numeric::fdiv(sum_of_squares_,(nr_samples-1)); } + + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & previous_mean_; + ar & sum_of_squares_; + } private: diff --git a/include/boost/accumulators/statistics/rolling_window.hpp b/include/boost/accumulators/statistics/rolling_window.hpp index 2e0a334..a43ecdf 100644 --- a/include/boost/accumulators/statistics/rolling_window.hpp +++ b/include/boost/accumulators/statistics/rolling_window.hpp @@ -21,6 +21,45 @@ #include #include #include +#include + +namespace boost { namespace serialization { + +// implement serialization for boost::circular_buffer +template +void save(Archive& ar, const circular_buffer& b, const unsigned int /* version */) +{ + typename circular_buffer::size_type size = b.size(); + ar << b.capacity(); + ar << size; + const typename circular_buffer::const_array_range one = b.array_one(); + const typename circular_buffer::const_array_range two = b.array_two(); + ar.save_binary(one.first, one.second*sizeof(T)); + ar.save_binary(two.first, two.second*sizeof(T)); +} + +template +void load(Archive& ar, circular_buffer& b, const unsigned int /* version */) +{ + typename circular_buffer::capacity_type capacity; + typename circular_buffer::size_type size; + ar >> capacity; + b.set_capacity(capacity); + ar >> size; + b.clear(); + const typename circular_buffer::pointer buff = new T[size*sizeof(T)]; + ar.load_binary(buff, size*sizeof(T)); + b.insert(b.begin(), buff, buff+size); + delete[] buff; +} + +template +inline void serialize(Archive & ar, circular_buffer& b, const unsigned int version) +{ + split_free(ar, b, version); +} + +} } // end namespace boost::serialization namespace boost { namespace accumulators { @@ -83,6 +122,12 @@ namespace impl return result_type(this->buffer_.begin(), this->buffer_.end()); } + template + void serialize(Archive & ar, const unsigned int version) + { + ar & buffer_; + } + private: circular_buffer buffer_; }; @@ -112,6 +157,10 @@ namespace impl { return rolling_window_plus1(args).advance_begin(is_rolling_window_plus1_full(args)); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; } // namespace impl diff --git a/include/boost/accumulators/statistics/skewness.hpp b/include/boost/accumulators/statistics/skewness.hpp index c383ec4..9c9c376 100644 --- a/include/boost/accumulators/statistics/skewness.hpp +++ b/include/boost/accumulators/statistics/skewness.hpp @@ -65,6 +65,10 @@ namespace impl * std::sqrt( accumulators::moment<2>(args) - mean(args) * mean(args) ) ); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; } // namespace impl diff --git a/include/boost/accumulators/statistics/sum.hpp b/include/boost/accumulators/statistics/sum.hpp index 126ce24..7e507cc 100644 --- a/include/boost/accumulators/statistics/sum.hpp +++ b/include/boost/accumulators/statistics/sum.hpp @@ -51,8 +51,13 @@ namespace impl return this->sum; } - private: + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum; + } + private: Sample sum; }; diff --git a/include/boost/accumulators/statistics/sum_kahan.hpp b/include/boost/accumulators/statistics/sum_kahan.hpp index 97ade18..b5e9092 100644 --- a/include/boost/accumulators/statistics/sum_kahan.hpp +++ b/include/boost/accumulators/statistics/sum_kahan.hpp @@ -66,6 +66,14 @@ struct sum_kahan_impl return this->sum; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum; + ar & compensation; + } + private: Sample sum; Sample compensation; diff --git a/include/boost/accumulators/statistics/tail.hpp b/include/boost/accumulators/statistics/tail.hpp index be6cdee..154a30c 100644 --- a/include/boost/accumulators/statistics/tail.hpp +++ b/include/boost/accumulators/statistics/tail.hpp @@ -268,6 +268,17 @@ namespace impl std::vector const &samples; }; + public: + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & is_sorted; + ar & indices; + ar & samples; + } + + private: mutable bool is_sorted; mutable std::vector indices; std::vector samples; diff --git a/include/boost/accumulators/statistics/tail_mean.hpp b/include/boost/accumulators/statistics/tail_mean.hpp index 67dae37..f56606d 100644 --- a/include/boost/accumulators/statistics/tail_mean.hpp +++ b/include/boost/accumulators/statistics/tail_mean.hpp @@ -88,6 +88,10 @@ namespace impl - numeric::fdiv(n, count(args)) ); } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; /////////////////////////////////////////////////////////////////////////////// @@ -159,6 +163,10 @@ namespace impl } } } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; } // namespace impl diff --git a/include/boost/accumulators/statistics/tail_quantile.hpp b/include/boost/accumulators/statistics/tail_quantile.hpp index 9ff56b5..ed1f6e6 100644 --- a/include/boost/accumulators/statistics/tail_quantile.hpp +++ b/include/boost/accumulators/statistics/tail_quantile.hpp @@ -98,6 +98,10 @@ namespace impl } } } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; } // namespace impl diff --git a/include/boost/accumulators/statistics/tail_variate.hpp b/include/boost/accumulators/statistics/tail_variate.hpp index a9fc7d2..6885ece 100644 --- a/include/boost/accumulators/statistics/tail_variate.hpp +++ b/include/boost/accumulators/statistics/tail_variate.hpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace boost { namespace accumulators { @@ -69,6 +70,14 @@ namespace impl ); } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & variates; + } + + private: std::vector variates; }; diff --git a/include/boost/accumulators/statistics/tail_variate_means.hpp b/include/boost/accumulators/statistics/tail_variate_means.hpp index a97eab5..efe9f7c 100644 --- a/include/boost/accumulators/statistics/tail_variate_means.hpp +++ b/include/boost/accumulators/statistics/tail_variate_means.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef _MSC_VER # pragma warning(push) @@ -145,6 +146,13 @@ namespace impl return make_iterator_range(this->tail_means_); } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & tail_means_; + } + private: mutable array_type tail_means_; diff --git a/include/boost/accumulators/statistics/variance.hpp b/include/boost/accumulators/statistics/variance.hpp index baac556..9db858d 100644 --- a/include/boost/accumulators/statistics/variance.hpp +++ b/include/boost/accumulators/statistics/variance.hpp @@ -53,6 +53,10 @@ namespace impl result_type tmp = mean(args); return accumulators::moment<2>(args) - tmp * tmp; } + + // serialization is done by accumulators it depends on + template + void serialize(Archive & ar, const unsigned int file_version) {} }; //! Iterative calculation of variance. @@ -113,6 +117,13 @@ namespace impl return this->variance; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & variance; + } + private: result_type variance; }; diff --git a/include/boost/accumulators/statistics/weighted_covariance.hpp b/include/boost/accumulators/statistics/weighted_covariance.hpp index 25d613c..e423a22 100644 --- a/include/boost/accumulators/statistics/weighted_covariance.hpp +++ b/include/boost/accumulators/statistics/weighted_covariance.hpp @@ -97,6 +97,13 @@ namespace impl return this->cov_; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & cov_; + } + private: result_type cov_; }; diff --git a/include/boost/accumulators/statistics/weighted_density.hpp b/include/boost/accumulators/statistics/weighted_density.hpp index 1407368..6b5a0ee 100644 --- a/include/boost/accumulators/statistics/weighted_density.hpp +++ b/include/boost/accumulators/statistics/weighted_density.hpp @@ -23,6 +23,8 @@ #include #include #include // for named parameters density_cache_size and density_num_bins +#include +#include namespace boost { namespace accumulators { @@ -171,6 +173,20 @@ namespace impl return make_iterator_range(this->histogram); } + // make this accumulator serializeable + // TODO split to save/load and check on parameters provided in ctor + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & cache_size; + ar & cache; + ar & num_bins; + ar & samples_in_bin; + ar & bin_positions; + ar & histogram; + ar & is_dirty; + } + private: std::size_t cache_size; // number of cached samples histogram_type cache; // cache to store the first cache_size samples with their weights as std::pair diff --git a/include/boost/accumulators/statistics/weighted_extended_p_square.hpp b/include/boost/accumulators/statistics/weighted_extended_p_square.hpp index ac857e0..f88e9b9 100644 --- a/include/boost/accumulators/statistics/weighted_extended_p_square.hpp +++ b/include/boost/accumulators/statistics/weighted_extended_p_square.hpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace boost { namespace accumulators { @@ -251,6 +252,17 @@ namespace impl ); } + // make this accumulator serializeable + // TODO: do we need to split to load/save and verify that the parameters did not change? + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & probabilities; + ar & heights; + ar & actual_positions; + ar & desired_positions; + } + private: array_type probabilities; // the quantile probabilities array_type heights; // q_i diff --git a/include/boost/accumulators/statistics/weighted_mean.hpp b/include/boost/accumulators/statistics/weighted_mean.hpp index a80ef09..1ddce8d 100644 --- a/include/boost/accumulators/statistics/weighted_mean.hpp +++ b/include/boost/accumulators/statistics/weighted_mean.hpp @@ -97,6 +97,13 @@ namespace impl return this->mean; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & mean; + } + private: result_type mean; }; diff --git a/include/boost/accumulators/statistics/weighted_median.hpp b/include/boost/accumulators/statistics/weighted_median.hpp index ed7cadb..22224a8 100644 --- a/include/boost/accumulators/statistics/weighted_median.hpp +++ b/include/boost/accumulators/statistics/weighted_median.hpp @@ -106,6 +106,15 @@ namespace impl return this->median; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum; + ar & is_dirty; + ar & median; + } + private: mutable float_type sum; mutable bool is_dirty; @@ -162,6 +171,15 @@ namespace impl return this->median; } + + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & is_dirty; + ar & median; + } + private: mutable bool is_dirty; mutable float_type median; diff --git a/include/boost/accumulators/statistics/weighted_moment.hpp b/include/boost/accumulators/statistics/weighted_moment.hpp index 011701c..5b61290 100644 --- a/include/boost/accumulators/statistics/weighted_moment.hpp +++ b/include/boost/accumulators/statistics/weighted_moment.hpp @@ -60,6 +60,13 @@ namespace impl return numeric::fdiv(this->sum, sum_of_weights(args)); } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sum; + } + private: weighted_sample sum; }; diff --git a/include/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp b/include/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp index ce750ed..f8a44d6 100644 --- a/include/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp +++ b/include/boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp @@ -221,6 +221,19 @@ namespace impl return make_iterator_range(this->histogram); } + // make this accumulator serializeable + // TODO split to save/load and check on parameters provided in ctor + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & num_cells; + ar & heights; + ar & actual_positions; + ar & desired_positions; + ar & histogram; + ar & is_dirty; + } + private: std::size_t num_cells; // number of cells b array_type heights; // q_i diff --git a/include/boost/accumulators/statistics/weighted_p_square_quantile.hpp b/include/boost/accumulators/statistics/weighted_p_square_quantile.hpp index 2ebc7b1..fecd993 100644 --- a/include/boost/accumulators/statistics/weighted_p_square_quantile.hpp +++ b/include/boost/accumulators/statistics/weighted_p_square_quantile.hpp @@ -208,6 +208,17 @@ namespace impl { return this->heights[2]; } + // make this accumulator serializeable + // TODO split to save/load and check on parameters provided in ctor + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & p; + ar & heights; + ar & actual_positions; + ar & desired_positions; + } + private: float_type p; // the quantile probability p array_type heights; // q_i diff --git a/include/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp b/include/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp index 418b38c..f3dc327 100644 --- a/include/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp +++ b/include/boost/accumulators/statistics/weighted_peaks_over_threshold.hpp @@ -109,6 +109,19 @@ namespace impl return this->fit_parameters_; } + // make this accumulator serializeable + // TODO: do we need to split to load/save and verify that threshold did not change? + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & sign_; + ar & mu_; + ar & sigma2_; + ar & threshold_; + ar & fit_parameters_; + ar & is_dirty_; + } + private: short sign_; // for left tail fitting, mirror the extreme values mutable float_type mu_; // mean of samples above threshold diff --git a/include/boost/accumulators/statistics/weighted_sum.hpp b/include/boost/accumulators/statistics/weighted_sum.hpp index 2715390..41091f8 100644 --- a/include/boost/accumulators/statistics/weighted_sum.hpp +++ b/include/boost/accumulators/statistics/weighted_sum.hpp @@ -55,6 +55,13 @@ namespace impl return this->weighted_sum_; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & weighted_sum_; + } + private: weighted_sample weighted_sum_; diff --git a/include/boost/accumulators/statistics/weighted_sum_kahan.hpp b/include/boost/accumulators/statistics/weighted_sum_kahan.hpp index fbb0303..5ee5250 100644 --- a/include/boost/accumulators/statistics/weighted_sum_kahan.hpp +++ b/include/boost/accumulators/statistics/weighted_sum_kahan.hpp @@ -68,6 +68,14 @@ namespace impl return this->weighted_sum_; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & weighted_sum_; + ar & compensation; + } + private: weighted_sample weighted_sum_; weighted_sample compensation; diff --git a/include/boost/accumulators/statistics/weighted_tail_variate_means.hpp b/include/boost/accumulators/statistics/weighted_tail_variate_means.hpp index b113310..f096a93 100644 --- a/include/boost/accumulators/statistics/weighted_tail_variate_means.hpp +++ b/include/boost/accumulators/statistics/weighted_tail_variate_means.hpp @@ -179,6 +179,13 @@ namespace impl return make_iterator_range(this->tail_means_); } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & tail_means_; + } + private: mutable array_type tail_means_; diff --git a/include/boost/accumulators/statistics/weighted_variance.hpp b/include/boost/accumulators/statistics/weighted_variance.hpp index bc199af..f7d2b6e 100644 --- a/include/boost/accumulators/statistics/weighted_variance.hpp +++ b/include/boost/accumulators/statistics/weighted_variance.hpp @@ -103,6 +103,13 @@ namespace impl return this->weighted_variance; } + // make this accumulator serializeable + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & weighted_variance; + } + private: result_type weighted_variance; }; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 56cab5d..6d2dbf0 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -24,9 +24,11 @@ project # MSVC's iterator debugging causes some tests to run forever. msvc:off intel-win:off + "-Wno-deprecated-declarations" + /boost/serialization ; -test-suite "accumulators" +alias accumulators_regular_tests : [ run count.cpp ] [ run covariance.cpp ] [ run droppable.cpp ] @@ -41,21 +43,20 @@ test-suite "accumulators" [ run median.cpp ] [ run min.cpp ] [ run moment.cpp ] - [ run pot_quantile.cpp ] [ run p_square_cumul_dist.cpp ] [ run p_square_quantile.cpp ] [ run reference.cpp ] [ run rolling_count.cpp ] [ run rolling_sum.cpp ] [ run rolling_mean.cpp ] + [ run rolling_variance.cpp ] + [ run rolling_moment.cpp ] [ run skewness.cpp ] [ run sum.cpp ] [ run sum_kahan.cpp ] [ run tail.cpp ] [ run tail_mean.cpp ] [ run tail_quantile.cpp ] - [ run tail_variate_means.cpp ] - [ run valarray.cpp ] [ run variance.cpp ] [ run vector.cpp ] [ run weighted_covariance.cpp ] @@ -70,9 +71,69 @@ test-suite "accumulators" [ run weighted_sum.cpp ] [ run weighted_sum_kahan.cpp ] [ run weighted_variance.cpp ] + ; + +alias accumulators_test_valarray + : + : linux + clang +# TODO: Find the correct attribute that detects libc++. + ; + +alias accumulators_test_valarray + : + : darwin + ; + +alias accumulators_test_valarray + : [ run valarray.cpp ] + ; + +alias accumulators_test_tail_variate_means + : + : msvc + 14.0 + ; + +alias accumulators_test_tail_variate_means + : [ run tail_variate_means.cpp ] + ; + +alias accumulators_tests_pot_quantile_and_weighted_tail + : + : linux + gcc + 4.4.7 + ; + +alias accumulators_tests_pot_quantile_and_weighted_tail + : [ run pot_quantile.cpp ] [ run weighted_pot_quantile.cpp ] [ run weighted_tail_mean.cpp ] [ run weighted_tail_quantile.cpp ] - [ run weighted_tail_variate_means.cpp ] + ; + +alias accumulators_test_weighted_tail_variate_means + : + : linux + gcc + 4.4.7 + ; +alias accumulators_test_weighted_tail_variate_means + : + : msvc + 14.0 + ; + +alias accumulators_test_weighted_tail_variate_means + : [ run weighted_tail_variate_means.cpp ] + ; + +test-suite "accumulators" + : accumulators_regular_tests + accumulators_test_valarray + accumulators_test_tail_variate_means + accumulators_tests_pot_quantile_and_weighted_tail + accumulators_test_weighted_tail_variate_means ; diff --git a/test/count.cpp b/test/count.cpp index 01d48a5..e2f4436 100644 --- a/test/count.cpp +++ b/test/count.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -35,6 +38,31 @@ void test_stat() BOOST_CHECK_EQUAL(5u, count(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + { + accumulator_set > acc; + acc(1); + acc(1); + acc(1); + acc(1); + BOOST_CHECK_EQUAL(4u, count(acc)); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > acc; + BOOST_CHECK_EQUAL(0u, count(acc)); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(4u, count(acc)); + +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -43,6 +71,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("count test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/covariance.cpp b/test/covariance.cpp index 6a7fbec..abdbc9e 100644 --- a/test/covariance.cpp +++ b/test/covariance.cpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -88,6 +91,36 @@ void test_stat() BOOST_CHECK_CLOSE((covariance(acc4))(1,1), 0.25, epsilon); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + // tolerance + double epsilon = 1e-6; + { + + accumulator_set > > acc; + acc(1., covariate1 = 2.); + acc(1., covariate1 = 4.); + acc(2., covariate1 = 3.); + acc(6., covariate1 = 1.); + + + BOOST_CHECK_CLOSE((covariance(acc)), -1.75, epsilon); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > > acc; + BOOST_CHECK_CLOSE((covariance(acc)), 0., epsilon); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_CLOSE((covariance(acc)), -1.75, epsilon); + +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -96,6 +129,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("covariance test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/extended_p_square.cpp b/test/extended_p_square.cpp index f3a6320..09f50cf 100644 --- a/test/extended_p_square.cpp +++ b/test/extended_p_square.cpp @@ -15,17 +15,21 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; using namespace boost::accumulators; +typedef accumulator_set > accumulator_t; + /////////////////////////////////////////////////////////////////////////////// // test_stat // void test_stat() { - typedef accumulator_set > accumulator_t; // tolerance double epsilon = 3; @@ -61,6 +65,36 @@ void test_stat() } } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + // tolerance + double epsilon = 3.; + std::vector probs; + probs.push_back(0.75); + { + accumulator_t acc(extended_p_square_probabilities = probs); + // a random number generator + boost::lagged_fibonacci607 rng; + + for (int i=0; i<10000; ++i) + acc(rng()); + + BOOST_CHECK_CLOSE(extended_p_square(acc)[0], probs[0], epsilon); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_t acc(extended_p_square_probabilities = probs); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_CLOSE(extended_p_square(acc)[0], probs[0], epsilon); + +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -69,6 +103,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("extended_p_square test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/extended_p_square_quantile.cpp b/test/extended_p_square_quantile.cpp index e56223b..7d60201 100644 --- a/test/extended_p_square_quantile.cpp +++ b/test/extended_p_square_quantile.cpp @@ -15,21 +15,24 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; using namespace boost::accumulators; +typedef accumulator_set > accumulator_t; +typedef accumulator_set, double > accumulator_t_weighted; +typedef accumulator_set > accumulator_t_quadratic; +typedef accumulator_set, double > accumulator_t_weighted_quadratic; + /////////////////////////////////////////////////////////////////////////////// // test_stat // void test_stat() { - typedef accumulator_set > accumulator_t; - typedef accumulator_set, double > accumulator_t_weighted; - typedef accumulator_set > accumulator_t_quadratic; - typedef accumulator_set, double > accumulator_t_weighted_quadratic; - // tolerance double epsilon = 1; @@ -88,6 +91,74 @@ void test_stat() } } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + + // tolerance + double epsilon = 1.; + + // a random number generator + boost::lagged_fibonacci607 rng; + + std::vector probs; + probs.push_back(0.990); + probs.push_back(0.991); + probs.push_back(0.992); + probs.push_back(0.993); + probs.push_back(0.994); + probs.push_back(0.995); + probs.push_back(0.996); + probs.push_back(0.997); + probs.push_back(0.998); + probs.push_back(0.999); + + { + accumulator_t acc(extended_p_square_probabilities = probs); + accumulator_t_weighted acc_weighted(extended_p_square_probabilities = probs); + + for (int i=0; i<10000; ++i) + { + double sample = rng(); + acc(sample); + acc_weighted(sample, weight = 1.); + } + + BOOST_CHECK_CLOSE( + quantile(acc, quantile_probability = 0.99025) + , 0.99025 + , epsilon + ); + BOOST_CHECK_CLOSE( + quantile(acc_weighted, quantile_probability = 0.99025) + , 0.99025 + , epsilon + ); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + acc_weighted.serialize(oa, 0); + } + + accumulator_t acc(extended_p_square_probabilities = probs); + accumulator_t_weighted acc_weighted(extended_p_square_probabilities = probs); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + acc_weighted.serialize(ia, 0); + BOOST_CHECK_CLOSE( + quantile(acc, quantile_probability = 0.99025) + , 0.99025 + , epsilon + ); + BOOST_CHECK_CLOSE( + quantile(acc_weighted, quantile_probability = 0.99025) + , 0.99025 + , epsilon + ); +} /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -96,6 +167,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("extended_p_square_quantile test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/kurtosis.cpp b/test/kurtosis.cpp index 8283375..92c5cfe 100644 --- a/test/kurtosis.cpp +++ b/test/kurtosis.cpp @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -56,6 +59,34 @@ void test_stat() BOOST_CHECK_CLOSE( kurtosis(acc2), -1.39965397924, 1e-6 ); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + // tolerance + double epsilon = 1e-6; + double kurtosis_value = -1.39965397924; + { + accumulator_set > acc; + acc(2); + acc(7); + acc(4); + acc(9); + acc(3); + BOOST_CHECK_CLOSE( kurtosis(acc), kurtosis_value, epsilon); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + + accumulator_set > acc; + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_CLOSE( kurtosis(acc), kurtosis_value, epsilon); + +} /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -64,6 +95,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("kurtosis test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/max.cpp b/test/max.cpp index 6a6b96c..00a9793 100644 --- a/test/max.cpp +++ b/test/max.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -29,6 +32,27 @@ void test_stat() BOOST_CHECK_EQUAL(2, (max)(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + accumulator_set > acc; + acc(1); + acc(0); + acc(2); + BOOST_CHECK_EQUAL(2u, max(acc)); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > acc; + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(2u, max(acc)); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -37,6 +61,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("max test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/mean.cpp b/test/mean.cpp index b08a2d7..29d4877 100644 --- a/test/mean.cpp +++ b/test/mean.cpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -20,18 +23,18 @@ void assert_is_double(T const &) BOOST_MPL_ASSERT((is_same)); } +typedef accumulator_set > > mean_t; + +typedef accumulator_set(immediate) > > immediate_mean_t; + /////////////////////////////////////////////////////////////////////////////// // test_stat // void test_stat() { - accumulator_set< - int - , stats< - tag::mean - , tag::mean_of_variates - > - > acc, test_acc(sample = 0); + mean_t acc, test_acc(sample = 0); acc(1, covariate1 = 3); BOOST_CHECK_CLOSE(1., mean(acc), 1e-5); @@ -53,13 +56,7 @@ void test_stat() assert_is_double(mean(acc)); - accumulator_set< - int - , stats< - tag::mean(immediate) - , tag::mean_of_variates(immediate) - > - > acc2, test_acc2(sample = 0); + immediate_mean_t acc2, test_acc2(sample = 0); acc2(1, covariate1 = 3); BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5); @@ -79,6 +76,39 @@ void test_stat() assert_is_double(mean(acc2)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + mean_t acc1; + immediate_mean_t acc2; + + acc1(1, covariate1 = 3); + acc1(0, covariate1 = 4); + acc1(2, covariate1 = 8); + acc2(1, covariate1 = 3); + acc2(0, covariate1 = 4); + acc2(2, covariate1 = 8); + BOOST_CHECK_CLOSE(1., mean(acc1), 1e-5); + BOOST_CHECK_CLOSE(5., (accumulators::mean_of_variates(acc1)), 1e-5); + BOOST_CHECK_CLOSE(1., mean(acc2), 1e-5); + BOOST_CHECK_CLOSE(5., (accumulators::mean_of_variates(acc2)), 1e-5); + boost::archive::text_oarchive oa(ss); + acc1.serialize(oa, 0); + acc2.serialize(oa, 0); + } + mean_t acc1; + immediate_mean_t acc2; + boost::archive::text_iarchive ia(ss); + acc1.serialize(ia, 0); + acc2.serialize(ia, 0); + BOOST_CHECK_CLOSE(1., mean(acc1), 1e-5); + BOOST_CHECK_CLOSE(5., (accumulators::mean_of_variates(acc2)), 1e-5); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -87,6 +117,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("mean test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/median.cpp b/test/median.cpp index 697c252..e348393 100644 --- a/test/median.cpp +++ b/test/median.cpp @@ -9,11 +9,19 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; using namespace accumulators; + +typedef accumulator_set > p_square_median_t; +typedef accumulator_set > dist_median_t; +typedef accumulator_set > p_square_dist_median_t; + /////////////////////////////////////////////////////////////////////////////// // test_stat // @@ -25,11 +33,9 @@ void test_stat() boost::normal_distribution<> mean_sigma(mu,1); boost::variate_generator > normal(rng, mean_sigma); - accumulator_set > acc; - accumulator_set > - acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); - accumulator_set > - acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); + p_square_median_t acc; + dist_median_t acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); + p_square_dist_median_t acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); for (std::size_t i=0; i<100000; ++i) { @@ -44,6 +50,52 @@ void test_stat() BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // two random number generators + double mu = 1.; + boost::lagged_fibonacci607 rng; + boost::normal_distribution<> mean_sigma(mu,1); + boost::variate_generator > normal(rng, mean_sigma); + std::stringstream ss; + { + p_square_median_t acc; + dist_median_t acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); + p_square_dist_median_t acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); + + for (std::size_t i=0; i<100000; ++i) + { + double sample = normal(); + acc(sample); + acc_dens(sample); + acc_cdist(sample); + } + + BOOST_CHECK_CLOSE(1., median(acc), 1.); + BOOST_CHECK_CLOSE(1., median(acc_dens), 1.); + BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.); + + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + acc_dens.serialize(oa, 0); + acc_cdist.serialize(oa, 0); + } + + p_square_median_t acc; + dist_median_t acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); + p_square_dist_median_t acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + acc_dens.serialize(ia, 0); + acc_cdist.serialize(ia, 0); + BOOST_CHECK_CLOSE(1., median(acc), 1.); + BOOST_CHECK_CLOSE(1., median(acc_dens), 1.); + BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -52,6 +104,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("median test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/min.cpp b/test/min.cpp index 52ca6ac..614fab4 100644 --- a/test/min.cpp +++ b/test/min.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -29,6 +32,27 @@ void test_stat() BOOST_CHECK_EQUAL(0, (min)(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + accumulator_set > acc; + acc(1); + acc(0); + acc(2); + BOOST_CHECK_EQUAL(0, (min)(acc)); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > acc; + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(0, (min)(acc)); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -37,6 +61,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("min test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/moment.cpp b/test/moment.cpp index b91d0af..44fa2a5 100644 --- a/test/moment.cpp +++ b/test/moment.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -38,6 +41,29 @@ void test_stat() BOOST_CHECK_CLOSE(1106., accumulators::moment<5>(acc2), 1e-5); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + double epsilon = 1e-5; + std::stringstream ss; + { + accumulator_set > > acc; + acc(2); // 4 + acc(4); // 16 + acc(5); // + 25 + // = 45 / 3 = 15 + BOOST_CHECK_CLOSE(15., accumulators::moment<2>(acc), epsilon); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > > acc; + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_CLOSE(15., accumulators::moment<2>(acc), epsilon); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -46,6 +72,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("moment test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/p_square_cumul_dist.cpp b/test/p_square_cumul_dist.cpp index 4bc014d..33e8109 100644 --- a/test/p_square_cumul_dist.cpp +++ b/test/p_square_cumul_dist.cpp @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -34,6 +37,9 @@ double my_erf(double const& x, int const& n = 1000) return sum * 2. / std::sqrt(3.141592653); } +typedef accumulator_set > accumulator_t; +typedef iterator_range >::iterator > histogram_type; + /////////////////////////////////////////////////////////////////////////////// // test_stat // @@ -42,8 +48,6 @@ void test_stat() // tolerance in % double epsilon = 3; - typedef accumulator_set > accumulator_t; - accumulator_t acc(p_square_cumulative_distribution_num_cells = 100); // two random number generators @@ -51,12 +55,11 @@ void test_stat() boost::normal_distribution<> mean_sigma(0,1); boost::variate_generator > normal(rng, mean_sigma); - for (std::size_t i=0; i<100000; ++i) + for (std::size_t i=0; i<1000000; ++i) { acc(normal()); } - typedef iterator_range >::iterator > histogram_type; histogram_type histogram = p_square_cumulative_distribution(acc); for (std::size_t i = 0; i < histogram.size(); ++i) @@ -67,6 +70,45 @@ void test_stat() } } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + // tolerance in % + double epsilon = 3; + { + accumulator_t acc(p_square_cumulative_distribution_num_cells = 100); + + // two random number generators + boost::lagged_fibonacci607 rng; + boost::normal_distribution<> mean_sigma(0,1); + boost::variate_generator > normal(rng, mean_sigma); + + for (std::size_t i=0; i<1000000; ++i) + { + acc(normal()); + } + + histogram_type histogram = p_square_cumulative_distribution(acc); + + BOOST_CHECK_CLOSE(0.5 * (1.0 + my_erf(histogram[25].first / std::sqrt(2.0))), histogram[25].second, epsilon); + BOOST_CHECK_CLOSE(0.5 * (1.0 + my_erf(histogram[50].first / std::sqrt(2.0))), histogram[50].second, epsilon); + BOOST_CHECK_CLOSE(0.5 * (1.0 + my_erf(histogram[75].first / std::sqrt(2.0))), histogram[75].second, epsilon); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_t acc(p_square_cumulative_distribution_num_cells = 100); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + histogram_type histogram = p_square_cumulative_distribution(acc); + BOOST_CHECK_CLOSE(0.5 * (1.0 + my_erf(histogram[25].first / std::sqrt(2.0))), histogram[25].second, epsilon); + BOOST_CHECK_CLOSE(0.5 * (1.0 + my_erf(histogram[50].first / std::sqrt(2.0))), histogram[50].second, epsilon); + BOOST_CHECK_CLOSE(0.5 * (1.0 + my_erf(histogram[75].first / std::sqrt(2.0))), histogram[75].second, epsilon); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -75,6 +117,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("p_square_cumulative_distribution test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/p_square_quantile.cpp b/test/p_square_quantile.cpp index 3f21281..ba67823 100644 --- a/test/p_square_quantile.cpp +++ b/test/p_square_quantile.cpp @@ -14,18 +14,21 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; using namespace boost::accumulators; +typedef accumulator_set > accumulator_t; + /////////////////////////////////////////////////////////////////////////////// // test_stat // void test_stat() { - typedef accumulator_set > accumulator_t; - // tolerance in % double epsilon = 1; @@ -67,6 +70,43 @@ void test_stat() BOOST_CHECK_CLOSE( p_square_quantile(acc8), 0.999, epsilon ); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + // tolerance in % + double epsilon = 1; + // a random number generator + boost::lagged_fibonacci607 rng; + { + accumulator_t acc1(quantile_probability = 0.75 ); + accumulator_t acc2(quantile_probability = 0.999); + + for (int i=0; i<100000; ++i) + { + double sample = rng(); + acc1(sample); + acc2(sample); + } + + BOOST_CHECK_CLOSE(p_square_quantile(acc1), 0.75 , epsilon); + BOOST_CHECK_CLOSE(p_square_quantile(acc2), 0.999, epsilon); + boost::archive::text_oarchive oa(ss); + acc1.serialize(oa, 0); + acc2.serialize(oa, 0); + } + accumulator_t acc1(quantile_probability = 0.75); + accumulator_t acc2(quantile_probability = 0.999); + boost::archive::text_iarchive ia(ss); + acc1.serialize(ia, 0); + acc2.serialize(ia, 0); + BOOST_CHECK_CLOSE(p_square_quantile(acc1), 0.75 , epsilon); + BOOST_CHECK_CLOSE(p_square_quantile(acc2), 0.999, epsilon); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -75,6 +115,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("p_square_quantile test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/p_square_quantile_extended.cpp b/test/p_square_quantile_extended.cpp index 97d3480..debe33c 100644 --- a/test/p_square_quantile_extended.cpp +++ b/test/p_square_quantile_extended.cpp @@ -15,18 +15,21 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; using namespace boost::accumulators; +typedef accumulator_set > accumulator_t; + /////////////////////////////////////////////////////////////////////////////// // test_stat // void test_stat() { - typedef accumulator_set > accumulator_t; - // tolerance double epsilon = 1e-6; @@ -56,6 +59,49 @@ void test_stat() } } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // "persistent" storage + std::stringstream ss; + // tolerance in % + double epsilon = 1; + // a random number generator + boost::lagged_fibonacci607 rng; + + std::vector probs; + probs.push_back(0.001); + probs.push_back(0.01 ); + probs.push_back(0.1 ); + probs.push_back(0.25 ); + probs.push_back(0.5 ); + probs.push_back(0.75 ); + probs.push_back(0.9 ); + probs.push_back(0.99 ); + probs.push_back(0.999); + { + accumulator_t acc(tag::p_square_quantile_extended::probabilities = probs); + + for (int i=0; i<10000; ++i) + acc(rng()); + + for (std::size_t i=0; iadd(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/pot_quantile.cpp b/test/pot_quantile.cpp index 4457071..4e12ad6 100644 --- a/test/pot_quantile.cpp +++ b/test/pot_quantile.cpp @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -83,6 +86,36 @@ void test_stat() BOOST_CHECK_CLOSE( quantile(acc6, quantile_probability = 0.999), 6.908, 3*epsilon ); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // tolerance in % + double epsilon = 1.; + // "persistent" storage + std::stringstream ss; + { + // random number generators + boost::lagged_fibonacci607 rng; + boost::normal_distribution<> mean_sigma(0,1); + boost::variate_generator > normal(rng, mean_sigma); + + accumulator_set(with_threshold_value)> > acc(pot_threshold_value = 3.); + + for (std::size_t i = 0; i < 100000; ++i) + acc(normal()); + + BOOST_CHECK_CLOSE(quantile(acc, quantile_probability = 0.999), 3.090232, 3*epsilon); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set(with_threshold_value)> > acc(pot_threshold_value = 3.); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_CLOSE(quantile(acc, quantile_probability = 0.999), 3.090232, 3*epsilon); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -91,6 +124,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("pot_quantile test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/rolling_count.cpp b/test/rolling_count.cpp index fef132c..a1b6b6f 100644 --- a/test/rolling_count.cpp +++ b/test/rolling_count.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -37,6 +40,30 @@ void test_stat() BOOST_CHECK_EQUAL(3u, rolling_count(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + accumulator_set > acc(tag::rolling_window::window_size = 3); + acc(1); + acc(1); + acc(1); + acc(1); + acc(1); + acc(1); + BOOST_CHECK_EQUAL(3u, rolling_count(acc)); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > acc(tag::rolling_window::window_size = 3); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(3u, rolling_count(acc)); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -45,6 +72,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("rolling count test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/rolling_mean.cpp b/test/rolling_mean.cpp index 54888b9..f8037b4 100644 --- a/test/rolling_mean.cpp +++ b/test/rolling_mean.cpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -54,6 +57,67 @@ test_rolling_mean_test_impl(accumulator_set_type& acc) assert_is_double(rolling_mean(acc)); } +template +void +test_rolling_mean_unsigned_test_impl(accumulator_set_type& acc) +{ + acc(7U); + BOOST_CHECK_CLOSE(7., rolling_mean(acc), 1e-5); + + acc(6U); + BOOST_CHECK_CLOSE(6.5, rolling_mean(acc), 1e-5); + + acc(5U); + BOOST_CHECK_CLOSE(6., rolling_mean(acc), 1e-5); + + acc(4U); + BOOST_CHECK_CLOSE(5.5, rolling_mean(acc), 1e-5); + + acc(3U); + BOOST_CHECK_CLOSE(5., rolling_mean(acc), 1e-5); + + acc(2U); + BOOST_CHECK_CLOSE(4., rolling_mean(acc), 1e-5); + + acc(1U); + BOOST_CHECK_CLOSE(3., rolling_mean(acc), 1e-5); + + assert_is_double(rolling_mean(acc)); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_persistency_impl +// +template +void test_persistency_impl(accumulator_set_type& acc) +{ + std::stringstream ss; + { + acc(1); + acc(2); + acc(3); + acc(4); + acc(5); + acc(6); + acc(7); + BOOST_CHECK_CLOSE(5., rolling_mean(acc), 1e-5); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + // initialize from acc to make sure all values are passed + accumulator_set_type other_acc = acc; + // accumulate more, to make sure that deserialization set the right value + // and not the copy ctor + other_acc(100); + other_acc(100); + other_acc(100); + other_acc(100); + other_acc(100); + boost::archive::text_iarchive ia(ss); + other_acc.serialize(ia, 0); + BOOST_CHECK_CLOSE(5., rolling_mean(other_acc), 1e-5); +} + /////////////////////////////////////////////////////////////////////////////// // test_rolling_mean void test_rolling_mean() @@ -97,8 +161,50 @@ void test_rolling_mean() BOOST_CHECK (sizeof(acc_lazy_rolling_mean) == sizeof(acc_lazy_rolling_mean3)); BOOST_CHECK (sizeof(acc_immediate_rolling_mean) == sizeof(acc_immediate_rolling_mean2)); BOOST_CHECK (sizeof(acc_immediate_rolling_mean) == sizeof(acc_immediate_rolling_mean3)); + + //// test unsigned int with both implementations + accumulator_set > + acc_immediate_rolling_mean4(tag::immediate_rolling_mean::window_size = window_size), + acc_immediate_rolling_mean5(tag::immediate_rolling_mean::window_size = window_size, sample = 0); + + test_rolling_mean_unsigned_test_impl(acc_immediate_rolling_mean4); + test_rolling_mean_unsigned_test_impl(acc_immediate_rolling_mean5); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +void test_persistency() +{ + accumulator_set > + acc_immediate_rolling_mean(tag::immediate_rolling_mean::window_size = window_size), + acc_immediate_rolling_mean2(tag::immediate_rolling_mean::window_size = window_size, sample = 0); + + accumulator_set > + acc_immediate_rolling_mean3(tag::immediate_rolling_mean::window_size = window_size); + + accumulator_set > + acc_lazy_rolling_mean(tag::lazy_rolling_mean::window_size = window_size), + acc_lazy_rolling_mean2(tag::lazy_rolling_mean::window_size = window_size, sample = 0); + + accumulator_set > + acc_lazy_rolling_mean3(tag::lazy_rolling_mean::window_size = window_size); + + accumulator_set > + acc_default_rolling_mean(tag::rolling_mean::window_size = window_size), + acc_default_rolling_mean2(tag::rolling_mean::window_size = window_size, sample = 0); + + //// test the different implementations + test_persistency_impl(acc_lazy_rolling_mean); + test_persistency_impl(acc_default_rolling_mean); + test_persistency_impl(acc_immediate_rolling_mean); + + test_persistency_impl(acc_lazy_rolling_mean2); + test_persistency_impl(acc_default_rolling_mean2); + test_persistency_impl(acc_immediate_rolling_mean2); + + test_persistency_impl(acc_lazy_rolling_mean3); + test_persistency_impl(acc_immediate_rolling_mean3); +} /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -107,6 +213,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("rolling mean test"); test->add(BOOST_TEST_CASE(&test_rolling_mean)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/rolling_moment.cpp b/test/rolling_moment.cpp index 9a25920..30d0c88 100644 --- a/test/rolling_moment.cpp +++ b/test/rolling_moment.cpp @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -71,6 +74,36 @@ void test_rolling_fifth_moment() assert_is_double(rolling_moment<5>(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + accumulator_set > > acc2(tag::rolling_moment<2>::window_size = 3); + accumulator_set > > acc5(tag::rolling_moment<5>::window_size = 3); + + acc2(2); acc5(2); + acc2(4); acc5(3); + acc2(5); acc5(4); + acc2(6); acc5(5); + + BOOST_CHECK_CLOSE(rolling_moment<2>(acc2), (16.0 + 25.0 + 36.0)/3, 1e-5); + BOOST_CHECK_CLOSE(rolling_moment<5>(acc5), (243.0 + 1024.0 + 3125.0)/3, 1e-5); + boost::archive::text_oarchive oa(ss); + acc2.serialize(oa, 0); + acc5.serialize(oa, 0); + } + accumulator_set > > acc2(tag::rolling_moment<2>::window_size = 3); + accumulator_set > > acc5(tag::rolling_moment<5>::window_size = 3); + boost::archive::text_iarchive ia(ss); + acc2.serialize(ia, 0); + acc5.serialize(ia, 0); + BOOST_CHECK_CLOSE(rolling_moment<2>(acc2), (16.0 + 25.0 + 36.0)/3, 1e-5); + BOOST_CHECK_CLOSE(rolling_moment<5>(acc5), (243.0 + 1024.0 + 3125.0)/3, 1e-5); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -80,6 +113,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test->add(BOOST_TEST_CASE(&test_rolling_second_moment)); test->add(BOOST_TEST_CASE(&test_rolling_fifth_moment)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; -} \ No newline at end of file +} diff --git a/test/rolling_sum.cpp b/test/rolling_sum.cpp index 6e20d47..374514c 100644 --- a/test/rolling_sum.cpp +++ b/test/rolling_sum.cpp @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -37,6 +40,29 @@ void test_stat() BOOST_CHECK_EQUAL(12, rolling_sum(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + accumulator_set > acc(tag::rolling_window::window_size = 3); + acc(1); + acc(2); + acc(3); + acc(4); + acc(5); + BOOST_CHECK_EQUAL(12, rolling_sum(acc)); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > acc(tag::rolling_window::window_size = 3); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(12, rolling_sum(acc)); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -45,6 +71,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("rolling sum test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/rolling_variance.cpp b/test/rolling_variance.cpp index df41fef..d7f0075 100644 --- a/test/rolling_variance.cpp +++ b/test/rolling_variance.cpp @@ -9,7 +9,9 @@ #include #include #include - +#include +#include +#include #include using namespace boost; @@ -132,6 +134,66 @@ void test_rolling_variance() BOOST_CHECK (sizeof(acc_lazy_rolling_variance) == sizeof(acc_lazy_rolling_variance2)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency_impl +// +template +void test_persistency_impl(accumulator_set_type& acc) +{ + std::stringstream ss; + { + acc(1.2); + acc(2.3); + acc(3.4); + acc(4.5); + acc(0.4); + acc(2.2); + acc(7.1); + acc(4.0); + BOOST_CHECK_CLOSE(rolling_variance(acc),8.16250000000000,1e-10); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set_type other_acc = acc; + boost::archive::text_iarchive ia(ss); + other_acc.serialize(ia, 0); + BOOST_CHECK_CLOSE(rolling_variance(acc),8.16250000000000,1e-10); + +} + +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // tag::rolling_window::window_size + accumulator_set > + acc_immediate_rolling_variance(tag::immediate_rolling_variance::window_size = window_size); + + accumulator_set > + acc_immediate_rolling_variance2(tag::immediate_rolling_variance::window_size = window_size); + + accumulator_set > + acc_immediate_rolling_variance3(tag::immediate_rolling_variance::window_size = window_size); + + accumulator_set > + acc_lazy_rolling_variance(tag::lazy_rolling_variance::window_size = window_size); + + accumulator_set > + acc_lazy_rolling_variance2(tag::immediate_rolling_variance::window_size = window_size); + + accumulator_set > + acc_default_rolling_variance(tag::rolling_variance::window_size = window_size); + + //// test the different implementations + test_persistency_impl(acc_immediate_rolling_variance); + test_persistency_impl(acc_immediate_rolling_variance2); + test_persistency_impl(acc_immediate_rolling_variance3); + test_persistency_impl(acc_lazy_rolling_variance); + test_persistency_impl(acc_lazy_rolling_variance2); + test_persistency_impl(acc_default_rolling_variance); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -140,6 +202,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("rolling variance test"); test->add(BOOST_TEST_CASE(&test_rolling_variance)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; -} \ No newline at end of file +} diff --git a/test/skewness.cpp b/test/skewness.cpp index 7aaea90..8a82468 100644 --- a/test/skewness.cpp +++ b/test/skewness.cpp @@ -14,6 +14,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -55,6 +58,33 @@ void test_stat() BOOST_CHECK_CLOSE( skewness(acc2), 0.406040288214, 1e-6 ); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + double epsilon = 1e-6; + std::stringstream ss; + { + accumulator_set > acc; + acc(2); + acc(7); + acc(4); + acc(9); + acc(3); + + BOOST_CHECK_EQUAL(accumulators::moment<3>(acc), 1171./5.); + BOOST_CHECK_CLOSE(skewness(acc), 0.406040288214, epsilon); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set > acc; + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(accumulators::moment<3>(acc), 1171./5.); + BOOST_CHECK_CLOSE(skewness(acc), 0.406040288214, epsilon); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -63,6 +93,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("skewness test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/sum.cpp b/test/sum.cpp index 52eeae6..c0c8f8c 100644 --- a/test/sum.cpp +++ b/test/sum.cpp @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -37,6 +40,32 @@ void test_stat() BOOST_CHECK_EQUAL(18, sum_of_variates(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + accumulator_set >, int> acc; + acc(1, weight = 2, covariate1 = 3); + acc(2, weight = 4, covariate1 = 6); + acc(3, weight = 6, covariate1 = 9); + BOOST_CHECK_EQUAL(28, sum(acc)); + BOOST_CHECK_EQUAL(12, sum_of_weights(acc)); + BOOST_CHECK_EQUAL(18, sum_of_variates(acc)); + + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set >, int> acc; + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(28, sum(acc)); + BOOST_CHECK_EQUAL(12, sum_of_weights(acc)); + BOOST_CHECK_EQUAL(18, sum_of_variates(acc)); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -45,6 +74,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("sum test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/sum_kahan.cpp b/test/sum_kahan.cpp index fcfd9fb..85edb11 100644 --- a/test/sum_kahan.cpp +++ b/test/sum_kahan.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -66,6 +69,41 @@ void test_sum_of_variates_kahan() BOOST_CHECK_EQUAL(1.0f, sum_of_variates_kahan(acc)); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + std::stringstream ss; + { + accumulator_set< + float, + stats >, + float + > + acc; + + BOOST_CHECK_EQUAL(0.0f, sum_of_variates_kahan(acc)); + + for (size_t i = 0; i < 1e6; ++i) { + acc(0, covariate1 = 1e-6f); + } + + BOOST_CHECK_EQUAL(1.0f, sum_of_variates_kahan(acc)); + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + } + accumulator_set< + float, + stats >, + float + > + acc; + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + BOOST_CHECK_EQUAL(1.0f, sum_of_variates_kahan(acc)); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -76,6 +114,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test->add(BOOST_TEST_CASE(&test_sum_kahan)); test->add(BOOST_TEST_CASE(&test_sum_of_weights_kahan)); test->add(BOOST_TEST_CASE(&test_sum_of_variates_kahan)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/variance.cpp b/test/variance.cpp index 710fa14..8c48713 100644 --- a/test/variance.cpp +++ b/test/variance.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include +#include using namespace boost; using namespace unit_test; @@ -55,6 +58,41 @@ void test_stat() BOOST_CHECK_CLOSE(2., variance(acc2), 1e-5); } +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + double epsilon = 1e-5; + std::stringstream ss; + { + accumulator_set > acc1; + accumulator_set > acc2; + acc1(1); + acc1(2); + acc1(3); + acc1(4); + acc1(5); + acc2(1); + acc2(2); + acc2(3); + acc2(4); + acc2(5); + BOOST_CHECK_CLOSE(2., variance(acc2), epsilon); + BOOST_CHECK_CLOSE(2., variance(acc1), epsilon); + boost::archive::text_oarchive oa(ss); + acc1.serialize(oa, 0); + acc2.serialize(oa, 0); + } + accumulator_set > acc1; + accumulator_set > acc2; + boost::archive::text_iarchive ia(ss); + acc1.serialize(ia, 0); + acc2.serialize(ia, 0); + BOOST_CHECK_CLOSE(2., variance(acc2), epsilon); + BOOST_CHECK_CLOSE(2., variance(acc1), epsilon); +} + /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // @@ -63,6 +101,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) test_suite *test = BOOST_TEST_SUITE("variance test"); test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); return test; } diff --git a/test/weighted_median.cpp b/test/weighted_median.cpp index eed3ad9..60321d1 100644 --- a/test/weighted_median.cpp +++ b/test/weighted_median.cpp @@ -38,12 +38,17 @@ void test_stat() acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); - for (std::size_t i=0; i<100000; ++i) + for (std::size_t i=0; i<1000000; ++i) { double sample = normal_narrow(); - acc(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma ))); - acc_dens(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma ))); - acc_cdist(sample, weight = std::exp(0.5 * (sample - mu) * (sample - mu) * ( 1./sigma_narrow/sigma_narrow - 1./sigma/sigma ))); + double w = std::exp( + 0.5 * (sample - mu) * (sample - mu) * ( + 1./sigma_narrow/sigma_narrow - 1./sigma/sigma + ) + ); + acc(sample, weight = w); + acc_dens(sample, weight = w); + acc_cdist(sample, weight = w); } BOOST_CHECK_CLOSE(1., weighted_median(acc), 2);