The OpenD Programming Language

VarianceAccumulator

Constructors

this
this(Range r)
this
this(T x)

Members

Functions

centeredSumOfSquares
F centeredSumOfSquares()
count
size_t count()
mean
F mean()
put
void put(Range r)
put
void put(T x)
put
void put(VarianceAccumulator!(U, varianceAlgo, sumAlgo) v)
sumOfSquares
F sumOfSquares()
variance
F variance(bool isPopulation)

Examples

naive

import mir.math.common: approxEqual;
import mir.ndslice.slice: sliced;

auto x = [0.0, 1.0, 1.5, 2.0, 3.5, 4.25,
          2.0, 7.5, 5.0, 1.0, 1.5, 0.0].sliced;

VarianceAccumulator!(double, VarianceAlgo.naive, Summation.naive) v;
v.put(x);
assert(v.variance(true).approxEqual(54.76562 / 12));
assert(v.variance(false).approxEqual(54.76562 / 11));

v.put(4.0);
assert(v.variance(true).approxEqual(57.01923 / 13));
assert(v.variance(false).approxEqual(57.01923 / 12));

Meta