pik-copan / pyunicorn

Unified Complex Network and Recurrence Analysis Toolbox
http://pik-potsdam.de/~donges/pyunicorn/
Other
195 stars 86 forks source link

Unconsistent results with funcnet.cross_correlation() #162

Closed rimajj closed 9 months ago

rimajj commented 2 years ago

The following code demonstrates inconsistencies regarding the two lag modes "all" and "max" of the funcnet.cross_correlation() function. Regarding the fact that at tau=0 the entries in the diagonal are not 1 in "all" mode, I suspect that the "all" mode is incorrect.

from pyunicorn import funcnet import numpy as np

data=funcnet.CouplingAnalysis.test_data() func=funcnet.CouplingAnalysis(data) x1=func.cross_correlation(tau_max=0,lag_mode="all") y1, lags=func.cross_correlation(tau_max=0,lag_mode="max") print(np.array_equal(x1,y1))

x2=func.cross_correlation(tau_max=3,lag_mode="all") y2=func.cross_correlation(tau_max=3,lag_mode="max") print(x2[:,:,0]) print(np.array_equal(np.max(x2,axis=2),y2))

fkuehlein commented 9 months ago

Hi @rimajj,

very sorry for the late response, we have been working with limited resources here.

  1. You are absolutely right pointing out that the correlation matrix should not consist of only zeros for tau=0 and lag_mode="all". There was an indexing error in the Cython source code which I fixed in 7533f95, thank you for the hint!

    To apply this, as soon as #195 is merged, please pull the latest version of the master branch and reinstall. Also, we are currently working on a new release, so stay tuned.

  2. Still, in your example code the outputs for x1 and y1 can never be equal, because they are of shape (4,4,1) and (4,4) respectively. Take x1[:,:,0] and use numpy.allclose() instead of np.array_equal(), you'll be fine now. A similar point applies to y2, which is a tuple of two matrices; either assign y2, lags as before, or take y2[0], again using numpy.allclose() for checking.

Cheers!