Struct MeanSD

Output range to compute mean, stdev, variance online. Getter methods for stdev, var cost a few floating point ops. Getter for mean costs a single branch to check for N == 0. Relatively expensive floating point ops, if you only need mean, try Mean. This struct uses O(1) space and does *NOT* store the individual elements.

struct MeanSD ;

Properties

NameTypeDescription
mean[get] double
mse[get] doubleMean squared error. In other words, a biased estimate of variance.
N[get] double
stdev[get] double
sum[get] double
toMean[get] MeanConverts this struct to a Mean struct. Also called when an implicit conversion via alias this takes place.
toMeanSD[get] MeanSDSimply returns this. Useful in generic programming contexts.
var[get] double

Methods

NameDescription
put
put Combine two MeanSD's.
toString

Note

This struct can implicitly convert to a Mean struct.

References

Computing Higher-Order Moments Online.

http

//people.xiph.org/~tterribe/notes/homs.html

Examples

MeanSD summ;
summ.put(1);
summ.put(2);
summ.put(3);
summ.put(4);
summ.put(5);
assert(summ.mean == 3);
assert(summ.stdev == sqrt(2.5));
assert(summ.var == 2.5);