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

Use diffusion_mapping in MATLAB and got complex number in the eigvalue #98

Open
tw70455 opened this issue Apr 25, 2023 · 2 comments
Open

Comments

@tw70455
Copy link

tw70455 commented Apr 25, 2023

Hello,

I would like to use diffusion_map to obtain the embedding and eigenvalues. I provided a symmetric cosine similarity matrix (no negative value) as input data with an alpha value of 0.5 and a diffusion time of 0. Although I obtained both the embedding and eigenvalues, I noticed that the eigenvalues are not sorted. Upon reviewing the code, I discovered that the eigval is a complex number ([eigvec, eigval] = eig(M)). As a result, the sorting ([eigval, idx] = sort(eigval,'descend');) did not work. I am wondering if this is because I used the wrong matrix for input? Thank you.

@ReinderVosDeWael
Copy link
Collaborator

Could you try running your matrix through the standard GradientMaps object with the kernel set to 'none', and other parameters set appropriately? This would be the recommended approach, and already handles some standard error cases. Does this yield the same outcome?

@tw70455
Copy link
Author

tw70455 commented Apr 26, 2023

Thank you for your reply. I noticed that there is a slight difference between the MATLAB and Python code for diffusion_map estimation.

In MATLAB code, 'data' is the input matrix, and 'M' is the matrix for eigenvalue/eigenvector estimation.
'd = sum(data,2) .^ -alpha;
L = data .* (d*d.');

d2 = sum(L,2) .^ -1;
M = bsxfun(@times, L, d2);'

In Python code, 'adj' is the input matrix and also for the eigenvalue/eigenvector estimation.
' if alpha > 0:
if use_sparse:
d = np.power(adj.sum(axis=1).A1, -alpha)
adj.data *= d[adj.row]
adj.data *= d[adj.col]
else:
d = adj.sum(axis=1, keepdims=True)
d = np.power(d, -alpha)
adj *= d.T
adj *= d'

It looks like the matrix in MATLAB will be asymmetry for the eigenvalue estimation, and it won't happen in the Python code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants