The OpenD Programming Language

VarianceAccumulator

Constructors

this
this(Slice!(Iterator, N, kind) slice)
this
this(U[] array)
this
this(T withAsSlice)
this
this(T x)

Members

Functions

count
size_t count()
mean
F mean()
variance
F variance(bool isPopulation)

Variables

centeredSumOfSquares
Summator!(T, summation) centeredSumOfSquares;
meanAccumulator
MeanAccumulator!(T, summation) meanAccumulator;

Examples

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;

enum PopulationTrueCT = true;
enum PopulationFalseCT = false;
bool PopulationTrueRT = true;
bool PopulationFalseRT = false;

auto v = VarianceAccumulator!(double, VarianceAlgo.twoPass, Summation.naive)(x);
assert(v.variance(PopulationTrueRT).approxEqual(54.76562 / 12));
assert(v.variance(PopulationTrueCT).approxEqual(54.76562 / 12));
assert(v.variance(PopulationFalseRT).approxEqual(54.76562 / 11));
assert(v.variance(PopulationFalseCT).approxEqual(54.76562 / 11));

Meta