|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50392 - in trunk: boost/accumulators boost/accumulators/statistics libs/accumulators/doc libs/accumulators/test
From: eric_at_[hidden]
Date: 2008-12-27 20:44:01
Author: eric_niebler
Date: 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
New Revision: 50392
URL: http://svn.boost.org/trac/boost/changeset/50392
Log:
add rolling_window, rolling_count, rolling_sum and rolling_mean
Added:
trunk/boost/accumulators/statistics/rolling_count.hpp (contents, props changed)
trunk/boost/accumulators/statistics/rolling_mean.hpp (contents, props changed)
trunk/boost/accumulators/statistics/rolling_sum.hpp (contents, props changed)
trunk/boost/accumulators/statistics/rolling_window.hpp (contents, props changed)
trunk/libs/accumulators/test/rolling_count.cpp (contents, props changed)
trunk/libs/accumulators/test/rolling_mean.cpp (contents, props changed)
trunk/libs/accumulators/test/rolling_sum.cpp (contents, props changed)
Text files modified:
trunk/boost/accumulators/statistics_fwd.hpp | 18 +++++
trunk/libs/accumulators/doc/accumulators.qbk | 140 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/accumulators/test/Jamfile.v2 | 3
3 files changed, 161 insertions(+), 0 deletions(-)
Added: trunk/boost/accumulators/statistics/rolling_count.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/accumulators/statistics/rolling_count.hpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -0,0 +1,78 @@
+///////////////////////////////////////////////////////////////////////////////
+// rolling_count.hpp
+//
+// Copyright 2008 Eric Niebler. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_COUNT_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_COUNT_HPP_EAN_26_12_2008
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/rolling_window.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // rolling_count_impl
+ // returns the count of elements in the rolling window
+ template<typename Sample>
+ struct rolling_count_impl
+ : accumulator_base
+ {
+ typedef std::size_t result_type;
+
+ rolling_count_impl(dont_care)
+ {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return static_cast<std::size_t>(rolling_window_plus1(args).size()) - is_rolling_window_plus1_full(args);
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::rolling_count
+//
+namespace tag
+{
+ struct rolling_count
+ : depends_on< rolling_window_plus1 >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::rolling_count_impl< mpl::_1 > impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::rolling_window::window_size named parameter
+ static boost::parameter::keyword<tag::rolling_window_size> const window_size;
+ #endif
+ };
+} // namespace tag
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::rolling_count
+//
+namespace extract
+{
+ extractor<tag::rolling_count> const rolling_count = {};
+}
+
+using extract::rolling_count;
+
+}} // namespace boost::accumulators
+
+#endif
Added: trunk/boost/accumulators/statistics/rolling_mean.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/accumulators/statistics/rolling_mean.hpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -0,0 +1,79 @@
+///////////////////////////////////////////////////////////////////////////////
+// rolling_mean.hpp
+//
+// Copyright 2008 Eric Niebler. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MEAN_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MEAN_HPP_EAN_26_12_2008
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/rolling_sum.hpp>
+#include <boost/accumulators/statistics/rolling_count.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // rolling_mean_impl
+ // returns the unshifted results from the shifted rolling window
+ template<typename Sample>
+ struct rolling_mean_impl
+ : accumulator_base
+ {
+ typedef typename numeric::functional::average<Sample, std::size_t>::result_type result_type;
+
+ rolling_mean_impl(dont_care)
+ {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return numeric::average(rolling_sum(args), rolling_count(args));
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::rolling_mean
+//
+namespace tag
+{
+ struct rolling_mean
+ : depends_on< rolling_sum, rolling_count >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::rolling_mean_impl< mpl::_1 > impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::rolling_window::window_size named parameter
+ static boost::parameter::keyword<tag::rolling_window_size> const window_size;
+ #endif
+ };
+} // namespace tag
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::rolling_mean
+//
+namespace extract
+{
+ extractor<tag::rolling_mean> const rolling_mean = {};
+}
+
+using extract::rolling_mean;
+
+}} // namespace boost::accumulators
+
+#endif
Added: trunk/boost/accumulators/statistics/rolling_sum.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/accumulators/statistics/rolling_sum.hpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -0,0 +1,91 @@
+///////////////////////////////////////////////////////////////////////////////
+// rolling_sum.hpp
+//
+// Copyright 2008 Eric Niebler. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_SUM_HPP_EAN_26_12_2008
+
+#include <boost/mpl/placeholders.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/rolling_window.hpp>
+
+namespace boost { namespace accumulators
+{
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // rolling_sum_impl
+ // returns the sum of the samples in the rolling window
+ template<typename Sample>
+ struct rolling_sum_impl
+ : accumulator_base
+ {
+ typedef Sample result_type;
+
+ template<typename Args>
+ rolling_sum_impl(Args const &args)
+ : sum_(args[sample | Sample()])
+ {}
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ if(is_rolling_window_plus1_full(args))
+ {
+ this->sum_ -= rolling_window_plus1(args).front();
+ }
+ this->sum_ += args[sample];
+ }
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return this->sum_;
+ }
+
+ private:
+ Sample sum_;
+ };
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::rolling_sum
+//
+namespace tag
+{
+ struct rolling_sum
+ : depends_on< rolling_window_plus1 >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::rolling_sum_impl< mpl::_1 > impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::rolling_window::window_size named parameter
+ static boost::parameter::keyword<tag::rolling_window_size> const window_size;
+ #endif
+ };
+} // namespace tag
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::rolling_sum
+//
+namespace extract
+{
+ extractor<tag::rolling_sum> const rolling_sum = {};
+}
+
+using extract::rolling_sum;
+
+}} // namespace boost::accumulators
+
+#endif
Added: trunk/boost/accumulators/statistics/rolling_window.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/accumulators/statistics/rolling_window.hpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -0,0 +1,165 @@
+///////////////////////////////////////////////////////////////////////////////
+// rolling_window.hpp
+//
+// Copyright 2008 Eric Niebler. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_WINDOW_HPP_EAN_26_12_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_WINDOW_HPP_EAN_26_12_2008
+
+#include <cstddef>
+#include <boost/version.hpp>
+#include <boost/assert.hpp>
+#include <boost/circular_buffer.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/parameters/accumulator.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+
+namespace boost { namespace accumulators
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::rolling_window::size named parameter
+BOOST_PARAMETER_NESTED_KEYWORD(tag, rolling_window_size, window_size)
+
+namespace impl
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // rolling_window_plus1_impl
+ // stores the latest N+1 samples, where N is specified at construction time
+ // with the rolling_window_size named parameter
+ template<typename Sample>
+ struct rolling_window_plus1_impl
+ : accumulator_base
+ {
+ typedef typename circular_buffer<Sample>::const_iterator const_iterator;
+ typedef iterator_range<const_iterator> result_type;
+
+ template<typename Args>
+ rolling_window_plus1_impl(Args const & args)
+ : buffer_(args[rolling_window_size] + 1)
+ {}
+
+ #if BOOST_VERSION < 103600
+ // Before Boost 1.36, copying a circular buffer didn't copy
+ // it's capacity, and we need that behavior.
+ rolling_window_plus1_impl(rolling_window_plus1_impl const &that)
+ : buffer_(that.buffer_)
+ {
+ this->buffer_.set_capacity(that.buffer_.capacity());
+ }
+
+ rolling_window_plus1_impl &operator =(rolling_window_plus1_impl const &that)
+ {
+ this->buffer_ = that.buffer_;
+ this->buffer_.set_capacity(that.buffer_.capacity());
+ }
+ #endif
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ this->buffer_.push_back(args[sample]);
+ }
+
+ bool full() const
+ {
+ return this->buffer_.full();
+ }
+
+ // The result of a shifted rolling window is the range including
+ // everything except the most recently added element.
+ result_type result(dont_care) const
+ {
+ return result_type(this->buffer_.begin(), this->buffer_.end());
+ }
+
+ private:
+ circular_buffer<Sample> buffer_;
+ };
+
+ template<typename Args>
+ bool is_rolling_window_plus1_full(Args const &args)
+ {
+ return find_accumulator<tag::rolling_window_plus1>(args[accumulator]).full();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // rolling_window_impl
+ // stores the latest N samples, where N is specified at construction type
+ // with the rolling_window_size named parameter
+ template<typename Sample>
+ struct rolling_window_impl
+ : accumulator_base
+ {
+ typedef typename circular_buffer<Sample>::const_iterator const_iterator;
+ typedef iterator_range<const_iterator> result_type;
+
+ rolling_window_impl(dont_care)
+ {}
+
+ template<typename Args>
+ result_type result(Args const &args) const
+ {
+ return rolling_window_plus1(args).advance_begin(is_rolling_window_plus1_full(args));
+ }
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::rolling_window_plus1
+// tag::rolling_window
+//
+namespace tag
+{
+ struct rolling_window_plus1
+ : depends_on<>
+ , tag::rolling_window_size
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::rolling_window_plus1_impl< mpl::_1 > impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::rolling_window::size named parameter
+ static boost::parameter::keyword<tag::rolling_window_size> const window_size;
+ #endif
+ };
+
+ struct rolling_window
+ : depends_on< rolling_window_plus1 >
+ {
+ /// INTERNAL ONLY
+ ///
+ typedef accumulators::impl::rolling_window_impl< mpl::_1 > impl;
+
+ #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
+ /// tag::rolling_window::size named parameter
+ static boost::parameter::keyword<tag::rolling_window_size> const window_size;
+ #endif
+ };
+
+} // namespace tag
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::rolling_window_plus1
+// extract::rolling_window
+//
+namespace extract
+{
+ extractor<tag::rolling_window_plus1> const rolling_window_plus1 = {};
+ extractor<tag::rolling_window> const rolling_window = {};
+}
+
+using extract::rolling_window_plus1;
+using extract::rolling_window;
+
+}} // namespace boost::accumulators
+
+#endif
Modified: trunk/boost/accumulators/statistics_fwd.hpp
==============================================================================
--- trunk/boost/accumulators/statistics_fwd.hpp (original)
+++ trunk/boost/accumulators/statistics_fwd.hpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -180,6 +180,11 @@
struct weighted_sum;
template<typename VariateType, typename VariateTag>
struct weighted_sum_of_variates;
+ struct rolling_window_plus1;
+ struct rolling_window;
+ struct rolling_sum;
+ struct rolling_count;
+ struct rolling_mean;
} // namespace tag
namespace impl
@@ -344,7 +349,20 @@
template<typename Sample, typename Weight, typename MeanFeature, typename Tag>
struct weighted_variance_impl;
+ template<typename Sample>
+ struct rolling_window_plus1_impl;
+
+ template<typename Sample>
+ struct rolling_window_impl;
+
+ template<typename Sample>
+ struct rolling_sum_impl;
+
+ template<typename Sample>
+ struct rolling_count_impl;
+ template<typename Sample>
+ struct rolling_mean_impl;
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
Modified: trunk/libs/accumulators/doc/accumulators.qbk
==============================================================================
--- trunk/libs/accumulators/doc/accumulators.qbk (original)
+++ trunk/libs/accumulators/doc/accumulators.qbk 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -2023,6 +2023,146 @@
[endsect]
+[section:rolling_count rolling_count]
+
+The rolling count is the current number of elements in the rolling window.
+
+[variablelist
+ [[Result Type] [``std::size_t``]]
+ [[Depends On] [`rolling_window_plus1`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::rolling_window::window_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Header]
+[def _ROLLING_COUNT_HPP_ [headerref boost/accumulators/statistics/rolling_count.hpp]]
+
+ #include <_ROLLING_COUNT_HPP_>
+
+[*Example]
+
+ accumulator_set<int, stats<tag::rolling_count> > acc(tag::rolling_window::window_size = 3);
+
+ BOOST_CHECK_EQUAL(0u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(2u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(3u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(3u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(3u, rolling_count(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::rolling_count_impl [^rolling_count_impl]]
+
+[endsect]
+
+[section:rolling_sum rolling_sum]
+
+The rolling sum is the sum of the last /N/ samples.
+
+[variablelist
+ [[Result Type] [``_sample_type_``]]
+ [[Depends On] [`rolling_window_plus1`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::rolling_window::window_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Header]
+[def _ROLLING_SUM_HPP_ [headerref boost/accumulators/statistics/rolling_sum.hpp]]
+
+ #include <_ROLLING_SUM_HPP_>
+
+[*Example]
+
+ accumulator_set<int, stats<tag::rolling_sum> > acc(tag::rolling_window::window_size = 3);
+
+ BOOST_CHECK_EQUAL(0, rolling_sum(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1, rolling_sum(acc));
+
+ acc(2);
+ BOOST_CHECK_EQUAL(3, rolling_sum(acc));
+
+ acc(3);
+ BOOST_CHECK_EQUAL(6, rolling_sum(acc));
+
+ acc(4);
+ BOOST_CHECK_EQUAL(9, rolling_sum(acc));
+
+ acc(5);
+ BOOST_CHECK_EQUAL(12, rolling_sum(acc));
+
+[*See also]
+
+* [classref boost::accumulators::impl::rolling_sum_impl [^rolling_sum_impl]]
+
+[endsect]
+
+[section:rolling_mean rolling_mean]
+
+The rolling mean is the mean over the last /N/ samples. It is computed by dividing
+the rolling sum by the rolling count.
+
+[variablelist
+ [[Result Type] [``
+ numeric::functional::average<_sample_type_, std::size_t>::result_type
+ ``]]
+ [[Depends On] [`rolling_sum` \n `rolling_count`]]
+ [[Variants] [['none]]]
+ [[Initialization Parameters] [`tag::rolling_window::window_size`]]
+ [[Accumulator Parameters] [['none]]]
+ [[Extractor Parameters] [['none]]]
+ [[Accumulator Complexity] [O(1)]]
+ [[Extractor Complexity] [O(1)]]
+]
+
+[*Header]
+[def _ROLLING_MEAN_HPP_ [headerref boost/accumulators/statistics/rolling_mean.hpp]]
+
+ #include <_ROLLING_MEAN_HPP_>
+
+[*Example]
+
+ accumulator_set<int, stats<tag::rolling_mean> > acc(tag::rolling_window::window_size = 5);
+
+ acc(1);
+ acc(2);
+ acc(3);
+
+ BOOST_CHECK_CLOSE( rolling_mean(acc), 2.0, 1e-6 );
+
+ acc(4);
+ acc(5);
+ acc(6);
+ acc(7);
+
+ BOOST_CHECK_CLOSE( rolling_mean(acc), 5.0, 1e-6 );
+
+[*See also]
+
+* [classref boost::accumulators::impl::rolling_mean_impl [^rolling_mean_impl]]
+
+[endsect]
+
[section:skewness skewness]
The skewness of a sample distribution is defined as the ratio of the 3rd central moment and the [^3/2]-th power
Modified: trunk/libs/accumulators/test/Jamfile.v2
==============================================================================
--- trunk/libs/accumulators/test/Jamfile.v2 (original)
+++ trunk/libs/accumulators/test/Jamfile.v2 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -45,6 +45,9 @@
[ run p_square_cumulative_distribution.cpp ]
[ run p_square_quantile.cpp ]
[ run reference.cpp ]
+ [ run rolling_count.cpp ]
+ [ run rolling_sum.cpp ]
+ [ run rolling_mean.cpp ]
[ run skewness.cpp ]
[ run sum.cpp ]
[ run tail.cpp ]
Added: trunk/libs/accumulators/test/rolling_count.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/accumulators/test/rolling_count.cpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -0,0 +1,50 @@
+// (C) Copyright Eric Niebler 2005.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/rolling_count.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::rolling_count> > acc(tag::rolling_window::window_size = 3);
+
+ BOOST_CHECK_EQUAL(0u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(2u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(3u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(3u, rolling_count(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(3u, rolling_count(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+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));
+
+ return test;
+}
Added: trunk/libs/accumulators/test/rolling_mean.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/accumulators/test/rolling_mean.cpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -0,0 +1,70 @@
+// (C) Copyright Eric Niebler 2008.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/rolling_mean.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+template<typename T>
+void assert_is_double(T const &)
+{
+ BOOST_MPL_ASSERT((is_same<T, double>));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<
+ int
+ , stats<
+ tag::rolling_mean
+ >
+ > acc(tag::rolling_mean::window_size = 5), test_acc(tag::rolling_mean::window_size = 5, sample = 0);
+
+ acc(1);
+ BOOST_CHECK_CLOSE(1., rolling_mean(acc), 1e-5);
+
+ acc(2);
+ BOOST_CHECK_CLOSE(1.5, rolling_mean(acc), 1e-5);
+
+ acc(3);
+ BOOST_CHECK_CLOSE(2, rolling_mean(acc), 1e-5);
+
+ acc(4);
+ BOOST_CHECK_CLOSE(2.5, rolling_mean(acc), 1e-5);
+
+ acc(5);
+ BOOST_CHECK_CLOSE(3., rolling_mean(acc), 1e-5);
+
+ acc(6);
+ BOOST_CHECK_CLOSE(4., rolling_mean(acc), 1e-5);
+
+ acc(7);
+ BOOST_CHECK_CLOSE(5., rolling_mean(acc), 1e-5);
+
+ assert_is_double(rolling_mean(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+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_stat));
+
+ return test;
+}
Added: trunk/libs/accumulators/test/rolling_sum.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/accumulators/test/rolling_sum.cpp 2008-12-27 20:44:00 EST (Sat, 27 Dec 2008)
@@ -0,0 +1,50 @@
+// (C) Copyright Eric Niebler 2008.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/test/unit_test.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/rolling_sum.hpp>
+
+using namespace boost;
+using namespace unit_test;
+using namespace accumulators;
+
+///////////////////////////////////////////////////////////////////////////////
+// test_stat
+//
+void test_stat()
+{
+ accumulator_set<int, stats<tag::rolling_sum> > acc(tag::rolling_window::window_size = 3);
+
+ BOOST_CHECK_EQUAL(0, rolling_sum(acc));
+
+ acc(1);
+ BOOST_CHECK_EQUAL(1, rolling_sum(acc));
+
+ acc(2);
+ BOOST_CHECK_EQUAL(3, rolling_sum(acc));
+
+ acc(3);
+ BOOST_CHECK_EQUAL(6, rolling_sum(acc));
+
+ acc(4);
+ BOOST_CHECK_EQUAL(9, rolling_sum(acc));
+
+ acc(5);
+ BOOST_CHECK_EQUAL(12, rolling_sum(acc));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// init_unit_test_suite
+//
+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));
+
+ return test;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk