SBMMixtureDataset๏ƒ

class dgl.data.SBMMixtureDataset(n_graphs, n_nodes, n_communities, k=2, avg_deg=3, pq='Appendix_C', rng=None)[source]๏ƒ

Bases: DGLDataset

Symmetric Stochastic Block Model Mixture

Reference: Appendix C of Supervised Community Detection with Hierarchical Graph Neural Networks

Parameters:
  • n_graphs (int) โ€“ Number of graphs.

  • n_nodes (int) โ€“ Number of nodes.

  • n_communities (int) โ€“ Number of communities.

  • k (int, optional) โ€“ Multiplier. Default: 2

  • avg_deg (int, optional) โ€“ Average degree. Default: 3

  • pq (list of pair of nonnegative float or str, optional) โ€“ Random densities. This parameter is for future extension, for now itโ€™s always using the default value. Default: Appendix_C

  • rng (numpy.random.RandomState, optional) โ€“ Random number generator. If not given, itโ€™s numpy.random.RandomState() with seed=None, which read data from /dev/urandom (or the Windows analogue) if available or seed from the clock otherwise. Default: None

Raises:

RuntimeError is raised if pq is not a list or string. โ€“

Examples

>>> data = SBMMixtureDataset(n_graphs=16, n_nodes=10000, n_communities=2)
>>> from torch.utils.data import DataLoader
>>> dataloader = DataLoader(data, batch_size=1, collate_fn=data.collate_fn)
>>> for graph, line_graph, graph_degrees, line_graph_degrees, pm_pd in dataloader:
...     # your code here
__getitem__(idx)[source]๏ƒ

Get one example by index

Parameters:

idx (int) โ€“ Item index

Returns:

  • graph (dgl.DGLGraph) โ€“ The original graph

  • line_graph (dgl.DGLGraph) โ€“ The line graph of graph

  • graph_degree (numpy.ndarray) โ€“ In degrees for each node in graph

  • line_graph_degree (numpy.ndarray) โ€“ In degrees for each node in line_graph

  • pm_pd (numpy.ndarray) โ€“ Edge indicator matrices Pm and Pd

__len__()[source]๏ƒ

Number of graphs in the dataset.

collate_fn(x)[source]๏ƒ

The collate function for dataloader

Parameters:

x (tuple) โ€“

a batch of data that contains:

  • graph: dgl.DGLGraph

    The original graph

  • line_graph: dgl.DGLGraph

    The line graph of graph

  • graph_degree: numpy.ndarray

    In degrees for each node in graph

  • line_graph_degree: numpy.ndarray

    In degrees for each node in line_graph

  • pm_pd: numpy.ndarray

    Edge indicator matrices Pm and Pd

Returns:

  • g_batch (dgl.DGLGraph) โ€“ Batched graphs

  • lg_batch (dgl.DGLGraph) โ€“ Batched line graphs

  • degg_batch (numpy.ndarray) โ€“ A batch of in degrees for each node in g_batch

  • deglg_batch (numpy.ndarray) โ€“ A batch of in degrees for each node in lg_batch

  • pm_pd_batch (numpy.ndarray) โ€“ A batch of edge indicator matrices Pm and Pd