Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ dirichlet_lpdf() [2/3]

template<bool propto, typename T_prob , typename T_prior_size , require_all_not_nonscalar_prim_or_rev_kernel_expression_t< T_prob, T_prior_size > * = nullptr>
return_type_t< T_prob, T_prior_size > stan::math::dirichlet_lpdf ( const T_prob &  theta,
const T_prior_size &  alpha 
)

The log of the Dirichlet density for the given theta and a vector of prior sample sizes, alpha.

Each element of alpha must be greater than 0. Each element of theta must be greater than or 0. Theta sums to 1.

\[ \theta\sim\mbox{Dirichlet}(\alpha_1,\ldots,\alpha_k)\\ \log(p(\theta\,|\,\alpha_1,\ldots,\alpha_k))=\log\left( \frac{\Gamma(\alpha_1+\cdots+\alpha_k)}{\Gamma(\alpha_1)+ \cdots+\Gamma(\alpha_k)}* \left(\theta_1^{\alpha_1-1}+ \cdots+\theta_k^{\alpha_k-1}\right)\right)\\ =\log(\Gamma(\alpha_1+\cdots+\alpha_k))-\left( \log(\Gamma(\alpha_1))+\cdots+\log(\Gamma(\alpha_k))\right)+ (\alpha_1-1)\log(\theta_1)+\cdots+(\alpha_k-1)\log(\theta_k) \]

\[ \frac{\partial }{\partial \theta_x}\log(p(\theta\,|\,\alpha_1,\ldots,\alpha_k))= \frac{\alpha_x-1}{\theta_x} \]

\[ \frac{\partial}{\partial\alpha_x}\log(p(\theta\,|\,\alpha_1,\ldots,\alpha_k)) =\psi_{(0)}(\sum\alpha)-\psi_{(0)}(\alpha_x)+\log\theta_x \]

Template Parameters
T_probtype of scalar
T_prior_sizetype of prior sample sizes
Parameters
thetaA scalar vector.
alphaPrior sample sizes.
Returns
The log of the Dirichlet density.
Exceptions
std::domain_errorif any element of alpha is less than or equal to 0.
std::domain_errorif any element of theta is less than 0.
std::domain_errorif the sum of theta is not 1.

Definition at line 59 of file dirichlet_lpdf.hpp.