| Matrices and scalings | |
|---|---|
| the size of the square matrices | |
| the matrix to be scaled, with entries , all positive in Steps 1 to 4 | |
| the row scalings, a positive vector in | |
| the column scalings, a positive vector in | |
| the diagonal matrix with (or ) on its diagonal; the paper writes for and for | |
| the scaled matrix , with entries | |
| the vector of ones; is doubly stochastic when | |
| the doubly stochastic matrix of the form , the limit of the iteration | |
| the sum of column just after a row step; the total | |
| Potential | |
| , entrywise | |
| , entrywise | |
| the potential ; its slopes are the row and column sums of minus 1 | |
| the term of entry in , at | |
| the free factor: , or in logarithms, leaves and unchanged | |
| The 2 × 2 plane | |
| , the horizontal coordinate | |
| , the vertical coordinate | |
| , the total of the scaled entries with | |
| , the potential minimized over the common factor, up to a constant | |
| the cross-ratio , unchanged by scaling | |
| the diagonal entry of for , with | |
| Rate and uses | |
| the second-largest singular value of a matrix | |
| target row sums, positive | |
| target column sums, positive, with the same total as | |
| a cost matrix in optimal transport | |
| the weight of the entropy term; Cuturi writes | |
| , entrywise, the matrix that entropic transport scales | |
Context. Any square matrix with positive entries can be made doubly stochastic, with every row and column summing to 1, by multiplying each row by one positive factor and each column by another. Sinkhorn (1964) proves that this scaled matrix is unique and that alternating row and column normalizations converge to it. Sinkhorn originally motivated the problem in statistics, scaling an estimated transition matrix of a Markov chain known to be doubly stochastic. Now called Sinkhorn-Knopp, the same iteration solves entropy-regularized optimal transport, balances cluster assignments in self-supervised learning, and keeps the stream-mixing matrices of mHCmanifold-constrained hyper-connections (Xie et al., 2025): a residual design with several parallel copies of the stream, mixed at every layer by learned matrices that are projected onto the doubly stochastic matrices by 20 Sinkhorn-Knopp iterations, so that their product over depth stays bounded. Reading note: Signal propagation in depth bounded across depth.
The proof rests on one convex potential in the logarithms of the scalings. Its partial derivatives equal the row and column sums of the scaled matrix minus 1, so any doubly stochastic scaling is a global minimum. With every entry positive, the potential rises in every direction except one flat line along which both the potential and the scaled matrix stay unchanged. A minimum therefore exists and produces a unique scaled matrix. Row normalization minimizes the potential exactly over the row scalings, and column normalization over the column scalings, so the alternation descends to that minimum. For a 2 × 2 matrix the potential reduces to a function on the plane, where the figures below draw each step exactly.
Setting. Let an matrix whose entries are all positive be an matrix with every entry . For positive vectors the row scalings and the column scalings ; is the diagonal matrix with diagonal , write and for the diagonal matrices with diagonals and . Scaling row by and column by givesThe matrix is doubly stochastic when and , where is the vector of ones. Sinkhorn's theorem guarantees that exactly one doubly stochastic matrix has the form , with and unique up to , for . Alternately dividing each row by its sum and each column by its sum converges to it.
Counting equations and unknowns does not settle existence. Removing the shared factor leaves unknowns, and the sum constraints have one redundancy because row sums and column sums share the same total. The counts match, yet the system is bilinear in and , so equal counts guarantee no solution. Nor does the iteration obviously converge: normalizing columns disturbs the row sums just set.
A convex potential whose slopes are the row and column sums minus 1. Passing to logarithms the entrywise logarithm of the row scalings, and the entrywise logarithm of the column scalings, removes the positivity constraints and turns each product into . DefineThe first sum is the entry total of , soDoubly stochastic scalings are thus the critical points of . Because every is convex and the remaining terms are linear, is convex, so its critical points are global minima. Shifting to along the flat directionthe line , : every and the sum are unchanged along it, so and are too leaves every and the sum unchanged, so both and stay fixed. That invariance is the scaling freedom , .
For the potential can be drawn. Write the log-ratio of the two row scalings, and the log-ratio of the two column scalings, . Modulo the flat direction, the only remaining coordinate is the common log-factor on all four entries. With denoting the entry total at , the potential reads . Minimizing over sets , fixing the entry total of at 2 and leaving, up to an additive constant,In the figure, has rows and , the gray curves are level sets of , and the blue dot marks its minimum.
Every entry walls off a direction, so has a lowest point. A convex function need not attain a minimum if it can fall forever toward infinity. Using splits into one term per matrix entry:Each the term of entry , , evaluated at ; is the scaled entry is convex and hits its minimum at . Because , it grows to on both sides, exponentially as and linearly as . On any sublevel set , each is at most minus the other terms' minima, trapping every sum in a bounded interval.
Those bounded sums trap modulo the flat direction, because for all forces and . Restrict to the slice , which crosses each flat line once. On that slice has closed, bounded sublevel sets and therefore attains a minimum. Because is constant along the flat direction, that minimizer is a critical point on all of , giving a doubly stochastic scaling by Step 1. In the figure, the level sets form closed curves around the blue dot. Setting removes that entry's wall, so the level sets open into a channel toward , , and the minimum escapes the plane.
Across the flat direction is strictly convex, so the scaled matrix is unique. Differentiating twice in at drops the linear terms:Because every , this second derivative is strictly positive unless every , which means points along the flat direction (Step 2). Suppose two scalings are both doubly stochastic. Both minimize the convex function , so is constant along the segment joining them and its second derivative vanishes there. That segment must run along the flat direction, so the two scalings differ only by , and produce the same matrix . In the figure this yields the single lowest point. Sinkhorn draws an immediate corollary for symmetric . Since is also doubly stochastic, uniqueness forces and with .
Normalizing the rows minimizes exactly over , and every step lowers . At fixed , setting gives , which divides row by its sum. Row normalization therefore minimizes exactly over , and column normalization over , making the alternation block coordinate descentminimizing a function over one block of variables at a time, here and then , with the other block held fixed. After a row step the entries total . The next column step divides column by its sum the sum of column of the current matrix just after a row step; the are positive and total , replacing with while keeping the entry total at . Neither the exponential sum nor changes, so moves solely through :The inequality applies Taylor's bound for , and the linear terms vanish because . A row step after a column step satisfies the same bound with rows and columns swapped.
Because is bounded below (Step 2), the total drop across all steps is finite, so the column sums after each row step tend to 1. By the same bound, the row sums after each column step also tend to 1. Every iterate stays in the initial sublevel set, where every is bounded (Step 2), keeping all scaled entries bounded above and away from 0. Since the arrays form a closed subspace, any limit point is doubly stochastic and keeps the form . Step 3 leaves only one such matrix, so the bounded sequence converges to it.
In the plane, the row step minimizes over both row scalings at fixed , which minimizes over at fixed . It travels horizontally to the lowest level set that horizontal line touches. That point lies on the curve where the two row sums match,labeled “row sums 1” because at entry total 2 both row sums equal 1. The column step travels vertically onto the matching column-sum curve,The doubly stochastic scaling sits where the two curves cross. In the figure, the blue path starts at , lands on one curve after each move, and meets its gray level set tangentially at every endpoint.
How fast. Convergence is linear. Near the limit the doubly stochastic matrix of the theorem, the limit of the iteration, each sweep of one row step and one column step shrinks the distance to by a factor approaching the square of the second-largest singular value of ; the largest is 1, with singular vectors (Knight, 2008). For , scaling preserves the cross-ratio , unchanged by any row or column scaling. That invariant fixes directly: its rows are and with . Differentiating both curves at their crossing gives on the row curve and on the column curve. Each half-step therefore scales the coordinate error by , so a full sweep contracts it bythe readout shown in the figure.
In the plane, the slope is on the row curve and on the column curve. When nears 1, the two curves cross at a shallow angle and the zigzag crawls. That occurs when is far from 1, so resembles a diagonal or anti-diagonal matrix. At , has rank one and a single sweep is exact. At , the contraction factor approaches 1 and the iterates walk off along the open channel.
Zero entries (Sinkhorn and Knopp, 1967). Sinkhorn (1964) already showed by example that zero entries can break convergence, and that even a converging iteration need not admit finite scalings . Sinkhorn and Knopp (1967) establish the exact conditions. A nonnegative matrix has support has a positive diagonal: a permutation of with all positive if it has a positive diagonal, meaning some permutation with every . It has total support and every positive entry of lies on some positive diagonal if and every positive entry lies on one. A doubly stochastic scaling exists if and only if has total support, and it is then unique. Necessity of total support follows from Birkhoff's theoremthe doubly stochastic matrices are exactly the averages, with nonnegative weights summing to 1, of the permutation matrices, since every doubly stochastic matrix is a convex combination of permutation matrices and puts every positive entry on a positive diagonal. Those scaling vectors are unique up to if and only if is fully indecomposableno permutation matrices bring to the block form with square.
Convergence requires less than existence of finite scalings. The alternation converges if and only if has support. When support is not total, every entry outside all positive diagonals vanishes in the limit, leaving a doubly stochastic matrix not of the form . The figures at show this case. The matrix with rows and has the positive diagonal , while lies on none, so the iterates converge to the identity as and .
In hindsight. Sinkhorn and Knopp's original convergence proof tracks one product along a positive diagonal, . Because is a permutation, . Just after a row step the column sums average 1, so the arithmetic-geometric mean inequality gives . The next column step divides by , so never falls and the column sums approach 1. Since the matrix entries total after every step, throughout the iteration. Their monotone product is the potential , and their AM-GM step is the drop bound of Step 4.
Other row and column sums. Positive target row sums and column sums with equal total change only the linear terms of the potential, to . The same proof works with (computed here). Row steps now scale row by divided by its current sum, and column steps scale column by divided by its current sum.
Where it is used. Cuturi (2013) adds an entropy termthe transport problem over matrices with row sums and column sums , where ; Cuturi writes and for the marginals to optimal transport between histograms and under cost matrix . The optimal coupling takes the form with entrywise, so Sinkhorn-Knopp with targets computes it directly. On large histograms, his implementation ran over 100,000 times faster than exact transport solvers at tolerance 0.01. As became diagonally dominant, iteration counts rose, matching the slow regime above. In representation learning, SwAVa self-supervised image method (Caron et al., 2020) that predicts the cluster assignment of one augmented view of an image from another view of the same image assigns batch images softly to equal-share prototypes via three Sinkhorn-Knopp iterations on with . Fewer iterations failed to converge. DINOv2 (Oquab et al., 2024) uses the same three-iteration step to center teacher outputs, though its ablation left k-NN and linear accuracy unchanged. SuperGluea graph neural network (Sarlin et al., 2020) that matches keypoints between two images and outputs a partial assignment runs 100 iterations on a score matrix padded with one row and one column for unmatched points. mHC runs 20 iterations on the entrywise exponentials of its learned mixing matrices.
Terms
- Sinkhorn's theorem
- For with all entries positive, exactly one doubly stochastic matrix has the form ; are unique up to ; alternate row and column normalization converges to it.
- Potential
- with , ; gradient = row and column sums minus 1; convex, flat only along .
- Existence
- with ; each term rises on both sides, so sublevel sets are bounded across the flat direction.
- Uniqueness
- Second derivative off the flat direction.
- Convergence
- A row step is the exact minimizer over ; a column step lowers by .
- Rate
- Linear, factor per sweep; for , . Slow when is near a permutation pattern.
- Zeros
- Scaling exists iff total support; iteration converges iff support (Sinkhorn and Knopp, 1967).
- Uses
- Entropic optimal transport (), equal-size soft assignments (SwAV, DINOv2: 3 iterations), keypoint matching (SuperGlue), mHC (20 iterations).
Sources
- Richard Sinkhorn. A Relationship Between Arbitrary Positive Matrices and Doubly Stochastic Matrices. The Annals of Mathematical Statistics 35(2), 876-879, 1964.
- Richard Sinkhorn and Paul Knopp. Concerning Nonnegative Matrices and Doubly Stochastic Matrices. Pacific Journal of Mathematics 21(2), 343-348, 1967.
- Philip A. Knight. The Sinkhorn-Knopp Algorithm: Convergence and Applications. SIAM Journal on Matrix Analysis and Applications 30(1), 261-275, 2008.
- Martin Idel. A Review of Matrix Scaling and Sinkhorn's Normal Form for Matrices and Positive Maps. arXiv preprint, 2016.
- Marco Cuturi. Sinkhorn Distances: Lightspeed Computation of Optimal Transportation Distances. Advances in Neural Information Processing Systems, 2013.
- Mathilde Caron, Ishan Misra, Julien Mairal, Priya Goyal, Piotr Bojanowski, and Armand Joulin. Unsupervised Learning of Visual Features by Contrasting Cluster Assignments. Advances in Neural Information Processing Systems, 2020.
- Maxime Oquab, Timothée Darcet, Théo Moutakanni, et al. DINOv2: Learning Robust Visual Features without Supervision. Transactions on Machine Learning Research, 2024.
- Paul-Edouard Sarlin, Daniel DeTone, Tomasz Malisiewicz, and Andrew Rabinovich. SuperGlue: Learning Feature Matching with Graph Neural Networks. IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2020.
- Zhenda Xie, Yixuan Wei, Huanqi Cao, et al. mHC: Manifold-Constrained Hyper-Connections. arXiv preprint, 2025.
Connected notes
- Softmax attention as a sum of RNNsEfficient sequence models · Additive paths carry signal through depth and time
Linear attention's state is a running sum of key-value products that never forgets. Of Mamba-2's components added one at a time to a 300M model, a data-dependent decay of that sum and a short convolution carry nearly all the gain. Test loss goes from 3.13 to 2.88 with the decay alone, 2.93 with the convolution alone and 2.77 with both, while the other components move it by 0.07 or less.
PreNorm's unweighted running sum grows with depth and dilutes every earlier output, so Attention Residuals replace it with softmax-weighted averages over earlier block sums, bounding the mixed input by while keeping direct shortcuts across depth without the matrix-product instability of multi-stream mixing.
- A Mathematical Framework for Transformer CircuitsSuperposition · Additive paths carry signal through depth and time
Because every layer reads the residual stream linearly and adds its output back, an attention-only transformer expands directly into a sum of independent paths, linking any earlier write matrix directly to any later read matrix through virtual weights across intervening layers.
- Cross-layer connectionsNanoGPT speedrun · Additive paths carry signal through depth and time
The ordinary residual stream already carries early layers forward. In an 8-layer model a value shortcut from layer 2 or later adds little, because is reachable through the stream, and it helps once the residual chain is started at . Deep layers want the first-layer shortcut most, so a direct path helps where the single running sum no longer carries that information cleanly.