torch_geometric.data.TemporalData
- class TemporalData(src: Optional[Tensor] = None, dst: Optional[Tensor] = None, t: Optional[Tensor] = None, msg: Optional[Tensor] = None, **kwargs)[source]
Bases:
BaseDataA data object composed by a stream of events describing a temporal graph. The
TemporalDataobject can hold a list of events (that can be understood as temporal edges in a graph) with structured messages. An event is composed by a source node, a destination node, a timestamp and a message. Any Continuous-Time Dynamic Graph (CTDG) can be represented with these four values.In general,
TemporalDatatries to mimic the behavior of a regular Python dictionary. In addition, it provides useful functionality for analyzing graph structures, and provides basic PyTorch tensor functionalities.from torch import Tensor from torch_geometric.data import TemporalData events = TemporalData( src=Tensor([1,2,3,4]), dst=Tensor([2,3,4,5]), t=Tensor([1000,1010,1100,2000]), msg=Tensor([1,1,0,0]) ) # Add additional arguments to `events`: events.y = Tensor([1,1,0,0]) # It is also possible to set additional arguments in the constructor events = TemporalData( ..., y=Tensor([1,1,0,0]) ) # Get the number of events: events.num_events >>> 4 # Analyzing the graph structure: events.num_nodes >>> 5 # PyTorch tensor functionality: events = events.pin_memory() events = events.to('cuda:0', non_blocking=True)
- Parameters
src (torch.Tensor, optional) – A list of source nodes for the events with shape
[num_events]. (default:None)dst (torch.Tensor, optional) – A list of destination nodes for the events with shape
[num_events]. (default:None)t (torch.Tensor, optional) – The timestamps for each event with shape
[num_events]. (default:None)msg (torch.Tensor, optional) – Messages feature matrix with shape
[num_events, num_msg_features]. (default:None)**kwargs (optional) – Additional attributes.
Note
The shape of
src,dst,tand the first dimension of :obj`msg` should be the same (num_events).- to_namedtuple() NamedTuple[source]
Returns a
NamedTupleof stored key/value pairs.
- property num_events: int
Returns the number of events loaded.
Note
In a
TemporalData, each row denotes an event. Thus, they can be also understood as edges.
- property num_edges: int
Alias for
num_events().
- size(dim: Optional[int] = None) Optional[Union[Tuple[Optional[int], Optional[int]], int]][source]
Returns the size of the adjacency matrix induced by the graph.
- __cat_dim__(key: str, value: Any, *args, **kwargs) Any[source]
Returns the dimension for which the value
valueof the attributekeywill get concatenated when creating mini-batches usingtorch_geometric.loader.DataLoader.Note
This method is for internal use only, and should only be overridden in case the mini-batch creation process is corrupted for a specific attribute.
- __inc__(key: str, value: Any, *args, **kwargs) Any[source]
Returns the incremental count to cumulatively increase the value
valueof the attributekeywhen creating mini-batches usingtorch_geometric.loader.DataLoader.Note
This method is for internal use only, and should only be overridden in case the mini-batch creation process is corrupted for a specific attribute.
- train_val_test_split(val_ratio: float = 0.15, test_ratio: float = 0.15)[source]
Splits the data in training, validation and test sets according to time.
- apply(func: Callable, *args: List[str])
Applies the function
func, either to all attributes or only the ones given in*args.
- apply_(func: Callable, *args: List[str])
Applies the in-place function
func, either to all attributes or only the ones given in*args.
- clone(*args: List[str])
Performs cloning of tensors, either for all attributes or only the ones given in
*args.
- contiguous(*args: List[str])
Ensures a contiguous memory layout, either for all attributes or only the ones given in
*args.
- cpu(*args: List[str])
Copies attributes to CPU memory, either for all attributes or only the ones given in
*args.
- cuda(device: Optional[Union[int, str]] = None, *args: List[str], non_blocking: bool = False)
Copies attributes to CUDA memory, either for all attributes or only the ones given in
*args.
- detach(*args: List[str])
Detaches attributes from the computation graph by creating a new tensor, either for all attributes or only the ones given in
*args.
- detach_(*args: List[str])
Detaches attributes from the computation graph, either for all attributes or only the ones given in
*args.
- generate_ids()
Generates and sets
n_idande_idattributes to assign each node and edge to a continuously ascending and unique ID.
- is_coalesced() bool
Returns
Trueif edge indicesedge_indexare sorted and do not contain duplicate entries.
- property is_cuda: bool
Returns
Trueif anytorch.Tensorattribute is stored on the GPU,Falseotherwise.
- pin_memory(*args: List[str])
Copies attributes to pinned memory, either for all attributes or only the ones given in
*args.
- record_stream(stream: Stream, *args: List[str])
Ensures that the tensor memory is not reused for another tensor until all current work queued on
streamhas been completed, either for all attributes or only the ones given in*args.
- requires_grad_(*args: List[str], requires_grad: bool = True)
Tracks gradient computation, either for all attributes or only the ones given in
*args.
Moves attributes to shared memory, either for all attributes or only the ones given in
*args.
- to(device: Union[int, str], *args: List[str], non_blocking: bool = False)
Performs tensor device conversion, either for all attributes or only the ones given in
*args.
- update(data: BaseData) BaseData
Updates the data object with the elements from another data object.