diff options
author | bothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-06 15:23:32 +0000 |
---|---|---|
committer | bothameister <bothameister@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-07-06 15:23:32 +0000 |
commit | 45b298139d494ee81ce9ea23424faaba5f177230 (patch) | |
tree | c9e0c5936ad361f7fbf779e2ce192cf762b191a5 /gi/pyp-topics/src/pyp.hh | |
parent | 6206d7a1638bbecbb2bb22754d1ce1217819be86 (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/pyp-topics/src/pyp.hh')
-rw-r--r-- | gi/pyp-topics/src/pyp.hh | 30 |
1 files changed, 29 insertions, 1 deletions
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) { |