LastNeighborLoader
¶
Keeps, for every node, its size most recent neighbors in an
ever-growing (undirected) temporal graph, as PyG's
torch_geometric.nn.models.tgn.LastNeighborLoader.
The state is kept on the host (NumPy); the returned arrays are MLX arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int
|
Number of nodes |
required |
size
|
int
|
Number of most recent neighbors to keep per node |
required |
Example:
from mlx_graphs.nn.models.tgn import LastNeighborLoader
loader = LastNeighborLoader(num_nodes=10, size=5)
loader.insert(mx.array([0, 1]), mx.array([2, 3]))
n_id, edge_index, e_id = loader(mx.array([0, 3]))
# edge_index (in the local indexing of `n_id`) points from the
# neighbors to the nodes, e_id are the events of the edges
Methods:
| Name | Description |
|---|---|
__call__ |
Returns the most recent neighborhood of the nodes |
insert |
Inserts new events (in time order) into the temporal graph. |
reset_state |
Removes all the inserted events. |
Source code in mlx_graphs/nn/models/tgn.py
__call__
¶
__call__(n_id: IndexLike) -> Tuple[array, array, array]
Returns the most recent neighborhood of the nodes n_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_id
|
IndexLike
|
Node indices |
required |
Returns:
| Type | Description |
|---|---|
array
|
The sorted unique nodes of the neighborhood ( |
array
|
neighbors), the |
array
|
in the local indexing of these nodes, and the event index of every |
Tuple[array, array, array]
|
edge. |
Source code in mlx_graphs/nn/models/tgn.py
insert
¶
Inserts new events (in time order) into the temporal graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
IndexLike
|
Source nodes, shape |
required |
dst
|
IndexLike
|
Destination nodes, shape |
required |
Source code in mlx_graphs/nn/models/tgn.py
from mlx_graphs.nn.models.tgn import LastNeighborLoader · mlx_graphs/nn/models/tgn.py