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 | 481a120564fdb73c8c6833e2102acb533683261c (patch) | |
tree | c4b39308283f8f5b64ac13691b1d29de31cc15ce /gi | |
parent | 4c2360119def2fb624d2691b355b1908c511f004 (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) |