Anonymous user
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>
MomentsAccumulator_() :
void operator()(double v)
{
double inc = 1.0;
for (auto& mi : m_)
m1_ += v;▼
{
}
}
};
template<class T_> double Stdev(const
{
assert(sofar.
const double
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)
{
|