Skip to content

vonMises: Avoid overflow for large kappa #2832

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

Merged
merged 6 commits into from
Feb 3, 2018

Conversation

aloctavodia
Copy link
Member

  • Use log_i0 instead of log(i0) for computing vonMises' logp.
  • Compute gelman-rubin statistic and effective_n using non-transfomed variables, this removes warnings for vonMises that were misleading.

Note: I still get some warnings about diverges (specially for kappa ~< 1). Despite these warnings the samples looks right compared against SciPy or sampling using Metropolis. I will see if I can fix this in a future PR.

@junpenglao
Copy link
Member

diverges might comes from funnel in the Real transformed space, looking at the Metropolis might not be very informative.

@@ -931,6 +931,7 @@ def test_ex_gaussian(self, value, mu, sigma, nu, logp):
pt = {'eg': value}
assert_almost_equal(model.fastlogp(pt), logp, decimal=select_by_precision(float64=6, float32=2), err_msg=str(pt))

@pytest.mark.xfail(condition=(theano.config.floatX == "float32"), reason="Fails on float32")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this not come up before? If the problem is scipy having overflow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because, before both overflow. Now we can use vonmises with larger values of kappa.

Copy link
Member

@junpenglao junpenglao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aloctavodia
Copy link
Member Author

Thanks for the feedback, one more thing @junpenglao. The only reason we have now i0 and i1 is to compute the variance when initializing the vonMises distribution. Should be remove them (and not compute the variance) or keep them?

@junpenglao
Copy link
Member

Is the current computation reliable? It is really quite minor and I doubt anybody is using it. So I would agree with removing it if the computation itself is also not very robust.

@@ -3,7 +3,7 @@
from theano.scalar.basic_scipy import GammaLn, Psi, I0, I1
from theano import scalar

__all__ = ['gammaln', 'multigammaln', 'psi', 'i0', 'i1', 'log_i0']
__all__ = ['gammaln', 'multigammaln', 'psi', 'log_i0']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also remove the import from theano above.

@aloctavodia aloctavodia merged commit d47e133 into pymc-devs:master Feb 3, 2018
@aloctavodia aloctavodia deleted the vM branch February 3, 2018 18:43
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

Successfully merging this pull request may close these issues.

3 participants