data¶
-
class
cogdl.data.
Data
(x=None, edge_index=None, edge_attr=None, y=None, pos=None, **kwargs)[source]¶ Bases:
object
A plain old python object modeling a single graph with various (optional) attributes:
- Args:
- x (Tensor, optional): Node feature matrix with shape :obj:`[num_nodes,
- num_node_features]`. (default:
None
) - edge_index (LongTensor, optional): Graph connectivity in COO format
- with shape
[2, num_edges]
. (default:None
) - edge_attr (Tensor, optional): Edge feature matrix with shape
[num_edges, num_edge_features]
. (default:None
)- y (Tensor, optional): Graph or node targets with arbitrary shape.
- (default:
None
) - pos (Tensor, optional): Node position matrix with shape
[num_nodes, num_dimensions]
. (default:None
)
The data object is not restricted to these attributes and can be extented by any other additional data.
-
apply
(func, *keys)[source]¶ Applies the function
func
to all attributes*keys
. If*keys
is not given,func
is applied to all present attributes.
-
cat_dim
(key, value)[source]¶ Returns the dimension in which the attribute
key
with contentvalue
gets concatenated when creating batches.Note
This method is for internal use only, and should only be overridden if the batch concatenation process is corrupted for a specific data attribute.
-
contiguous
(*keys)[source]¶ Ensures a contiguous memory layout for all attributes
*keys
. If*keys
is not given, all present attributes are ensured to have a contiguous memory layout.
-
is_coalesced
()[source]¶ Returns
True
, if edge indices are ordered and do not contain duplicate entries.
-
keys
¶ Returns all names of graph attributes.
-
num_classes
¶
-
num_edges
¶ Returns the number of edges in the graph.
-
num_features
¶ Returns the number of features per node in the graph.
-
num_nodes
¶
-
class
cogdl.data.
Batch
(batch=None, **kwargs)[source]¶ Bases:
cogdl.data.data.Data
A plain old python object modeling a batch of graphs as one big (dicconnected) graph. With
cogdl.data.Data
being the base class, all its methods can also be used here. In addition, single graphs can be reconstructed via the assignment vectorbatch
, which maps each node to its respective graph identifier.-
cumsum
(key, item)[source]¶ If
True
, the attributekey
with contentitem
should be added up cumulatively before concatenated together.Note
This method is for internal use only, and should only be overridden if the batch concatenation process is corrupted for a specific data attribute.
-
static
from_data_list
(data_list, follow_batch=[])[source]¶ Constructs a batch object from a python list holding
torch_geometric.data.Data
objects. The assignment vectorbatch
is created on the fly. Additionally, creates assignment batch vectors for each key infollow_batch
.
-
num_graphs
¶ Returns the number of graphs in the batch.
-
-
class
cogdl.data.
Dataset
(root, transform=None, pre_transform=None, pre_filter=None)[source]¶ Bases:
torch.utils.data.dataset.Dataset
Dataset base class for creating graph datasets. See here for the accompanying tutorial.
- Args:
root (string): Root directory where the dataset should be saved. transform (callable, optional): A function/transform that takes in an
cogdl.data.Data
object and returns a transformed version. The data object will be transformed before every access. (default:None
)- pre_transform (callable, optional): A function/transform that takes in
- an
cogdl.data.Data
object and returns a transformed version. The data object will be transformed before being saved to disk. (default:None
) - pre_filter (callable, optional): A function that takes in an
cogdl.data.Data
object and returns a boolean value, indicating whether the data object should be included in the final dataset. (default:None
)
-
num_classes
¶ The number of classes in the dataset.
-
num_features
¶ Returns the number of features per node in the graph.
-
processed_file_names
¶ The name of the files to find in the
self.processed_dir
folder in order to skip the processing.
-
processed_paths
¶ The filepaths to find in the
self.processed_dir
folder in order to skip the processing.
-
raw_file_names
¶ The name of the files to find in the
self.raw_dir
folder in order to skip the download.
-
raw_paths
¶ The filepaths to find in order to skip the download.
-
class
cogdl.data.
DataLoader
(dataset, batch_size=1, shuffle=True, **kwargs)[source]¶ Bases:
torch.utils.data.dataloader.DataLoader
Data loader which merges data objects from a
cogdl.data.dataset
to a mini-batch.- Args:
dataset (Dataset): The dataset from which to load the data. batch_size (int, optional): How may samples per batch to load.
(default:1
)