[Numpy-discussion] Cross-covariance function

Pierre Haessig pierre.haessig at crans.org
Fri Jan 27 05:09:53 EST 2012


Le 26/01/2012 19:19, josef.pktd at gmail.com a écrit :
> The discussion had this reversed, numpy matches the behavior of
> MATLAB, while R (statistics) only returns the cross covariance part as
> proposed.
>
I would also say that there was an attempt to match MATLAB behavior. 
However, there is big difference with numpy.cov because of the default 
value `rowvar` being True. Most softwares and textbooks I know consider 
that, in a 2D context, matrix rows are obvervations while columns are 
the variables.

Any idea why the "transposed" convention was selected in np.cov ?
(This question, I'm raising for informative purpose only... ;-) )

I also compared with octave to see how it works :
-- Function File: cov (X, Y)
Compute covariance.

If each row of X and Y is an observation and each column is a
variable, the (I, J)-th entry of `cov (X, Y)' is the covariance
between the I-th variable in X and the J-th variable in Y. If
called with one argument, compute `cov (X, X)'.

(http://www.gnu.org/software/octave/doc/interpreter/Correlation-and-Regression-Analysis.html)
I like the clear tone of this description. But strangely enough, this a 
bit different from Matlab.
(http://webcache.googleusercontent.com/search?q=cache:L3kF8BHcB4EJ:octave.1599824.n4.nabble.com/cov-m-function-behaves-different-from-Matlab-td1634956.html+&cd=1&hl=fr&ct=clnk&client=iceweasel-a)

> If there is a new xcov, then I think there should also be a xcorrcoef.
> This case needs a different implementation than corrcoef, since the
> xcov doesn't contain the variances and they need to be calculated
> separately.
Adding xcorrcoeff as well would make sense. The use of the np.var when 
setting the `axis` and `̀̀ddof` arguments to appropriate values should the 
bring variances needed for the normalization.

In the end, if adding xcov is the path of least resistance, this may be 
the way to go. What do people think ?

Pierre




More information about the NumPy-Discussion mailing list