Trim off the bottom fraction/2 and top fraction/2 data points. * At least (1 - fraction) of the data will remain. */
| 21 | * At least (1 - fraction) of the data will remain. |
| 22 | */ |
| 23 | Histogram Histogram::trimFraction(double fraction) const |
| 24 | { |
| 25 | double low_cutoff = fraction/2; |
| 26 | double high_cutoff = 1.0f - fraction/2; |
| 27 | size_type n = size(); |
| 28 | |
| 29 | double cumulative = 0; |
| 30 | Histogram newHist; |
| 31 | for (Histogram::Map::const_iterator it = m_map.begin(); |
| 32 | it != m_map.end(); it++) { |
| 33 | double temp_total = cumulative + (double)it->second / n; |
| 34 | if (temp_total > low_cutoff && cumulative < high_cutoff) |
| 35 | newHist.insert(it->first, it->second); |
| 36 | cumulative = temp_total; |
| 37 | } |
| 38 | |
| 39 | return newHist; |
| 40 | } |
| 41 | |
| 42 | /** Bin these elements into n buckets. The number of buckets returned |
| 43 | * may be smaller than n. |