MCPcopy Create free account
hub / github.com/NineAbyss/ZeroG / normalize_adjacency_matrix

Method normalize_adjacency_matrix

code/st_model.py:297–319  ·  view source on GitHub ↗
(self, edge_index, num_nodes)

Source from the content-addressed store, hash-verified

295 return [test_acc,test_f1]
296
297 def normalize_adjacency_matrix(self, edge_index, num_nodes):
298 # edge_index = data.edge_index
299 # num_nodes = data.y.shape[0]
300
301 edge_index_self_loops = torch.stack(
302 [torch.arange(num_nodes), torch.arange(num_nodes)], dim=0).to(self.args.device)
303 edge_index = torch.cat([edge_index, edge_index_self_loops], dim=1)
304
305 adj = torch.sparse_coo_tensor(edge_index, torch.ones(
306 edge_index.shape[1]).to(self.args.device), (num_nodes, num_nodes))
307
308 deg = torch.sparse.sum(adj, dim=1).to_dense()
309 deg_inv_sqrt = deg.pow(-0.5)
310 deg_inv_sqrt[deg_inv_sqrt == float('inf')] = 0
311
312 adj_normalized = adj
313 # adj_normalized = adj.coalesce()
314 deg_inv_sqrt_mat = torch.sparse_coo_tensor(torch.arange(num_nodes).unsqueeze(
315 0).repeat(2, 1).to(self.args.device), deg_inv_sqrt, (num_nodes, num_nodes))
316 adj_normalized = torch.sparse.mm(
317 deg_inv_sqrt_mat, torch.sparse.mm(adj_normalized, deg_inv_sqrt_mat))
318
319 return adj_normalized

Callers 2

forwardMethod · 0.95
zero_shot_evalMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected