Mercurial > hg > svcore
diff base/LogRange.cpp @ 1527:710e6250a401 zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:14 +0100 |
parents | 7e3532d56abb |
children |
line wrap: on
line diff
--- a/base/LogRange.cpp Mon Dec 12 15:18:52 2016 +0000 +++ b/base/LogRange.cpp Mon Sep 17 13:51:14 2018 +0100 @@ -23,30 +23,31 @@ void LogRange::mapRange(double &min, double &max, double logthresh) { + static double eps = 1e-10; + + // ensure that max > min: if (min > max) std::swap(min, max); if (max == min) max = min + 1; -// cerr << "LogRange::mapRange: min = " << min << ", max = " << max << endl; - - if (min >= 0.f) { + if (min >= 0.0) { - max = log10(max); // we know max != 0 + // and max > min, so we know min >= 0 and max > 0 + + max = log10(max); - if (min == 0.f) min = std::min(logthresh, max); + if (min == 0.0) min = std::min(logthresh, max); else min = log10(min); -// cerr << "LogRange::mapRange: positive: min = " << min << ", max = " << max << endl; + } else if (max <= 0.0) { - } else if (max <= 0.f) { + // and max > min, so we know min < 0 and max <= 0 - min = log10(-min); // we know min != 0 - - if (max == 0.f) max = std::min(logthresh, min); + min = log10(-min); + + if (max == 0.0) max = std::min(logthresh, min); else max = log10(-max); std::swap(min, max); - -// cerr << "LogRange::mapRange: negative: min = " << min << ", max = " << max << endl; } else { @@ -54,17 +55,15 @@ max = log10(std::max(max, -min)); min = std::min(logthresh, max); - -// cerr << "LogRange::mapRange: spanning: min = " << min << ", max = " << max << endl; } - if (min == max) min = max - 1; + if (fabs(max - min) < eps) min = max - 1; } double LogRange::map(double value, double thresh) { - if (value == 0.f) return thresh; + if (value == 0.0) return thresh; return log10(fabs(value)); } @@ -77,7 +76,7 @@ static double sd(const std::vector<double> &values, int start, int n) { - double sum = 0.f, mean = 0.f, variance = 0.f; + double sum = 0.0, mean = 0.0, variance = 0.0; for (int i = 0; i < n; ++i) { sum += values[start + i]; } @@ -91,7 +90,7 @@ } bool -LogRange::useLogScale(std::vector<double> values) +LogRange::shouldUseLogScale(std::vector<double> values) { // Principle: Partition the data into two sets around the median; // calculate the standard deviation of each set; if the two SDs