CMS 3D CMS Logo

Majority.h
Go to the documentation of this file.
1 /*
2  */
3 
4 #ifndef MAJORITY_H
5 #define MAJORITY_H
6 
7 #include <map>
8 
11 template <class T>
12 class Majority {
13  //constructor(s) and destructor(s)
14 public:
17  Majority() : n_(0) {}
18 
21  virtual ~Majority() {}
22 
23  void add(const T& value) {
24  votes_[value] += 1.;
25  n_ += 1.;
26  }
27 
28  T result(double* proba) const {
29  std::pair<T, double> m(T(), -1.);
30  for (typename std::map<T, double>::const_iterator it = votes_.begin(); it != votes_.end(); ++it) {
31  if (it->second > m.second) {
32  m = *it;
33  }
34  }
35  if (proba)
36  *proba = n_ > 0 ? m.second / n_ : -1;
37  return m.first;
38  }
39 
40  //method(s)
41 public:
42 private:
43  //attribute(s)
44 protected:
45 private:
46  std::map<T, double> votes_;
47  double n_;
48 };
49 
50 #endif //MAJORITY_H not defined
std::map< T, double > votes_
Definition: Majority.h:46
double n_
Definition: Majority.h:47
virtual ~Majority()
Definition: Majority.h:21
void add(const T &value)
Definition: Majority.h:23
Definition: value.py:1
T result(double *proba) const
Definition: Majority.h:28
long double T
Majority()
Definition: Majority.h:17