blob: fec763f6ed89292535dd3a1b9ba956e92d839c45 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#ifndef _GAMMA_POISSON_H_
#define _GAMMA_POISSON_H_
#include <m.h>
// http://en.wikipedia.org/wiki/Conjugate_prior
struct GammaPoisson {
GammaPoisson(double shape, double rate) :
a(shape), b(rate), n(), marginal() {}
double prob(unsigned x) const {
return exp(Md::log_negative_binom(x, a + marginal, 1.0 - (b + n) / (1 + b + n)));
}
void increment(unsigned x) {
++n;
marginal += x;
}
void decrement(unsigned x) {
--n;
marginal -= x;
}
double log_likelihood() const {
return 0;
}
double a, b;
int n, marginal;
};
#endif
|