-
- // What follows after estimates the time as the mode of the
- // distribution.
-
- // Select the awesomest (i.e. most frequent) result. We do this by
- // sorting and then computing the longest run length.
- sort(begin, end);
-
- // Eliminate outliers. A time much larger than the minimum time is
- // considered an outlier.
- while (end[-1] > 2.0 * *begin) {
- --end;
- if (begin == end) {
- LOG(INFO) << *begin;
- }
- assert(begin < end);
- }
-
- double result = 0;
-
- /* Code used just for comparison purposes */ {
- unsigned bestFrequency = 0;
- unsigned candidateFrequency = 1;
- double candidateValue = *begin;
- for (auto current = begin + 1; ; ++current) {
- if (current == end || *current != candidateValue) {
- // Done with the current run, see if it was best
- if (candidateFrequency > bestFrequency) {
- bestFrequency = candidateFrequency;
- result = candidateValue;
- }
- if (current == end) {
- break;
- }
- // Start a new run
- candidateValue = *current;
- candidateFrequency = 1;
- } else {
- // Cool, inside a run, increase the frequency
- ++candidateFrequency;
- }
- }
- }
-
- result = mode(begin, end);
-
- return result;