Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconsistent results with funcnet.cross_correlation() #162

Closed
rimajj opened this issue May 9, 2022 · 1 comment · Fixed by #195
Closed

Unconsistent results with funcnet.cross_correlation() #162

rimajj opened this issue May 9, 2022 · 1 comment · Fixed by #195
Assignees
Milestone

Comments

@rimajj
Copy link

rimajj commented May 9, 2022

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))

@lenas95 lenas95 self-assigned this Jun 24, 2022
@fkuehlein fkuehlein linked a pull request Sep 25, 2023 that will close this issue
fkuehlein added a commit to fkuehlein/pyunicorn that referenced this issue Sep 26, 2023
- and add respective test for funcnet.cross_correlation(lag_mode="all")
- solves issue pik-copan#162
@fkuehlein
Copy link
Collaborator

fkuehlein commented Sep 26, 2023

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 MAINT: fully cythonize funcnet.CouplingAnalysis #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!

@ntfrgl ntfrgl added this to the Release 0.7 milestone Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants