Stan Math Library
4.9.0
Automatic Differentiation
|
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 \]
T_prob | type of scalar |
T_prior_size | type of prior sample sizes |
theta | A scalar vector. |
alpha | Prior sample sizes. |
std::domain_error | if any element of alpha is less than or equal to 0. |
std::domain_error | if any element of theta is less than 0. |
std::domain_error | if the sum of theta is not 1. |
Definition at line 59 of file dirichlet_lpdf.hpp.