From 45b298139d494ee81ce9ea23424faaba5f177230 Mon Sep 17 00:00:00 2001 From: bothameister Date: Tue, 6 Jul 2010 15:23:32 +0000 Subject: 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 --- gi/pyp-topics/src/Makefile.am | 4 ++-- gi/pyp-topics/src/pyp.hh | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'gi/pyp-topics') 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 #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 @@ -462,6 +472,24 @@ PYP::log_prior_b(double b, double gamma_c, double gamma_s) { return lgammadist(b, gamma_c, gamma_s); } +template +long double PYP::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 +long double PYP::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 void PYP::resample_prior() { -- cgit v1.2.3