|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r51994 - in sandbox/acvf: boost/accumulators/statistics boost/random libs/accumulators/statistics/doc libs/accumulators/statistics/example libs/accumulators/statistics/src
From: erwann.rogard_at_[hidden]
Date: 2009-03-26 17:03:43
Author: e_r
Date: 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
New Revision: 51994
URL: http://svn.boost.org/trac/boost/changeset/51994
Log:
Minor changes to /acvf
Added:
sandbox/acvf/libs/accumulators/statistics/doc/
sandbox/acvf/libs/accumulators/statistics/doc/readme.txt (contents, props changed)
sandbox/acvf/libs/accumulators/statistics/src/
Text files modified:
sandbox/acvf/boost/accumulators/statistics/acf.hpp | 6 --
sandbox/acvf/boost/accumulators/statistics/acv0.hpp | 6 --
sandbox/acvf/boost/accumulators/statistics/acvf_analysis.hpp | 96 ++++++++++++++++++++++++++-------------
sandbox/acvf/boost/accumulators/statistics/acvf_moving_average.hpp | 5 +
sandbox/acvf/boost/accumulators/statistics/integrated_acf.hpp | 5 --
sandbox/acvf/boost/random/moving_average.hpp | 5 +
sandbox/acvf/libs/accumulators/statistics/example/main.cpp | 66 ++++++++++++++-------------
7 files changed, 107 insertions(+), 82 deletions(-)
Modified: sandbox/acvf/boost/accumulators/statistics/acf.hpp
==============================================================================
--- sandbox/acvf/boost/accumulators/statistics/acf.hpp (original)
+++ sandbox/acvf/boost/accumulators/statistics/acf.hpp 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -113,9 +113,6 @@
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
@@ -124,8 +121,7 @@
return extract_result<the_tag>(acc);
}//typical call://acf<default_delay_discriminator>(acc)
-// TODO
-// overload (default) see acvf
+
}
Modified: sandbox/acvf/boost/accumulators/statistics/acv0.hpp
==============================================================================
--- sandbox/acvf/boost/accumulators/statistics/acv0.hpp (original)
+++ sandbox/acvf/boost/accumulators/statistics/acv0.hpp 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -89,8 +89,7 @@
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>
@@ -100,9 +99,6 @@
return extract_result<the_tag>(acc);
}
-// TODO
-// overload (default) see acvf
-
}
using extract::acv0;
Modified: sandbox/acvf/boost/accumulators/statistics/acvf_analysis.hpp
==============================================================================
--- sandbox/acvf/boost/accumulators/statistics/acvf_analysis.hpp (original)
+++ sandbox/acvf/boost/accumulators/statistics/acvf_analysis.hpp 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -4,6 +4,8 @@
// 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_ANALYSIS_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_ACVF_ANALYSIS_HPP_ER_2008_04
#include <iostream>
#include <algorithm>
#include <iterator>
@@ -14,6 +16,7 @@
#include <boost/parameter/parameters.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/bind.hpp>
+#include <boost/range.hpp>
#include <boost/ref.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/range/iterator_range.hpp>
@@ -28,38 +31,50 @@
#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{
+ template<
+ typename RealType,
+ typename Discriminator = default_delay_discriminator
+ >
class acvf_analysis{
- typedef boost::accumulators::default_delay_discriminator delaydisrc;
+ typedef Discriminator discr_t;
+ public:
+ typedef RealType value_type;
+
+ private:
+
typedef boost::accumulators::accumulator_set<
- double, boost::accumulators::stats<
+ value_type, 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<>
+ boost::accumulators::tag::acf<discr_t>,
+ boost::accumulators::tag::integrated_acvf<discr_t>,
+ boost::accumulators::tag::percentage_effective_sample_size<
+ discr_t>,
+ boost::accumulators::tag::standard_error_autocorrelated<discr_t>,
+ boost::accumulators::tag::standard_error_iid<discr_t>
>
> 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)){};
+ acc(boost::accumulators::tag::delay<discr_t>::cache_size=(K+1)){};
+
+ void operator()(value_type x){
+ return acc(x);
+ }
template<typename R>
void operator()(
- const R& range,//TODO specify range, container?
+ const R& range,
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;
+ typedef typename range_iterator<const R>::type const_iter_type;
+ typedef typename range_size<R>::type size_type;
const_iter_type i = boost::begin(range);
const_iter_type e = boost::end(range);
if(std::distance(i,e)>offset){
@@ -82,29 +97,46 @@
std::runtime_error("acvf_analysis");
}
}
+ std::size_t max_lag()const{ return K; }
+ value_type mean()const{ return accumulators::mean(acc); }
+ value_type standard_error_iid()const{
+ return accumulators::standard_error_iid<discr_t>(acc);
+ }
+ value_type standard_error_autocorrelated()const{
+ return accumulators
+ ::standard_error_autocorrelated<discr_t>(acc);
+ }
+ value_type integrated_acvf()const{
+ return accumulators
+ ::integrated_acvf<discr_t>(acc);
+ }
+
+ value_type percentage_effective_sample_size()const{
+ return accumulators
+ ::percentage_effective_sample_size<discr_t>(acc);
+ }
+
void print(std::ostream& os)const
{
- using namespace boost::accumulators;
- os << "->count: " << count(acc)
- << std::endl
- << "->estimated acf: ";
+ //using namespace boost::accumulators;
+ os << "count : " << accumulators::count(acc)
+ << "\nacf : ";
copy(
- begin(acf<delaydisrc>(acc)),
- end(acf<delaydisrc>(acc)),
- std::ostream_iterator<double>(os," ")
+ begin(accumulators::acf<discr_t>(acc)),
+ end(accumulators::acf<discr_t>(acc)),
+ std::ostream_iterator<value_type>(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;
+ os << "\nintegrated_acvf : "
+ << integrated_acvf()
+ << "\ness% : "
+ << percentage_effective_sample_size()
+ << "\nmean : " << mean()
+ << "\nstandard error : "
+ << "\n assuming iid : "
+ << standard_error_iid()
+ << "\n assuming acf is zero after lag "
+ << max_lag() << ": "
+ << standard_error_autocorrelated() << std::endl;
};
private:
Modified: sandbox/acvf/boost/accumulators/statistics/acvf_moving_average.hpp
==============================================================================
--- sandbox/acvf/boost/accumulators/statistics/acvf_moving_average.hpp (original)
+++ sandbox/acvf/boost/accumulators/statistics/acvf_moving_average.hpp 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -14,6 +14,7 @@
#include <stdexcept>
#include <boost/call_traits.hpp>
#include <boost/assert.hpp>
+#include <boost/range.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/iterator/iterator_traits.hpp>
namespace boost { namespace accumulators{
@@ -26,7 +27,7 @@
/// 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;
+ typedef typename range_iterator<const R>::type iterator_type;
public:
typedef std::size_t argument_type;
typedef typename
@@ -40,7 +41,7 @@
return *this;
}
result_type operator()(argument_type delay)const{
- typedef typename R::const_iterator iterator_type;
+ typedef typename range_iterator<const R>::type iterator_type;
result_type res = 0.0;
size_t h = delay;
if(coeffs.size()>0){
Modified: sandbox/acvf/boost/accumulators/statistics/integrated_acf.hpp
==============================================================================
--- sandbox/acvf/boost/accumulators/statistics/integrated_acf.hpp (original)
+++ sandbox/acvf/boost/accumulators/statistics/integrated_acf.hpp 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -96,8 +96,6 @@
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
@@ -106,9 +104,6 @@
return extract_result<the_tag>(acc);
}
-// TODO
-// overload (default) see acvf
-
}
using extract::integrated_acf;
Modified: sandbox/acvf/boost/random/moving_average.hpp
==============================================================================
--- sandbox/acvf/boost/random/moving_average.hpp (original)
+++ sandbox/acvf/boost/random/moving_average.hpp 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -43,7 +43,10 @@
private:
typedef accumulators::accumulator_set<
T,
- accumulators::stats<accumulators::tag::fir,accumulators::tag::delay<> >
+ accumulators::stats<
+ accumulators::tag::fir,
+ accumulators::tag::delay<>
+ >
> acc_type;
acc_type acc;
};
Added: sandbox/acvf/libs/accumulators/statistics/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/acvf/libs/accumulators/statistics/doc/readme.txt 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -0,0 +1,89 @@
+////////////////////////////////////////////////////////////////////////////
+// acvf
+// (C) Copyright 2008 Erwann Rogard
+// 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)
+////////////////////////////////////////////////////////////////////////////
+
+///////////
+/ Contact /
+///////////
+
+Please send questions or suggestions to erwann.rogard_at_[hidden]
+
+////////////////
+/ Requirements /
+////////////////
+
+Compiles fine under
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+The compiler search path must include
+boost_1_37_0
+sandbox/acvf
+sandbox/accumulators_filters
+
+////////////
+/ Overview /
+////////////
+
+Provides autocovariance and related statistics within the Boost.Accumulator
+framework.
+
+
+/////////
+/ Usage /
+/////////
+
+ typedef mpl::void_ discr_t;
+ typedef accumulator_set<
+ value_type, stats<
+ tag::acvf<discr_t>,
+ tag::acf<discr_t>,
+ tag::integrated_acvf<discr_t>,
+ tag::percentage_effective_sample_size<discr_t>,
+ tag::standard_error_autocorrelated<discr_t>,
+ tag::standard_error_iid<discr_t>
+ >
+ > acc_type;
+ std::size_t max_lag = 3;
+ acc_type acc(max_lag);
+ acc(-1.0); acc(+1.0); acc(-1.0); acc(1.0);
+ acvf<discr_t>(acc);
+ percentage_effective_sample_size(acc);
+
+ Bundled version:
+ typedef acvf_analysis<value_type,discr_t> bundled_t;
+ std::ofstream out;
+ bundle_t bundle(max_lag);
+ bundle.acvf();
+ bundle.percentage_effective_sample_size();
+ bundle.print(out);
+
+////////////////////////
+/ Output from main.cpp /
+////////////////////////
+->true_acvf: 1.29 -0.6 0.2 <-
+->true_acf: 1 -0.465116 0.155039 <-
+->true var: 0.49<-
+->true ess%: 263<-
+->sample size: 100000
+->estimated acvf: 1.27563 -0.58848 0.190071 <-
+->estimated acf: 1 -0.461325 0.149002 <-
+->estimated var: 0.478814<-
+->estimated ess%: 266<-
+->estimated standard error assuming iid: 0.0035716<-
+->estimated standard error assuming acf is zero after lag 2: 0.00218818<-
+ --------- output from acvf_analysis:
+count :100000
+acf : 1 -0.461325 0.149002 0.00284592
+integrated_acvf : 0.486075
+ess% : 262
+mean : 0.00306125
+standard error :
+ assuming iid : 0.0035716
+ assuming acf is zero after lag 3: 0.00220471
+
+
Modified: sandbox/acvf/libs/accumulators/statistics/example/main.cpp
==============================================================================
--- sandbox/acvf/libs/accumulators/statistics/example/main.cpp (original)
+++ sandbox/acvf/libs/accumulators/statistics/example/main.cpp 2009-03-26 17:03:42 EDT (Thu, 26 Mar 2009)
@@ -41,26 +41,28 @@
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 double value_type;
+ typedef boost::random::moving_average<value_type> ma_type;
+ typedef std::vector<value_type> ma_vals_type;
+ //typedef default_delay_discriminator delaydisrc;
+ typedef default_delay_discriminator discr_t;
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<>
+ value_type, stats<
+ tag::acvf<discr_t>,
+ tag::acf<discr_t>,
+ tag::integrated_acvf<discr_t>,
+ tag::percentage_effective_sample_size<discr_t>,
+ tag::standard_error_autocorrelated<discr_t>,
+ tag::standard_error_iid<discr_t>
>
> 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;
+ std::vector<value_type> coeffs;
+ std::vector<unsigned int> lags;
+ std::vector<value_type> true_acfs;
+ value_type 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;
@@ -69,20 +71,20 @@
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(
+ true_ess = boost::numeric::converter<std::size_t,value_type>::convert(
100.0*true_acfs[0]/true_integrated_acvf);
out << "->true_acvf: ";
copy(true_acfs.begin(),true_acfs.end(),
- std::ostream_iterator<double>(out," "));
+ std::ostream_iterator<value_type>(out," "));
out << "<-" << std::endl;
- { double div = 1.0/true_acfs[0];
+ { value_type div = 1.0/true_acfs[0];
transform(true_acfs.begin(),true_acfs.end(),true_acfs.begin(),
- boost::bind(std::multiplies<double>(),_1,div));
+ boost::bind(std::multiplies<value_type>(),_1,div));
}
out << "->true_acf: ";
copy(true_acfs.begin(),true_acfs.end(),
- std::ostream_iterator<double>(out," ")); out << "<-" << std::endl;
+ std::ostream_iterator<value_type>(out," ")); out << "<-" << std::endl;
out << "->true var: " << true_integrated_acvf << "<-" << std::endl;
out << "->true ess%: " << true_ess << "<-" << std::endl;
@@ -93,36 +95,36 @@
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);}
+ { (*i) = ma(gen_nd); }
//estimation
- acc_type acc(tag::delay<>::cache_size=(K+1));
+ acc_type acc(tag::delay<discr_t>::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," "));
+ copy(begin(acvf<discr_t>(acc)),end(acvf<discr_t>(acc)),
+ std::ostream_iterator<value_type>(out," "));
out<<"<-"<<std::endl;
out << "->estimated acf: ";
- copy(begin(acf<delaydisrc>(acc)),end(acf<delaydisrc>(acc)),
- std::ostream_iterator<double>(out," "));
+ copy(begin(acf<discr_t>(acc)),end(acf<discr_t>(acc)),
+ std::ostream_iterator<value_type>(out," "));
out<<"<-"<<std::endl;
out << "->estimated var: "
- << integrated_acvf<delaydisrc>(acc) << "<-" << std::endl;
+ << integrated_acvf<discr_t>(acc) << "<-" << std::endl;
out << "->estimated ess%: "
- << percentage_effective_sample_size<delaydisrc>(acc)
+ << percentage_effective_sample_size<discr_t>(acc)
<< "<-" << std::endl;
out << "->estimated standard error assuming iid: "
- << standard_error_iid<delaydisrc>(acc) << "<-" << std::endl;
+ << standard_error_iid<discr_t>(acc) << "<-" << std::endl;
out << "->estimated standard error assuming acf is zero after lag "
<< K << ": "
- << standard_error_autocorrelated<delaydisrc>(acc) << "<-" << std::endl;
+ << standard_error_autocorrelated<discr_t>(acc) << "<-" << std::endl;
//the above bundled into one class:
out << " --------- ";
@@ -130,11 +132,11 @@
const unsigned int offset = 0;
const unsigned int stride = 1;
const unsigned int assumed_lag = 3;
- statistics::acvf_analysis acvf_x(assumed_lag);
+ statistics::acvf_analysis<value_type,discr_t> acvf_x(assumed_lag);
acvf_x(ma_vals,offset,stride);
acvf_x.print(out);
- std::cout << "output libs/accumulators/main.cpp is in"
+ std::cout << "output of libs/accumulators/main.cpp was written to"
<< 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