statistic helper classes

test-cases
modified grid importance for better trap-detection
This commit is contained in:
2016-10-01 13:17:14 +02:00
parent 729340031d
commit 51c0945e12
15 changed files with 343 additions and 64 deletions

43
math/stats/Average.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef AVERAGE_H
#define AVERAGE_H
#include "../../Assertions.h"
namespace Stats {
template <typename Scalar> class Average {
private:
int cnt;
Scalar sum;
public:
/** ctor */
Average() : cnt(0), sum(0) {
;
}
/** contains a valid average? */
bool isValid() const {
return cnt > 0;
}
/** add a new value */
void add(const Scalar val) {
sum += val;
++cnt;
}
/** get the current value */
Scalar get() const {
Assert::isNot0(cnt, "add() values first!");
return sum / (Scalar)cnt;
}
};
}
#endif // AVERAGE_H