Search

Search papers and lessons

Stochastic Block Model

Level 4 · 11 min read

The stochastic block model generates a network by first sorting its vertices into hidden groups, then joining each pair with a probability that depends only on the groups the pair belongs to.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Inference
  • Condensed matter
  • ReadReady to readNot yet

TL;DR

A stochastic block model is a random network with hidden groups. Each vertex belongs to one group, and each pair of vertices is joined with a probability that depends only on the two groups involved, with pairs decided independently. Running the model produces a network with visible communities, and the model can also be run backwards: given a network, one can ask which grouping best explains it.

Builds on: Erdős–Rényi Random Graph, Latent Variable Model · Leads to: Community Detection

Where it's used

Finding communities in social networks. Sociologists and network scientists look at who talks to whom in a school, an office or an online forum. The block model asks for a grouping of people such that edges are dense inside groups and sparse between them. Karrer and Newman extended the model in 2011 so that each vertex can also have its own number of connections, which fits real networks much better.

Biological networks. Protein interaction maps and gene regulatory networks contain modules, sets of molecules that interact heavily with one another. A block model gives a principled way to propose such modules and to score how well a proposed set of modules explains the observed interactions.

Benchmarks for algorithms. A community-detection method needs test inputs where the true groups are known. Because the model generates a network from known groups, it provides such inputs with a controllable difficulty: when the inside probability is much larger than the outside one, the groups are easy to see; when the two are close, they are hard.

How it works

Take a small network with two groups. Vertices 1 and 2 are in group A, and vertex 3 is in group B. The probability table is

B=(0.80.20.20.5),B = \begin{pmatrix} 0.8 & 0.2 \\ 0.2 & 0.5 \end{pmatrix},

so two vertices in the same group join with probability 0.80.8 if both are in A and 0.50.5 if both are in B, and vertices in different groups join with probability 0.20.2.

  1. Assign each vertex a group. Vertices 1 and 2 get group A, vertex 3 gets group B. These labels are hidden from anyone who only sees the network. Check: each vertex has exactly one group.
  2. Look up the probability for each pair. Pair 1–2 has both vertices in A, so its probability is BAA=0.8B_{AA} = 0.8. Pair 1–3 and pair 2–3 each mix A and B, so their probability is BAB=0.2B_{AB} = 0.2. Check: the table is symmetric, so BAB=BBA=0.2B_{AB} = B_{BA} = 0.2.
  3. Flip for each pair, independently. The pair 1–2 is joined with probability 0.80.8, and each of the other two pairs with probability 0.20.2. The coins do not affect one another. Check: three pairs, three independent decisions.
  4. Compute the probability of one outcome. Suppose the only edge drawn is 1–2. Then pair 1–2 is present and the other two are absent, which has probability 0.8×(1−0.2)×(1−0.2)=0.8×0.8×0.8=0.5120.8 \times (1 - 0.2) \times (1 - 0.2) = 0.8 \times 0.8 \times 0.8 = 0.512. Check: the factor for an absent pair is one minus its probability.
  5. Run the model backwards in principle. Given only the edges, the group labels are unknown. Finding the labels that best explain the network is the inference problem the rest of this lesson is about. Check: step 4 used the labels; step 5 must recover them.

The generating process is a flow:

flowchart LR
  A["n vertices"] --> B["assign each vertex a hidden group"]
  B --> C["for each pair, look up probability in the group table"]
  C --> D["flip a coin for the pair"]
  D --> E["network with visible communities"]

The math

Definition: Stochastic block model

Let nn be the number of vertices and KK the number of groups. Let π=(π1,…,πK)\pi = (\pi_1, \dots, \pi_K) be group proportions summing to 11, and let BB be a symmetric K×KK \times K matrix with entries in [0,1][0, 1]. Draw a label zi∈{1,…,K}z_i \in \{1, \dots, K\} for each vertex ii, independently with Pr⁡[zi=k]=πk\Pr[z_i = k] = \pi_k. Then, given the labels, each pair i<ji \lt j is joined independently with probability BzizjB_{z_i z_j}. The adjacency entries are Aij∈{0,1}A_{ij} \in \{0, 1\}.

Step 1 in symbols: the labels

Each vertex draws a label from the categorical distribution with probabilities πk\pi_k. If nkn_k is the number of vertices with label kk, then nkn_k is a random variable, with mean nπkn \pi_k. In the walkthrough the labels are fixed, z1=z2=Az_1 = z_2 = A and z3=Bz_3 = B, so the observed group proportions are 23\tfrac{2}{3} for A and 13\tfrac{1}{3} for B.

Step 2 in symbols: the edges

Given the labels, each entry of the adjacency matrix is independent:

