/** * Calculate average of mode elements (most frequently appearing elements). * @param cont Container of numeric values. * @return Mode average. */ template<typename Cont> Cont::value_type ModeAverage(const Cont& cont) { typedef map<Cont::value_type, int> ValueCounter; ValueCounter counter;
// Count up value furequency and get max frequency. int maxFreq = 0; { Cont::const_iterator it; for (it = cont.begin(); it != cont.end(); it++) { int& c = counter[*it]; c += 1; maxFreq = MAX(maxFreq, c); } }