torch_geometric_signed_directed.data.directed.DirectedData ========================================================== .. py:module:: torch_geometric_signed_directed.data.directed.DirectedData Classes ------- .. autoapisummary:: torch_geometric_signed_directed.data.directed.DirectedData.DirectedData Module Contents --------------- .. py:class:: DirectedData(x: torch_geometric.typing.OptTensor = None, edge_index: torch_geometric.typing.OptTensor = None, edge_attr: torch_geometric.typing.OptTensor = None, edge_weight: torch_geometric.typing.OptTensor = None, y: torch_geometric.typing.OptTensor = None, pos: torch_geometric.typing.OptTensor = None, A: scipy.sparse.spmatrix = None, init_data: Optional[torch_geometric.data.Data] = None, **kwargs) Bases: :py:obj:`torch_geometric.data.Data` A data object describing a homogeneous directed graph. :Parameters: * **x** (*Tensor, optional*) -- Node feature matrix with shape :obj:`[num_nodes, num_node_features]`. (default: :obj:`None`) * **edge_index** (*LongTensor, optional*) -- Graph connectivity in COO format with shape :obj:`[2, num_edges]`. (default: :obj:`None`) * **edge_attr** (*Tensor, optional*) -- Edge feature matrix with shape :obj:`[num_edges, num_edge_features]`. (default: :obj:`None`) * **edge_weight** (*Tensor, optional*) -- Edge weights with shape :obj:`[num_edges,]`. (default: :obj:`None`) * **y** (*Tensor, optional*) -- Graph-level or node-level ground-truth labels with arbitrary shape. (default: :obj:`None`) * **pos** (*Tensor, optional*) -- Node position matrix with shape :obj:`[num_nodes, num_dimensions]`. (default: :obj:`None`) * **A** (*sp.spmatrix, optional*) -- SciPy sparse adjacency matrix. (default: :obj:`None`) * **init_data** (*Data, optional*) -- Initial data object, whose attributes will be inherited. (default: :obj:`None`) * **\*\*kwargs** (*optional*) -- Additional attributes. .. py:attribute:: A .. py:attribute:: edge_weight .. py:attribute:: edge_index .. py:property:: is_directed :type: bool .. py:property:: is_weighted :type: bool .. py:method:: to_unweighted() .. py:method:: set_hermitian_features(k: int = 2) create Hermitian feature (rw normalized) :Parameters: **k** (*int*) -- Half of the dimension of features. Default is 2. .. py:method:: inherit_attributes(data: torch_geometric.data.Data) .. py:method:: node_split(train_size: Union[int, float] = None, val_size: Union[int, float] = None, test_size: Union[int, float] = None, seed_size: Union[int, float] = None, train_size_per_class: Union[int, float] = None, val_size_per_class: Union[int, float] = None, test_size_per_class: Union[int, float] = None, seed_size_per_class: Union[int, float] = None, seed: List[int] = [], data_split: int = 2) Train/Val/Test/Seed split for node classification tasks. The size parameters can either be int or float. If a size parameter is int, then this means the actual number, if it is float, then this means a ratio. ``train_size`` or ``train_size_per_class`` is mandatory, with the former regardless of class labels. Validation and seed masks are optional. Seed masks here masks nodes within the training set, e.g., in a semi-supervised setting as described in the `SSSNET: Semi-Supervised Signed Network Clustering `_ paper. If test_size and test_size_per_class are both None, all the remaining nodes after selecting training (and validation) nodes will be included. :Parameters: * **data** (*torch_geometric.data.Data or DirectedData, required*) -- The data object for data split. * **train_size** (*int or float, optional*) -- The size of random splits for the training dataset. If the input is a float number, the ratio of nodes in each class will be sampled. * **val_size** (*int or float, optional*) -- The size of random splits for the validation dataset. If the input is a float number, the ratio of nodes in each class will be sampled. * **test_size** (*int or float, optional*) -- The size of random splits for the validation dataset. If the input is a float number, the ratio of nodes in each class will be sampled. (Default: None. All nodes not selected for training/validation are used for testing) * **seed_size** (*int or float, optional*) -- The size of random splits for the seed nodes within the training set. If the input is a float number, the ratio of nodes in each class will be sampled. * **train_size_per_class** (*int or float, optional*) -- The size per class of random splits for the training dataset. If the input is a float number, the ratio of nodes in each class will be sampled. * **val_size_per_class** (*int or float, optional*) -- The size per class of random splits for the validation dataset. If the input is a float number, the ratio of nodes in each class will be sampled. * **test_size_per_class** (*int or float, optional*) -- The size per class of random splits for the testing dataset. If the input is a float number, the ratio of nodes in each class will be sampled. (Default: None. All nodes not selected for training/validation are used for testing) * **seed_size_per_class** (*int or float, optional*) -- The size per class of random splits for seed nodes within the training set. If the input is a float number, the ratio of nodes in each class will be sampled. * **seed** (*An empty list or a list with the length of data_split, optional*) -- The random seed list for each data split. * **data_split** (*int, optional*) -- number of splits (Default : 2) .. py:method:: link_split(size: int = None, splits: int = 2, prob_test: float = 0.15, prob_val: float = 0.05, task: str = 'direction', seed: int = 0, ratio: float = 1.0, maintain_connect: bool = True, device: str = 'cpu') -> dict Get train/val/test dataset for the link prediction task. Arg types: * **prob_val** (float, optional) - The proportion of edges selected for validation (Default: 0.05). * **prob_test** (float, optional) - The proportion of edges selected for testing (Default: 0.15). * **splits** (int, optional) - The split size (Default: 2). * **size** (int, optional) - The size of the input graph. If none, the graph size is the maximum index of nodes plus 1 (Default: None). * **task** (str, optional) - The evaluation task: three_class_digraph (three-class link prediction); direction (direction prediction); existence (existence prediction). (Default: 'direction') * **seed** (int, optional) - The random seed for dataset generation (Default: 0). * **ratio** (float, optional) - The maximum ratio of edges used for dataset generation. (Default: 1.0) * **maintain_connect** (bool, optional) - If maintaining connectivity when removing edges for validation and testing. The connectivity is maintained by obtaining edges in the minimum spanning tree/forest first. These edges will not be removed for validation and testing (Default: True). * **device** (int, optional) - The device to hold the return value (Default: 'cpu'). Return types: * **datasets** - A dict include training/validation/testing splits of edges and labels. For split index i: * datasets[i]['graph'] (torch.LongTensor): the observed edge list after removing edges for validation and testing. * datasets[i]['train'/'val'/'testing']['edges'] (List): the edge list for training/validation/testing. * datasets[i]['train'/'val'/'testing']['label'] (List): the labels of edges: * If task == "existence": 0 (the directed edge exists in the graph), 1 (the edge doesn't exist).The undirected edges in the directed input graph are removed to avoid ambiguity. * If task == "direction": 0 (the directed edge exists in the graph), 1 (the edge of the reversed direction exists). The undirected edges in the directed input graph are removed to avoid ambiguity. * If task == "three_class_digraph": 0 (the directed edge exists in the graph), 1 (the edge of the reversed direction exists), 2 (the edge doesn't exist in both directions). The undirected edges in the directed input graph are removed to avoid ambiguity.