summaryrefslogtreecommitdiff
path: root/gi
diff options
context:
space:
mode:
authorbothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-06 15:23:32 +0000
committerbothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-06 15:23:32 +0000
commit45b298139d494ee81ce9ea23424faaba5f177230 (patch)
treec9e0c5936ad361f7fbf779e2ce192cf762b191a5 /gi
parent6206d7a1638bbecbb2bb22754d1ce1217819be86 (diff)
removed dependency on gammadist.c to be absolutely sure our code doesn't use the old non-threadsafe RNG
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@149 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'gi')
-rw-r--r--gi/pyp-topics/src/Makefile.am4
-rw-r--r--gi/pyp-topics/src/pyp.hh30
2 files changed, 31 insertions, 3 deletions
diff --git a/gi/pyp-topics/src/Makefile.am b/gi/pyp-topics/src/Makefile.am
index e4c4c1b9..681a9a0c 100644
--- a/gi/pyp-topics/src/Makefile.am
+++ b/gi/pyp-topics/src/Makefile.am
@@ -3,10 +3,10 @@ bin_PROGRAMS = pyp-topics-train pyp-contexts-train
contexts_lexer.cc: contexts_lexer.l
$(LEX) -s -CF -8 -o$@ $<
-pyp_topics_train_SOURCES = corpus.cc gammadist.c gzstream.cc mt19937ar.c pyp-topics.cc train.cc contexts_lexer.cc contexts_corpus.cc
+pyp_topics_train_SOURCES = corpus.cc gzstream.cc mt19937ar.c pyp-topics.cc train.cc contexts_lexer.cc contexts_corpus.cc
pyp_topics_train_LDADD = $(top_srcdir)/decoder/libcdec.a -lz
-pyp_contexts_train_SOURCES = corpus.cc gammadist.c gzstream.cc mt19937ar.c pyp-topics.cc contexts_lexer.cc contexts_corpus.cc train-contexts.cc
+pyp_contexts_train_SOURCES = corpus.cc gzstream.cc mt19937ar.c pyp-topics.cc contexts_lexer.cc contexts_corpus.cc train-contexts.cc
pyp_contexts_train_LDADD = $(top_srcdir)/decoder/libcdec.a -lz
AM_CPPFLAGS = -W -Wall -Wno-sign-compare -funroll-loops
diff --git a/gi/pyp-topics/src/pyp.hh b/gi/pyp-topics/src/pyp.hh
index 64fb5b58..7a520d6a 100644
--- a/gi/pyp-topics/src/pyp.hh
+++ b/gi/pyp-topics/src/pyp.hh
@@ -10,7 +10,6 @@
#include <boost/random/mersenne_twister.hpp>
#include "log_add.h"
-#include "gammadist.h"
#include "slice-sampler.h"
//
@@ -132,6 +131,17 @@ private:
return log_prob + log_prior;
}
};
+
+ /* lbetadist() returns the log probability density of x under a Beta(alpha,beta)
+ * distribution. - copied from Mark Johnson's gammadist.c
+ */
+ static long double lbetadist(long double x, long double alpha, long double beta);
+
+ /* lgammadist() returns the log probability density of x under a Gamma(alpha,beta)
+ * distribution - copied from Mark Johnson's gammadist.c
+ */
+ static long double lgammadist(long double x, long double alpha, long double beta);
+
};
template <typename Dish, typename Hash>
@@ -463,6 +473,24 @@ PYP<Dish,Hash>::log_prior_b(double b, double gamma_c, double gamma_s) {
}
template <typename Dish, typename Hash>
+long double PYP<Dish,Hash>::lbetadist(long double x, long double alpha, long double beta) {
+ assert(x > 0);
+ assert(x < 1);
+ assert(alpha > 0);
+ assert(beta > 0);
+ return (alpha-1)*log(x)+(beta-1)*log(1-x)+lgamma(alpha+beta)-lgamma(alpha)-lgamma(beta);
+//boost::math::lgamma
+}
+
+template <typename Dish, typename Hash>
+long double PYP<Dish,Hash>::lgammadist(long double x, long double alpha, long double beta) {
+ assert(alpha > 0);
+ assert(beta > 0);
+ return (alpha-1)*log(x) - alpha*log(beta) - x/beta - lgamma(alpha);
+}
+
+
+template <typename Dish, typename Hash>
void
PYP<Dish,Hash>::resample_prior() {
for (int num_its=5; num_its >= 0; --num_its) {