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::immediate_rolling_variance_impl< Sample > Struct Template Reference

Iterative calculation of the rolling variance. More...

#include <rolling_variance.hpp>

Inheritance diagram for boost::accumulators::impl::immediate_rolling_variance_impl< Sample >:
Collaboration diagram for boost::accumulators::impl::immediate_rolling_variance_impl< Sample >:

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 >
 immediate_rolling_variance_impl (Args const &args)
 
template<typename Args >
void operator() (Args const &args)
 
template<typename Args >
result_type result (Args const &args) 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>
struct boost::accumulators::impl::immediate_rolling_variance_impl< Sample >

Iterative calculation of the rolling variance.

Iterative calculation of sample variance $\sigma_n^2$ is done as follows, see also http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance. For a rolling window of size $N$, for the first $N$ samples, the variance is computed according to the formula

\[ \sigma_n^2 = \frac{1}{n-1} \sum_{i = 1}^n (x_i - \mu_n)^2 = \frac{1}{n-1}M_{2,n}, \]

where the sum of squares $M_{2,n}$ can be recursively computed as:

\[ M_{2,n} = \sum_{i = 1}^n (x_i - \mu_n)^2 = M_{2,n-1} + (x_n - \mu_n)(x_n - \mu_{n-1}), \]

and the estimate of the sample mean as:

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

For further samples, when the rolling window is fully filled with data, one has to take into account that the oldest sample $x_{n-N}$ is dropped from the window. The sample variance over the window now becomes:

\[ \sigma_n^2 = \frac{1}{N-1} \sum_{i = n-N+1}^n (x_i - \mu_n)^2 = \frac{1}{n-1}M_{2,n}, \]

where the sum of squares $M_{2,n}$ now equals:

\[ M_{2,n} = \sum_{i = n-N+1}^n (x_i - \mu_n)^2 = M_{2,n-1} + (x_n - \mu_n)(x_n - \mu_{n-1}) - (x_{n-N} - \mu_n)(x_{n-N} - \mu_{n-1}), \]

and the estimated mean is:

\[ \mu_n = \frac{1}{N} \sum_{i = n-N+1}^n x_i = \mu_{n-1} + \frac{1}{n}(x_n - x_{n-N}). \]

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

Member Typedef Documentation

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

Constructor & Destructor Documentation

template<typename Sample >
template<typename Args >
boost::accumulators::impl::immediate_rolling_variance_impl< Sample >::immediate_rolling_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 >
template<typename Args >
result_type boost::accumulators::impl::immediate_rolling_variance_impl< Sample >::result ( Args const &  args) const
inline

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