X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Fmathfuncs.cpp;h=2eaa55153c6f73c6325dd66e4335dad3c0fcd912;hp=c07445253d3355a5f92df91b67842f7b44d6d904;hb=f7d2b7144f32a7bd157b7689022e62944b82fcc1;hpb=fd1d136a94a6d20013f38d6a997bdfefad0f5e98 diff --git a/libctsupport/mathfuncs.cpp b/libctsupport/mathfuncs.cpp index c074452..2eaa551 100644 --- a/libctsupport/mathfuncs.cpp +++ b/libctsupport/mathfuncs.cpp @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: mathfuncs.cpp,v 1.3 2000/12/20 20:08:48 kevin Exp $ +** $Id: mathfuncs.cpp,v 1.4 2000/12/21 03:40:58 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -84,17 +84,16 @@ normalizeAngle (double theta) void -vectorNumericStatistics (std::vector vec, double& min, double& max, double& mean, double& mode, double& median, double& stddev) +vectorNumericStatistics (std::vector vec, const int nPoints, double& min, double& max, double& mean, double& mode, double& median, double& stddev) { - int n = vec.size(); - if (n <= 0) + if (nPoints <= 0) return; mean = 0; min = vec[0]; max = vec[0]; int i; - for (i = 0; i < n; i++) { + for (i = 0; i < nPoints; i++) { double v = vec[i]; if (v > max) max = v; @@ -102,21 +101,21 @@ vectorNumericStatistics (std::vector vec, double& min, double& max, doub min = v; mean += v; } - mean /= n; + mean /= nPoints; static const int nbin = 1024; int hist[ nbin ] = {0}; double spread = max - min; mode = 0; stddev = 0; - for (i = 0; i < n; i++) { + for (i = 0; i < nPoints; i++) { double v = vec[i]; int b = static_cast((((v - min) / spread) * (nbin - 1)) + 0.5); hist[b]++; double diff = (v - mean); stddev += diff * diff; } - stddev = sqrt (stddev / n); + stddev = sqrt (stddev / nPoints); int max_binindex = 0; int max_bin = -1; @@ -131,8 +130,8 @@ vectorNumericStatistics (std::vector vec, double& min, double& max, doub std::sort(vec.begin(), vec.end()); - if (n % 2) // Odd - median = vec[((n - 1) / 2)]; + if (nPoints % 2) // Odd + median = vec[((nPoints - 1) / 2)]; else // Even - median = (vec[ (n / 2) - 1 ] + vec[ n / 2 ]) / 2; + median = (vec[ (nPoints / 2) - 1 ] + vec[ nPoints / 2 ]) / 2; }