<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 26, 2016 at 3:20 PM,  <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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="gmail-m_7873832066901095103h5">On Wed, Oct 26, 2016 at 3:11 PM, Mathew S. Madhavacheril <span dir="ltr"><<a href="mailto:mathewsyriac@gmail.com" target="_blank">mathewsyriac@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="gmail-m_7873832066901095103m_6469966294266325335gmail-h5">On Wed, Oct 26, 2016 at 2:56 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>On Wed, Oct 26, 2016 at 11:13 AM, Stephan Hoyer <<a href="mailto:shoyer@gmail.com" target="_blank">shoyer@gmail.com</a>> wrote:<br>
> On Wed, Oct 26, 2016 at 11:03 AM, Mathew S. Madhavacheril<br>
> <<a href="mailto:mathewsyriac@gmail.com" target="_blank">mathewsyriac@gmail.com</a>> wrote:<br>
>><br>
>> On Wed, Oct 26, 2016 at 1:46 PM, Stephan Hoyer <<a href="mailto:shoyer@gmail.com" target="_blank">shoyer@gmail.com</a>> wrote:<br>
>>><br>
>>> I wonder if the goals of this addition could be achieved by simply adding<br>
>>> an optional `cov` argument<br>
>>><br>
>>> to np.corr, which would provide a pre-computed covariance.<br>
>><br>
>><br>
>> That's a fair suggestion which I'm happy to switch to. This eliminates the<br>
>> need for two new functions.<br>
>> I'll add an optional `cov = False` argument to numpy.corrcoef that returns<br>
>> a tuple (corr, cov) instead.<br>
>><br>
>>><br>
>>><br>
>>> Either way, `covcorr` feels like a helper function that could exist in<br>
>>> user code rather than numpy proper.<br>
>><br>
>><br>
>> The user would have to re-implement the part that converts the covariance<br>
>> matrix to a correlation<br>
>> coefficient. I made this PR to avoid that code duplication.<br>
><br>
><br>
> With the API I was envisioning (or even your proposed API, for that matter),<br>
> this function would only be a few lines, e.g.,<br>
><br>
> def covcorr(x):<br>
>     cov = np.cov(x)<br>
>     corr = np.corrcoef(x, cov=cov)<br>
<br>
</span>IIUC, if you have a covariance matrix then you can compute the<br>
correlation matrix directly, without looking at 'x', so corrcoef(x,<br>
cov=cov) is a bit odd-looking. I think probably the API that makes the<br>
most sense is just to expose something like the covtocorr function<br>
(maybe it could have a less telegraphic name?)? And then, yeah, users<br>
can use that to build their own covcorr or whatever if they want it.<br></blockquote><div><br></div></div></div><div>Right, agreed, this is why I said `x` becomes redundant when `cov` is specified</div><div>when calling `numpy.corrcoef`.  So we have two alternatives:</div><div><br></div><div>1) Have `np.corrcoef` accept a boolean optional argument `covmat = False` that lets</div><div>one obtain a tuple containing the covariance and the correlation matrices in the same call</div><div>2) Modify my original PR so that `np.covtocorr` remains (with possibly a better</div><div>name) but remove `np.covcorr` since this is easy for the user to add.</div><div><br></div><div>My preference is option 2. </div></div></div></div></blockquote><div><br></div></div></div><div>cov2corr is a useful function</div><div><a href="http://www.statsmodels.org/dev/generated/statsmodels.stats.moment_helpers.cov2corr.html" target="_blank">http://www.statsmodels.org/dev<wbr>/generated/statsmodels.stats.<wbr>moment_helpers.cov2corr.html</a></div><div>I also wrote the inverse function corr2cov, but AFAIR use it only in some test cases.</div><div><br></div><div><br></div><div>I don't think adding any of the options to corrcoef or covcor is useful since there is no computational advantage to it.</div></div></div></div></blockquote><div><br></div><div>I'm not sure I agree with that statement. If a user wants to calculate both a covariance and correlation matrix,</div><div>they currently have two options:</div><div>A) Call np.cov and np.corrcoef separately, which takes at least twice as long as one call to np.cov. For data-sets that</div><div>I am used to, a np.cov call takes 5-10 seconds.</div><div>B) Call np.cov and then separately implement their own correlation matrix code, which means the user</div><div>isn't able to fully take advantage of code that is already in numpy.<br><br>In any case, I've updated the PR:<br><a href="https://github.com/numpy/numpy/pull/8211">https://github.com/numpy/numpy/pull/8211</a></div><br>Relative to my original PR, it:<br>a) removes the numpy.covcorr function which the user can easily implement<br>b) have numpy.cov2corr be the function exposed in the API (previously<br>called numpy.covtocorr in the PR), which accepts a pre-calculated covariance<br>matrix<br>c) have numpy.corrcoef call numpy.cov2corr<div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div></div>
<br>______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman<wbr>/listinfo/numpy-discussion</a><br>
<br></blockquote></span></div><br></div></div>
<br>______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman<wbr>/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div></div>