Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The rotation zoo

Orthogonal mixers, what each one looks for, and why a marginal pass needs one

00 · The rotation zoo

Open In Colab

Part 1 built the marginal map zd=Φ−1(Fd(xd))z_d = \Phi^{-1}(F_d(x_d)) that sends one coordinate to a standard normal. A stack of such maps acts on each coordinate separately, so it can fix every marginal but never the dependence between coordinates. On correlated data it makes each coordinate look like N(0,1)\mathcal{N}(0, 1) and then stops, with the joint still far from N(0,I)\mathcal{N}(\vect{0}, \mat{I}).

The other half of Gaussianization is a rotation between marginal passes, which mixes the coordinates so that the next marginal pass has something left to do. Alternating the two is the density destructor of (3), and with a fresh rotation at every layer it is RBIG Laparra et al., 2011.

Python implementation: CPython
Python version       : 3.13.12
IPython version      : 9.12.0

numpy     : 2.4.3
matplotlib: 3.11.2
rbig      : 0.1.16

Compiler    : Clang 21.1.4 
OS          : Linux
Release     : 6.8.0-1044-azure
Machine     : x86_64
Processor   : x86_64
CPU cores   : 16
Architecture: 64bit

1. A rotation is free

A rotation here is an orthogonal linear map

z=Qx\vect{z} = \mat{Q} \vect{x}

with Q⊤Q=I\mat{Q}^\top \mat{Q} = \mat{I}. Orthogonality gives two things at once. The inverse is exact and cheap, x=Q⊤z\vect{x} = \mat{Q}^\top \vect{z}, and since det⁡Q=±1\det \mat{Q} = \pm 1 the map preserves volume, so its Jacobian adds nothing to the log-determinant of a flow,

log⁡∣det⁡Jf(x)∣=log⁡∣det⁡Q∣=0\log \vert \det \mat{J}_f(\vect{x}) \vert = \log \vert \det \mat{Q} \vert = 0

which is the “rotations are free” term of the composition rule (4). Whitening is a rotation followed by a rescale, and the rescale is not free. With the eigendecomposition of the data covariance

Σx=VΛV⊤\gmat{\Sigma}_x = \mat{V} \gmat{\Lambda} \mat{V}^\top

where the columns of V\mat{V} are the principal axes and the diagonal Λ\gmat{\Lambda} holds the variance along each, PCA whitening is z=Λ−1/2V⊤x\vect{z} = \gmat{\Lambda}^{-1/2} \mat{V}^\top \vect{x}, and its log-determinant is that of the diagonal,

log⁡∣det⁡Jf(x)∣=−12log⁡det⁡Λ=−12log⁡det⁡Σx\log \vert \det \mat{J}_f(\vect{x}) \vert = -\frac{1}{2} \log \det \gmat{\Lambda} = -\frac{1}{2} \log \det \gmat{\Sigma}_x

We check both on a correlated Gaussian cloud: two coordinates that share one standard normal factor, with loadings 2 and 1.2 and independent noise of standard deviation 0.6.

rbig.PCARotation rotates onto the principal axes, and with whiten=True it also applies Λ−1/2\gmat{\Lambda}^{-1/2}.

We compare the whitening log-determinant with (4), from the eigenvalues of the sample covariance.

rotation only : log|det J| = +0.0000
whitening     : log|det J| = -0.3698
formula       : log|det J| = -0.3698

The rotation costs nothing and the whitening log-determinant is (4) to every digit printed. Most RBIG variants keep the rotation pure and let the marginal step do any rescaling, which keeps the bookkeeping clean.

2. The rotation zoo

The rotations in rbig differ only in how they choose Q\mat{Q}.

RotationHow Q\mat{Q} is chosenWhat it finds
PCAthe eigenvectors V⊤\mat{V}^\top of the covariance (3)the directions of largest variance
randomHaar-uniform on the orthogonal group, from a QR factorisation (5)nothing; it costs no fitting
ICA Hyvärinen & Oja, 2000the rotation whose outputs are most independent (6)non-Gaussian directions

A random rotation factorises a matrix G\mat{G} of independent standard normal entries,

G=QR\mat{G} = \mat{Q} \mat{R}

into an orthogonal Q\mat{Q} and an upper-triangular R\mat{R}, and flips the sign of each column of Q\mat{Q} where the diagonal of R\mat{R} is negative, which makes Q\mat{Q} uniform on the orthogonal group. ICA asks for the rotation that makes the output coordinates as independent as possible. A rotation keeps the joint entropy, H[pQx]=H[px]\mathbb{H}[p_{\mat{Q}\vect{x}}] = \mathbb{H}[p_x], so in the total correlation (5) of the rotated data

