summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ipa/rpi/controller/histogram.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ipa/rpi/controller/histogram.cpp b/src/ipa/rpi/controller/histogram.cpp
index 0a27ba2c..78116141 100644
--- a/src/ipa/rpi/controller/histogram.cpp
+++ b/src/ipa/rpi/controller/histogram.cpp
@@ -47,7 +47,7 @@ double Histogram::quantile(double q, int first, int last) const
double Histogram::interBinMean(double binLo, double binHi) const
{
- assert(binHi > binLo);
+ assert(binHi >= binLo);
double sumBinFreq = 0, cumulFreq = 0;
for (double binNext = floor(binLo) + 1.0; binNext <= ceil(binHi);
binLo = binNext, binNext += 1.0) {
@@ -57,13 +57,19 @@ double Histogram::interBinMean(double binLo, double binHi) const
sumBinFreq += bin * freq;
cumulFreq += freq;
}
+
+ if (cumulFreq == 0) {
+ /* interval had zero width or contained no weight? */
+ return binHi;
+ }
+
/* add 0.5 to give an average for bin mid-points */
return sumBinFreq / cumulFreq + 0.5;
}
double Histogram::interQuantileMean(double qLo, double qHi) const
{
- assert(qHi > qLo);
+ assert(qHi >= qLo);
double pLo = quantile(qLo);
double pHi = quantile(qHi, (int)pLo);
return interBinMean(pLo, pHi);