pylibcugraph.negative_sampling#

pylibcugraph.negative_sampling(
ResourceHandle resource_handle,
_GPUGraph graph,
size_t num_samples,
random_state=None,
vertices=None,
src_bias=None,
dst_bias=None,
remove_duplicates=False,
remove_false_negatives=False,
exact_number_of_samples=False,
do_expensive_check=False,
)[source]#

Performs negative sampling, which is essentially a form of graph generation.

By setting vertices, src_bias, and dst_bias, this function can perform biased negative sampling.

Parameters:
resource_handle: ResourceHandle

Handle to the underlying device and host resources needed for referencing data and running algorithms.

input_graph: SGGraph or MGGraph

The stored cuGraph graph to create negative samples for.

num_samples: int

The number of negative edges to generate for each positive edge.

random_state: int (Optional)

Random state to use when generating samples. Optional argument, defaults to a hash of process id, time, and hostname. (See pylibcugraph.random.CuGraphRandomState)

vertices: device array type (Optional)

Vertex ids corresponding to the src/dst biases, if provided. Ignored if src/dst biases are not provided.

src_bias: device array type (Optional)

Probability per edge that a vertex is selected as a source vertex. Does not have to be normalized. Uses a uniform distribution if not provided.

dst_bias: device array type (Optional)

Probability per edge that a vertex is selected as a destination vertex. Does not have to be normalized. Uses a uniform distribution if not provided.

remove_duplicates: bool (Optional)

Whether to remove duplicate edges from the generated edgelist. Defaults to False (does not remove duplicates).

remove_false_negatives: bool (Optional)

Whether to remove false negatives from the generated edgelist. Defaults to False (does not check for and remove false negatives).

exact_number_of_samples: bool (Optional)

Whether to manually regenerate samples until the desired number as specified by num_samples has been generated. Defaults to False (does not regenerate if enough samples are not produced in the initial round).

do_expensive_check: bool (Optional)

Whether to perform an expensive error check at the C++ level. Defaults to False (no error check).

Returns:
dict[str, cupy.ndarray]

Generated edges in COO format.