forked from mjhajharia/transforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multi-logit-normal implementation
Adapted from mjhajharia#74
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |