Dataset
¶
Dataset(
name: str,
base_dir: Optional[str] = None,
pre_transform: Optional[Callable] = None,
transform: Optional[Callable] = None,
)
Bases: BaseDataset
A dataset class for graph data. download and process methods must be
implemented by children classes. The save and load methods save and load
only the processed self.graphs attribute by default. You may want to
override them to store/load additional processed attributes.
Graph data within the dataset should be stored in self.graphs as
a list[GraphData]. The creation and preprocessing of this list of graphs
is typically done within the overridden process method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
name of the dataset |
required |
base_dir
|
Optional[str]
|
Directory where to store dataset files. Default is
in the local directory |
None
|
pre_transform
|
Optional[Callable]
|
A function/transform that takes in a |
None
|
transform
|
Optional[Callable]
|
A function/transform that takes in a |
None
|
Methods:
| Name | Description |
|---|---|
index_select |
Returns a new dataset with the graphs at the indices |
shuffle |
Returns a copy of the dataset with the graphs in random order. |
Attributes:
| Name | Type | Description |
|---|---|---|
processed_path |
str
|
The path where raw files are stored. Defaults at |
num_graphs |
int
|
Returns the number of graphs in the dataset. |
num_node_classes |
Union[int, dict[str, int]]
|
Returns the number of node classes to predict. |
num_edge_classes |
Union[int, dict[str, int]]
|
Returns the number of edge classes to predict. |
num_graph_classes |
Union[int, dict[str, int]]
|
Returns the number of graph classes to predict. |
num_node_features |
int
|
Returns the number of node features, after |
num_edge_features |
int
|
Returns the number of edge features, after |
num_graph_features |
int
|
Returns the number of graph features, after |
num_classes |
int
|
PyG-style number of classes of the labels |
num_features |
int
|
PyG-style alias of |
Source code in mlx_graphs/datasets/dataset.py
processed_path
property
¶
processed_path: str
The path where raw files are stored. Defaults at <base_dir>/<name>/processed
num_node_classes
property
¶
Returns the number of node classes to predict.
num_edge_classes
property
¶
Returns the number of edge classes to predict.
num_graph_classes
property
¶
Returns the number of graph classes to predict.
num_node_features
property
¶
num_node_features: int
Returns the number of node features, after transform (as in PyG).
num_edge_features
property
¶
num_edge_features: int
Returns the number of edge features, after transform (as in PyG).
num_graph_features
property
¶
num_graph_features: int
Returns the number of graph features, after transform (as in PyG).
num_classes
property
¶
num_classes: int
PyG-style number of classes of the labels y (the node labels if
the graphs have some, the graph labels otherwise, see
GraphData.y), inferred as in PyG from the labels of all the
graphs (after transform):
- integer labels with one entry per node (graph):
max + 1; - floating-point labels with one entry per node (graph): the number of distinct values (with a warning if there are more than two);
- labels with several entries per node (graph), e.g. multi-label
targets of shape
[*, num_tasks]: their last dimension.
Returns 0 if no graph has labels.
index_select
¶
Returns a new dataset with the graphs at the indices idx.
The graphs are shared with this dataset (not copied), and the
transform of the dataset is still applied lazily when a graph is
accessed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
Union[slice, array, ndarray, Sequence]
|
The graphs to select, as a slice, a list or array of indices
(negative indices are allowed), or a boolean mask of shape
|
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
The dataset restricted to the selected graphs. |
Example:
Source code in mlx_graphs/datasets/dataset.py
shuffle
¶
Returns a copy of the dataset with the graphs in random order.
The permutation comes from mx.random.permutation, so it is
reproducible with mx.random.seed. The graphs themselves are shared,
not copied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
return_perm
|
bool
|
Whether to also return the permutation. Default:
|
False
|
Returns:
| Type | Description |
|---|---|
Union[Dataset, tuple[Dataset, array]]
|
The shuffled dataset, and the permutation if |
Union[Dataset, tuple[Dataset, array]]
|
|
Union[Dataset, tuple[Dataset, array]]
|
of this one). |
Example:
Source code in mlx_graphs/datasets/dataset.py
from mlx_graphs.datasets import Dataset · mlx_graphs/datasets/dataset.py