Search

Search papers and lessons

Doubly Stochastic Matrix

Level 2 · 10 min read

A square table of non-negative numbers whose rows and columns each add up to 1, so every source gives out exactly one unit and every target receives exactly one unit.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

A doubly stochastic matrix is a square grid of non-negative numbers in which every row adds up to 1 and every column adds up to 1. Read it as a fair-share table: each row gives out exactly one whole unit, and each column collects exactly one whole unit. Matrices like this are the bridge between "a table of probabilities" and "a one-to-one matching".

Where you'll see it: in assignment and matching problems, in Markov chains whose long-run behaviour is uniform, and in soft matching layers of neural networks and in optimal transport.

Intuition

Start from a sharing problem

Suppose three workers each have one full day to spend, and three tasks each need exactly one day's worth of attention in total. Let the entry in row ii, column jj be the fraction of worker ii's day spent on task jj. Two rules must hold:

  1. Worker ii spends the whole day, so the fractions in row ii add to 1. Nobody has time left over and nobody works more than a day.
  2. Task jj gets exactly one day in total, so the fractions in column jj add to 1. No task is starved and none is overfunded.

A grid that obeys both rules is doubly stochastic. The word "stochastic" means that each row is a split of one whole, and "doubly" means that the columns are splits of one whole too.

Why the second rule is the interesting one

A row-only rule is common and easy to satisfy. Every Markov chain has a transition matrix whose rows sum to 1: from each state the chain has to go somewhere. Columns are a different matter. Column sums ask how much probability flows into each state, and that is usually not 1. Requiring both rows and columns to sum to 1 is a much stronger condition, and it forces the matrix to be balanced in a way the row rule does not.

flowchart LR
  A[Non-negative entries] --> B[Rows sum to 1: each source spends one unit]
  A --> C[Columns sum to 1: each target receives one unit]
  B --> D[Doubly stochastic]
  C --> D
  D --> E[Mixture of one-to-one matchings]

The math

Definition

Definition: Doubly stochastic matrix

An n×nn \times n matrix P=(pij)P = (p_{ij}) is doubly stochastic if

  1. every entry is non-negative: pij≥0p_{ij} \ge 0 for all i,ji, j;
  2. every row sums to 1: ∑j=1npij=1\sum_{j=1}^{n} p_{ij} = 1 for every ii;
  3. every column sums to 1: ∑i=1npij=1\sum_{i=1}^{n} p_{ij} = 1 for every jj.

Here pijp_{ij} is the entry in row ii and column jj, and nn is the size of the square grid. The first condition says entries are never negative. The second is the row rule and the third is the column rule. A matrix that satisfies only the first two is called row-stochastic, and it is exactly what a transition matrix is.

Two simple examples always work. The identity matrix (1s on the diagonal, 0s elsewhere) is doubly stochastic, because each row and each column has exactly one 1. The matrix whose every entry is 1/n1/n is doubly stochastic too, because each row and column has nn entries of 1/n1/n and those add to 1.

Permutation matrices

A permutation matrix is a 0-1 matrix with exactly one 1 in each row and exactly one 1 in each column. It encodes a one-to-one matching: row ii is sent to the column where its 1 sits. For n=3n = 3, one example is

