Giter Site home page Giter Site logo

test_katz fails in CI about linkpred HOT 6 CLOSED

rafguns avatar rafguns commented on June 7, 2024
test_katz fails in CI

from linkpred.

Comments (6)

rafguns avatar rafguns commented on June 7, 2024

Seems like the difference is in the output of Katz.predict. On my computer, this yields 0.010038160200000002, whereas in CI it gives 0.010101010100000004.

Given this test case:

G.add_weighted_edges_from(
    [(1, 2, 1), (0, 2, 5), (2, 3, 1), (0, 4, 2), (1, 4, 1), (3, 5, 1), (4, 5, 3)]
)

the difference happens for nodes 1 and 2.

from linkpred.

rafguns avatar rafguns commented on June 7, 2024

Hmm, looks like it's not due to numpy or networkx version...

from linkpred.

rafguns avatar rafguns commented on June 7, 2024

Minimal testcase:

import networkx as nx
from linkpred.predictors import Katz


G = nx.Graph()
G.add_weighted_edges_from(
    [(1, 2, 1), (0, 2, 5), (2, 3, 1), (0, 4, 2), (1, 4, 1), (3, 5, 1), (4, 5, 3)]
)

katz = Katz(G).predict(beta=beta, weight="weight", dtype=int)
assert katz[(1, 2)] == 0.010038160200000002

from linkpred.

rafguns avatar rafguns commented on June 7, 2024

Seems like the difference is between scipy 1.9 and 1.10.

from linkpred.

rafguns avatar rafguns commented on June 7, 2024

Matrix multiplication in scipy.sparse 1.10 is fundamentally different! It does element-wise multiplication.

In 1.9:

[9]: adj.todense()

array([[0, 1, 0, 0, 1, 0],
       [1, 0, 5, 1, 0, 0],
       [0, 5, 0, 0, 2, 0],
       [0, 1, 0, 0, 0, 1],
       [1, 0, 2, 0, 0, 3],
       [0, 0, 0, 1, 3, 0]], dtype=int32)

[10]: (adj**2).todense()

array([[ 2,  0,  7,  1,  0,  3],
       [ 0, 27,  0,  0, 11,  1],
       [ 7,  0, 29,  5,  0,  6],
       [ 1,  0,  5,  2,  3,  0],
       [ 0, 11,  0,  3, 14,  0],
       [ 3,  1,  6,  0,  0, 10]], dtype=int32)

In 1.10:

[10]: (adj**2).todense()

array([[ 0,  1,  0,  0,  1,  0],
       [ 1,  0, 25,  1,  0,  0],
       [ 0, 25,  0,  0,  4,  0],
       [ 0,  1,  0,  0,  0,  1],
       [ 1,  0,  4,  0,  0,  9],
       [ 0,  0,  0,  1,  9,  0]], dtype=int32)

from linkpred.

rafguns avatar rafguns commented on June 7, 2024

This is presumably related to this note from the scipy.sparse documentation:

x * y no longer performs matrix multiplication, but element-wise multiplication (just like with NumPy arrays). To make code work with both arrays and matrices, use x @ y for matrix multiplication.

from linkpred.

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.