| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
dirichlet_log.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_DIRICHLET_LOG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_DIRICHLET_LOG_HPP
3
4 #include <boost/math/special_functions/gamma.hpp>
5 #include <boost/random/gamma_distribution.hpp>
6 #include <boost/random/variate_generator.hpp>
7 #include <stan/math/prim/mat/err/check_simplex.hpp>
8 #include <stan/math/prim/scal/err/check_consistent_sizes.hpp>
9 #include <stan/math/prim/scal/err/check_positive.hpp>
10 #include <stan/math/prim/scal/fun/multiply_log.hpp>
11 #include <stan/math/prim/scal/fun/constants.hpp>
12 #include <stan/math/prim/scal/meta/include_summand.hpp>
13
14 namespace stan {
15
16 namespace math {
17
43 template <bool propto,
44 typename T_prob, typename T_prior_sample_size>
45 typename boost::math::tools::promote_args<T_prob, T_prior_sample_size>::type
46 dirichlet_log(const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>& theta,
47 const Eigen::Matrix
48 <T_prior_sample_size, Eigen::Dynamic, 1>& alpha) {
49 static const char* function("stan::math::dirichlet_log");
50 using boost::math::lgamma;
51 using boost::math::tools::promote_args;
52 using stan::math::check_consistent_sizes;
53 using stan::math::check_positive;
54 using stan::math::check_simplex;
55 using stan::math::multiply_log;
56
57 typename promote_args<T_prob, T_prior_sample_size>::type lp(0.0);
58 check_consistent_sizes(function,
59 "probabilities", theta,
60 "prior sample sizes", alpha);
61 check_positive(function, "prior sample sizes", alpha);
62 check_simplex(function, "probabilities", theta);
63
64 if (include_summand<propto, T_prior_sample_size>::value) {
65 lp += lgamma(alpha.sum());
66 for (int k = 0; k < alpha.rows(); ++k)
67 lp -= lgamma(alpha[k]);
68 }
69 if (include_summand<propto, T_prob, T_prior_sample_size>::value) {
70 for (int k = 0; k < theta.rows(); ++k)
71 lp += multiply_log(alpha[k]-1, theta[k]);
72 }
73 return lp;
74 }
75
76 template <typename T_prob, typename T_prior_sample_size>
77 inline
78 typename boost::math::tools::promote_args<T_prob, T_prior_sample_size>::type
79 dirichlet_log(const Eigen::Matrix<T_prob, Eigen::Dynamic, 1>& theta,
80 const Eigen::Matrix
81 <T_prior_sample_size, Eigen::Dynamic, 1>& alpha) {
82 return dirichlet_log<false>(theta, alpha);
83 }
84 }
85 }
86 #endif
check_simplex.hpp
stan::math::lgamma
fvar< T > lgamma(const fvar< T > &x)
Definition: lgamma.hpp:15
check_positive.hpp
stan::math::dirichlet_log
boost::math::tools::promote_args< T_prob, T_prior_sample_size >::type dirichlet_log(const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta, const Eigen::Matrix< T_prior_sample_size, Eigen::Dynamic, 1 > &alpha)
The log of the Dirichlet density for the given theta and a vector of prior sample sizes...
Definition: dirichlet_log.hpp:46
stan::math::include_summand
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Definition: include_summand.hpp:36
include_summand.hpp
multiply_log.hpp
stan::math::check_positive
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
Definition: check_positive.hpp:68
stan::math::multiply_log
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)
Definition: multiply_log.hpp:15
constants.hpp
stan::math::check_consistent_sizes
bool check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Return true if the dimension of x1 is consistent with x2.
Definition: check_consistent_sizes.hpp:31
stan::math::check_simplex
bool check_simplex(const char *function, const char *name, const Eigen::Matrix< T_prob, Eigen::Dynamic, 1 > &theta)
Return true if the specified vector is simplex.
Definition: check_simplex.hpp:41
check_consistent_sizes.hpp

[ Stan Home Page ] © 2011–2015, Stan Development Team.