Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag > Struct Template Reference

Iterative calculation of variance. More...

#include <statistics_fwd.hpp>

Inheritance diagram for boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag >:
Collaboration diagram for boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag >:

Public Types

typedef
numeric::functional::fdiv
< Sample, std::size_t >
::result_type 
result_type
 
typedef mpl::false_ is_droppable
 

Public Member Functions

template<typename Args >
 variance_impl (Args const &args)
 
template<typename Args >
void operator() (Args const &args)
 
result_type result (dont_care) const
 
detail::void_ operator() (dont_care)
 
detail::void_ add_ref (dont_care)
 
detail::void_ drop (dont_care)
 
detail::void_ on_drop (dont_care)
 

Detailed Description

template<typename Sample, typename MeanFeature, typename Tag>
struct boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag >

Iterative calculation of variance.

Iterative calculation of sample variance $\sigma_n^2$ according to the formula

\[ \sigma_n^2 = \frac{1}{n} \sum_{i = 1}^n (x_i - \mu_n)^2 = \frac{n-1}{n} \sigma_{n-1}^2 + \frac{1}{n-1}(x_n - \mu_n)^2. \]

where

\[ \mu_n = \frac{1}{n} \sum_{i = 1}^n x_i. \]

is the estimate of the sample mean and $n$ is the number of samples.

Note that the sample variance is not defined for $n <= 1$.

A simplification can be obtained by the approximate recursion

\[ \sigma_n^2 \approx \frac{n-1}{n} \sigma_{n-1}^2 + \frac{1}{n}(x_n - \mu_n)^2. \]

because the difference

\[ \left(\frac{1}{n-1} - \frac{1}{n}\right)(x_n - \mu_n)^2 = \frac{1}{n(n-1)}(x_n - \mu_n)^2. \]

converges to zero as $n \rightarrow \infty$. However, for small $ n $ the difference can be non-negligible.

Member Typedef Documentation

template<typename Sample , typename MeanFeature , typename Tag >
typedef numeric::functional::fdiv<Sample, std::size_t>::result_type boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag >::result_type

Constructor & Destructor Documentation

template<typename Sample , typename MeanFeature , typename Tag >
template<typename Args >
boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag >::variance_impl ( Args const &  args)
inline

Member Function Documentation

detail::void_ boost::accumulators::accumulator_base::add_ref ( dont_care  )
inlineinherited
detail::void_ boost::accumulators::accumulator_base::drop ( dont_care  )
inlineinherited
detail::void_ boost::accumulators::accumulator_base::on_drop ( dont_care  )
inlineinherited
detail::void_ boost::accumulators::accumulator_base::operator() ( dont_care  )
inlineinherited
template<typename Sample , typename MeanFeature , typename Tag >
template<typename Args >
void boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag >::operator() ( Args const &  args)
inline
template<typename Sample , typename MeanFeature , typename Tag >
result_type boost::accumulators::impl::variance_impl< Sample, MeanFeature, Tag >::result ( dont_care  ) const
inline

The documentation for this struct was generated from the following file: