batched_negative_sampling
¶
batched_negative_sampling(
edge_index: array,
batch_indices: Union[array, tuple[array, array]],
num_neg_samples: Optional[Union[int, float]] = None,
force_undirected: bool = False,
) -> array
Samples random negative edges within each graph of a batch of graphs (see
negative_sampling()): no negative edge connects two different
graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge of the batch |
required |
batch_indices
|
Union[array, tuple[array, array]]
|
The graph of each node, of shape |
required |
num_neg_samples
|
Optional[Union[int, float]]
|
Number of negative edges to sample per graph. A float
is interpreted as a ratio of the number of edges of each graph.
Default: |
None
|
force_undirected
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
array
|
A |
array
|
dtype of |
Example:
edge_index = mx.array([[0, 1, 2, 3, 4, 5], [1, 2, 0, 4, 5, 3]])
batch_indices = mx.array([0, 0, 0, 1, 1, 1])
batched_negative_sampling(edge_index, batch_indices)
# e.g. mx.array([[1, 2, 0, 5, 3, 4], [0, 1, 2, 4, 5, 3]])
Source code in mlx_graphs/utils/negative_sampling.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
from mlx_graphs.utils import batched_negative_sampling · mlx_graphs/utils/negative_sampling.py