statistic helper classes
test-cases modified grid importance for better trap-detection
This commit is contained in:
43
math/stats/Average.h
Normal file
43
math/stats/Average.h
Normal 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
|
||||
Reference in New Issue
Block a user