VarianceAccumulator

Constructors

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

Members

Functions

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

Variables

centeredSumOfSquares
Summator!(T, summation) centeredSumOfSquares;

Examples

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

auto a = [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;
auto x = a.center;

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

VarianceAccumulator!(double, VarianceAlgo.assumeZeroMean, Summation.naive) v;
v.put(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));

v.put(4.0);
assert(v.variance(PopulationTrueRT).approxEqual(70.76562 / 13));
assert(v.variance(PopulationTrueCT).approxEqual(70.76562 / 13));
assert(v.variance(PopulationFalseRT).approxEqual(70.76562 / 12));
assert(v.variance(PopulationFalseCT).approxEqual(70.76562 / 12));
import mir.math.common: approxEqual;
import mir.ndslice.slice: sliced;

auto a = [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;
auto b = a.center;
auto x = b[0 .. 6];
auto y = b[6 .. $];

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

VarianceAccumulator!(double, VarianceAlgo.assumeZeroMean, Summation.naive) v;
v.put(x);
assert(v.variance(PopulationTrueRT).approxEqual(13.492188 / 6));
assert(v.variance(PopulationTrueCT).approxEqual(13.492188 / 6));
assert(v.variance(PopulationFalseRT).approxEqual(13.492188 / 5));
assert(v.variance(PopulationFalseCT).approxEqual(13.492188 / 5));

v.put(y);
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