Q=(010001100).Q = \begin{pmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{pmatrix}.

Every permutation matrix is doubly stochastic, since each row and column contains a single 1. The converse is not true in general, but the next result says how the two families are related.

The Birkhoff–von Neumann theorem

Definition: Convex combination

A convex combination of matrices M1,…,MkM_1, \dots, M_k is a sum θ1M1+⋯+θkMk\theta_1 M_1 + \dots + \theta_k M_k with every weight θm≥0\theta_m \ge 0 and θ1+⋯+θk=1\theta_1 + \dots + \theta_k = 1. Weights are like a recipe whose proportions add to one. See convex sets.

The theorem says that every doubly stochastic matrix is a convex combination of permutation matrices:

P=∑m=1kθmQm,θm≥0,∑m=1kθm=1,P = \sum_{m=1}^{k} \theta_m Q_m, \qquad \theta_m \ge 0, \quad \sum_{m=1}^{k} \theta_m = 1,

where each QmQ_m is a permutation matrix. Conversely, any such combination is doubly stochastic, because a convex combination of matrices with row and column sums equal to 1 still has row and column sums equal to 1. So the doubly stochastic matrices are exactly the convex hull of the permutation matrices. In plain terms: a fractional sharing plan is always a mixture of exact one-to-one plans.

Closure under products

If PP and QQ are doubly stochastic, so is their product PQPQ. The entries of PQPQ are (PQ)ij=∑kpikqkj(PQ)_{ij} = \sum_k p_{ik} q_{kj}, which are non-negative because every term pikqkjp_{ik} q_{kj} is a product of two non-negative numbers. For the row sums,

∑j(PQ)ij=∑kpik∑jqkj=∑kpik⋅1=1.\sum_{j} (PQ)_{ij} = \sum_{k} p_{ik} \sum_{j} q_{kj} = \sum_{k} p_{ik} \cdot 1 = 1.

The column sums work the same way with the roles of rows and columns swapped. This is why the class is closed under the operations you use to chain sharing steps together.

Uniform stationary distribution

Let π\boldsymbol{\pi} be a row Vector of length nn with entries 1/n1/n. Then πP\boldsymbol{\pi} P has jj-th entry ∑i(1/n) pij=(1/n)⋅1=1/n\sum_i (1/n)\, p_{ij} = (1/n) \cdot 1 = 1/n. So πP=π\boldsymbol{\pi} P = \boldsymbol{\pi}: the uniform distribution is stationary for PP. This is the reason doubly stochastic transition matrices are used when you want a chain that settles into equal probability over its states.

Worked examples

Example
1. A tiny check by hand

Test two 2×22 \times 2 matrices.

A=(0.50.50.50.5)A = \begin{pmatrix} 0.5 & 0.5 \\ 0.5 & 0.5 \end{pmatrix}

  1. All entries are non-negative.
  2. Row sums: 0.5+0.5=10.5 + 0.5 = 1 and 0.5+0.5=10.5 + 0.5 = 1.
  3. Column sums: 0.5+0.5=10.5 + 0.5 = 1 and 0.5+0.5=10.5 + 0.5 = 1.

So AA is doubly stochastic.

B=(0.70.30.20.8)B = \begin{pmatrix} 0.7 & 0.3 \\ 0.2 & 0.8 \end{pmatrix}

  1. All entries are non-negative.
  2. Row sums: 0.7+0.3=10.7 + 0.3 = 1 and 0.2+0.8=10.2 + 0.8 = 1.
  3. Column 1 sums to 0.7+0.2=0.90.7 + 0.2 = 0.9, not 1.

So BB is row-stochastic but not doubly stochastic. Passing the row test is not enough.

Example
2. A standard 3 × 3 case

Take

P=(0.20.50.30.60.10.30.20.40.4).P = \begin{pmatrix} 0.2 & 0.5 & 0.3 \\ 0.6 & 0.1 & 0.3 \\ 0.2 & 0.4 & 0.4 \end{pmatrix}.
  1. Row 1: 0.2+0.5+0.3=1.00.2 + 0.5 + 0.3 = 1.0.
  2. Row 2: 0.6+0.1+0.3=1.00.6 + 0.1 + 0.3 = 1.0.
  3. Row 3: 0.2+0.4+0.4=1.00.2 + 0.4 + 0.4 = 1.0.
  4. Column 1: 0.2+0.6+0.2=1.00.2 + 0.6 + 0.2 = 1.0.
  5. Column 2: 0.5+0.1+0.4=1.00.5 + 0.1 + 0.4 = 1.0.
  6. Column 3: 0.3+0.3+0.4=1.00.3 + 0.3 + 0.4 = 1.0.

Every row and column is a whole unit, so PP is doubly stochastic. Read it as three workers splitting their time across three tasks, where each task receives exactly one unit of attention in total.

To check the uniform-stationary claim, multiply π=(1/3,1/3,1/3)\boldsymbol{\pi} = (1/3, 1/3, 1/3) by PP. The first entry is (0.2+0.6+0.2)/3=1/3(0.2 + 0.6 + 0.2)/3 = 1/3, the second is (0.5+0.1+0.4)/3=1/3(0.5 + 0.1 + 0.4)/3 = 1/3, and the third is (0.3+0.3+0.4)/3=1/3(0.3 + 0.3 + 0.4)/3 = 1/3. The vector comes back unchanged.

Example
3. From raw scores to a doubly stochastic matrix

Suppose a matching model gives each pair a positive score, and you want soft assignment weights that obey both sharing rules. Start with

S=(1234).S = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}.

The Sinkhorn method repeats two steps: divide each row by its sum, then divide each column by its sum. Sinkhorn showed in 1964 that for a matrix with all positive entries, this alternation converges to a doubly stochastic matrix.

Step 1, row normalisation. Row 1 sums to 3 and row 2 sums to 7, so the rows become (1/3,2/3)(1/3, 2/3) and (3/7,4/7)(3/7, 4/7), which is about (0.3333,0.6667)(0.3333, 0.6667) and (0.4286,0.5714)(0.4286, 0.5714).

Step 2, column normalisation. Column 1 sums to 0.3333+0.4286=0.76190.3333 + 0.4286 = 0.7619 and column 2 sums to 0.6667+0.5714=1.23810.6667 + 0.5714 = 1.2381. Dividing gives

(0.43750.53850.56250.4615).\begin{pmatrix} 0.4375 & 0.5385 \\ 0.5625 & 0.4615 \end{pmatrix}.

The columns now sum to 1, but the rows do not: the first row is 0.4375+0.5385=0.9760.4375 + 0.5385 = 0.976 and the second is 1.0241.024. One more round of row and column scaling pulls them closer to 1. Repeating the two steps until both sums are 1 (to the accuracy you need) yields the doubly stochastic matrix that the scores determine.

Tradeoffs and failure modes

SituationProblemBetter choice
Each source must spend exactly one unit and each target must receive exactly one unitChecking only rows misses unbalanced targetsDoubly stochastic, checked on both rows and columns
Only the outgoing probabilities from each state matterRequiring column sums adds a constraint you do not needRow-stochastic transition matrix, as in a Markov chain
You need a hard one-to-one assignment, not fractionsA doubly stochastic matrix gives shares, not decisionsRound to a permutation matrix, or solve the assignment problem directly
You start from arbitrary positive scoresRows and columns cannot both be normalised in one stepSinkhorn iterations, which converge but may need many rounds
The matrix is very largeStoring and scaling n2n^2 entries becomes expensiveSparse representations, or a method that never forms the full matrix

The most common mistake is to check rows, see that they sum to 1, and stop. Always check the columns as well. A second common mistake is to treat a convex mixture of permutation matrices as a single assignment. It is a fractional plan, and a fractional plan is not the same thing as a matching.

History

Garrett Birkhoff proved the central result in 1946, in a short paper that showed doubly stochastic matrices are mixtures of permutation matrices. John von Neumann worked on closely related results a few years later, which is why the theorem carries both names. In the 1960s, Richard Sinkhorn showed that scaling the rows and columns of a positive matrix in turn converges to a doubly stochastic one. Sinkhorn's scaling idea is the basis of the Sinkhorn–Knopp algorithm, which later became a standard tool in optimal transport and machine learning. The idea caught on because it turns a messy set of scores into a balanced table, and that balance is useful wherever a fair split of resources has to be found.

Recap

A doubly stochastic matrix is a non-negative square matrix with every row and every column summing to 1. Its rows alone make a transition matrix, and the extra column rule gives a uniform stationary distribution. Products of such matrices stay doubly stochastic, and the Birkhoff–von Neumann theorem says every one is a mixture of permutation matrices, which are exact one-to-one matchings.

Check yourself

QuestionBesides non-negativity, which two conditions make a square matrix doubly stochastic?Show answer

Every row must sum to 1 and every column must sum to 1. Checking only one of them is not enough: a matrix can have every row summing to 1 and still have a column that sums to 0.9 or 1.2.

QuestionIs (0.250.750.60.4)\begin{pmatrix} 0.25 & 0.75 \\ 0.6 & 0.4 \end{pmatrix} doubly stochastic?Show answer

No. The rows sum to 0.25+0.75=10.25 + 0.75 = 1 and 0.6+0.4=10.6 + 0.4 = 1, so it passes the row test. The columns are 0.25+0.6=0.850.25 + 0.6 = 0.85 and 0.75+0.4=1.150.75 + 0.4 = 1.15, and neither is 1. It is row-stochastic only.

QuestionWhy is the product of two doubly stochastic matrices doubly stochastic?Show answer

Each entry of the product is a sum of products of non-negative numbers, so it is non-negative. For a row sum, first add across the columns of the second matrix: ∑jqkj=1\sum_j q_{kj} = 1 for each kk, because QQ has row sums 1. The row total of the product then becomes ∑kpik⋅1=1\sum_k p_{ik} \cdot 1 = 1, because PP has row sums 1. The column case is symmetric and uses the column sums of PP instead.

QuestionA Markov chain on three states has a doubly stochastic transition matrix. What is its stationary distribution, and why?Show answer

The uniform distribution (1/3,1/3,1/3)(1/3, 1/3, 1/3). Multiplying it by a doubly stochastic matrix gives column sums divided by 3, and each column sum is 1, so the vector does not change. Equal probability across the states is preserved by every step.

Sources