-
-
Notifications
You must be signed in to change notification settings - Fork 985
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
Bivariate von Mises Distribution #2821
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @OlaRonning, nice contribution. I'm curious what inference algorithms you'd like to support with this distribution. As I understand, this will support MCMC because the .log_prob()
is differentiable, but SVI would be trickier because .sample()
is not reparametrizable. Often when creating new distributions I mention in the docstring which inference algorithms are supported and what parameters can be learned.
Hi @fritzo, Thanks for the review! I had not considered the issue with reparameterizing and intended to use SVI; however, HMC should still work. I'll update the docstring as you suggest and look into the possibility of a transform RxR -> S^1xS^1 (not for this PR :)). |
Hi @OlaRonning, for SVI you might also consider a ProjectedNormal prior together with a ProjectedNormalReparam and an |
That's neat, I'll definitely try this out! Thanks. |
Using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
I have checked coding idioms but I have not checked math.
- Can you please confirm that the the examples params in
tests/distributions/conftest.py
exercise a sufficiently diverse range of parameter space, such thattest_gof
can be trusted to verify agreement between.log_prob()
and.sample()
? I see that this test passesbut I want to make sure you're testing with some symmetry breaking parameters, e.g. randomly sampled from their supports, or otherwise asymmetric so as to detect math errors like writingpytest -vx tests/distributions/test_distributions.py::test_gof -k SineBiv
sin
instead ofcos
. - Is there any math you'd like checked in particular?
Thanks for the second review, @fritzo. I've added some more fixtures as you requested, and I believe these now sufficient exercise critical parameterizations (i.e., loc close to pi, high correlation, low correlation, and low concentration). It would be nice to avoid the transcendental functions when sampling the second angle; however, this would involve reimplementing the von Mises distribution. Kent et al. provide an R implementation under supplementary material, together with their article, I believe the maths is reasonably straight forward. The main difference between the R implementation and this is I log transform the terms in the bound and batch sampling, so those would be the critical points. |
With the bug fix in 1789fb0, my mixture model is behaving as expected. |
Hi @OlaRonning, could you try merging dev and pushing? I'm unsure why doc tests are failing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I haven't thoroughly checked math and algorithms, but the interfaces look good and I trust the thorough tests.
This PR introduces the Sine Bivariate von Mises (BvM) distribution which is a distribution on the torus described by Singh et al.. The sampling method works for the univariate case and follows the process developed by Kent et al..
In bioinformatics, BvM is well suited for molding torsion angles for peptide bonds. I'll submit an example using this distribution together with the Sine Skewed distribution in a separate PR.
Sampling may fail if the distribution is bimodal; I've added a
raise Exception
if this occurs. However, I'm not sure of the preferred behavior in this case.