cdlib.benchmark.SBM¶
- cdlib.benchmark.SBM(sizes: list, p: list, nodelist: list | None = None, seed: object = 42, directed: bool = False, selfloops: bool = False, sparse: bool = True) [<class 'object'>, <class 'object'>] ¶
Returns a stochastic block model graph.
This model partitions the nodes in blocks of arbitrary sizes, and places edges between pairs of nodes independently, with a probability that depends on the blocks.
- Parameters:
sizes – Sizes of blocks (list of ints)
p – Element (r,s) gives the density of edges going from the nodes of group r to nodes of group s. p must match the number of groups (len(sizes) == len(p)), and it must be symmetric if the graph is undirected. (List of floats)
nodelist – The block tags are assigned according to the node identifiers in nodelist. If nodelist is None, then the ordering is the range [0,sum(sizes)-1]. Optional, default None.
seed – Indicator of random number generation state.
directed – hether to create a directed graph or not. Boolean, default False.
selfloops – Whether to include self-loops or not. Optional, default False.
sparse – Use the sparse heuristic to speed up the generator. Optional, default True.
- Returns:
A networkx synthetic graph, the set of communities (NodeClustering object)
- Example:
>>> from cdlib.benchmark import SBM >>> sizes = [75, 75, 300] >>> probs = [[0.25, 0.05, 0.02], [0.05, 0.35, 0.07], [0.02, 0.07, 0.40]] >>> G, coms = SBM(sizes, probs, seed=0)
- References:
Holland, P. W., Laskey, K. B., & Leinhardt, S., “Stochastic blockmodels: First steps”, Social networks, 5(2), 109-137, 1983.