Stan  1.0
probability, sampling & optimization
dirichlet.hpp
Go to the documentation of this file.
1 #ifndef __STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__DIRICHLET_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__MULTIVARIATE__CONTINUOUS__DIRICHLET_HPP__
3 
8 #include <stan/prob/traits.hpp>
9 
10 namespace stan {
11 
12  namespace prob {
13 
39  template <bool propto,
40  typename T_prob, typename T_prior_sample_size,
41  class Policy>
42  typename boost::math::tools::promote_args<T_prob,T_prior_sample_size>::type
43  dirichlet_log(const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& theta,
44  const Eigen::Matrix<T_prior_sample_size,Eigen::Dynamic,1>& alpha,
45  const Policy&) {
46  // FIXME: parameter check
47  using boost::math::tools::promote_args;
48  typename promote_args<T_prob,T_prior_sample_size>::type lp(0.0);
49 
52  lp += lgamma(alpha.sum());
53  for (int k = 0; k < alpha.rows(); ++k)
54  lp -= lgamma(alpha[k]);
55  }
57  for (int k = 0; k < theta.rows(); ++k)
58  lp += multiply_log(alpha[k]-1, theta[k]);
59  return lp;
60  }
61 
62  template <bool propto,
63  typename T_prob, typename T_prior_sample_size>
64  inline
65  typename boost::math::tools::promote_args<T_prob,T_prior_sample_size>::type
66  dirichlet_log(const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& theta,
67  const Eigen::Matrix<T_prior_sample_size,Eigen::Dynamic,1>& alpha) {
68  return dirichlet_log<propto>(theta,alpha,stan::math::default_policy());
69  }
70 
71 
72  template <typename T_prob, typename T_prior_sample_size,
73  class Policy>
74  inline
75  typename boost::math::tools::promote_args<T_prob,T_prior_sample_size>::type
76  dirichlet_log(const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& theta,
77  const Eigen::Matrix<T_prior_sample_size,Eigen::Dynamic,1>& alpha,
78  const Policy&) {
79  return dirichlet_log<false>(theta,alpha,Policy());
80  }
81 
82  template <typename T_prob, typename T_prior_sample_size>
83  inline
84  typename boost::math::tools::promote_args<T_prob,T_prior_sample_size>::type
85  dirichlet_log(const Eigen::Matrix<T_prob,Eigen::Dynamic,1>& theta,
86  const Eigen::Matrix<T_prior_sample_size,Eigen::Dynamic,1>& alpha) {
87  return dirichlet_log<false>(theta,alpha,stan::math::default_policy());
88  }
89 
90 
91  }
92 }
93 #endif
var multiply_log(const var &a, const var &b)
Return the value of a*log(b).
var lgamma(const stan::agrad::var &a)
The log gamma function for variables (C99).
boost::math::tools::promote_args< T_a, T_b >::type multiply_log(T_a a, T_b b)
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
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, const Policy &)
The log of the Dirichlet density for the given theta and a vector of prior sample sizes,...
Definition: dirichlet.hpp:43
Probability, optimization and sampling library.
Definition: agrad.cpp:6
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Definition: traits.hpp:33

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