-
Notifications
You must be signed in to change notification settings - Fork 89
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
CoulombMatrix(permutation="sorted_l2")
is not symmetric
#89
Comments
Hi @MomoLangenstein, Thanks for the report. I need to check what is going on. If this is the case, we definitely need to fix it and introduce a better test that also checks the symmetricity. |
Hi @MomoLangenstein, Indeed there was an issue where the rows and columns of the matrix were not being permuted as expected, causing non-symmetric matrices. There is now a fix in the branch v1.2.2, which will be made into a release in the near future. It would be great if you can verify this fix as well. I have added a new symmetricity test into our test suite and your examples now also pass after changing the sorting on the python side slightly like this: sorted_row_indices = np.argsort(-row_norms) The sorting in your manual implementation needs to be exactly the same as in our C++ implementation due to ambiguity in sorting by row norm. In several cases the norms of the matrix rows are identical and in order to get the exact same results, the sorting logic needs to be identical in your example and in our C++ implementation. |
Hi @lauri-codes, Thank you for working out the fix for this issue! I can confirm that my small test now works on the sorted_row_indices = np.argsort(-row_norms) instead of sorted_row_indices = np.argsort(row_norms)[::-1] I get exactly the same results with my manual implementation as with |
Hi, Yes, the sorting simply affects the way that rows with equal norm are handled. If there are no equal norms, then the output is completely independent of the sorting algorithm (see e.g. the The small differences only start kicking in when there are equal norms. I think import numpy as np
a = [
[2, 1],
[1, 2],
]
row_norms = np.linalg.norm(a, axis=1)
indices1 = np.argsort(row_norms)[::-1]
print(indices1) # [1, 0]
indices2 = np.argsort(-row_norms)
print(indices2) # [0, 1] In the end it does not really matter which way you sort the rows with equal norms, just as long as you are consistent throughout your data. |
Now fixed in v1.2.2. |
When using the
dscribe
Python library, v1.2.1, Coulomb matrices generated using thesorted_l2
permutation are no longer symmetric matrices. I compared dscribe's result with a manual implementation of the sorting based on doi:10.1002/qua.24954 to check that the algorithm in general works.This manual implementation matches
dscribe/dscribe/descriptors/matrixdescriptor.py
Lines 143 to 159 in 79a1393
Therefore, I'd guess that something might be wrong with the C++ implementation in
dscribe/dscribe/ext/cm.cpp
Lines 111 to 136 in 79a1393
Below is an example to reproduce the issue:
The text was updated successfully, but these errors were encountered: