The OpenD Programming Language

MomentAccumulator

Constructors

this
this(Range r)
this
this(Range r, T m)
this
this(Range r, T m, T s)
this
this(T x)
this
this(T x, T m)
this
this(T x, T m, T s)

Members

Functions

moment
F moment()
put
void put(Range r)
put
void put(Range r, T m)
put
void put(Range r, T m, T s)
put
void put(T x)
put
void put(MomentAccumulator!(T, N, summation) m)
sumOfPower
F sumOfPower()

Variables

count
size_t count;
summator
Summator!(T, summation) summator;

Examples

Raw moment

import mir.math.common: approxEqual;
import mir.ndslice.slice: sliced;
import mir.stat.transform: center;

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;

MomentAccumulator!(double, 2, Summation.naive) v;
v.put(x);

assert(v.moment.approxEqual(54.76562 / 12));

v.put(4.0);
assert(v.moment.approxEqual(70.76562 / 13));

Central moment

import mir.math.common: approxEqual;
import mir.ndslice.slice: sliced;
import mir.stat.transform: center;

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;

MomentAccumulator!(double, 2, Summation.naive) v;
auto m = mean(x);
v.put(x, m);
assert(v.moment.approxEqual(54.76562 / 12));

Standardized moment with scaled calculation

import mir.math.common: approxEqual, sqrt;
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;

auto u = VarianceAccumulator!(double, VarianceAlgo.twoPass, Summation.naive)(x);
MomentAccumulator!(double, 3, Summation.naive) v;
v.put(x, u.mean, u.variance(true).sqrt);
assert(v.moment.approxEqual(12.000999 / 12));
assert(v.count == 12);

Meta