probability.h
Go to the documentation of this file.
/* probability.h
*/
#ifndef _STAT_PROBABILITY_H
#define _STAT_PROBABILITY_H
#include <algorithm>
#include <cmath>
namespace osl
{
namespace stat
{
struct Probability
{
unsigned long numerator, denominator;
explicit Probability(unsigned long n=0, unsigned long d=0)
: numerator(n), denominator(d)
{
}
double probability(double stabilizer=1.0) const
{
return std::max(stabilizer,numerator-stabilizer)
/ std::max(stabilizer,static_cast<double>(denominator));
}
double logProb(unsigned int stabilizer=1u) const
{
const double prob = probability(stabilizer);
return log(prob)/log(0.5)*100;
}
void merge(const Probability& other)
{
numerator += other.numerator;
denominator += other.denominator;
}
};
} // namespace stat
} // namespace osl
#endif /* _STAT_PROBABILITY_H */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
osl::stat
Definition rating/featureSet.h:18
osl
Definition additionalEffect.h:6
osl::stat::Probability::probability
double probability(double stabilizer=1.0) const
Definition probability.h:19
osl::stat::Probability::logProb
double logProb(unsigned int stabilizer=1u) const
Definition probability.h:24
osl::stat::Probability::merge
void merge(const Probability &other)
Definition probability.h:30
osl::stat::Probability::numerator
unsigned long numerator
Definition probability.h:14
osl::stat::Probability::Probability
Probability(unsigned long n=0, unsigned long d=0)
Definition probability.h:15
osl::stat::Probability::denominator
unsigned long denominator
Definition probability.h:14