14 #ifndef PROB_PDF_H_INCLUDED
15 #define PROB_PDF_H_INCLUDED
44 #if BOOST_VERSION < 104600
50 return boost::math::pdf<boost::math::negative_binomial, double>(
dist,
x);
60 return pdf(dist.dist_, log(x)) /
x;
70 typename std::map<T, double>::const_iterator
i = dist.db.find(x);
71 return i == dist.db.end() ? 0.0 : i->second/dist.total_weight_;
77 double pdf(
const MV_gaussian_distribution& P,
const Vector&
x);
82 template<
class Distribution>
91 for(
size_t i = 0;
i < dist.dists.size();
i++)
93 f += (
pdf(dist.coeffs,
i + 1) *
pdf(dist.dists[
i], x));
109 inline double log_pdf(
const Beta_binomial_distribution& dist,
double k);
153 return cdf(dist.dist_, log(x));
173 typename std::map<T, double>::const_iterator y = dist.db.upper_bound(x);
174 for(
typename std::map<T, double>::const_iterator
i = dist.db.begin();
177 F +=
i->second / dist.total_weight_;
186 template<
class Distribution>
195 for(
size_t i = 0;
i < dist.dists.size();
i++)
197 f += (
cdf(dist.coeffs,
i + 1) *
cdf(dist.dists[
i], x));
207 using boost::math::quantile;
219 template<
class Distribution>
222 const Distribution& P,
226 return std::log(
pdf(P, x));
236 const double na = k + dist.
alpha;
237 const double nb = dist.
n - k + dist.
beta;
239 const double lnumer = lgamma(na) + lgamma(nb) - lgamma(na+nb);
240 const double ldenom = lgamma(dist.
alpha) + lgamma(dist.
beta) - lgamma(dist.
alpha + dist.
beta);
242 return lcoeff + lnumer - ldenom;
253 double mu = P.mean();
254 double variance = P.standard_deviation() * P.standard_deviation();
256 return -(0.5 * log(2 *
M_PI * variance))
257 - (((x - mu) * (x - mu)) / (2 * variance));
268 double mu = P.location();
269 double b = P.scale();
271 return -log(2 * b) - (fabs(x - mu) / b);
282 const double p = P.success_fraction();
283 const double n = P.trials();
285 result += k * log(p) + (n -
k) * log(1-p);
295 double log_pdf(
const MV_gaussian_distribution& P,
const Vector& x);
307 return -log(kjb_c::unit_sphere_surface_area(
D));
314 static const double LOG_2_PI = log(2*
M_PI);
316 double kappa_ = dist.
kappa();
323 double log_normalization = log(kappa_) - (LOG_2_PI + log(exp(kappa_) - exp(-kappa_)));
327 double test_1 = log(kappa_ / (2 *
M_PI * (exp(kappa_) - exp(-kappa_))));
328 double test_2 = log(kappa_ / (4*
M_PI * std::sinh(kappa_)));
330 double test_3 = (
D/2.0 - 1) * log(kappa_) - (
D/2.0)*log(2 *
M_PI) - log(boost::math::cyl_bessel_i(
D/2.0-1, kappa_));
333 assert(fabs(log_normalization - test_1) < FLT_EPSILON);
334 assert(fabs(log_normalization - test_2) < FLT_EPSILON);
335 assert(fabs(log_normalization - test_3) < FLT_EPSILON);
337 return log_exponential + log_normalization;
344 double log_normalization = (
D/2.0 - 1) * log(kappa_) - (
D/2.0)*log(2 *
M_PI) - log(boost::math::cyl_bessel_i(
D/2.0-1, kappa_));
345 return log_exponential + log_normalization;
355 const Chinese_restaurant_process& cpr,
362 const Chinese_restaurant_process& cpr,
const kjb::Vector_d< D > & mu() const
Definition: prob_distribution.h:996
Definition of various standard probability distributions.
double log_binomial_coefficient(size_t n, size_t k)
Definition: m_special.cpp:25
double kappa() const
Definition: prob_distribution.h:998
std::vector< std::vector< size_t > > Type
Definition: prob_distribution.h:1019
This class implements a mixture distribution. In other words, it is the sum of a finite number of fra...
Definition: prob_distribution.h:867
for k
Definition: APPgetLargeConnectedEdges.m:61
Log-normal distribution.
Definition: prob_distribution.h:827
double cdf(const Mixture_distribution< Distribution > &dist, const typename Distribution_traits< Mixture_distribution< Distribution > >::type &x)
Computes the CDF of a mixture distribution at x.
Definition: prob_pdf.h:188
Vector_d< D > normalized() const
Non-mutating (functionally pure) version of normalize()
Definition: m_vector_d.impl.h:384
boost::math::normal Gaussian_distribution
Definition: prob_distribution.h:66
Definition: prob_distribution.h:984
double pdf(const MV_gaussian_distribution &P, const Vector &x)
Computes the joint PDF of a multivariate Gaussian at x.
Definition: prob_pdf.cpp:32
A categorical distribution.
Definition: prob_distribution.h:131
double beta
Definition: prob_distribution.h:96
boost::math::laplace Laplace_distribution
Definition: prob_distribution.h:67
double dist(const pt a, const pt b)
compute approx. Great Circle distance between two UTM points
Definition: layer.cpp:45
double n
Definition: prob_distribution.h:96
double type
Definition: prob_distribution.h:111
x
Definition: APPgetLargeConnectedEdges.m:100
Generic traits struct for all distributions.
Definition: prob_distribution.h:109
double log_pdf(const MV_gaussian_distribution &P, const Vector &x)
Computes the log PDF a multivariate normal distribution at x.
Definition: prob_pdf.cpp:64
double pdf(const Uniform_sphere_distribution< D > &P, const kjb::Vector_d< D > &x)
Evaluate the probability density function of a uniform sphere distribution (x's magnitude is ignored ...
Definition: prob_pdf.h:135
Definition: prob_distribution.h:79
boost::math::binomial Binomial_distribution
Definition: prob_distribution.h:62
#define M_PI
Definition: fft.cpp:206
double cdf(const Log_normal_distribution &dist, double x)
Computes the cdf of a log-normal distribution at x.
Definition: prob_pdf.h:151
Definition: g_quaternion.h:37
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
long int dot(const Int_vector &op1, const Int_vector &op2)
Returns dot product of this and op2.
Definition: l_int_vector.h:1532
D
Definition: APPgetLargeConnectedEdges.m:106
Definition: prob_distribution.h:89
double alpha
Definition: prob_distribution.h:96