The OpenD Programming Language

WMeanAccumulator

Output range for wmean.

Members

Functions

put
void put(Slice1 s, Slice2 w)
put
void put(SliceLike1 s, SliceLike2 w)
put
void put(Range r)
put
void put(RangeA r, RangeB w)
put
void put(T x, U w)
put
void put(T x)
put
void put(WMeanAccumulator!(F, summation, assumeWeights, G, weightsSummation) wm)
weight
F weight()
wmean
F wmean()
wsum
F wsum()

Variables

weights
Summator!(U, weightsSummation) weights;
wsummator
Summator!(T, summation) wsummator;

Examples

Assume weights sum to 1

import mir.math.sum: Summation;
import mir.ndslice.slice: sliced;
import mir.test: should;

WMeanAccumulator!(double, Summation.pairwise, AssumeWeights.sumToOne) x;
x.put([0.0, 1, 2, 3, 4].sliced, [0.2, 0.2, 0.2, 0.2, 0.2].sliced);
x.wmean.should == 2;
x.put(5, 0.0);
x.wmean.should == 2;

Do not assume weights sum to 1

import mir.math.sum: Summation;
import mir.ndslice.slice: sliced;
import mir.test: shouldApprox;

WMeanAccumulator!(double, Summation.pairwise, AssumeWeights.primary) x;
x.put([0.0, 1, 2, 3, 4].sliced, [1, 2, 3, 4, 5].sliced);
x.wmean.shouldApprox == 40.0 / 15;
x.put(5, 6);
x.wmean.shouldApprox == 70.0 / 21;

Assume no weights, like MeanAccumulator

import mir.math.sum: Summation;
import mir.ndslice.slice: sliced;
import mir.test: shouldApprox;

WMeanAccumulator!(double, Summation.pairwise, AssumeWeights.primary) x;
x.put([0.0, 1, 2, 3, 4].sliced);
x.wmean.shouldApprox == 2;
x.put(5);
x.wmean.shouldApprox == 2.5;

Meta