[Numpy-discussion] How to limit cross correlation window width in Numpy?

Honi Sanders honi at brandeis.edu
Wed Jun 17 18:22:33 EDT 2015


I will also repeat what I said in response on Github (discussions at: https://github.com/scipy/scipy/issues/4940, https://github.com/numpy/numpy/issues/5954):
I do want a function that computes cross-correlograms, however the implementation is exactly the same for cross-correlograms as convolution. Not only that, is the numpy.correlate() function not for computing cross-correlograms? Maxlag and lagstep still make sense in the context of convolution. Say you have a time series (this is not the best example) of rain amounts and you have a kernel for plant growth given rain in the recent past. Your time series is the entire year, but you are only interested in the plant growth during the months of April through August. Not only that, you do not need daily readout of plant growth; weekly resolution is enough for your needs. You wouldn’t want to compute the convolution for the entire time series, instead you would do: numpy.convolve(rain, growth_kernel, (april, september, 7), lagvec) and get lagvec back with the indices of the sundays in april through august, and a return vector with the amount of plant growth on those days.

I don’t really think it would be good to add an entirely new function to scipy.signal. It was already hard enough as a new user trying to figure out which of the five seemingly identical functions in numpy, scipy, and matplotlib that I should be using. Besides, if all of these functions are essentially doing the same computation, there should only be a single base implementation that they all use, so that 1) the learning curve is decreased and 2) that any optimizations be passed on to all of the functions instead of having to be independently reimplemented several times. So, even if we do decide that scipy.signal should have a new correlogram command, it should be a wrapper for numpy.correlate. But why wouldn't one just use scipy.signal.correlate for the 1d case as well?

Also, see https://github.com/numpy/numpy/pull/5978 for the pull request with a list of specific issues in my implementation that may need attention.  

Honi

> On Jun 17, 2015, at 6:13 PM, Sturla Molden <sturla.molden at gmail.com> wrote:
> 
> On 17/06/15 04:38, Honi Sanders wrote:
> 
>> I have now implemented this functionality in numpy.correlate() and numpy.convolve(). https://github.com/bringingheavendown/numpy. The files that were edited are:
>> numpy/core/src/multiarray/multiarraymodule.c
>> numpy/core/numeric.py
>> numpy/core/tests/test_numeric.py
>> Please look over the code, my design decisions, and the unit tests I have written. This is my first time contributing, so I am not confident about any of these and welcome feedback.
> 
> I'll just repeat here what I already said on Github.
> 
> I think this stems from the need to compute cross-correlograms as used 
> in statistical signal analysis, whereas numpy.correlate and 
> scipy.signal.correlate are better suited for matched filtering.
> 
> I think the best solution would be to add a function called 
> scipy.signal.correlogram, which would return a cross-correlation and an 
> array of time lags. It could take minlag and maxlag as optional arguments.
> 
> Adding maxlag and minlag arguments to numpy.convolve makes very little 
> sense, as far as I am concerned.
> 
> Sturla
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion




More information about the NumPy-Discussion mailing list