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;
Output range for wmean.