Skip to content

data

Defines a container for graphs and the means to process them in TensorFlow.

This package defines a container (dataset) of graphs, based on the class of the same name in Spektral. The package also defines two loaders for datasets, based on the loaders defined in Spektral. The Graph class from Spektral can be imported from this package, and used for the definition of datasets.

The package contains the following classes:

  • Graph
  • Dataset
  • SingleGraphLoader
  • MultipleGraphLoader

Dataset

Dataset(name: str, **kwargs: Any)

Bases: Dataset

Container for graphs.

This class is supposed to be extended by overriding the read and download methods. See Spektral's documentation for additional information, as this class is directly derived from Spektral's Dataset class.

Attributes:

  • name

    A string name for the dataset.

Parameters:

  • name (str) –

    The name for the dataset.

  • **kwargs (Any, default: {} ) –

    The keyword arguments to pass to Spektral's Dataset class constructor.

Source code in libmg/data/dataset.py
def __init__(self, name: str, **kwargs: Any):
    """Initializes the instance with the given name, then the superclass will call the ``download`` and ``read`` methods as needed.

    Args:
        name: The name for the dataset.
        **kwargs: The keyword arguments to pass to Spektral's ``Dataset`` class constructor.
    """
    self.name = name
    super().__init__(**kwargs)

SingleGraphLoader

SingleGraphLoader(dataset, epochs=None, sample_weights=None)

Bases: SingleLoader

Loads a dataset made up by a single graph to be used by a TensorFlow model.

Once instantiated, call the load method to obtain the generator that can be used with TensorFlow APIs. See Spektral's documentation for additional information, as this class is directly derived from Spektral's SingleLoader class.

Source code in libmg/data/loaders.py
def __init__(self, dataset, epochs=None, sample_weights=None):
    super().__init__(dataset, epochs, sample_weights)

MultipleGraphLoader

MultipleGraphLoader(dataset, batch_size=1, epochs=None, shuffle=True)

Bases: DisjointLoader

Loads a dataset made up by more than one graph to be used by a TensorFlow model.

Once instantiated, call the load method to obtain the generator that can be used with TensorFlow APIs. See Spektral's documentation for additional information, as this class is directly derived from Spektral's DisjointLoader class.

Source code in libmg/data/loaders.py
def __init__(self, dataset, batch_size=1, epochs=None, shuffle=True):
    super().__init__(dataset, node_level=True, batch_size=batch_size, epochs=epochs, shuffle=shuffle)