Pr⁡[Aij=1∣z]=Bzizj.\Pr[A_{ij} = 1 \mid z] = B_{z_i z_j}.

Read the subscript as "the entry of BB in the row of vertex ii's group and the column of vertex jj's group". This is the walkthrough's table lookup.

Step 3 in symbols: the expected network

Let ZZ be the n×Kn \times K membership matrix, with Zik=1Z_{ik} = 1 if zi=kz_i = k and 00 otherwise. Then the matrix of edge probabilities is

E[A∣z]=ZBZ⊤.\mathbb{E}[A \mid z] = Z B Z^{\top}.

Its (i,j)(i, j) entry is BzizjB_{z_i z_j}, which is exactly the table lookup of step 2. The diagonal entries are the probabilities of self-pairs; they are excluded from the network, so the expected degree must subtract them.

Step 4 in symbols: the likelihood of a network

For a network with adjacency entries AijA_{ij}, given labels zz,

Pr⁡[A∣z]=∏i<jBzizjAij(1−Bzizj)1−Aij.\Pr[A \mid z] = \prod_{i \lt j} B_{z_i z_j}^{A_{ij}} \left(1 - B_{z_i z_j}\right)^{1 - A_{ij}}.

The labels are hidden, so the probability of the network alone sums this over all labelings: Pr⁡[A]=∑zPr⁡[A∣z]Pr⁡[z]\Pr[A] = \sum_z \Pr[A \mid z]\Pr[z]. This sum has KnK^n terms, which is why exact computation is hard for large nn. This is where the expectation-maximization algorithm and maximum likelihood come in.

Step 5 in symbols: when can the groups be found?

Consider two groups of equal size and sparse edges, with pin=a/np_{\text{in}} = a / n and pout=b/np_{\text{out}} = b / n, so that a typical vertex has about (a+b)/2(a+b)/2 neighbours. A famous condition from statistical physics, conjectured by Decelle, Krzakala, Moore and Zdeborová in 2011 and proved by later work of Mossel, Neeman and Sly and of Massoulié, is

(a−b)2>2(a+b).(a - b)^2 \gt 2(a + b).

Above this threshold, a grouping better than chance can be found from the network; below it, no method can do so as nn grows.

Worked examples

Example
1. A tiny case: three vertices
  1. Use the table from the walkthrough: BAA=0.8B_{AA} = 0.8, BAB=0.2B_{AB} = 0.2, and vertices 1 and 2 in A, vertex 3 in B.
  2. Pairs: 1–2 is A–A with probability 0.80.8; 1–3 and 2–3 are A–B with probability 0.20.2.
  3. Outcome: the only edge is 1–2. Probability: 0.8×(1−0.2)×(1−0.2)0.8 \times (1 - 0.2) \times (1 - 0.2).
  4. Arithmetic: 0.8×0.8=0.640.8 \times 0.8 = 0.64, then 0.64×0.8=0.5120.64 \times 0.8 = 0.512.

Answer: Pr⁡[only edge 1–2∣labels]=0.512\Pr[\text{only edge } 1\text{–}2 \mid \text{labels}] = 0.512.

Example
2. The standard case: four vertices, two groups
  1. Groups: vertices 1 and 2 in group X, vertices 3 and 4 in group Y, so nX=nY=2n_X = n_Y = 2.
  2. Probability table: B=(0.90.10.10.9)B = \begin{pmatrix} 0.9 & 0.1 \\ 0.1 & 0.9 \end{pmatrix}.
  3. Expected degree of vertex 1. It can join the 3 other vertices. Vertex 2 is in its own group, probability 0.90.9. Vertices 3 and 4 are in the other group, probability 0.10.1 each.
  4. Sum: 0.9+0.1+0.1=1.10.9 + 0.1 + 0.1 = 1.1.
  5. Check with the formula ∑lnlBkl−Bkk\sum_l n_l B_{kl} - B_{kk} for k=Xk = X: 2⋅0.9+2⋅0.1−0.9=1.12 \cdot 0.9 + 2 \cdot 0.1 - 0.9 = 1.1. The subtraction removes the self-pair that the sum counted.
  6. Expected number of edges: each of 4 vertices has expected degree 1.11.1, so the expected number of edges is 4⋅1.12=2.2\tfrac{4 \cdot 1.1}{2} = 2.2.

Answer: each vertex has expected degree 1.11.1, and the network has 2.22.2 expected edges.

Example
3. A realistic size: two classes of a thousand students

