seg1d.algorithm.rolling_corr

seg1d.algorithm.rolling_corr(x, yData, winSize, cMax=False)[source]

Rolling Correlation

Calculates the rolling correlation coefficient over the given window sizes

Parameters:
x1-D array

array of target data

yData2-D array

array of reference data

winSizeint

scale of the that the reference data should be rescaled to

Returns:
ndarray

1-D array of length (size(x) - winSize + 1)

Other Parameters:
 
cMaxbool, optional

Use maximum of correlations (Default False)

Warning

The reference data (yData) must be smaller than the target data (x) AFTER resampling.
This means if the reference data is length 80, and the target data is length 100, it will work. However, if the winSize is supposed to be length 120, the reference will be scaled and correlation will crash.

See also

combine_corr
(takes the return of this function)

Examples

>>> import numpy as np
>>> import seg1d.algorithm as alg
>>> #make waves
>>> x = np.sin( np.linspace(-np.pi*1, np.pi*1, 20) )
>>> y = np.sin( np.linspace(-np.pi*2, np.pi*2, 80) ).reshape(4,20)
>>> #apply rolling correlations with 10 and 15
>>> alg.rolling_corr(x, y, 10 )
array([-0.00766151,  0.02078156,  0.03501678,  0.04019572,  0.04211895,
        0.04262637,  0.04211895,  0.04019572,  0.03501678,  0.02078156,
       -0.00766151])
>>> alg.rolling_corr(x, y, 15 )
array([0.03321832, 0.03972237, 0.04254858, 0.04254858, 0.03972237,
       0.03321832])