Skip to content
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

building symmetric adjacency matrix in utils #84

Open
marigoold opened this issue Apr 8, 2021 · 1 comment
Open

building symmetric adjacency matrix in utils #84

marigoold opened this issue Apr 8, 2021 · 1 comment

Comments

@marigoold
Copy link

marigoold commented Apr 8, 2021

def build_symmetric_adj(adj, self_loop=True):
adj = adj + adj.T.multiply(adj.T > adj) - adj.multiply(adj.T > adj)
if self_loop:
adj = adj + sp.eye(adj.shape[0])
return adj

The original adjacency matrix built from faiss is not symmetric, so what is the purpose to convert it to symmetric matrix? And why do you implement it in this way?

@marigoold
Copy link
Author

def row_normalize(mx):
"""Row-normalize sparse matrix"""
rowsum = np.array(mx.sum(1))
# if rowsum <= 0, keep its previous value
rowsum[rowsum <= 0] = 1
r_inv = np.power(rowsum, -1).flatten()
r_inv[np.isinf(r_inv)] = 0.
r_mat_inv = sp.diags(r_inv)
mx = r_mat_inv.dot(mx)
return mx

By the way, what is the purpose of row_normalize, and # if rowsum <= 0, keep its previous value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant