20 #ifndef OST_STAT_ACCUMULATOR_HH
21 #define OST_STAT_ACCUMULATOR_HH
27 namespace ost {
namespace img {
namespace alg {
29 template<
unsigned int MAX_MOMENT=4>
45 Real delta,delta_n,delta_n2,term;
51 delta_n2 = delta_n * delta_n;
54 term = delta * delta_n * (n_-1);
57 m4_ += term * delta_n2 * (n_*n_ - 3*n_ + 3) + 6 * delta_n2 * m2_ - 4 * delta_n * m3_;
60 m3_ += term * delta_n * (n_ - 2) - 3 * delta_n * m2_;
95 Real delta,delta_n,delta_n2,na,nanb;
99 delta = acc.mean_ - mean_;
100 delta_n = delta / (na+nb);
106 delta_n2 = delta_n * delta_n;
109 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_);
112 m3_+=acc.m3_+delta*delta_n2*nanb*(na-nb)+3.0*delta_n*(na*acc.m2_-nb*m2_);
115 m2_ += acc.m2_+delta*delta_n*nanb;
134 throw Error(
"Mean was not calculated.");
147 throw Error(
"Variance was not calculated.");
165 return sqrt(sum2_/(n_-1));
171 throw Error(
"Skewness was not calculated.");
176 return m3_/sqrt(m2_*m2_*m2_);
183 throw Error(
"Kurtosis was not calculated.");
188 return ((n_-1)*m4_) / (m2_*m2_);
203 #endif // OST_STAT_ACCUMULATOR_HH