comparison base/LogRange.cpp @ 1385:b061b9f8fca5

Debug notes, tidying
author Chris Cannam
date Thu, 23 Feb 2017 09:22:56 +0000
parents d4212687520e
children 667e369cfeab
comparison
equal deleted inserted replaced
1384:368449629a30 1385:b061b9f8fca5
21 #include <cmath> 21 #include <cmath>
22 22
23 void 23 void
24 LogRange::mapRange(double &min, double &max, double logthresh) 24 LogRange::mapRange(double &min, double &max, double logthresh)
25 { 25 {
26 // ensure that max > min:
26 if (min > max) std::swap(min, max); 27 if (min > max) std::swap(min, max);
27 if (max == min) max = min + 1; 28 if (max == min) max = min + 1;
28 29
29 // cerr << "LogRange::mapRange: min = " << min << ", max = " << max << endl; 30 // cerr << "LogRange::mapRange: min = " << min << ", max = " << max << endl;
30 31
31 if (min >= 0.f) { 32 if (min >= 0.0) {
32 33
33 max = log10(max); // we know max != 0 34 // and max > min, so we know min >= 0 and max > 0
35
36 max = log10(max);
34 37
35 if (min == 0.f) min = std::min(logthresh, max); 38 if (min == 0.0) min = std::min(logthresh, max);
36 else min = log10(min); 39 else min = log10(min);
37 40
38 // cerr << "LogRange::mapRange: positive: min = " << min << ", max = " << max << endl; 41 // cerr << "LogRange::mapRange: positive: min = " << min << ", max = " << max << endl;
39 42
40 } else if (max <= 0.f) { 43 } else if (max <= 0.0) {
44
45 // and max > min, so we know min < 0 and max <= 0
41 46
42 min = log10(-min); // we know min != 0 47 min = log10(-min);
43 48
44 if (max == 0.f) max = std::min(logthresh, min); 49 if (max == 0.0) max = std::min(logthresh, min);
45 else max = log10(-max); 50 else max = log10(-max);
46 51
47 std::swap(min, max); 52 std::swap(min, max);
48 53
49 // cerr << "LogRange::mapRange: negative: min = " << min << ", max = " << max << endl; 54 // cerr << "LogRange::mapRange: negative: min = " << min << ", max = " << max << endl;
62 } 67 }
63 68
64 double 69 double
65 LogRange::map(double value, double thresh) 70 LogRange::map(double value, double thresh)
66 { 71 {
67 if (value == 0.f) return thresh; 72 if (value == 0.0) return thresh;
68 return log10(fabs(value)); 73 return log10(fabs(value));
69 } 74 }
70 75
71 double 76 double
72 LogRange::unmap(double value) 77 LogRange::unmap(double value)
75 } 80 }
76 81
77 static double 82 static double
78 sd(const std::vector<double> &values, int start, int n) 83 sd(const std::vector<double> &values, int start, int n)
79 { 84 {
80 double sum = 0.f, mean = 0.f, variance = 0.f; 85 double sum = 0.0, mean = 0.0, variance = 0.0;
81 for (int i = 0; i < n; ++i) { 86 for (int i = 0; i < n; ++i) {
82 sum += values[start + i]; 87 sum += values[start + i];
83 } 88 }
84 mean = sum / n; 89 mean = sum / n;
85 for (int i = 0; i < n; ++i) { 90 for (int i = 0; i < n; ++i) {