added new math-stats

started working on a new grid walker
This commit is contained in:
2017-10-12 10:55:47 +02:00
parent da477866c1
commit 556bbe8829
2 changed files with 170 additions and 0 deletions

48
math/stats/Variance.h Normal file
View File

@@ -0,0 +1,48 @@
#ifndef STATS_VARIANCE_H
#define STATS_VARIANCE_H
#include "../../Assertions.h"
#include "Average.h"
namespace Stats {
template <typename Scalar> class Variance {
Average<Scalar> avg;
Average<Scalar> avg2;
public:
/** ctor */
Variance() {
;
}
/** contains valid data? */
bool isValid() const {
return avg.isValid();
}
/** add a new value */
void add(const Scalar val) {
avg.add(val);
avg2.add(val*val);
}
/** get the current variance */
Scalar get() const {
Assert::isTrue(avg.isValid(), "add() values first!");
return avg2.get() - (avg.get()*avg.get());
}
/** get the current stadard-deviation */
Scalar getStdDev() const {
return std::sqrt(get);
}
};
}
#endif // STATS_VARIANCE_H