From 4d4f58a4fb7d208a0a9c9e4677094899383d03b9 Mon Sep 17 00:00:00 2001 From: Oleg Zabluda Date: Sun, 4 Mar 2018 15:34:06 -0800 Subject: MAINT: Covariance must be symmetric as well as positive-semidefinite. (#10669) * [BUG] add "symmetric" to "positive-semidefinite" * Break line, fix comments * break long line --- numpy/random/mtrand/mtrand.pyx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'numpy') 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 -- cgit v1.2.1