Histogram.cc
changeset 0 6b8091ca909a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Histogram.cc	Thu May 18 23:12:51 2006 +0200
@@ -0,0 +1,44 @@
+#include "Histogram.h"
+#include <math.h>
+
+inline double sqr(double x) {return(x*x);}
+
+void Histogram::calc_mean()
+{
+	int total_weight = 0;
+	int i;
+	for(i = 0; i < rows; i++)
+		total_weight = total_weight + weights[i];
+	mean = (double) total_weight / (double) rows;
+}
+
+void Histogram::calc_variance()
+{
+	double sum = 0;
+	for(int i = 0; i < rows; i++)
+		sum += sqr(weights[i] - mean);
+	variance = (double) sum / (double) rows;
+}
+
+void Histogram::calc_std_dev()
+{
+	std_dev = sqrt(variance);
+}
+
+void Histogram::calcStatistics()
+{
+	calc_mean();
+	calc_variance();
+	calc_std_dev();
+}
+
+Histogram::Histogram(int numrows)
+{
+	rows = numrows;
+	weights = new int[numrows];
+}
+
+Histogram::~Histogram()
+{
+	delete[] weights;
+}