summaryrefslogtreecommitdiff
path: root/graphics/asymptote/statistics.h
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/asymptote/statistics.h
Initial commit
Diffstat (limited to 'graphics/asymptote/statistics.h')
-rw-r--r--graphics/asymptote/statistics.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/graphics/asymptote/statistics.h b/graphics/asymptote/statistics.h
new file mode 100644
index 0000000000..7e3d2d340d
--- /dev/null
+++ b/graphics/asymptote/statistics.h
@@ -0,0 +1,51 @@
+#ifndef __statistics_h__
+#define __statistics_h__ 1
+
+#include <math.h>
+
+namespace utils {
+
+class statistics {
+ unsigned int N;
+ double A;
+ double varL;
+ double varH;
+public:
+ statistics() : N(0), A(0.0), varL(0.0), varH(0.0) {}
+ double count() {return N;}
+ double mean() {return A;}
+ void add(double t) {
+ ++N;
+ double diff=t-A;
+ A += diff/N;
+ double v=diff*(t-A);
+ if(diff < 0.0)
+ varL += v;
+ else
+ varH += v;
+ }
+ double stdev(double var, double f) {
+ double factor=N > f ? f/(N-f) : 0.0;
+ return sqrt(var*factor);
+ }
+ double stdev() {
+ return stdev(varL+varH,1.0);
+ }
+ double stdevL() {
+ return stdev(varL,2.0);
+ }
+ double stdevH() {
+ return stdev(varH,2.0);
+ }
+ void output(const char *text, unsigned int m) {
+ std::cout << text << ":\n"
+ << m << "\t"
+ << A << "\t"
+ << stdevL() << "\t"
+ << stdevH() << std::endl;
+ }
+};
+
+}
+
+#endif