26 static double eps = 1e-10;
29 if (min > max) std::swap(min, max);
30 if (max == min) max = min + 1;
38 if (min == 0.0) min = std::min(logthresh, max);
39 else min = log10(min);
41 }
else if (max <= 0.0) {
47 if (max == 0.0) max = std::min(logthresh, min);
48 else max = log10(-max);
56 max = log10(std::max(max, -min));
57 min = std::min(logthresh, max);
60 if (fabs(max - min) < eps) min = max - 1;
66 if (value == 0.0)
return thresh;
67 return log10(fabs(value));
73 return pow(10.0, value);
77 sd(
const std::vector<double> &values,
int start,
int n)
79 double sum = 0.0, mean = 0.0, variance = 0.0;
80 for (
int i = 0; i < n; ++i) {
81 sum += values[start + i];
84 for (
int i = 0; i < n; ++i) {
85 double diff = values[start + i] - mean;
86 variance += diff * diff;
88 variance = variance / n;
89 return sqrt(variance);
99 int n = int(values.size());
100 if (n < 4)
return false;
101 std::sort(values.begin(), values.end());
104 double sd0 =
sd(values, 0, mi);
105 double sd1 =
sd(values, mi, n - mi);
107 SVDEBUG <<
"LogRange::useLogScale: sd0 = " 108 << sd0 <<
", sd1 = " << sd1 << endl;
110 if (sd0 == 0 || sd1 == 0)
return false;
114 if (std::max(sd0, sd1) / std::min(sd0, sd1) > 10.)
return true;
static void mapRange(double &min, double &max, double thresh=-10)
Map a linear range onto a logarithmic range.
static double unmap(double value)
Map a value from the logarithmic range back again.
static double map(double value, double thresh=-10)
Map a value onto a logarithmic range.
static double sd(const std::vector< double > &values, int start, int n)
static bool shouldUseLogScale(std::vector< double > values)
Estimate whether a set of values would be more properly shown using a logarithmic than a linear scale...