TC[pQx]=∑d=1DxH[p(Qx)d]−H[px]\mathrm{TC}[p_{\mat{Q}\vect{x}}] = \sum_{d=1}^{D_x} \mathbb{H}[p_{(\mat{Q}\vect{x})_d}] - \mathbb{H}[p_x]

only the sum of marginal entropies depends on Q\mat{Q}, and the most independent rotation is the one with the smallest sum. rbig.ICARotation and rbig.PicardRotation both fit it with the Picard algorithm Ablin et al., 2018 when the picard package is installed, as it is here, so they agree.

PCA sees only the covariance, so to tell the rotations apart we use data whose covariance carries no information: two independent Laplace sources of unit variance, mixed by a 30° rotation. The covariance is close to I\mat{I}, so every rotation leaves it unchanged, but the source axes are where the marginals are most non-Gaussian.

We fit each rotation and score it two ways: the sum of marginal entropies of its output, which is the part of (6) a rotation can change, and the angle between its first output axis and the nearest source axis. rbig.marginal_entropy estimates each entropy from a kernel density.

rbig keeps the fitted matrix in a different attribute for each rotation, and PCA also subtracts the mean, so we read Q\mat{Q} back from the transform itself: the images of the basis vectors minus the image of the origin.

Now we fit each rotation and score it.

PCA         ∑ H = 2.649, angle  2.4°
random      ∑ H = 2.708, angle 18.9°
ICA (rbig)  ∑ H = 2.735, angle 29.0°

In this draw PCA lands within a few degrees of the sources and rbig’s ICA about 30° away, with a larger entropy sum than PCA. Both results are misleading, and the next section shows why.

3. Orthogonal ICA in rbig

Picard first whitens the data with a matrix K\mat{K} and then finds an orthogonal unmixing W\mat{W} for the whitened data, so the full unmixing is WK\mat{W} \mat{K}. To stay orthogonal, rbig.ICARotation with orthogonal=True applies W\mat{W} alone. But K\mat{K} is not just a rescale: it also rotates the data into Picard’s own frame, and W\mat{W} is correct only in that frame. Dropping K\mat{K} drops that rotation too, so W\mat{W} is applied in the wrong frame even when the data are already white, as here. rbig.PicardRotation does the same.

The orthogonal part of K\mat{K}, the factor UKVK⊤\mat{U}_K \mat{V}_K^\top of its singular value decomposition K=UKdiag(⋅)VK⊤\mat{K} = \mat{U}_K \mathrm{diag}(\cdot) \mat{V}_K^\top, keeps that rotation and drops only the rescale, so WUKVK⊤\mat{W} \mat{U}_K \mat{V}_K^\top is orthogonal. For white data, as here, it is Picard’s full unmixing; for data that are not white it keeps Picard’s frame and drops its rescale.

We apply it to the same fit, check that it is orthogonal, and score it like the others.

ICA (corr.) ∑ H = 2.648, angle  1.4°
max |Q^T Q - I| = 7.8e-16
<Figure size 1700x380 with 5 Axes>

Figure 1:The same mixed Laplace data (left) in the frame each rotation chooses. The dashed lines are the source axes carried into that frame, and a rotation that finds the sources lines them up with the coordinate axes. In this draw PCA and the corrected ICA do, the random rotation and rbig’s orthogonal ICA do not.

The corrected rotation is orthogonal to machine precision, has the smallest entropy sum and lies within about a degree of the source axes. PCA’s good result in this draw was luck: the covariance of the sources is I\mat{I}, so every frame is a principal frame and PCA’s axes are set by sampling noise. We repeat the fit on 20 fresh draws.

We summarise each rotation’s angle over the 20 draws.

PCA             angle: median 12.4°, max 38.8°
ICA (rbig)      angle: median 35.3°, max 45.0°
ICA (corrected) angle: median  0.5°, max  3.8°

Over 20 draws PCA’s axes wander up to about 40° from the sources, rbig’s orthogonal ICA is off by about 35° at the median, and the corrected ICA stays within 4°. PCA cannot see structure that the covariance does not carry, and ICA can, once it is applied in the right frame.

4. Marginal passes stall, a rotation unsticks them

Now the reason rotations matter. We take the correlated Gaussian cloud of section 1, where only the dependence stands between the data and N(0,I)\mathcal{N}(\vect{0}, \mat{I}), and run eight marginal passes three ways: alone, with a PCA rotation after each pass, and with a fresh random rotation after each pass. We track the total correlation (5), which is zero exactly when the coordinates are independent.

