gammagl.utils.negative_sampling

class negative_sampling(edge_index, num_nodes=None, num_neg_samples=None, method='sparse', force_undirected=False)[source]

Samples random negative edges of a graph given by edge_index.

Parameters:
  • edge_index (tensor) – The edge indices.

  • num_nodes (int, tuple[int, int], optional) – The number of nodes, i.e. max_val + 1 of edge_index. If given as a tuple, then edge_index is interpreted as a bipartite graph with shape (num_src_nodes, num_dst_nodes). (default: None)

  • num_neg_samples (int, optional) – The (approximate) number of negative samples to return. If set to None, will try to return a negative edge for every positive edge. (default: None)

  • method (str, optional) – The method to use for negative sampling, i.e., "sparse" or "dense". This is a memory/runtime trade-off. "sparse" will work on any graph of any size, while "dense" can perform faster true-negative checks. (default: "sparse")

  • force_undirected (bool, optional) – If set to True, sampled negative edges will be undirected. (default: False)