CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Majority.h
Go to the documentation of this file.
1 /*
2  * $Id: Majority.h,v 1.1 2009/02/25 14:44:25 pgras Exp $
3  */
4 
5 #ifndef MAJORITY_H
6 #define MAJORITY_H
7 
8 #include <map>
9 
13 template<class T>
14 class Majority {
15  //constructor(s) and destructor(s)
16 public:
19  Majority(): n_(0){}
20 
23  virtual ~Majority(){}
24 
28  void
29  add(const T& value){
30  votes_[value] += 1.;
31  n_ += 1.;
32  }
33 
39  T result(double* proba) const{
40  std::pair<T, double> m(T(), -1.);
41  for(typename std::map<T, double>::const_iterator it = votes_.begin();
42  it != votes_.end();
43  ++it){
44  if(it->second > m.second){
45  m = *it;
46  }
47  }
48  if(proba) *proba = n_>0?m.second/n_:-1;
49  return m.first;
50  }
51 
52  //method(s)
53 public:
54 private:
55 
56  //attribute(s)
57 protected:
58 private:
59  std::map<T, double> votes_;
60  double n_;
61 };
62 
63 #endif //MAJORITY_H not defined
std::map< T, double > votes_
Definition: Majority.h:50
double n_
Definition: Majority.h:51
virtual ~Majority()
Definition: Majority.h:23
void add(const T &value)
Definition: Majority.h:29
T result(double *proba) const
Definition: Majority.h:39
long double T
Majority()
Definition: Majority.h:19