stochastic_blockmodel_graph
¶
stochastic_blockmodel_graph(
block_sizes: Union[Sequence[int], array],
edge_probs: Union[Sequence[Sequence[float]], array],
directed: bool = False,
) -> array
Returns the edges of a random graph from the stochastic block model: the
nodes are split into blocks, and each possible edge (without self-loops)
between a node of block a and a node of block b is present
independently with probability edge_probs[a][b].
Randomness comes from mx.random, so results are reproducible with
mx.random.seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_sizes
|
Union[Sequence[int], array]
|
Number of nodes of each block. The nodes of block 0 come first, then those of block 1, and so on. |
required |
edge_probs
|
Union[Sequence[Sequence[float]], array]
|
Square matrix of the edge probabilities between blocks.
It must be symmetric if |
required |
directed
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
array
|
The sorted int32 |
Example:
block_sizes = [2, 3]
edge_probs = [[0.9, 0.1], [0.1, 0.8]]
stochastic_blockmodel_graph(block_sizes, edge_probs)
# e.g. mx.array([[0, 1, 2, 2, 3, 3, 4, 4], [1, 0, 3, 4, 2, 4, 2, 3]])
Source code in mlx_graphs/utils/generators.py
from mlx_graphs.utils import stochastic_blockmodel_graph · mlx_graphs/utils/generators.py