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 graphline_graph (
dgl.DGLGraph
) β The line graph of graphgraph_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
- collate_fn(x)[source]ο
The collate function for dataloader
- Parameters:
x (tuple) β
a batch of data that contains:
- graph:
dgl.DGLGraph
The original graph
- graph:
- line_graph:
dgl.DGLGraph
The line graph of graph
- line_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 graphslg_batch (
dgl.DGLGraph
) β Batched line graphsdegg_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