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

multivariate_normal warns about non-PSD covariance for float32 inputs #10839

Closed
mbillingr opened this issue Apr 3, 2018 · 0 comments · Fixed by #12547
Closed

multivariate_normal warns about non-PSD covariance for float32 inputs #10839

mbillingr opened this issue Apr 3, 2018 · 0 comments · Fixed by #12547

Comments

@mbillingr
Copy link

mbillingr commented Apr 3, 2018

Passing a clearly positive definite covariance matrix with float32 data type causes the warning

RuntimeWarning: covariance is not positive-semidefinite.

Using the same matrix with float64 does not raise the warning.

Steps to reproduce:

import numpy as np
cov = np.array([[1, 0.1], [0.1, 1]], dtype=np.float32)
np.random.multivariate_normal([0, 0], cov)

This was raised as a question at StackOverflow.

I suspect that the behavior may be related to the way the function's tol argument is passed to both rtol and atol in psd = np.allclose(np.dot(v.T * s, v), cov, rtol=tol, atol=tol). The default of tol=1e-8 is much lower than np.isclose's default for rtol=1e-5.

bashtage added a commit to bashtage/numpy that referenced this issue Dec 14, 2018
Cast the covariance in the multivariate normal to double
so that the interpretation of tol is cleaner.

closes numpy#10839
grlee77 pushed a commit to grlee77/numpy that referenced this issue Mar 26, 2019
Cast the covariance in the multivariate normal to double
so that the interpretation of tol is cleaner.

closes numpy#10839
charris pushed a commit to charris/numpy that referenced this issue Apr 6, 2019
Cast the covariance in the multivariate normal to double
so that the interpretation of tol is cleaner.

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

Successfully merging a pull request may close this issue.

2 participants