Suppose a school has n=1000n = 1000 students in two equal classes, and the probability of a friendship is pin=0.01p_{\text{in}} = 0.01 within a class and pout=0.005p_{\text{out}} = 0.005 across classes. Are the classes detectable from the friendship network alone?

  1. Compute a=n⋅pin=1000⋅0.01=10a = n \cdot p_{\text{in}} = 1000 \cdot 0.01 = 10.
  2. Compute b=n⋅pout=1000⋅0.005=5b = n \cdot p_{\text{out}} = 1000 \cdot 0.005 = 5.
  3. Evaluate the left side: (a−b)2=52=25(a - b)^2 = 5^2 = 25.
  4. Evaluate the right side: 2(a+b)=2⋅15=302(a + b) = 2 \cdot 15 = 30.
  5. Compare: 25<3025 \lt 30, so the condition fails.

Answer: the classes are below the threshold, so no method can find them better than chance as the school grows.

Try it: a network of n=2000n = 2000 people in two equal groups has pin=0.01p_{\text{in}} = 0.01 and pout=0.002p_{\text{out}} = 0.002. Is the grouping detectable?

Answer: a=20a = 20 and b=4b = 4. Then (a−b)2=256(a - b)^2 = 256 and 2(a+b)=482(a + b) = 48. Since 256>48256 \gt 48, the groups are detectable.

Common mistakes and tradeoffs

It is tempting to think a block model's groups are visible in the network. In fact the groups are hidden labels, and a network drawn from the model can look random if the inside and outside probabilities are close. The model describes a distribution over networks, not a picture of one.

It is tempting to think a block model always produces dense groups. In fact the probability table decides the structure: a group can be dense inside and sparse to the rest, or sparse inside and dense to another group. Both are valid block structures, and "community" in the usual sense is only one of them.

It is tempting to think a block model fitted to a network is the true generating process. In fact real networks rarely match the model exactly, and a better fit does not prove the groups are real. Model checking, such as comparing simulated networks against the observed one, is needed.

Use the block model when you want an explicit, testable account of groups and when you can tolerate its assumption that the groups explain the edges independently. Do not use it when the network has strong degree differences that the plain model cannot capture, unless you use a degree-corrected variant. Alternatives include modularity maximisation, which optimises a score without a generative model, and spectral methods based on the adjacency matrix.

History

The block model was introduced by Holland, Laskey and Leinhardt in 1983 as a way to describe the roles people play in social networks. Earlier work on random graphs with structure, such as planted bisection problems in computer science in the 1980s, asked similar questions about recovering a hidden split.

In the 2000s, the planted partition formulation, a block model with one probability inside groups and another across, became a standard benchmark for computer scientists. Statistical physicists studying the same model found the threshold in step 5 by analysing belief propagation, which is why the condition has the form it has. Proofs that the threshold is sharp came from mathematicians in the following decade.

The model caught on because it is simple to simulate and gives a precise question: can the hidden groups be recovered? That question connects network science, statistics and statistical physics.

Recap

  • A block model gives each vertex a hidden group, and each pair of vertices is joined independently with a probability read from a table indexed by the two groups.
  • Given the labels, the expected adjacency matrix is ZBZ⊤Z B Z^{\top}, which makes the model a low-rank structure.
  • The labels are unknown, so inference sums over all labelings or approximates the sum, which is where expectation-maximization enters.
  • For two equal sparse groups, the sharp detectability threshold is (a−b)2>2(a+b)(a-b)^2 \gt 2(a+b).
  • Read next: Community Detection for the methods that find groups in a network, which the block model justifies and tests.

Check yourself

QuestionIn the block model, what is the probability that two vertices in the same group are joined, given the labels?Show answer

It is the diagonal entry BziziB_{z_i z_i} of the table for that group, because the probability depends only on the two groups, and both vertices are in the same group.

QuestionTwo vertices are in groups X and Y, and BXY=0.3B_{XY} = 0.3. What is the probability that the pair is joined, and what is the probability that it is not?Show answer

The pair is joined with probability 0.30.3 and not joined with probability 1−0.3=0.71 - 0.3 = 0.7.

QuestionWhy is the sum over labelings hard to compute for a large network, and why does that matter for fitting the model?Show answer

Each vertex can take any of KK labels, so there are KnK^n labelings, and the sum over them has that many terms. For large nn this is too many to enumerate, so fitting the model must use approximate methods such as expectation-maximization or Markov chain Monte Carlo.

QuestionA network has n=1000n = 1000 vertices in two equal groups with pin=0.02p_{\text{in}} = 0.02 and pout=0.01p_{\text{out}} = 0.01. Is the grouping detectable by the threshold in step 5?Show answer

Yes. Here a=20a = 20 and b=10b = 10, so (a−b)2=100(a - b)^2 = 100 and 2(a+b)=602(a + b) = 60. Since 100>60100 \gt 60, the groups are above the threshold, and a grouping better than chance can be found.

Sources