[Numpy-discussion] Definition of correlation, correlate and so on ?

Travis Oliphant oliphant.travis at ieee.org
Tue Dec 12 13:30:45 EST 2006


>
> On 12/12/06, *David Cournapeau* <david at ar.media.kyoto-u.ac.jp 
> <mailto:david at ar.media.kyoto-u.ac.jp>> wrote:
>
>     Hi,
>
>         I am polishing some code to compute autocorrelation using fft, and
>     when testing the code against numpy.correlate, I realised that I
>     am not
>     sure about the definition... There are various function related to
>     correlation as far as numpy/scipoy is concerned:
>
>         numpy.correlate
>         numpy.corrcoef
>         scipy.signal.correlate
>
>         For me, the correlation between two sequences X and Y at lag t is
>     the sum(X[i] * Y*[i+lag]) where Y* is the complex conjugate of Y.
>     numpy.correlate does not use the conjugate, scipy.signal.correlate as
>     well, and I don't understand numpy.corrcoef. I've never seen complex
>     correlation used without the conjugate, so I was curious why this
>
>
> Neither have I, it is one of those oddities that may have been 
> inherited from Numeric. I wouldn't mind seeing it changed but it is 
> probably a bit late for that.

It is inherited from Numeric and can't really change.  We can move 
forward with a different function, however, that uses the conjugate for 
complex data.    The non-conjugated version is still well-defined, 
however.  Convolution, for example, is defined without the conjugation, 
and the correlate function is the basis for that computation.  So, it is 
not a good idea to change it. 

The scipy.signal.correlate function is a generalization to N-D of the 
numpy.correlate function which is 1-d only, the numpy.corrcoef function 
is completely different and just computes the correlation coefficients 
from the covariance matrix assuming observations of random vectors.

-Travis




More information about the NumPy-Discussion mailing list