STRUCT TEMPLAT(3)

NAME
boost::accumulators::impl::variance_impl - Iterative calculation of variance.

SYNOPSIS

// In header: <boost/accumulators/statistics/variance.hpp>
template<typename Sample, typename MeanFeature, typename Tag>
struct variance_impl {
  // types
  typedef numeric::functional::average< Sample, std::size_t >::result_type result_type;
  // construct/copy/destruct
  template<typename Args> variance_impl(Args const &);
  // public member functions
  template<typename Args> void operator()(Args const &);
  result_type result(dont_care) const;
};

DESCRIPTION

Iterative calculation of sample variance [1][IMAGE][2] [$igma_n^2$] according to the formula Equation 1.23.  [3].sp .RS 4 [IMAGE][4] \[ \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. \] .RE where Equation 1.24.  [5].sp .RS 4 [IMAGE][6] \[ \mu_n = \frac{1}{n} \sum_{i = 1}^n x_i. \] .RE is the estimate of the sample mean and [7][IMAGE][8] [$n$] is the number of samples.

Note that the sample variance is not defined for [9][IMAGE][10] [$n <= 1$].

A simplification can be obtained by the approximate recursion Equation 1.25.  [11].sp .RS 4 [IMAGE][12] \[ \sigma_n^2 \approx \frac{n-1}{n} \sigma_{n-1}^2 + \frac{1}{n}(x_n - \mu_n)^2. \] .RE because the difference Equation 1.26.  [13].sp .RS 4 [IMAGE][14] \[ \left(\frac{1}{n-1} - \frac{1}{n}\right)(x_n - \mu_n)^2 = \frac{1}{n(n-1)}(x_n - \mu_n)^2. \] .RE converges to zero as [15][IMAGE][16] [$n ightarrow infty$]. However, for small [17][IMAGE][18] [$ n $] the difference can be non-negligible.

  variance_impl public construct/copy/destruct

    1.

    template<typename Args> variance_impl(Args const & args);

  variance_impl public member functions

    1.

    template<typename Args> void operator()(Args const & args);

    2.

    result_type result(dont_care) const;