Boost logo

Boost-Commit :

From: erwann.rogard_at_[hidden]
Date: 2008-05-25 23:10:42


Author: e_r
Date: 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
New Revision: 45760
URL: http://svn.boost.org/trac/boost/changeset/45760

Log:
adding library acvf
Added:
   sandbox/acvf/
   sandbox/acvf/boost/
   sandbox/acvf/boost/accumulators/
   sandbox/acvf/boost/accumulators/statistics/
   sandbox/acvf/boost/accumulators/statistics/acf.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/acv0.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/acvf.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/acvf_analysis.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/acvf_moving_average.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/integrated_acf.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/integrated_acvf.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/percentage_effective_sample_size.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/standard_error_autocorrelated.hpp (contents, props changed)
   sandbox/acvf/boost/accumulators/statistics/standard_error_iid.hpp (contents, props changed)
   sandbox/acvf/boost/random/
   sandbox/acvf/boost/random/moving_average.hpp (contents, props changed)
   sandbox/acvf/libs/
   sandbox/acvf/libs/accumulators/
   sandbox/acvf/libs/accumulators/statistics/
   sandbox/acvf/libs/accumulators/statistics/example/
   sandbox/acvf/libs/accumulators/statistics/example/main.cpp (contents, props changed)

Added: sandbox/acvf/boost/accumulators/statistics/acf.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/acf.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,138 @@
+///////////////////////////////////////////////////////////////////////////////
+// acf.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_ACF_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ACF_HPP_ER_04_2008
+
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <functional>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/assert.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/bind.hpp>
+
+#include <boost/accumulators/framework/extractor.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/acvf.hpp>
+#include <boost/accumulators/statistics/delay.hpp>
+
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // acf_impl
+ template<typename Sample,typename Discriminator>
+ class acf_impl
+ : public accumulator_base
+ {
+ //TODO via the feature for delay (?)
+ typedef acvf_impl<Sample,Discriminator> acvf_type;
+ typedef typename acvf_type::result_type acvfs_result_type;
+ typedef std::vector<Sample> acfs_type;
+ public:
+ typedef boost::iterator_range<
+ typename acfs_type::const_iterator> result_type;
+
+ acf_impl(dont_care):acfs(0,(Sample)(0.0)){}
+
+ template<typename Args>
+ void operator ()(Args const &args){
+ const acvfs_result_type& range
+ = acvf<Discriminator>(args[accumulator]);
+ std::size_t sz = range.size();
+ acfs.resize(sz);
+ Sample acv0 = (*begin(range));
+ if(acv0>0.0){
+ Sample div=(1.0/acv0);
+ transform(
+ begin(range),
+ end(range),
+ acfs.begin(),
+ boost::bind(
+ std::multiplies<Sample>(),
+ _1,
+ div
+ )
+ );
+ }else{
+ std::fill_n(acfs.begin(),sz,0.0);
+ }
+ }
+ result_type result(dont_care) const
+ {
+ return boost::make_iterator_range(acfs.begin(),acfs.end());
+ }
+ private:
+ mutable acfs_type acfs;
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::acf
+//
+
+namespace tag
+{
+ template <typename Discriminator = default_delay_discriminator>
+ struct acf
+ : depends_on<acvf<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef accumulators::impl::acf_impl<mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::acf
+//
+
+namespace extract
+{
+
+// extractor<tag::acf<> > const acf = {};
+
+ // see acvf about default_delay_discriminator
+ template<typename Discriminator,typename AccumulatorSet>
+ typename
+ mpl::apply<AccumulatorSet,tag::acf<Discriminator> >::type::result_type
+ acf(AccumulatorSet const& acc){
+ typedef tag::acf<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }//typical call://acf<default_delay_discriminator>(acc)
+
+// TODO
+// overload (default) see acvf
+
+
+}
+
+using extract::acf;
+
+
+}} // namespace boost::accumulators
+
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/acv0.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/acv0.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,114 @@
+///////////////////////////////////////////////////////////////////////////////
+// acv0.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_ACV0_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ACV0_HPP_ER_04_2008
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.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/acvf.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // acv0_impl
+ template<typename Sample,typename Discriminator>
+ class acv0_impl
+ : public accumulator_base
+ {
+ public:
+ typedef Sample result_type;
+ acv0_impl(dont_care)
+ {}
+
+ template<typename Args>
+ void operator()(Args const &args)
+ {
+ val = (*begin(acvf<Discriminator>(args[accumulator])));
+ }
+
+
+ result_type result(dont_care) const
+ {
+ return val;
+ }
+ private:
+ Sample val;
+ };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::acv0
+//
+
+namespace tag
+{
+ template <typename Discriminator = default_delay_discriminator>
+ struct acv0
+ : depends_on<acvf<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef
+ accumulators::impl::acv0_impl<
+ mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::acv0
+//
+
+namespace extract
+{
+
+// extractor<tag::acv0<> > const acv0 = {};
+ // see acvf about default_delay_discriminator
+ template<typename Discriminator,typename AccumulatorSet>
+ typename mpl::apply<
+ AccumulatorSet,tag::acv0<Discriminator>
+ >::type::result_type
+ acv0(AccumulatorSet const& acc){
+ typedef tag::acv0<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }
+
+// TODO
+// overload (default) see acvf
+
+}
+
+using extract::acv0;
+
+
+
+}} // namespace boost::accumulators
+
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/acvf.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/acvf.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,176 @@
+///////////////////////////////////////////////////////////////////////////////
+// acvf.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_ACVF_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ACVF_HPP_ER_04_2008
+
+//TODO check if any header not needed
+
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/delay.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // acvf_impl (Autocovariance function)
+ template<typename Sample,typename Discriminator>
+ class acvf_impl
+ : public accumulator_base
+ {
+ typedef std::vector<Sample> acvs_type;
+ typedef delay_impl<Sample,Discriminator> delay_type;
+ typedef typename delay_type::result_type input_type;
+ public:
+ typedef boost::iterator_range<
+ typename acvs_type::const_iterator
+ > result_type;
+
+
+ template<typename Args>
+ acvf_impl(Args const &args)
+ :acvs(
+ args[tag::delay<Discriminator>::cache_size|delay(args).size()],
+ (Sample)(0.0)
+ )
+ {
+ }
+
+ acvf_impl(const acvf_impl& that)
+ :acvs(that.acvs){}
+
+ acvf_impl& operator=(const acvf_impl& that){
+ if(&that!=this){acvs = that.acvs;} return *this;
+ }
+
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ input_type in = delay(args); //0,1,2,...,K
+ typedef typename input_type::const_iterator in_iter_type;
+ typedef typename acvs_type::iterator out_iter_type;
+ std::size_t in_sz = in.size();
+
+ BOOST_ASSERT((in_sz<acvs.size())||(in_sz==acvs.size()));
+ in_iter_type i = begin(in);
+ in_iter_type e = end(in);
+
+ Sample x0 = (*i);
+ std::size_t n = count(args);
+ std::size_t k = 0;
+ //TODO replace by
+ //for_each(make_zip_iterator(
+ // make_tuple(begin(in),acvs.begin())),...,local_class(...))
+ while((k<in_sz) && (n>1+k)){
+ BOOST_ASSERT(i<e);
+ Sample xk = (*i);
+ Sample div = (Sample) ((n-1)-k);
+ Sample sum_prod = acvs[k] * div;
+ Sample mean_val = mean(args);
+ sum_prod += (xk - mean_val) * (x0 - mean_val);
+ div = (Sample)(n-k);
+ acvs[k] = sum_prod / div;
+ ++i;
+ ++k;
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return boost::make_iterator_range(acvs.begin(),acvs.end());
+ }
+
+ private:
+ acvs_type acvs;
+
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::acvf
+//
+
+namespace tag
+{
+ template <typename Discriminator = default_delay_discriminator>
+ struct acvf
+ : depends_on<count,mean,delay<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef accumulators::impl::acvf_impl<mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::acvf
+//
+
+namespace extract
+{
+// extractor<tag::acvf<> > const acvf = {};
+// //a non-default discriminator requires
+// //struct my_other_delay {};
+// //extractor<tag::delay<my_other_delay> > other_delay={};
+
+ template<typename Discriminator,typename AccumulatorSet>
+ typename
+ mpl::apply<AccumulatorSet,tag::acvf<Discriminator> >::type::result_type
+ acvf(AccumulatorSet const& acc){
+ typedef tag::acvf<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }//typical call://acvf<default_delay_discriminator>(acc)
+
+// TODO
+// //overload
+// template<typename AccumulatorSet>
+// typename mpl::apply<AccumulatorSet,tag::acvf<> >::type::result_type
+// acvf(AccumulatorSet const& acc){
+// return acvf<default_delay_discriminator,AccumulatorSet>(acc);
+// }
+// /../boost_1_35_0/boost/mpl/aux_/preprocessed/gcc/apply_wrap.hpp|39|error: no
+// class template named ‘apply’
+// in ‘struct boost::accumulators::default_delay_discriminator’|
+
+}
+
+using extract::acvf;
+
+
+}} // namespace boost::accumulators
+
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/acvf_analysis.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/acvf_analysis.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,123 @@
+///////////////////////////////////////////////////////////////////////////////
+// acvf_analysis.hpp
+//
+// Copyright 2008 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <iostream>
+#include <algorithm>
+#include <iterator>
+#include <functional>
+#include <stdexcept>
+#include <boost/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/bind.hpp>
+#include <boost/ref.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/range/iterator_range.hpp>
+
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/delay.hpp>
+#include <boost/accumulators/statistics/acvf_moving_average.hpp>
+#include <boost/accumulators/statistics/acvf.hpp>
+#include <boost/accumulators/statistics/acf.hpp>
+#include <boost/accumulators/statistics/percentage_effective_sample_size.hpp>
+#include <boost/accumulators/statistics/standard_error_autocorrelated.hpp>
+#include <boost/accumulators/statistics/standard_error_iid.hpp>
+
+#ifndef BOOST_ACCUMULATORS_STATISTICS_ACVF_ANALYSIS_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_ACVF_ANALYSIS_HPP_ER_2008_04
+namespace boost{namespace accumulators{
+namespace statistics{
+
+ class acvf_analysis{
+ typedef boost::accumulators::default_delay_discriminator delaydisrc;
+ typedef boost::accumulators::accumulator_set<
+ double, boost::accumulators::stats<
+ boost::accumulators::tag::mean,
+ boost::accumulators::tag::acf<>,
+ boost::accumulators::tag::integrated_acvf<>,
+ boost::accumulators::tag::percentage_effective_sample_size<>,
+ boost::accumulators::tag::standard_error_autocorrelated<>,
+ boost::accumulators::tag::standard_error_iid<>
+ >
+ > acc_type;
+
+ public://TODO define copy and assign
+ acvf_analysis(std::size_t max_lag)
+ :K(max_lag),
+ acc(boost::accumulators::tag::delay<>::cache_size=(K+1)){};
+
+ template<typename R>
+ void operator()(
+ const R& range,//TODO specify range, container?
+ std::size_t offset,
+ std::size_t stride){
+
+ // an iterator range?
+ typedef typename R::const_iterator const_iter_type;
+ typedef typename R::size_type size_type;
+ const_iter_type i = boost::begin(range);
+ const_iter_type e = boost::end(range);
+ if(std::distance(i,e)>offset){
+ std::advance(i,offset);
+ //this has the effect of rounding to smallest
+ std::size_t d = (std::distance(i,e)-1)/stride;
+ d *= stride;
+ e = i; std::advance(e,d+1);
+
+ while(i<e){
+ acc(*i);
+ std::advance(i,stride);
+ }
+// for_each(
+// boost::begin(range),
+// boost::end(range),
+// boost::bind<void>(boost::ref(acc),_1)
+// );
+ }else{
+ std::runtime_error("acvf_analysis");
+ }
+ }
+ void print(std::ostream& os)const
+ {
+ using namespace boost::accumulators;
+ os << "->count: " << count(acc)
+ << std::endl
+ << "->estimated acf: ";
+ copy(
+ begin(acf<delaydisrc>(acc)),
+ end(acf<delaydisrc>(acc)),
+ std::ostream_iterator<double>(os," ")
+ );
+ os << std::endl
+ << "->estimated var: "
+ << integrated_acvf<delaydisrc>(acc) << std::endl
+ << "->estimated ess%: "
+ << percentage_effective_sample_size<delaydisrc>(acc)
+ << std::endl
+ << "->mean: " << mean(acc) << std::endl
+ << "->estimated standard error assuming iid: "
+ << standard_error_iid<delaydisrc>(acc) << std::endl
+ << "->estimated standard error assuming acf is zero after lag "
+ << K << ": "
+ << standard_error_autocorrelated<delaydisrc>(acc) << std::endl;
+ };
+ private:
+
+ std::size_t K;
+ acc_type acc;
+ };
+
+//TODO
+// std::ostream& operator<<(std::ostream& os,const acvf_analysis& a){
+// a.print(os);
+// return os;
+// };
+
+}
+}}
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/acvf_moving_average.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/acvf_moving_average.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,73 @@
+///////////////////////////////////////////////////////////////////////////////
+// acvf_moving_average.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_ACVF_MOVING_AVERAGE_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_ACVF_MOVING_AVERAGE_HPP_ER_04_2008
+
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <stdexcept>
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+namespace boost { namespace accumulators{
+
+ /// This is not an accumulator, only a formula:
+ /// Under model \f$ x_t = theta_0 e_{t-0} + ... + theta_q e_{t-q} \f$,
+ /// where the \f$ e_i \f$'s are independent and \f$Var[e_i]=1 \f$,
+ /// \f$ acvf(h) = sum_{j=0}^{q-h} theta_j theta_{j+h},
+ /// 0\leq h \leq q \f$
+ /// Multiply result by \f$ Var[e_i] \f$ if it is not 1.
+ template<typename R>
+ class acvf_moving_average{
+ typedef typename R::const_iterator iterator_type;
+ public:
+ typedef std::size_t argument_type;
+ typedef typename
+ boost::iterator_value<iterator_type>::type result_type;
+ acvf_moving_average(const R& coeffs_):coeffs(coeffs_){}
+ acvf_moving_average(const acvf_moving_average& that)
+ :coeffs(that.coeffs){}
+ acvf_moving_average& operator=(const acvf_moving_average& that){
+ if(&that!=this){
+ std::runtime_error("acvf_moving_average::operator=");}
+ return *this;
+ }
+ result_type operator()(argument_type delay)const{
+ typedef typename R::const_iterator iterator_type;
+ result_type res = 0.0;
+ size_t h = delay;
+ if(coeffs.size()>0){
+ std::size_t q = coeffs.size()-1;//MA(q)
+ if(!(h>q)){
+ iterator_type i = coeffs.begin();
+ iterator_type e = i; std::advance(e,q+1-h);
+ iterator_type i_shifted = i; std::advance(i_shifted,h);
+ iterator_type e_shifted = e; std::advance(e_shifted,h);
+ while(i<e){
+ res+=(*i)*(*i_shifted);
+ ++i; ++i_shifted;
+ }//TODO accumulate(make_zip_iterator(...
+ }
+ }
+ return res;
+ }
+ private:
+ const R& coeffs;
+ };
+
+ template<typename R>
+ acvf_moving_average<R> make_acvf_moving_average(const R& coeffs){
+ return acvf_moving_average<R>(coeffs);
+ };
+
+
+}}
+
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/integrated_acf.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/integrated_acf.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,119 @@
+///////////////////////////////////////////////////////////////////////////////
+// integrated_acf.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_INTEGRATED_ACF_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_INTEGRATED_ACF_HPP_ER_04_2008
+
+//TODO check if any header not needed
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <iostream>//tmp
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.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/acv0.hpp>
+#include <boost/accumulators/statistics/integrated_acvf.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // integrated_acf_impl
+ template<typename Sample,typename Discriminator>
+ class integrated_acf_impl
+ : public accumulator_base
+ {
+ public:
+ typedef Sample result_type;
+
+ integrated_acf_impl(dont_care):val((Sample)(0.0)){}
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ Sample iacvf = integrated_acvf<Discriminator>(args[accumulator]);
+ Sample acv0_val = acv0<Discriminator>(args[accumulator]);
+ if(acv0_val>0.0){val=iacvf/acv0_val;}else{val = 0.0;}
+ }
+
+ result_type result(dont_care) const{return val;}
+
+ private:
+ Sample val;
+
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acf
+//
+
+namespace tag
+{
+
+ template <typename Discriminator = default_delay_discriminator>
+ struct integrated_acf
+ : depends_on<acv0<Discriminator>,integrated_acvf<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef
+ accumulators::impl::integrated_acf_impl<mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::integrated_acf
+//
+
+namespace extract
+{
+
+// extractor<tag::integrated_acf<> > const integrated_acf = {};
+ // see acvf about default_delay_discriminator
+ template<typename Discriminator,typename AccumulatorSet>
+ typename mpl::apply<
+ AccumulatorSet,tag::integrated_acf<Discriminator> >::type::result_type
+ integrated_acf(AccumulatorSet const& acc){
+ typedef tag::integrated_acf<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }
+
+// TODO
+// overload (default) see acvf
+
+}
+
+using extract::integrated_acf;
+
+
+}} // namespace boost::accumulators
+
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/integrated_acvf.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/integrated_acvf.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,122 @@
+///////////////////////////////////////////////////////////////////////////////
+// integrated_acvf.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_INTEGRATED_ACVF_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_INTEGRATED_ACVF_HPP_ER_04_2008
+
+//TODO check if any header not needed
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <numeric>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.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/acvf.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // integrated_acvf_impl
+ template<typename Sample,typename Discriminator>
+ class integrated_acvf_impl
+ : public accumulator_base
+ {
+ //TODO or via feature?
+ typedef acvf_impl<Sample,Discriminator> acvf_type;
+ typedef typename acvf_type::result_type range_type;
+ public:
+ typedef Sample result_type;
+ integrated_acvf_impl(dont_care):val(0.0){}
+
+ template<typename Args>
+ void operator ()(Args const &args)
+ {
+ range_type range = acvf<Discriminator>(args[accumulator]);
+ typedef typename range_type::const_iterator iter_type;
+ Sample acv0_val = (*begin(range));
+ val = std::accumulate(begin(range),end(range),0.0);
+ val *=2.0;
+ val -=acv0_val;
+ }
+
+ result_type result(dont_care) const{return val;}
+
+ private:
+ Sample val;
+
+ };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acvf
+//
+
+namespace tag
+{
+ template <typename Discriminator = default_delay_discriminator>
+ struct integrated_acvf
+ : depends_on<acvf<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef accumulators::impl::integrated_acvf_impl<mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::integrated_acvf
+//
+
+namespace extract
+{
+
+// extractor<tag::integrated_acvf<> > const integrated_acvf = {};
+
+ // see acvf about default_delay_discriminator
+ template<typename Discriminator,typename AccumulatorSet>
+ typename mpl::apply<
+ AccumulatorSet,tag::integrated_acvf<Discriminator>
+ >::type::result_type
+ integrated_acvf(AccumulatorSet const& acc){
+ typedef tag::integrated_acvf<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }
+
+// TODO
+// overload (default) see acvf
+
+}
+
+using extract::integrated_acvf;
+
+
+}} // namespace boost::accumulators
+
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/percentage_effective_sample_size.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/percentage_effective_sample_size.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,124 @@
+///////////////////////////////////////////////////////////////////////////////
+// percentage_effective_sample_size.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_PERCENTAGE_EFFECTIVE_SAMPLE_SIZE_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_PERCENTAGE_EFFECTIVE_SAMPLE_SIZE_HPP_ER_04_2008
+
+//TODO check if any header not needed
+
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+
+#include <boost/accumulators/framework/extractor.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/integrated_acvf.hpp>
+#include <boost/accumulators/statistics/acv0.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // percentage_effective_sample_size
+ template<typename Sample,typename Discriminator>
+ class percentage_effective_sample_size_impl
+ : public accumulator_base
+ {
+ public:
+ typedef std::size_t result_type;
+
+ percentage_effective_sample_size_impl(dont_care):val(0){}
+
+ template<typename Args>
+ void operator()(const Args& args)
+ {
+ Sample iacvf = integrated_acvf<Discriminator>(args[accumulator]);
+ if(iacvf>0.0){
+
+ typedef boost::numeric::converter<result_type,Sample> Sample2res;
+ Sample acv0_val = acv0<Discriminator>(args[accumulator]);
+ Sample tmp = 100.0*acv0_val/iacvf;
+ val = Sample2res::convert(tmp);
+ }else{
+ val = 0;
+ }
+ }
+
+ result_type result(dont_care) const
+ {
+ return val;
+ }
+ private:
+ result_type val;
+ };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acvf
+//
+
+namespace tag
+{
+ template <typename Discriminator = default_delay_discriminator>
+ struct percentage_effective_sample_size
+ : depends_on<acv0<Discriminator>, integrated_acvf<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef
+ accumulators::impl::percentage_effective_sample_size_impl<
+ mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::percentage_effective_sample_size
+//
+
+namespace extract
+{
+
+// extractor<tag::percentage_effective_sample_size<> >
+// const percentage_effective_sample_size = {};
+
+ // see acvf about default_delay_discriminator
+ template<typename Discriminator,typename AccumulatorSet>
+ typename mpl::apply<
+ AccumulatorSet,tag::percentage_effective_sample_size<Discriminator>
+ >::type::result_type
+ percentage_effective_sample_size(AccumulatorSet const& acc){
+ typedef tag::percentage_effective_sample_size<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }
+
+// TODO
+// overload (default) see acvf
+
+}
+
+using extract::percentage_effective_sample_size;
+}}
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/standard_error_autocorrelated.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/standard_error_autocorrelated.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,121 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_error_autocorrelated.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_STANDARD_ERROR_AUTOCORRELATED_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_STANDARD_ERROR_AUTOCORRELATED_HPP_ER_04_2008
+
+//TODO check if any header not needed
+
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.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/integrated_acvf.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // standard_error_autocorrelated
+ template<typename Sample,typename Discriminator>
+ class standard_error_autocorrelated_impl
+ : public accumulator_base
+ {
+ public:
+ typedef Sample result_type;
+
+ standard_error_autocorrelated_impl(dont_care)
+ {}
+
+ template<typename Args>
+ void operator()(Args const &args)
+ {
+ Sample iacv = integrated_acvf<Discriminator>(args[accumulator]);
+ Sample n = (Sample)(count(args));
+ val = 0.0;
+ if((iacv>0.0) && (n>0.0)){val = sqrt(iacv/n);}//also = sqrt(acv0/ess)
+ }
+
+ result_type result(dont_care) const
+ {
+ return val;
+ }
+ private:
+ Sample val;
+ };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acvf
+//
+
+namespace tag
+{
+ template <typename Discriminator = default_delay_discriminator>
+ struct standard_error_autocorrelated
+ : depends_on<count,integrated_acvf<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef
+ accumulators::impl::standard_error_autocorrelated_impl<
+ mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::standard_error_autocorrelated
+//
+
+namespace extract
+{
+
+// extractor<tag::standard_error_autocorrelated<> >
+// const standard_error_autocorrelated = {};
+
+ // see acvf about default_delay_discriminator
+ template<typename Discriminator,typename AccumulatorSet>
+ typename mpl::apply<
+ AccumulatorSet,tag::standard_error_autocorrelated<Discriminator>
+ >::type::result_type
+ standard_error_autocorrelated(AccumulatorSet const& acc){
+ typedef tag::standard_error_autocorrelated<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }
+
+// TODO
+// overload (default) see acvf
+
+}
+
+using extract::standard_error_autocorrelated;
+
+}}
+
+#endif

Added: sandbox/acvf/boost/accumulators/statistics/standard_error_iid.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/accumulators/statistics/standard_error_iid.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,122 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_error_iid.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_STANDARD_ERROR_IID_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_STATISTICS_STANDARD_ERROR_IID_HPP_ER_04_2008
+
+//TODO check if any header not needed
+
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.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/acv0.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+ ////////////////////////////////////////////////////////////////////////////
+ // standard_error_iid
+ template<typename Sample,typename Discriminator>
+ class standard_error_iid_impl
+ : public accumulator_base
+ {
+ public:
+ typedef Sample result_type;
+
+ standard_error_iid_impl(dont_care)
+ {}
+
+ template<typename Args>
+ void operator()(Args const &args)
+ {
+ Sample acv0_val = acv0<Discriminator>(args[accumulator]);
+ Sample n = (Sample)(count(args));
+ val = 0.0;
+ if((acv0_val>0.0) && (n>0.0)){val = sqrt(acv0_val/n);}
+ }
+
+
+ result_type result(dont_care) const
+ {
+ return val;
+ }
+ private:
+ Sample val;
+ };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::standard_error_iid
+//
+
+namespace tag
+{
+ template <typename Discriminator = default_delay_discriminator>
+ struct standard_error_iid
+ : depends_on<count,acv0<Discriminator> >
+ {
+ /// INTERNAL ONLY
+ typedef
+ accumulators::impl::standard_error_iid_impl<
+ mpl::_1,Discriminator> impl;
+
+ };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::standard_error_iid
+//
+
+namespace extract
+{
+
+// extractor<tag::standard_error_iid<> >
+// const standard_error_iid = {};
+
+ // see acvf about default_delay_discriminator
+ template<typename Discriminator,typename AccumulatorSet>
+ typename mpl::apply<
+ AccumulatorSet,tag::standard_error_iid<Discriminator>
+ >::type::result_type
+ standard_error_iid(AccumulatorSet const& acc){
+ typedef tag::standard_error_iid<Discriminator> the_tag;
+ return extract_result<the_tag>(acc);
+ }
+
+// TODO
+// overload (default) see acvf
+
+}
+
+using extract::standard_error_iid;
+
+}}
+
+#endif

Added: sandbox/acvf/boost/random/moving_average.hpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/boost/random/moving_average.hpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,52 @@
+///////////////////////////////////////////////////////////////////////////////
+// moving_average.hpp
+//
+// Copyright 2008 Erwann Rogard. 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_RANDOM_MOVING_AVERAGE_HPP_ER_04_2008
+#define BOOST_ACCUMULATORS_RANDOM_MOVING_AVERAGE_HPP_ER_04_2008
+
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/fir.hpp>
+#include <boost/range/iterator_range.hpp>
+namespace boost{namespace random
+{
+
+// Simulates a Moving average process
+template<typename T>
+class moving_average{
+public:
+ typedef T input_type;
+ typedef T result_type ;
+ template<typename R>
+ moving_average(const R& coeffs)
+ :acc(
+ accumulators::tag::fir::coefficients=coeffs,
+ accumulators::tag::delay<>::cache_size=coeffs.size()){}
+ moving_average(const moving_average& that)
+ :acc(that.acc){}
+ moving_average& operator=(const moving_average& that){
+ if(&that!=this){
+ acc = that.acc;
+ }
+ return *this;
+ }
+ template<typename G>//G models NumberGenerator
+ result_type operator()(G& gen){
+ T x = gen();
+ acc(x);
+ return accumulators::extract::fir(acc);
+ }
+private:
+ typedef accumulators::accumulator_set<
+ T,
+ accumulators::stats<accumulators::tag::fir,accumulators::tag::delay<> >
+ > acc_type;
+ acc_type acc;
+};
+
+}}
+#endif

