11
/** Probability density function */
15
/** Construct a PDF from a histogram. */
16
PDF(const Histogram& h) : m_dist(h.maximum() + 1), m_stdDev(h.sd())
18
unsigned count = h.size();
19
m_minp = (double)1 / count;
20
for (size_t i = 0; i < m_dist.size(); i++) {
21
unsigned n = h.count(i);
22
m_dist[i] = n > 0 ? (double)n / count : m_minp;
26
/** Return the probability of x. */
27
double getP(size_t x) const
29
return x < m_dist.size() ? m_dist[x] : m_minp;
32
double getMinP() const { return m_minp; }
34
size_t getMaxIdx() const {
35
assert(!m_dist.empty());
36
return m_dist.size() - 1;
39
double getSampleStdDev(unsigned n) const
41
return m_stdDev / sqrt(n);
45
std::vector<double> m_dist;
52
inline void swap(PDF&, PDF&) { assert(false); }