(edge_index, damp: float = 0.85, k: int = 10)
| 160 | |
| 161 | def get_pagerank_weights(data, aggr: str = 'sink', k: int = 10): |
| 162 | def _compute_pagerank(edge_index, damp: float = 0.85, k: int = 10): |
| 163 | num_nodes = edge_index.max().item() + 1 |
| 164 | deg_out = degree(edge_index[0]) |
| 165 | x = torch.ones((num_nodes,)).to(edge_index.device).to(torch.float32) |
| 166 | |
| 167 | for i in range(k): |
| 168 | edge_msg = x[edge_index[0]] / deg_out[edge_index[0]] |
| 169 | agg_msg = scatter(edge_msg, edge_index[1], reduce='sum') |
| 170 | |
| 171 | x = (1 - damp) * x + damp * agg_msg |
| 172 | |
| 173 | return x |
| 174 | |
| 175 | pv = _compute_pagerank(data.edge_index, k=k) |
| 176 | pv_row = pv[data.edge_index[0]].to(torch.float32) |
no outgoing calls
no test coverage detected