diff options
author | Oleg Zabluda <ozabluda@gmail.com> | 2018-03-04 15:34:06 -0800 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2018-03-04 16:34:06 -0700 |
commit | 4d4f58a4fb7d208a0a9c9e4677094899383d03b9 (patch) | |
tree | f439b7e1e0429619983007aae18f89d3d006d36d | |
parent | a016167e0a44ace62a246e3d251bd41ff4aa0282 (diff) | |
download | python-numpy-4d4f58a4fb7d208a0a9c9e4677094899383d03b9.tar.gz python-numpy-4d4f58a4fb7d208a0a9c9e4677094899383d03b9.tar.bz2 python-numpy-4d4f58a4fb7d208a0a9c9e4677094899383d03b9.zip |
MAINT: Covariance must be symmetric as well as positive-semidefinite. (#10669)
* [BUG] add "symmetric" to "positive-semidefinite"
* Break line, fix comments
* break long line
-rw-r--r-- | numpy/random/mtrand/mtrand.pyx | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index 501c1e5b3..16d649c4a 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -4514,12 +4514,11 @@ cdef class RandomState: # covariance. Note that sqrt(s)*v where (u,s,v) is the singular value # decomposition of cov is such an A. # - # Also check that cov is positive-semidefinite. If so, the u.T and v + # Also check that cov is symmetric positive-semidefinite. If so, the u.T and v # matrices should be equal up to roundoff error if cov is - # symmetrical and the singular value of the corresponding row is + # symmetric and the singular value of the corresponding row is # not zero. We continue to use the SVD rather than Cholesky in - # order to preserve current outputs. Note that symmetry has not - # been checked. + # order to preserve current outputs. (u, s, v) = svd(cov) @@ -4530,10 +4529,12 @@ cdef class RandomState: psd = np.allclose(np.dot(v.T * s, v), cov, rtol=tol, atol=tol) if not psd: if check_valid == 'warn': - warnings.warn("covariance is not positive-semidefinite.", - RuntimeWarning) + warnings.warn( + "covariance is not symmetric positive-semidefinite.", + RuntimeWarning) else: - raise ValueError("covariance is not positive-semidefinite.") + raise ValueError( + "covariance is not symmetric positive-semidefinite.") x = np.dot(x, np.sqrt(s)[:, None] * v) x += mean |