Skip to content

Commit

Permalink
Add multi-logit-normal implementation
Browse files Browse the repository at this point in the history
Adapted from mjhajharia#74
  • Loading branch information
sethaxen committed Jun 4, 2024
1 parent f99feb5 commit 7c8b995
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions targets/functions/multi-logit-normal.stanfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Return the multivariate logistic normal density for the specified simplex.
*
* See: https://en.wikipedia.org/wiki/Logit-normal_distribution#Multivariate_generalization
*
* @param theta a simplex (N rows)
* @param mu location of normal (N-1 rows)
* @param L_Sigma Cholesky factor of covariance (N-1 rows, N-1 cols)
*/
real multi_logit_normal_cholesky_lpdf(vector theta, vector mu, matrix L_Sigma) {
vector[rows(theta)] log_theta = log(theta);
return sum(-log_theta)
+ multi_log_logit_normal_cholesky_lpdf(log_theta | mu, L_Sigma);
}

/**
* Return the multivariate logistic normal density for the specified log simplex.
*
* See: https://en.wikipedia.org/wiki/Logit-normal_distribution#Multivariate_generalization
*
* @param theta a log simplex (N rows)
* @param mu location of normal (N-1 rows)
* @param L_Sigma Cholesky factor of covariance (N-1 rows, N-1 cols)
*/
real multi_log_logit_normal_cholesky_lpdf(vector log_theta, vector mu, matrix L_Sigma) {
int N = rows(log_theta);
return multi_normal_cholesky_lpdf(log_theta[1:N-1] - log_theta[N] | mu, L_Sigma);
}

0 comments on commit 7c8b995

Please sign in to comment.