MCPcopy Create free account
hub / github.com/PyGCL/PyGCL / random_walk_subgraph

Function random_walk_subgraph

GCL/augmentors/functional.py:321–332  ·  view source on GitHub ↗
(edge_index: torch.LongTensor, edge_weight: Optional[torch.FloatTensor] = None, batch_size: int = 1000, length: int = 10)

Source from the content-addressed store, hash-verified

319
320
321def random_walk_subgraph(edge_index: torch.LongTensor, edge_weight: Optional[torch.FloatTensor] = None, batch_size: int = 1000, length: int = 10):
322 num_nodes = edge_index.max().item() + 1
323
324 row, col = edge_index
325 adj = SparseTensor(row=row, col=col, sparse_sizes=(num_nodes, num_nodes))
326
327 start = torch.randint(0, num_nodes, size=(batch_size, ), dtype=torch.long).to(edge_index.device)
328 node_idx = adj.random_walk(start.flatten(), length).view(-1)
329
330 edge_index, edge_weight = subgraph(node_idx, edge_index, edge_weight)
331
332 return edge_index, edge_weight

Callers 1

augmentMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected