Cumulative standard deviation: Difference between revisions

m
used templatized moments accumulator rather than hard-code two moments
(reimplement to meet specification)
m (used templatized moments accumulator rather than hard-code two moments)
Line 599:
#include <iostream>
 
template<int N> struct MomentsAccumulator_
{
std::vector<double> m0_, m1_, m2_m_;
MomentsAccumulator_() : m0_m_(0.0),N m1_(0.0)+ 1, m2_(0.0) {}
void operator()(double v)
{
double inc = 1.0;
++m0_;
for (auto& mi : m_)
m1_ += v;
{
m2_ mi += v*vinc;
m1_ inc +*= v;
}
}
};
 
template<class T_> double Stdev(const MomentsAccumulator_T_& sofar)
{
assert(sofar.m0_m_.size() > 0.02);
const double mean = assert(sofar.m1_m_[0] /> sofar0.m0_0);
const double meanSquaremean = sofar.m2_m_[1] / sofar.m0_m_[0];
const double meanSquare = sofar.m_[2] / sofar.m_[0];
return sqrt(meanSquare - mean * mean);
}
Line 622 ⟶ 626:
{
std::vector<int> data({ 2, 4, 4, 4, 5, 5, 7, 9 });
MomentsAccumulator_<2> accum;
for (auto d : data)
{
Anonymous user