rbig.total_correlation estimates the marginal entropies with kernel densities and the joint entropy by fitting a Gaussian. The Gaussian fit suits this cloud, which stays close to Gaussian under every marginal pass and rotation, so the estimate is accurate here; its small negative values are estimation noise.

Each scheme starts from the same cloud and records the total correlation before the first pass and after each one.

We run it with no rotation, a PCA rotation and a fresh random rotation after each pass.

marginal only               TC:  0.647  0.651  0.651  0.651  0.651  0.651  0.651  0.651  0.651
marginal + PCA rotation     TC:  0.647 -0.005 -0.005 -0.000  0.000  0.000  0.000  0.000  0.000
marginal + random rotation  TC:  0.647  0.594 -0.002 -0.002 -0.001 -0.002 -0.000 -0.001  0.000

For the figure we also keep the points after eight passes of the first two schemes.

<Figure size 1200x450 with 2 Axes>

Figure 2:Left: the total correlation over eight passes. Marginal passes alone leave it where it started, while a PCA rotation after each pass removes it in one pass and a random rotation in two. Right: the points after eight passes. Marginal passes alone leave a tilted ellipse with standard normal marginals; with rotations the cloud is isotropic.

Marginal passes alone leave the total correlation at about 0.65 nats from start to finish. Each pass makes both coordinates standard normal, but the cloud stays a tilted ellipse. With a PCA rotation after each pass the total correlation is gone after one pass, and with a random rotation after two. We count the passes to TC<0.01\mathrm{TC} < 0.01.

marginal only               passes to TC < 0.01: never
marginal + PCA rotation     passes to TC < 0.01: 1
marginal + random rotation  passes to TC < 0.01: 2

5. Why the rotation is what removes dependence

The KL divergence from N(0,I)\mathcal{N}(\vect{0}, \mat{I}) splits into the total correlation and one KL term per marginal (3). The two steps of a layer act on different terms.

A marginal pass applies an invertible map to each coordinate separately. That changes each marginal entropy and the joint entropy by the same log-derivatives, so the total correlation does not move,

TC[pg(x)]=TC[px]\mathrm{TC}[p_{g(\vect{x})}] = \mathrm{TC}[p_x]

for any coordinate-wise invertible gg, while the marginal KL terms drop to zero. A rotation leaves the total unchanged instead, because N(0,I)\mathcal{N}(\vect{0}, \mat{I}) looks the same in every orthogonal frame,

KL[pQx∥N(0,I)]=KL[px∥N(0,I)]\mathrm{KL}[p_{\mat{Q}\vect{x}} \Vert \mathcal{N}(\vect{0}, \mat{I})] = \mathrm{KL}[p_x \Vert \mathcal{N}(\vect{0}, \mat{I})]

but it moves divergence between the terms: part of the total correlation comes back as non-Gaussian marginals, which the next marginal pass removes. So each layer lowers the total by whatever the rotation moved into the marginals Laparra et al., 2011, and a rotation that moves more converges faster. The flat red line of Figure 2 is (7) measured. PCA wins here because after a marginal pass this cloud is a correlated Gaussian, whose dependence a decorrelating rotation turns into marginal structure all at once; on non-Gaussian data ICA can move more. Part 3 studies rotation choice properly.

Recap

IdeaEquationIn code
a rotation(1)rbig.PCARotation, rbig.RandomRotation, rbig.ICARotation
its log-determinant is zero(2)log_det_jacobian
whitening is not free(3), (4)PCARotation(whiten=True)
random rotations(5)rbig.RandomRotation
ICA minimises the marginal entropies(6)rbig.ICARotation, with WUKVK⊤\mat{W} \mat{U}_K \mat{V}_K^\top for an orthogonal map
marginal passes keep TC(7)Figure 2
rotations keep the total KL(8)Figure 2

Next. A PCA or random rotation is fixed once fitted. To learn a rotation inside a flow by gradient descent we need an orthogonal matrix that stays orthogonal under every update. The next notebook builds two: a product of Householder reflections and the Cayley map.

References
  1. Laparra, V., Camps-Valls, G., & Malo, J. (2011). Iterative Gaussianization: From ICA to Random Rotations. IEEE Transactions on Neural Networks, 22(4), 537–549. 10.1109/TNN.2011.2106511
  2. Hyvärinen, A., & Oja, E. (2000). Independent Component Analysis: Algorithms and Applications. Neural Networks, 13(4–5), 411–430.
  3. Ablin, P., Cardoso, J.-F., & Gramfort, A. (2018). Faster Independent Component Analysis by Preconditioning with Hessian Approximations. IEEE Transactions on Signal Processing, 66(15), 4040–4049.