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

NaNs in logcdf of ExGaussian. #4295

Closed
yarlett opened this issue Dec 5, 2020 · 0 comments · Fixed by #4407
Closed

NaNs in logcdf of ExGaussian. #4295

yarlett opened this issue Dec 5, 2020 · 0 comments · Fixed by #4407
Labels

Comments

@yarlett
Copy link

yarlett commented Dec 5, 2020

Description of your problem

I'm getting NaNs when I call ExGaussian.logcdf. I don't think this is arising as a result of invalid values of mu / nu / sigma and interestingly the values of x that cause the NaNs in logcdf appear to be clustered around a specific value suggesting some kind of boundary condition. See reproducible example below:

import numpy as np
import pymc3 as pm
import theano as th

th.config.floatX = "float32"

x = np.random.randn(10000).astype(th.config.floatX)
y = pm.ExGaussian.dist(mu=0, nu=.1, sigma=.1).logcdf(x).eval()
x[np.isnan(y)]

array([-0.4472333 , -0.4515727 , -0.4532674 , -0.43305278, -0.4459583 ,
       -0.4472994 , -0.4505409 , -0.4488517 , -0.43436724, -0.43309352,
       -0.44969806, -0.453023  , -0.44659823, -0.4462295 , -0.44922173,
       -0.43413943, -0.4502953 , -0.4507278 , -0.45263064, -0.4473039 ,
       -0.4496712 , -0.45111936, -0.4341618 , -0.44784546, -0.4528737 ,
       -0.4503683 , -0.4510499 , -0.45030335, -0.44865718, -0.4483132 ,
       -0.45047495, -0.45401436, -0.4479592 , -0.44907624, -0.44798186,
       -0.45309132, -0.45274436, -0.45385256, -0.4506684 , -0.44866312],
      dtype=float32)

I'm not sure if this is my error in calling, is a result of the mathematical definition of logcdf implemented in PyMC3, or is an arithmetic precision error to do with numpy / theano.

Also, if I set theano.config.floatX = "float64" the values of x that cause NaNs all cluster around approx. -0.72 instead of approx. -0.44.

Any help would be greatly appreciated. Thanks!

Versions and main components

  • PyMC3 Version: 3.9.3
  • Theano Version: 1.0.5
  • Python Version: 3.7.9
  • Operating system: MacOS
  • How did you install PyMC3: pip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants