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

Method normalize_adjacency_matrix

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

Source from the content-addressed store, hash-verified

115 return test_acc
116
117 def normalize_adjacency_matrix(self, edge_index, num_nodes):
118 # edge_index = data.edge_index
119 # num_nodes = data.y.shape[0]
120
121 edge_index_self_loops = torch.stack(
122 [torch.arange(num_nodes), torch.arange(num_nodes)], dim=0).to(self.args.device)
123 edge_index = torch.cat([edge_index, edge_index_self_loops], dim=1)
124
125 adj = torch.sparse_coo_tensor(edge_index, torch.ones(
126 edge_index.shape[1]).to(self.args.device), (num_nodes, num_nodes))
127
128 deg = torch.sparse.sum(adj, dim=1).to_dense()
129 deg_inv_sqrt = deg.pow(-0.5)
130 deg_inv_sqrt[deg_inv_sqrt == float('inf')] = 0
131
132 adj_normalized = adj
133 # adj_normalized = adj.coalesce()
134 deg_inv_sqrt_mat = torch.sparse_coo_tensor(torch.arange(num_nodes).unsqueeze(
135 0).repeat(2, 1).to(self.args.device), deg_inv_sqrt, (num_nodes, num_nodes))
136 adj_normalized = torch.sparse.mm(
137 deg_inv_sqrt_mat, torch.sparse.mm(adj_normalized, deg_inv_sqrt_mat))
138
139 return adj_normalized
140
141
142class Text_Lora(nn.Module):

Callers 2

forwardMethod · 0.95
zero_shot_evalMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected