Giter Club home page Giter Club logo

Comments (5)

lauri-codes avatar lauri-codes commented on June 20, 2024

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.

from dscribe.

lauri-codes avatar lauri-codes commented on June 20, 2024

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.

from dscribe.

juntyr avatar juntyr commented on June 20, 2024

Hi @lauri-codes,

Thank you for working out the fix for this issue! I can confirm that my small test now works on the v1.2.2 branch. I just wanted to clarify your proposed change to the manual Python implementation. If I do use

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 dscribe. Are both methods semantically correct, and only differ in their handling of how to order rows/columns with equivalent norms?

from dscribe.

lauri-codes avatar lauri-codes commented on June 20, 2024

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 kind attribute in the numpy docs) and whether you do np.argsort(-row_norms) or np.argsort(row_norms)[::-1].

The small differences only start kicking in when there are equal norms. I think np.argsort(-row_norms) and np.argsort(row_norms)[::-1] should not be equal in these cases, e.g.:

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.

from dscribe.

lauri-codes avatar lauri-codes commented on June 20, 2024

Now fixed in v1.2.2.

from dscribe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.