Mercurial > hg > svcore
comparison base/LogRange.cpp @ 478:1405f4a2caf3
* Add use-log-scale estimator. Not quite right yet; the model doesn't
actually have any data in it yet at the point where we want to make
this decision
* Update changelog
author | Chris Cannam |
---|---|
date | Tue, 11 Nov 2008 13:54:47 +0000 |
parents | 9525c9d7e54d |
children | bdc9bb371a9f |
comparison
equal
deleted
inserted
replaced
477:e0784311a103 | 478:1405f4a2caf3 |
---|---|
70 float | 70 float |
71 LogRange::unmap(float value) | 71 LogRange::unmap(float value) |
72 { | 72 { |
73 return powf(10.0, value); | 73 return powf(10.0, value); |
74 } | 74 } |
75 | |
76 static float | |
77 sd(const std::vector<float> &values, size_t start, size_t n) | |
78 { | |
79 float sum = 0.f, mean = 0.f, variance = 0.f; | |
80 for (size_t i = 0; i < n; ++i) { | |
81 sum += values[start + i]; | |
82 } | |
83 mean = sum / n; | |
84 for (size_t i = 0; i < n; ++i) { | |
85 float diff = values[start + i] - mean; | |
86 variance += diff * diff; | |
87 } | |
88 variance = variance / n; | |
89 return sqrtf(variance); | |
90 } | |
91 | |
92 bool | |
93 LogRange::useLogScale(std::vector<float> values) | |
94 { | |
95 // Principle: Partition the data into two sets around the median; | |
96 // calculate the standard deviation of each set; if the two SDs | |
97 // are very different, it's likely that a log scale would be good. | |
98 | |
99 if (values.size() < 4) return false; | |
100 std::sort(values.begin(), values.end()); | |
101 size_t mi = values.size() / 2; | |
102 | |
103 float sd0 = sd(values, 0, mi); | |
104 float sd1 = sd(values, mi, values.size() - mi); | |
105 | |
106 std::cerr << "LogRange::useLogScale: sd0 = " | |
107 << sd0 << ", sd1 = " << sd1 << std::endl; | |
108 | |
109 if (sd0 == 0 || sd1 == 0) return false; | |
110 | |
111 // I wonder what method of determining "one sd much bigger than | |
112 // the other" would be appropriate here... | |
113 if (std::max(sd0, sd1) / std::min(sd0, sd1) > 10.f) return true; | |
114 else return false; | |
115 } | |
116 |