summaryrefslogtreecommitdiff
path: root/gi/pf
diff options
context:
space:
mode:
Diffstat (limited to 'gi/pf')
-rw-r--r--gi/pf/base_distributions.cc (renamed from gi/pf/base_measures.cc)0
-rw-r--r--gi/pf/base_distributions.h (renamed from gi/pf/base_measures.h)14
2 files changed, 14 insertions, 0 deletions
diff --git a/gi/pf/base_measures.cc b/gi/pf/base_distributions.cc
index 4b1863fa..4b1863fa 100644
--- a/gi/pf/base_measures.cc
+++ b/gi/pf/base_distributions.cc
diff --git a/gi/pf/base_measures.h b/gi/pf/base_distributions.h
index b0495bfd..a23ac32b 100644
--- a/gi/pf/base_measures.h
+++ b/gi/pf/base_distributions.h
@@ -6,6 +6,7 @@
#include <string>
#include <cmath>
#include <iostream>
+#include <cassert>
#include "unigrams.h"
#include "trule.h"
@@ -18,6 +19,19 @@ inline double log_poisson(unsigned x, const double& lambda) {
return log(lambda) * x - lgamma(x + 1) - lambda;
}
+inline double log_binom_coeff(unsigned n, unsigned k) {
+ assert(n >= k);
+ if (n == k) return 0.0;
+ return lgamma(n + 1) - lgamma(k + 1) - lgamma(n - k + 1);
+}
+
+// http://en.wikipedia.org/wiki/Negative_binomial_distribution
+inline double log_negative_binom(unsigned x, unsigned r, double p) {
+ assert(p > 0.0);
+ assert(p < 1.0);
+ return log_binom_coeff(x + r - 1, x) + r * log(1 - p) + x * log(p);
+}
+
inline std::ostream& operator<<(std::ostream& os, const std::vector<WordID>& p) {
os << '[';
for (int i = 0; i < p.size(); ++i)