Git Product home page Git Product logo

Comments (5)

HeyWeCome avatar HeyWeCome commented on July 20, 2024

A cleaner approach is to add a small epsilon to the degree to avoid zeros, before taking the reciprocal square root.

Here is one way I provide to fix it:

def _normalize_adj(self, mat):
    # Add epsilon to avoid divide by zero
    degree = np.array(mat.sum(axis=-1)) + 1e-10
    d_inv_sqrt = np.reshape(1.0 / np.sqrt(degree), [-1])
    d_inv_sqrt[np.isinf(d_inv_sqrt)] = 0.0
    d_inv_sqrt_mat = sp.diags(d_inv_sqrt)
    return mat.dot(d_inv_sqrt_mat).transpose().dot(d_inv_sqrt_mat).tocoo()

By adding a small epsilon value, it guarantees there are no zeros in degree, avoiding the divide by zero.

The tiny epsilon doesn't meaningfully change the normalization, but avoids the need to handle inf/NaN values separately.

I hope it will help. By the way, I wanted to mention that I originally intended to submit code to a dev branch, but noticed that the project only has a master branch. In the future, would you consider adding a dev branch or something similar to facilitate the contributions? Thank you.

from sslrec.

Re-bin avatar Re-bin commented on July 20, 2024

Hi!

Thanks for your interest in SSLRec, and we appreciate your contribution!
Perhaps you could consider submitting a pull request so that we can merge your changes into the project ;)

Best regards,
Xubin

from sslrec.

HeyWeCome avatar HeyWeCome commented on July 20, 2024

Of course, I am more than happy to make a contribution. Currently, I have already submitted a pull request #7. If there are any issues with the code, please let me know. Thanks.

from sslrec.

Re-bin avatar Re-bin commented on July 20, 2024

Hi! Thank you for your contribution. It has been merged into the main branch :)

from sslrec.

HeyWeCome avatar HeyWeCome commented on July 20, 2024

Thank you for your recognition, good night~

from sslrec.

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.