IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Ver código fonte

test_normalize

master
Stanislaw Adaszewski 4 anos atrás
pai
commit
6b353878e1
1 arquivos alterados com 15 adições e 4 exclusões
  1. +15
    -4
      src/decagon_pytorch/normalize.py

+ 15
- 4
src/decagon_pytorch/normalize.py Ver arquivo

@@ -2,17 +2,28 @@ import numpy as np
import scipy.sparse as sp
def normalize_adjacency_matrix(self, adj):
def sparse_to_tuple(sparse_mx):
if not sp.isspmatrix_coo(sparse_mx):
sparse_mx = sparse_mx.tocoo()
coords = np.vstack((sparse_mx.row, sparse_mx.col)).transpose()
values = sparse_mx.data
shape = sparse_mx.shape
return coords, values, shape
def normalize_adjacency_matrix(adj):
adj = sp.coo_matrix(adj)
if adj.shape[0] == adj.shape[1]:
adj_ = adj + sp.eye(adj.shape[0])
rowsum = np.array(adj_.sum(1))
degree_mat_inv_sqrt = sp.diags(np.power(rowsum, -0.5).flatten())
adj_normalized = adj_.dot(degree_mat_inv_sqrt).transpose().dot(degree_mat_inv_sqrt).tocoo()
degree_mat_inv_sqrt = np.power(rowsum, -0.5).flatten()
degree_mat_inv_sqrt = sp.diags(degree_mat_inv_sqrt)
adj_normalized = adj_.dot(degree_mat_inv_sqrt).transpose().dot(degree_mat_inv_sqrt)
else:
rowsum = np.array(adj.sum(1))
colsum = np.array(adj.sum(0))
rowdegree_mat_inv = sp.diags(np.nan_to_num(np.power(rowsum, -0.5)).flatten())
coldegree_mat_inv = sp.diags(np.nan_to_num(np.power(colsum, -0.5)).flatten())
adj_normalized = rowdegree_mat_inv.dot(adj).dot(coldegree_mat_inv).tocoo()
return preprocessing.sparse_to_tuple(adj_normalized)
return sparse_to_tuple(adj_normalized)

Carregando…
Cancelar
Salvar