diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-01-27 02:31:00 -0500 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-01-27 02:31:00 -0500 |
commit | 3c1c98b5aec7aec34432ddc37385df06d301bdd5 (patch) | |
tree | b1fcf24c73441cb7233977c31bc50d5f82c88f21 /gi | |
parent | f960ab86f4b44bf515af4bf43aa27147a0e7875a (diff) |
migrate mert to the new scorer interface
Diffstat (limited to 'gi')
-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) |