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 17:34:05 pgras Exp $
3  */
4 
5 #ifndef MAJORITY_H
6 #define MAJORITY_H
7 
8 #include <map>
9 
12 template<class T>
13 class Majority {
14  //constructor(s) and destructor(s)
15 public:
18  Majority(): n_(0){}
19 
22  virtual ~Majority(){}
23 
24  void
25  add(const T& value){
26  votes_[value] += 1.;
27  n_ += 1.;
28  }
29 
30  T result(double* proba) const{
31  std::pair<T, double> m(T(), -1.);
32  for(typename std::map<T, double>::const_iterator it = votes_.begin();
33  it != votes_.end();
34  ++it){
35  if(it->second > m.second){
36  m = *it;
37  }
38  }
39  if(proba) *proba = n_>0?m.second/n_:-1;
40  return m.first;
41  }
42 
43  //method(s)
44 public:
45 private:
46 
47  //attribute(s)
48 protected:
49 private:
50  std::map<T, double> votes_;
51  double n_;
52 };
53 
54 #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:22
void add(const T &value)
Definition: Majority.h:25
T result(double *proba) const
Definition: Majority.h:30
long double T
Majority()
Definition: Majority.h:18