probability.h
Go to the documentation of this file.
00001 /* probability.h
00002  */
00003 #ifndef _STAT_PROBABILITY_H
00004 #define _STAT_PROBABILITY_H
00005 
00006 #include <algorithm>
00007 #include <cmath>
00008 namespace osl
00009 {
00010   namespace stat
00011   {
00012     struct Probability
00013     {
00014       unsigned long numerator, denominator;
00015       explicit Probability(unsigned long n=0, unsigned long d=0)
00016         : numerator(n), denominator(d)
00017       {
00018       }
00019       double probability(double stabilizer=1.0) const
00020       {
00021         return std::max(stabilizer,numerator-stabilizer)
00022           / std::max(stabilizer,static_cast<double>(denominator));
00023       }
00024       double logProb(unsigned int stabilizer=1u) const
00025       {
00026         const double prob = probability(stabilizer);
00027         return log(prob)/log(0.5)*100;
00028       }
00029 
00030       void merge(const Probability& other)
00031       {
00032         numerator += other.numerator;
00033         denominator += other.denominator;
00034       }
00035     };
00036   } // namespace stat
00037 } // namespace osl
00038 
00039 #endif /* _STAT_PROBABILITY_H */
00040 // ;;; Local Variables:
00041 // ;;; mode:c++
00042 // ;;; c-basic-offset:2
00043 // ;;; End:
00044 
00045 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines