Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve with_logabsdet_jacobian performance for SimplexBijector #303

Open
torfjelde opened this issue Apr 15, 2024 · 1 comment
Open

Improve with_logabsdet_jacobian performance for SimplexBijector #303

torfjelde opened this issue Apr 15, 2024 · 1 comment

Comments

@torfjelde
Copy link
Member

The PR made me wonder whether it would be possible to improve performance of with_logabsdet_jacobian for SimplexBijector by not performing transform and logabsdetjac separately when both are requested. Doesn't block this PR and maybe would lead to more code duplications though.

Originally posted by @devmotion in #302 (review)

@sethaxen
Copy link
Member

Yes, it's absolutely possible. The simplex transform we use (and Stan as well) is just the classic stick-breaking transform (called the inverse multiplicative log-ratio transform in the compositional data analysis literature) shifted in the unconstrained space so that for all symmetric Dirichlet distributions, the unconstrained distribution's mode is at the origin. Its Jacobian is the product of the elements of the output vector, but for numerical stability, it's better to perform the entire transform on the log-scale. There's a Stan implementation of this here: https://github.com/mjhajharia/transforms/blob/1207723c4c4208116f80204fe35f1631aaa30f6a/transforms/simplex/StickbreakingLogistic.stan#L2-L17 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants