Skip to content

Commit

Permalink
⬆️ RSC
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed May 13, 2024
1 parent d2c5341 commit 75a9d53
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cdlib/algorithms/internal/RSC.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __regularized_laplacian_matrix(adj_matrix, tau):
:param tau: the regularisation constant
:return: the first K eigenvector
"""
import scipy.sparse
import scipy.sparse as sp
import scipy

# Code inspired from nx.normalized_laplacian_matrix, with changes to allow regularisation
n, m = adj_matrix.shape
Expand All @@ -34,10 +35,10 @@ def __regularized_laplacian_matrix(adj_matrix, tau):

# diags will be zero at points where there is no edge and/or the node you are at
# ignore the error and make it zero later
#with scipy.errstate(divide="ignore"):
diags_sqrt = 1.0 / scipy.sqrt(diags)
with scipy.errstate(divide="ignore"):
diags_sqrt = 1.0 / scipy.sqrt(diags)
diags_sqrt[scipy.isinf(diags_sqrt)] = 0
D = scipy.sparse.spdiags(diags_sqrt, [0], m, n, format="csr")
D = sp.spdiags(diags_sqrt, [0], m, n, format="csr")

L = I - (D.dot(adj_matrix.dot(D)))
return L
Expand Down

0 comments on commit 75a9d53

Please sign in to comment.