-
Notifications
You must be signed in to change notification settings - Fork 32
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
invlink for simplex distributions #17
Comments
It looks to me like it's stable, but Mohamed the Master of Type Stability probably has a far better eye for that than me. |
Hi @trappmartin ! Your implementation looks type stable but I think we will run into numerical issues when inverting this. The main numerical stability problems were from julia> @btime invlink_simplex($y);
39.384 μs (1 allocation: 7.94 KiB)
julia> @btime invlink($d, $y);
43.395 μs (1 allocation: 7.94 KiB) I assume the extra time is from the extra epsilon arithmetic that is done. The real difference is probably more when you use |
I will also make a PR to fix the |
Sounds good. I wasn’t aiming for performance with my implementation but was surprised that the invlink is so much slower. |
Maybe as a side note, it might be good to have internal functions that do not require to pass a distribution object. This would allow a knowledgeable user to use the transformations without instantiating a Distributions object. Similar to the StatsFuns package. |
One last note. I think the invlink should be at least as fast as my code as I don’t optimise anything and invlink looks rather tuned. Your test shows that even after removing the |
@trappmartin The slowdown is from the epsilons to make |
No, I propose we try to get to code faster while keeping it numerical stable. |
Done, #20. The main improvement came from replacing julia> @btime invlink_simplex($y);
39.384 μs (1 allocation: 7.94 KiB)
julia> @btime invlink($d, $y);
39.020 μs (1 allocation: 7.94 KiB) |
Hi,
I've played around with the
invlink
function for simplex distributions and checked the correctness of the current implementation against the code used in Stan. (https://github.com/stan-dev/math/blob/502487c511594ccb93eb979df5b8fe163becb417/stan/math/rev/mat/fun/simplex_constrain.hpp)The reimplementation I used is:
and I found quite a bit of speed improvement if this implementation is used...
Should I make a PR for this or do we think there are stability issues with the code?
The text was updated successfully, but these errors were encountered: