sgtl.random.sbm#

sgtl.random.sbm(cluster_sizes, prob_mat_q, directed=False, self_loops=False)#

Generate a graph from the general stochastic block model.

The list cluster_sizes gives the number of vertices inside each cluster and the matrix Q gives the probability of each edge between pairs of clusters.

For two vertices \(u\) and \(v\) where \(u\) is in cluster \(i\) and \(v\) is in cluster \(j\), there is an edge between \(u\) and \(v\) with probability \(Q_{i, j}\).

For the undirected case, we assume that the matrix \(Q\) is symmetric (and in practice look only at the upper triangle). For the directed case, we generate edges \((u, v)\) and \((v, u)\) with probabilities \(Q_{i, j}\) and \(Q_{j, i}\) respectively.

Returns an sgtl.graph.Graph object.

Parameters:
  • cluster_sizes – The number of vertices in each cluster.

  • prob_mat_q – A square matrix where \(Q_{i, j}\) is the probability of each edge between clusters \(i\) and \(j\). Should be symmetric in the undirected case.

  • directed – Whether to generate a directed graph (default is false).

  • self_loops – Whether to generate self-loops (default is false).

Returns:

The generated graph as an sgtl.graph.Graph object.

Example:

To generate a graph with 4 clusters of different sizes, and a custom probability matrix \(Q\), you can use the following:

import sgtl.random
cluster_sizes = [20, 50, 100, 200]
Q = [[0.6, 0.1, 0.1, 0.3], [0.1, 0.5, 0.2, 0.1], [0.1, 0.2, 0.7, 0.2], [0.3, 0.1, 0.2, 0.5]]
graph = sgtl.random.sbm(cluster_sizes, Q)

For convenience, in the common case when every cluster has the same size or the internal and external probabilities are all the same, you can instead use sgtl.random.sbm_equal_clusters or sgtl.random.ssbm.