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

Bivariate von Mises Distribution #2821

Merged
merged 29 commits into from
May 19, 2021
Merged

Conversation

OlaRonning
Copy link
Member

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.

Copy link
Member

@fritzo fritzo left a 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.

pyro/distributions/bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/bivariate_von_mises.py Outdated Show resolved Hide resolved
tests/distributions/test_bivariate_von_mises.py Outdated Show resolved Hide resolved
@OlaRonning
Copy link
Member Author

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 :)).

@fritzo
Copy link
Member

fritzo commented Apr 25, 2021

Hi @OlaRonning, for SVI you might also consider a ProjectedNormal prior together with a ProjectedNormalReparam and an AutoMultivariateNormal guide. The ProjectedNormal distribution and reparametrizer aims to support the reparametrization trick while working around the torus topology by working in a higher dimensional euclidean space and projecting down to spherical (or toroidal) space. This combination supports learning of a bimodal posterior.

@OlaRonning
Copy link
Member Author

That's neat, I'll definitely try this out! Thanks.

@OlaRonning
Copy link
Member Author

Using infer.Predictive, I could not use autodiff in BvM._bfind; I resolved this by manually computing the first and second-order derivates.

@OlaRonning OlaRonning requested a review from fritzo May 2, 2021 17:46
Copy link
Member

@fritzo fritzo left a 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.

  1. Can you please confirm that the the examples params in tests/distributions/conftest.py exercise a sufficiently diverse range of parameter space, such that test_gof can be trusted to verify agreement between .log_prob() and .sample()? I see that this test passes
    pytest -vx tests/distributions/test_distributions.py::test_gof -k SineBiv
    but 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 writing sin instead of cos.
  2. Is there any math you'd like checked in particular?

pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
tests/distributions/conftest.py Outdated Show resolved Hide resolved
pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
pyro/distributions/sine_bivariate_von_mises.py Outdated Show resolved Hide resolved
@OlaRonning
Copy link
Member Author

OlaRonning commented May 5, 2021

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.

@OlaRonning
Copy link
Member Author

With the bug fix in 1789fb0, my mixture model is behaving as expected.

image

@fritzo
Copy link
Member

fritzo commented May 18, 2021

Hi @OlaRonning, could you try merging dev and pushing? I'm unsure why doc tests are failing.

@OlaRonning
Copy link
Member Author

OlaRonning commented May 18, 2021

Hi @fritzo, been slightly distracted by deadlines. I'll work out the problem with docs on Thursday if #2838 doesn't resolve it. #2838 solved it!

Copy link
Member

@fritzo fritzo left a 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.

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

Successfully merging this pull request may close these issues.

2 participants