-
Notifications
You must be signed in to change notification settings - Fork 15
Fix UnitVector implementation #67
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
base: master
Are you sure you want to change the base?
Conversation
Flux removed Tracker as a dependency in v0.10.0
Codecov Report
@@ Coverage Diff @@
## master #67 +/- ##
==========================================
+ Coverage 93.08% 93.44% +0.35%
==========================================
Files 7 7
Lines 246 244 -2
==========================================
- Hits 229 228 -1
+ Misses 17 16 -1
Continue to review full report at Codecov.
|
This PR is ready for review. |
This is slightly more standard. e.g. for the 1- and 3-spheres (related to 2D and 3D rotation groups), [1,0] and [1,0,0,0] correspond to identity elements.
And don't evaluate at exact origin where reverse-mode diffs are undefined.
Thanks for the very nice contribution! I am happy to include it, but I would prefer not to make a breaking change to So I would ask that you leave the existing |
I'm happy to make those changes. But I also think it's necessary to document that |
Perhaps I would not call it "broken", for some applications it can be fine. There are trade-offs between the two mappings, eg the spherical one is not invertible. It is best if the properties are documented so that the users can pick the appropriate one. |
Hmm I don't see a good way to revert such that I keep |
Closing because stale and I don't intend to work on this further. |
@sethaxen, I apologize for not pursuing this. |
@sethaxen, I apologize for not pursuing this. I fully understand that you don't want to work on this further, but would you give permission for me to use your code and fix the issue? |
No problem, after all, I had originally planned to do it myself. Yes, I'm very happy for you to use the code. |
This PR implements the proposed changes to
UnitVector
in #66 (i.e. Stan's approach). Ifx == zeros(n)
, the transformation is technically undefined. Stan handles this by always initializing with jitter. Since we can't control how users initialize,zeros(n)
is instead mapped deterministically to a valid unit vector.Along the way, a few tests had to be changed to handle cases like this where the "inverse" is only a right inverse. I also had to add a compat entry for Flux, since Tracker was removed from Flux in v0.10.
Here's a worked example, sampling from the uniform distribution on the circle and sphere:
This PR produces a uniform distribution on the circle (right), while the existing implementation (left) does not:
This PR likewise produces a uniform distribution on the sphere (right), while the existing implementation (left) gives a distribution only on the hemisphere: