---
title: Post-Hoc Matrix Scaling
url: https://www.emergentmind.com/topics/post-hoc-matrix-scaling
type: topic
---

# Post-Hoc Matrix Scaling

Post-hoc matrix scaling denotes a family of procedures that rescale an already existing matrix, data table, or fixed classifier output after the primary measurements or model have been produced. In the supplied literature, the term covers at least three distinct but related constructions: diagonal row/column rescaling of a matrix to equalize norms or isolate a scale-invariant representative, classwise multiplicative scaling of a pretrained classifier under prior shift, and multiclass logistic recalibration with a learned weight matrix acting on logits or log-probabilities [1901.01336] [1110.2805] [2309.08825] [2511.03685]. The shared motif is that the underlying object is held fixed and only a post-hoc scaling transformation is learned or computed.

## 1. Conceptual scope and formal patterns

A recurring formal pattern is the factorization of an object into scale factors and a normalized core. For a real \(m\times n\) data matrix \(A\), projective decomposition seeks
\[
A = D_r\,S\,D_c,
\]
where \(D_r=\mathrm{diag}(r_1,\dots,r_m)\) and \(D_c=\mathrm{diag}(c_1,\dots,c_n)\) are diagonal matrices of positive row- and column-scale factors, and \(S\) is an \(m\times n\) scale-normalized matrix whose rows and columns each have unit root-mean-square (RMS) [1901.01336]. In numerical linear algebra, equilibration uses the same diagonal-scaling template,
\[
\hat A = D_r A D_c,
\]
but the normalization target is approximate equality of row- and column-\(2\)-norms rather than preservation of ratio structure [1110.2805].

In post-hoc classification under prior shift, scaling is applied not to matrix entries directly but to a pretrained probability vector \(\hat\eta(x)\in\Delta_m\). A nonnegative scaling vector \(\beta\in\mathbb{R}^m_+\) defines
\[
f_{\beta,i}(x)=\frac{\beta_i\,\hat\eta_i(x)}{\sum_{j=1}^m \beta_j\,\hat\eta_j(x)},
\]
or equivalently a logit shift \(\mathrm{Logit}_i(x)\mapsto \mathrm{Logit}_i(x)+\log\beta_i\) [2309.08825]. In multiclass calibration, a more expressive post-hoc recalibrator applies a full softmax layer to centered log-probabilities,
\[
g(p)=\mathrm{Softmax}(Wz+b),
\]
with \(W\in\mathbb{R}^{k\times k}\), \(b\in\mathbb{R}^k\), and \(z=C_k[\log p_1,\dots,\log p_k]^\top\) [2511.03685].

These formulations are not interchangeable. Diagonal matrix scaling, classwise vector scaling, and full matrix scaling act on different objects and preserve different invariants. A plausible implication is that “matrix scaling” is best understood as a structural family of post-hoc rescaling methods rather than as a single algorithm.

## 2. Projective decomposition and scale-invariant normalization

Projective decomposition treats a data matrix as defining a relationship between information labeling rows and information labeling columns, and normalizes both organizations simultaneously rather than standardizing only one axis [1901.01336]. The canonical form \(S\) is defined by unit RMS constraints on every row and every column:
\[
|S_{i\cdot}|=1 \quad (i=1,\dots,m), \qquad |S_{\cdot j}|=1 \quad (j=1,\dots,n),
\]
with RMS operators
\[
|M|=\sqrt{\frac{1}{mn}\sum_{i=1}^m\sum_{j=1}^n M_{ij}^2},\quad
|M_{i\cdot}|=\sqrt{\frac{1}{n}\sum_{j=1}^n M_{ij}^2},\quad
|M_{\cdot j}|=\sqrt{\frac{1}{m}\sum_{i=1}^m M_{ij}^2}.
\]

The associated equivalence relation is “equivalent up to scale.” Two matrices \(A\) and \(B\) of the same size \(m\times n\) are equivalent up to scale if there exist strictly positive vectors \(p\in\mathbb{R}_+^m\) and \(q\in\mathbb{R}_+^n\) such that
\[
B = D_q^{-1} A D_p,
\]
equivalently \(D_q B = A D_p\). The set of all decompositions \(D_r S D_c\) with positive \(r,c\) yields an equivalence class of matrices that differ only by row and column dilations, and \(S\) is the canonical representative once the unit-RMS constraints are imposed [1901.01336].

A central property is preservation of pairwise relative ratios. Writing \(A_{ij}=r_i S_{ij} c_j\), one obtains, for any two distinct rows \(i\neq j\) and two distinct columns \(s\neq t\),
\[
\frac{(S_{is}/S_{it})}{(S_{js}/S_{jt})}
=
\frac{(A_{is}/A_{it})}{(A_{js}/A_{jt})}.
\]
The source text states this in words as preservation of every within-row or within-column ratio in \(A\), so that \(S\) is “ratio-scale invariant” [1901.01336]. This distinguishes projective decomposition from z-transformation, which enforces zero mean and unit standard deviation down each column, does nothing to the rows, and alters ratio structure because it subtracts column means.

Computation proceeds by an iterative proportional-scaling algorithm of Sinkhorn-Knopp type adapted to \(L_2\) norms. Starting from \(S^{(0)}=A\), \(r_i^{(0)}=1\), and \(c_j^{(0)}=1\), one alternates row normalization and column normalization until the maximum deviations of row and column RMS values from \(1\) fall below a tolerance. For sufficiently supported matrices, standard results adapted to \(L_2\) guarantee existence of the limit and uniqueness up to the one-dimensional diagonal scale symmetry [1901.01336].

## 3. Diagonal equilibration in numerical linear algebra

In numerical linear algebra, post-hoc matrix scaling usually means equilibration: finding diagonal matrices \(D_r\) and \(D_c\) so that the scaled matrix \(\hat A=D_r A D_c\) has row and column \(2\)-norms that are equal, or approximately equal [1110.2805]. For signed matrices, the problem is conveniently transferred to the nonnegative matrix
\[
B = A \odot A,
\]
and one seeks positive vectors \(r\in\mathbb{R}^m\), \(c\in\mathbb{R}^n\) such that \(RBC\) is doubly stochastic, where \(R=\mathrm{diag}(r)\) and \(C=\mathrm{diag}(c)\). Once these are found, one sets
\[
D_r = \mathrm{diag}(r^{-1/2}),\qquad D_c = \mathrm{diag}(c^{-1/2}).
\]

The classical exact formulation is Sinkhorn-Knopp iteration. If \(B\ge 0\) has total support, the iteration
\[
r^{k+1}=(Bc^k)^{-1},\qquad c^{k+1}=(B^\top r^{k+1})^{-1}
\]
converges to the unique scalings up to a scalar; the resulting doubly stochastic matrix is unique [1110.2805]. For symmetric \(B\), the iteration
\[
y^{k+1}=(By^k)^{-1},\qquad x^{k+1}=\sqrt{y^{k+1}\odot y^k}
\]
produces a symmetric scaling vector.

The matrix-free contribution of Bradley and Murray is to approximate the required actions of \(B\) and \(B^\top\) using only matrix-vector products with \(A\) and \(A^\top\). If \(u\in\mathbb{R}^n\) has iid zero-mean, unit-variance entries, then for fixed \(x>0\),
\[
\mathbb{E}\!\left[(A X^{1/2}u)^2\right]=(Bx)_i
\]
entrywise, so \(Bx\) can be estimated by squaring the output of a single matrix-vector product rather than forming \(B=A\odot A\) explicitly [1110.2805]. The resulting nonsymmetric stochastic iteration uses two matrix-vector products per iteration, while the symmetric version uses one. Storage is \(O(m+n)\), and the method can be applied when the matrix is available only through a fast operator.

The stated motivation is conditioning. Empirically and theoretically, equilibration often drives down the \(2\)-norm condition number \(\kappa_2(\hat A)\) relative to \(\kappa_2(A)\), thereby accelerating iterative solvers or improving numerical stability of factorizations. In the reported experiments on 700+ nonsymmetric and 400+ symmetric matrices, sizes up to \(2\times 10^5\), after only \(K\approx 100\) iterations the ratio \(\max\text{–norm}(r_i)/\min\text{–norm}(r_i)\) falls to \(1.5\)–\(6\), nearly indistinguishable from exact equilibration, and \(\kappa_2(D_r A D_c)\) is reduced almost as much as with exact Sinkhorn-Knopp or classic binormalization [1110.2805].

## 4. Distributionally robust post-hoc class scaling under prior shift

For fixed pretrained classifiers, post-hoc scaling can be used to address changes in class-prior or group-prior distributions. The DROPS procedure introduces a nonnegative scaling vector \(\beta\in\mathbb{R}_+^m\), one factor per class, and defines the post-scaled scorer
\[
f_\beta(x)=\mathrm{softmax}\bigl(\log\hat\eta(x)+\log\beta\bigr),
\]
equivalently
\[
f_{\beta,i}(x)=\frac{\beta_i\,\hat\eta_i(x)}{\sum_{j=1}^m \beta_j\,\hat\eta_j(x)}.
\]
A common parameterization is \(\beta_i=g_i/\hat\pi_i\), where \(g\in\Delta_m\) and \(\hat\pi\in\Delta_m\) is the empirical class-prior on a held-out validation set [2309.08825].

The optimization target is a distributionally robust loss around a chosen target prior \(u\in\Delta_m\). Let \(\ell_i(f)\) denote the average loss on class \(i\). Then
\[
\mathrm{DRE}(f;\delta)=\max_{g\in\Delta_m:\,D(g,u)\le\delta}\sum_{i=1}^m g_i\,\ell_i(f),
\]
where \(D(\cdot,\cdot)\) is a convex divergence on the simplex and \(\delta\) determines the size of the neighborhood around \(u\) [2309.08825]. The paper states that \(\delta=0\) recovers pure average-class risk, \(\delta\to\infty\) recovers true worst-class risk, and intermediate \(\delta\) values trade off average versus worst performance.

Theorem 3.1 identifies the Bayes-optimal form of the scorer for proper convex losses:
\[
f_i^*(x)\propto \frac{g_i^*}{\pi_i}\,\eta_i(x).
\]
This justifies post-hoc classwise scaling as the relevant solution class. On a validation set, the algorithm alternates a projected \(\lambda\)-update, an exponentiated-gradient ascent step for \(g\), and a closed-form scaling update for \(f\); in the common case \(D=\mathrm{KL}\), the \(g\)-update has a closed form [2309.08825].

Theorem 4.1 gives a post-hoc convergence guarantee. Under Lipschitz and convexity conditions, if the validation-set size satisfies \(n\ge O(Z\log(m/\alpha))\) and one runs \(T=O(n)\) steps with suitable learning rates, then with probability at least \(1-\alpha\) the returned averaged scorer \(\bar f\) satisfies
\[
\mathrm{DRE}(\bar f;\delta)\le \min_f \mathrm{DRE}(f;\delta)
+ O\!\left(\sqrt{\frac{\log(m|\mathcal F|/\alpha)}{n}+\mathbb{E}_x\|\hat\eta(x)-\eta(x)\|_1}\right),
\]
where \(\mathcal F\) is the class of all scalings of \(\hat\eta\) [2309.08825]. The reported practical consequence is that once \(\beta\) is fixed, deployment requires only adding \(\log\beta_i\) to logits or multiplying probabilities by \(\beta_i\) and renormalizing; no retraining or expensive computation is required at inference time beyond one vector addition per example.

## 5. Multiclass calibration via full and structured matrix scaling

In multiclass calibration, “matrix scaling” usually means a multinomial logistic recalibrator acting on a classifier’s log-probabilities. Given a black-box classifier \(f\) producing \(p=f(x)\in\Delta_k\), one defines centered log-probabilities
\[
z \equiv C_k[\log p_1,\dots,\log p_k]^\top,\qquad C_k = I_k-\tfrac1k\mathbf1\mathbf1^\top,
\]
and fits
\[
g(p)=\mathrm{Softmax}(Wz+b),
\]
with \(W\in\mathbb{R}^{k\times k}\) and \(b\in\mathbb{R}^k\) [2511.03685]. The centering step is required because softmax is invariant to adding the same scalar to every entry of its input. The paper motivates this construction by an idealized generative model in which logistic regression on the pre-softmax logits is well-specified, and notes that a quadratic term may arise but is often omitted in practice.

The central difficulty is parameter growth: a full \(k\times k\) matrix \(W\) has \(k^2\) parameters plus \(k\) intercepts, which can overfit when \(n_{\rm cal}\) is small. Structured Matrix Scaling (SMS) addresses this by decomposing \(W\) into disjoint parameter groups,
\[
W=\alpha I_k+\mathrm{diag}(v)+(\mathbf1\mathbf1^\top-I_k)\odot M,
\]
where \(\alpha\) is a global scalar, \(v\in\mathbb{R}^k\) is a diagonal deviation vector, and \(M\in\mathbb{R}^{k\times k}\) supplies off-diagonal terms [2511.03685]. The fitting objective is a single convex problem combining multiclass log-loss with penalties on \(b\), \(v\), and \(M\), scaled by group size and calibration-set size. In the special case \(M\equiv 0\), one recovers Structured Vector Scaling (SVS).

Optimization is performed with a composite stochastic gradient solver, SAGA, with proximal updates to handle \(\ell_1\) or group-LASSO penalties. The implementation uses robust preprocessing: a standard temperature scaling fit with Laplace smoothing is first applied to the raw probabilities, then \(z=\log p^{(1)}\) is clipped to \([-90,+90]\) [2511.03685]. The default practical choices reported are norm order \(\delta=2\), exponents \(\rho=1\) and \(\tau=1\), and group weights \(\lambda_b=\lambda_v=\lambda_M=1\).

The empirical evaluation includes 68 multiclass UCI-style datasets from TabRepo, 7 base learners, and \(3\) train/test folds \(\times\) \(8\)-fold CV for calibration, giving approximately 1400 experiments. Metrics are log-loss and Brier score on held-out test folds. SMS and SVS are reported to never overfit even on high-parameter regimes; standard unregularized matrix scaling often increases test loss on approximately \(50\%\) of datasets; SMS yields strictly better median log-loss and Brier improvements than all baselines; and fitting time is approximately comparable to torchcal Vector/Matrix and \(10\times\) faster than Dirichlet because the latter requires expensive cross-validated grid search [2511.03685]. On CIFAR-10, CIFAR-100, and ImageNet benchmarks, SMS gives the largest absolute log-loss gains in nearly all cases, while unregularized matrix scaling catastrophically overfits on CIFAR-100.

## 6. Comparative properties, limitations, and recurrent points of confusion

One recurrent source of confusion is that post-hoc matrix scaling does not denote a single invariant-preserving operation. In projective decomposition, the salient invariant is the family of pairwise relative ratios, and the method is presented as appropriate for ratio-scale data in which zero has absolute meaning and comparisons are by division [1901.01336]. In equilibration, the target is approximate equality of row and column \(2\)-norms, with the primary benefit a reduction in \(\kappa_2\) and improved numerical behavior of iterative or direct solvers [1110.2805]. In post-hoc classification, the target is either robustness to a \(\delta\)-ball of prior shifts around a specified prior \(u\) or improved probability calibration on a held-out set [2309.08825] [2511.03685].

A second point is symmetry. Projective decomposition is explicitly symmetric in rows and columns and is invariant under transposition; applying it to \(A\) or \(A^\top\) yields transposes of the same canonical form and the same scaling vectors [1901.01336]. Columnwise z-transformation is not symmetric: it standardizes columns, does nothing to rows, and alters ratios through centering. In classifier calibration, by contrast, the symmetry issue is not between rows and columns of a matrix but between classes: vector scaling treats classes independently through one factor per class, whereas full matrix scaling allows cross-class couplings through off-diagonal terms in \(W\) [2309.08825] [2511.03685].

A third point is feasibility and regularity. For \(L_2\)-adapted Sinkhorn-type normalization in projective decomposition, convergence is guaranteed for non-too-sparse matrices; in practice, any matrix where each row and column has at least one nonzero is fine [1901.01336]. Exact Sinkhorn-Knopp equilibration requires total support for scalability, and with support but not total support one may still observe partial equilibration [1110.2805]. DROPS requires a held-out validation set and states that the validation set must be approximately balanced across classes or groups so that \(\hat\ell_i\) and \(\hat\pi_i\) are reliable [2309.08825]. Structured matrix scaling emphasizes the calibration-set-size regime explicitly: if \(n_{\rm cal}\ll k\), SMS is expected to collapse toward temperature or vector scaling, and for very large \(k\), such as ImageNet with \(k=1000\), the recommendation is to use SVS or TS unless thousands of calibration examples are available [2511.03685].

A plausible synthesis is that post-hoc matrix scaling is best viewed as a controlled manipulation of scale degrees of freedom after model fitting or data acquisition. What varies across subfields is the object being rescaled, the invariants one intends to preserve, and the statistical or numerical criterion used to choose the scaling.

Source: https://www.emergentmind.com/topics/post-hoc-matrix-scaling