Added: sandbox/acvf/libs/accumulators/statistics/example/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/acvf/libs/accumulators/statistics/example/main.cpp 2008-05-25 23:10:41 EDT (Sun, 25 May 2008)
@@ -0,0 +1,141 @@
+///////////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+// Copyright 2008 Erwann Rogard. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <iostream>
+#include <algorithm>
+#include <iterator>
+#include <vector>
+#include <functional>
+#include <fstream>
+#include <boost/mpl/size_t.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/delay.hpp>
+#include <boost/accumulators/statistics/acvf_moving_average.hpp>
+#include <boost/accumulators/statistics/acvf.hpp>
+#include <boost/accumulators/statistics/acf.hpp>
+#include <boost/accumulators/statistics/integrated_acf.hpp>
+#include <boost/accumulators/statistics/integrated_acvf.hpp>
+#include <boost/accumulators/statistics/percentage_effective_sample_size.hpp>
+#include <boost/accumulators/statistics/standard_error_autocorrelated.hpp>
+#include <boost/accumulators/statistics/standard_error_iid.hpp>
+#include <boost/accumulators/statistics/acvf_analysis.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/moving_average.hpp>
+#include <boost/bind.hpp>
+#include <boost/ref.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+int main(){
+
+ const char* filepath = "./acvf_output";
+ std::ofstream out(filepath);
+
+ using namespace boost::accumulators;
+ typedef boost::mt19937 urng_type;
+ typedef boost::normal_distribution<> nd_type;
+ typedef boost::variate_generator<urng_type&,nd_type> gen_nd_type;
+ typedef boost::random::moving_average<double> ma_type;
+ typedef std::vector<double> ma_vals_type;
+ typedef default_delay_discriminator delaydisrc;
+ typedef accumulator_set<
+ double, stats<
+ tag::acvf<>,
+ tag::acf<>,
+ tag::integrated_acvf<>,
+ tag::percentage_effective_sample_size<>,
+ tag::standard_error_autocorrelated<>,
+ tag::standard_error_iid<>
+ >
+ > acc_type;
+
+ //model parameters and related quantities
+ std::vector<double> coeffs;
+ std::vector<unsigned int> lags;
+ std::vector<double> true_acfs;
+ double true_integrated_acvf = 0.0;
+ std::size_t true_ess = 0;
+ //with these coeffs, should expect ess% > 100
+ {using namespace boost::assign; coeffs+=1.0,-0.5,0.2; lags+=0,1,2;}
+ unsigned int K = coeffs.size()-1;
+ transform(lags.begin(),lags.end(),back_inserter(true_acfs),
+ make_acvf_moving_average(coeffs));
+ true_integrated_acvf
+ = 2*std::accumulate(true_acfs.begin(),true_acfs.end(),0.0);
+ true_integrated_acvf -= *true_acfs.begin();
+ true_ess = boost::numeric::converter<std::size_t,double>::convert(
+ 100.0*true_acfs[0]/true_integrated_acvf);
+
+ out << "->true_acvf: ";
+ copy(true_acfs.begin(),true_acfs.end(),
+ std::ostream_iterator<double>(out," "));
+ out << "<-" << std::endl;
+ { double div = 1.0/true_acfs[0];
+ transform(true_acfs.begin(),true_acfs.end(),true_acfs.begin(),
+ boost::bind(std::multiplies<double>(),_1,div));
+ }
+ out << "->true_acf: ";
+ copy(true_acfs.begin(),true_acfs.end(),
+ std::ostream_iterator<double>(out," ")); out << "<-" << std::endl;
+ out << "->true var: " << true_integrated_acvf << "<-" << std::endl;
+ out << "->true ess%: " << true_ess << "<-" << std::endl;
+
+ //generation of a Moving Average of order K process
+ const unsigned long N = 100000;
+ urng_type urng(0);
+ gen_nd_type gen_nd(urng,nd_type());
+ ma_type ma(boost::make_iterator_range(coeffs.begin(),coeffs.end()));
+ ma_vals_type ma_vals(N);
+ for(ma_vals_type::iterator i=ma_vals.begin(); i<ma_vals.end(); i++)
+ {(*i) = ma(gen_nd);}
+
+ //estimation
+ acc_type acc(tag::delay<>::cache_size=(K+1));
+ for_each(ma_vals.begin(),ma_vals.end(),
+ boost::bind<void>(boost::ref(acc),_1));
+ out << "->sample size: " << N << std::endl;
+ out << "->estimated acvf: ";
+ copy(begin(acvf<delaydisrc>(acc)),end(acvf<delaydisrc>(acc)),
+ std::ostream_iterator<double>(out," "));
+ out<<"<-"<<std::endl;
+
+ out << "->estimated acf: ";
+ copy(begin(acf<delaydisrc>(acc)),end(acf<delaydisrc>(acc)),
+ std::ostream_iterator<double>(out," "));
+ out<<"<-"<<std::endl;
+
+ out << "->estimated var: "
+ << integrated_acvf<delaydisrc>(acc) << "<-" << std::endl;
+
+ out << "->estimated ess%: "
+ << percentage_effective_sample_size<delaydisrc>(acc)
+ << "<-" << std::endl;
+
+ out << "->estimated standard error assuming iid: "
+ << standard_error_iid<delaydisrc>(acc) << "<-" << std::endl;
+
+ out << "->estimated standard error assuming acf is zero after lag "
+ << K << ": "
+ << standard_error_autocorrelated<delaydisrc>(acc) << "<-" << std::endl;
+
+ //the above bundled into one class:
+ out << " --------- ";
+ out << "output from acvf_analysis:" << std::endl;
+ const unsigned int offset = 0;
+ const unsigned int stride = 1;
+ const unsigned int assumed_lag = 3;
+ statistics::acvf_analysis acvf_x(assumed_lag);
+ acvf_x(ma_vals,offset,stride);
+ acvf_x.print(out);
+
+ std::cout << "output libs/accumulators/main.cpp is in"
+ << filepath << std::endl;
+
+ return 0;
+}


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