Skip to content

FakeDataset

FakeDataset(
    num_graphs: int = 1,
    avg_num_nodes: int = 1000,
    avg_degree: float = 10.0,
    num_channels: int = 64,
    edge_dim: int = 0,
    num_classes: int = 10,
    task: FAKE_TASKS = "auto",
    is_undirected: bool = True,
    seed: Optional[int] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
    **kwargs: Union[int, tuple[int, ...]],
)

Bases: Dataset

A fake dataset that returns randomly generated GraphData objects, useful to test models and pipelines without downloading anything.

Node features are standard normal samples shifted by the (node or graph) label, so that the classification task is learnable. Graphs are generated once at construction and are deterministic for a given seed.

This dataset follows the implementation of PyG, with an additional seed argument. The random values differ from PyG's since they are drawn from NumPy.

Parameters:

Name Type Description Default
num_graphs int

The number of graphs. Default: 1.

1
avg_num_nodes int

The average number of nodes in a graph; the number of nodes of each graph is drawn uniformly in [3/4 * avg_num_nodes, 5/4 * avg_num_nodes]. Default: 1000.

1000
avg_degree float

The average degree per node. Default: 10.0.

10.0
num_channels int

The number of node features. If 0, the graphs have no node features and num_nodes is set instead. Default: 64.

64
edge_dim int

The number of edge features. If 1, a 1-dimensional edge_weights attribute is set instead of edge_features. Default: 0.

0
num_classes int

The number of classes in the dataset. Default: 10.

10
task FAKE_TASKS

Whether to return node-level ("node") or graph-level ("graph") labels. If "auto", graph-level labels are used when num_graphs > 1, node-level labels otherwise. Default: "auto".

'auto'
is_undirected bool

Whether the graphs are undirected. Default: True.

True
seed Optional[int]

Seed of the random number generator. Default: None (non-deterministic).

None
pre_transform Optional[Callable]

A function/transform applied to each graph once, after generation.

None
transform Optional[Callable]

A function/transform applied to the graph at every access.

None
**kwargs Union[int, tuple[int, ...]]

Additional graph attributes and their shapes, e.g. global_features=5, filled with standard normal samples.

{}

Example:

from mlx_graphs.datasets import FakeDataset

dataset = FakeDataset(num_graphs=4, avg_num_nodes=20, seed=0)
>>> fake(num_graphs=4)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 316), int32)
        node_features(shape=(24, 64), float32)
        graph_labels(shape=(1,), int32))
Source code in mlx_graphs/datasets/fake.py
def __init__(
    self,
    num_graphs: int = 1,
    avg_num_nodes: int = 1000,
    avg_degree: float = 10.0,
    num_channels: int = 64,
    edge_dim: int = 0,
    num_classes: int = 10,
    task: FAKE_TASKS = "auto",
    is_undirected: bool = True,
    seed: Optional[int] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
    **kwargs: Union[int, tuple[int, ...]],
):
    if task == "auto":
        task = "graph" if num_graphs > 1 else "node"
    assert task in ["node", "graph"], "Invalid task"

    self._num_graphs = max(num_graphs, 1)
    self.avg_num_nodes = max(avg_num_nodes, int(avg_degree))
    self.avg_degree = max(avg_degree, 1)
    self.num_channels = num_channels
    self.edge_dim = edge_dim
    self._num_classes_ = num_classes
    self.task = task
    self.is_undirected = is_undirected
    self.seed = seed
    self.kwargs = kwargs
    super().__init__(name="fake", pre_transform=pre_transform, transform=transform)

from mlx_graphs.datasets import FakeDataset · mlx_graphs/datasets/fake.py