TemporalData
¶
TemporalData(
src: Optional[array] = None,
dst: Optional[array] = None,
t: Optional[array] = None,
msg: Optional[array] = None,
**kwargs,
)
A stream of events describing a temporal graph (a Continuous-Time
Dynamic Graph), as PyG's torch_geometric.data.TemporalData.
Each event i is a (temporal) edge from the source node src[i] to the
destination node dst[i] at time t[i], with a message (event
features) msg[i]. Any other per-event attribute (e.g. labels y) can
be passed to the constructor or set afterwards.
Indexing with a string returns an attribute (events["src"]); any other
index (an integer, a slice, a list, an integer array or a boolean mask)
selects events and returns a new TemporalData in which every
array whose first dimension is num_events is indexed, as in PyG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Optional[array]
|
Source node of each event, shape |
None
|
dst
|
Optional[array]
|
Destination node of each event, shape |
None
|
t
|
Optional[array]
|
Timestamp of each event, shape |
None
|
msg
|
Optional[array]
|
Message (features) of each event, shape
|
None
|
**kwargs
|
Additional attributes, e.g. event labels |
{}
|
Example:
import mlx.core as mx
from mlx_graphs.data import TemporalData
events = TemporalData(
src=mx.array([1, 2, 3, 4]),
dst=mx.array([2, 3, 4, 5]),
t=mx.array([1000, 1010, 1100, 2000]),
msg=mx.array([[1.0], [1.0], [0.0], [0.0]]),
y=mx.array([1, 1, 0, 0]),
)
events.num_events
>>> 4
events.num_nodes
>>> 6
train, val, test = events.train_val_test_split(0.25, 0.25)
References
Methods:
| Name | Description |
|---|---|
from_dict |
Creates a |
keys |
Names of the attributes that are set. |
items |
|
__call__ |
Iterates over |
to_dict |
Returns the attributes as a dictionary. |
clone |
Returns a deep copy, with copies of all the arrays. |
size |
|
index_select |
Selects events. |
train_val_test_split |
Splits the events into training, validation and test sets according to |
__cat_dim__ |
All attributes are concatenated along the first (event) axis. |
__inc__ |
Increment applied to |
from_data_list |
Concatenates several event streams into one, as PyG's |
Attributes:
| Name | Type | Description |
|---|---|---|
num_nodes |
int
|
The number of nodes, |
num_events |
int
|
The number of events (temporal edges). |
num_edges |
int
|
Alias of |
edge_index |
array
|
The |
Source code in mlx_graphs/data/temporal.py
edge_index
property
¶
The [2, num_events] stack of src and dst (or the
edge_index attribute if one was set).
from_dict
classmethod
¶
from_dict(mapping: dict) -> TemporalData
Creates a TemporalData from a dictionary of attributes.
keys
¶
items
¶
__call__
¶
Iterates over (name, value) pairs, restricted to keys if
given.
clone
¶
clone() -> TemporalData
size
¶
(src.max(), dst.max()) as in PyG, or one of the two.
index_select
¶
Selects events.
Every array attribute whose first dimension is num_events is
indexed; the others are kept as they are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
Union[int, slice, Sequence[int], ndarray, array]
|
An integer (kept as a one-event selection), a slice, a list or array of event positions, or a boolean mask over the events |
required |
Returns:
| Type | Description |
|---|---|
TemporalData
|
A new |
Source code in mlx_graphs/data/temporal.py
train_val_test_split
¶
train_val_test_split(
val_ratio: float = 0.15, test_ratio: float = 0.15
) -> tuple[TemporalData, TemporalData, TemporalData]
Splits the events into training, validation and test sets according to time, as in PyG.
The split times are the 1 - val_ratio - test_ratio and
1 - test_ratio quantiles of t, and events are assumed to be
sorted by time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val_ratio
|
float
|
Proportion of events in the validation set. Default:
|
0.15
|
test_ratio
|
float
|
Proportion of events in the test set. Default: |
0.15
|
Returns:
| Type | Description |
|---|---|
tuple[TemporalData, TemporalData, TemporalData]
|
The training, validation and test events. |
Source code in mlx_graphs/data/temporal.py
__cat_dim__
¶
__inc__
¶
Increment applied to key when batching: num_nodes for
src and dst, max + 1 for attributes containing "batch",
and no increment otherwise (as PyG).
Source code in mlx_graphs/data/temporal.py
from_data_list
classmethod
¶
from_data_list(data_list: Sequence[TemporalData]) -> TemporalData
Concatenates several event streams into one, as PyG's
Batch.from_data_list does for TemporalData.
src and dst of each stream are offset by the number of nodes of
the previous streams (see __inc__()), attributes containing
"batch" by their number of groups, and all the other array
attributes are concatenated as they are. Non-array attributes become
lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_list
|
Sequence[TemporalData]
|
The event streams, with the same attributes |
required |
Returns:
| Type | Description |
|---|---|
TemporalData
|
The concatenated events. |
Source code in mlx_graphs/data/temporal.py
from mlx_graphs.data.temporal import TemporalData · mlx_graphs/data/temporal.py