NegativeSampling
¶
NegativeSampling(
mode: Literal["binary", "triplet"],
amount: Union[int, float] = 1,
src_weight: Optional[Union[array, ndarray]] = None,
dst_weight: Optional[Union[array, ndarray]] = None,
)
Configuration of the negative sampling done by LinkNeighborLoader.
Negative nodes are drawn uniformly at random (or proportionally to
src_weight / dst_weight), without checking that the resulting
pairs are absent from the graph: like in PyG, negatives are not
guaranteed to be true negatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Literal['binary', 'triplet']
|
|
required |
amount
|
Union[int, float]
|
Number of negatives per positive edge. Can be a float for
|
1
|
src_weight
|
Optional[Union[array, ndarray]]
|
Optional sampling weight of every source node. |
None
|
dst_weight
|
Optional[Union[array, ndarray]]
|
Optional sampling weight of every destination node. |
None
|
Example:
Methods:
| Name | Description |
|---|---|
sample_in_time |
|
Source code in mlx_graphs/loaders/link_neighbor_loader.py
sample_in_time
¶
sample_in_time(
endpoint: Literal["src", "dst"],
seed_time: ndarray,
num_nodes: int,
node_time: Optional[ndarray],
) -> ndarray
ceil(amount) negatives per seed (in blocks of one negative per
seed, as in PyG), drawn among the nodes whose time is not later than
the seed's when node_time is given: invalid draws are redrawn up
to 5 times, then replaced by the earliest node (as in PyG).
Source code in mlx_graphs/loaders/link_neighbor_loader.py
from mlx_graphs.loaders import NegativeSampling · mlx_graphs/loaders/link_neighbor_loader.py