-
I wanted to add random nodes to the For example, the given batch has 5 graphs with the following
These five graphs contain I was planning to connect random nodes in a graph, using something like this: num_nodes = [g.number_of_nodes() for g in graphList] #[35, 19, 24, 24, 24]
nodes_cumsum = np.cumsum(num_nodes) # [ 35, 54, 78, 102, 126]
min_idx = 0
for i in range(len(nodes_cumsum)):
max_idx = nodes_cumsum[i]
rand_edge_idx = torch.randint(min_idx, max_idx, (2, num_connect))
batch.edge_index = torch.cat([batch.edge_index, rand_edge_index], dim=1)
min_idx = nodes_cumsum[i] With this method it might be possible that Also, is there a better(efficient) way of connecting random nodes in the graph? The psueodcode I have given above is a more generalised version of what I want to do. In particular, I would like to do something like:
I did take a look at #2302 and #754 but wasn't sure if the psueodcode given over there by @rusty1s matches with my requirements. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
You could use |
Beta Was this translation helpful? Give feedback.
You could use
torch_geometric.utils.batched_negative_sampling
for this and concatenate the resulting negative edges to youredge_index
. As an alternative, you can also apply such modifications via the usage oftransforms
, which has the advantage that you do not need to care about correct mini-batch treatment.