<div dir="ltr">I like your idea Josef, I'll add it to the PR. Just to be clear, we should have something like:<div><br><div>Have a single "check_valid" keyword arg, which will default to warn, since that is the current behavior. It will check approximate symmetry, PSDness, and for NaN & infs. Other options on the check_valid keyword arg will be ignore, and raise. <br><br>What should happen when "fix" is passed for check_valid? Set negative eigenvalues to 0 and symmetrize the matrix?</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 30, 2015 at 8:34 AM,  <span dir="ltr"><<a href="mailto:josef.pktd@gmail.com" target="_blank">josef.pktd@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sun, Mar 29, 2015 at 7:39 PM, Blake Griffith<br>
<<a href="mailto:blake.a.griffith@gmail.com">blake.a.griffith@gmail.com</a>> wrote:<br>
> I have an open PR which lets users control the checks on the input<br>
> covariance matrix. The matrix is required to be symmetric and positve<br>
> semi-definite (PSD). The current behavior is that NumPy raises a warning if<br>
> the matrix is not PSD, and does not even check for symmetry.<br>
><br>
> I added a symmetry check, which raises a warning when the input is not<br>
> symmetric. And added two keyword args which users can use to turn off the<br>
> checks/warnings when the matrix is ill formed. So this would only cause<br>
> another new warning to be raised in existing code.<br>
><br>
> This is needed because sometimes the covariance matrix is only *almost*<br>
> symmetric or PSD due to roundoff error.<br>
><br>
> Thoughts?<br>
<br>
</div></div>My only question is why is **exact** symmetry relevant?<br>
<br>
AFAIU<br>
A empirical covariance matrix might not be exactly symmetric unless we<br>
specifically force it to be. But I don't see why some roundoff errors<br>
that violate symmetry should be relevant.<br>
<br>
use allclose with floating point rtol or equivalent?<br>
<br>
Some user code might suddenly get irrelevant warnings.<br>
<br>
BTW:<br>
neg = (np.sum(u.T * v, axis=1) < 0) & (s > 0)<br>
doesn't need to be calculated if cov_psd is false.<br>
<br>
-----<br>
<br>
some more:<br>
<br>
svd can hang if the values are not finite, i.e. nan or infs<br>
<br>
counter proposal would be to add a `check_valid` keyword with option<br>
ignore. warn, raise, and "fix"<br>
<br>
and raise an error if there are nans and check_valid is not ignore.<br>
<br>
---------<br>
<br>
aside:<br>
np.random.multivariate_normal   is only relevant if you have a new cov<br>
each call (or don't mind repeated possibly expensive calculations),<br>
so, I guess, adding checks by default won't upset many users.<br>
<br>
<br>
Josef<br>
<br>
<br>
><br>
><br>
> PR: <a href="https://github.com/numpy/numpy/pull/5726" target="_blank">https://github.com/numpy/numpy/pull/5726</a><br>
><br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
><br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div><br></div>