20 #ifndef OST_STAT_ACCUMULATOR_HH
21 #define OST_STAT_ACCUMULATOR_HH
26 namespace ost {
namespace img {
namespace alg {
28 template<
unsigned int MAX_MOMENT=4>
44 Real delta,delta_n,delta_n2,term;
50 delta_n2 = delta_n * delta_n;
53 term = delta * delta_n * (n_-1);
56 m4_ += term * delta_n2 * (n_*n_ - 3*n_ + 3) + 6 * delta_n2 * m2_ - 4 * delta_n * m3_;
59 m3_ += term * delta_n * (n_ - 2) - 3 * delta_n * m2_;
94 Real delta,delta_n,delta_n2,na,nanb;
98 delta = acc.mean_ - mean_;
99 delta_n = delta / (na+nb);
105 delta_n2 = delta_n * delta_n;
108 m4_+=acc.m4_+delta*delta_n*delta_n2*nanb*(na*na-nanb+nb*nb)+6.0*delta_n2*(na*na*acc.m2_+nb*nb*m2_)+4.0*delta_n*(na*acc.m3_-nb*m3_);
111 m3_+=acc.m3_+delta*delta_n2*nanb*(na-nb)+3.0*delta_n*(na*acc.m2_-nb*m2_);
114 m2_ += acc.m2_+delta*delta_n*nanb;
133 throw Error(
"Mean was not calculated.");
146 throw Error(
"Variance was not calculated.");
154 Real GetStandardDeviation()
const
156 return sqrt(GetVariance());
164 return sqrt(sum2_/(n_-1));
170 throw Error(
"Skewness was not calculated.");
175 return m3_/sqrt(m2_*m2_*m2_);
182 throw Error(
"Kurtosis was not calculated.");
187 return ((n_-1)*m4_) / (m2_*m2_);
202 #endif // OST_STAT_ACCUMULATOR_HH