Squash to See
A cloud of dots floats in 3-D, but paper is flat. Shine a torch through it and look at the shadow. Which way should the torch point so the shadow shows the most?
This is a pancake of dots, tipped on its side. Drag the cloud to spin it. Then turn your torch with the sliders and make its shadow as wide as you can. A wide shadow keeps the most of the picture!
The dot cloud
Drag (or use arrow keys) to spin. Yellow line = your torch, with each dot's shadow on it. Robo's arrows appear when Robo looks.
The shadows, laid flat
grape apple banana
Challenges
Try this: start with the pancake. Spin it until you can see its wide flat side, then swing your torch along it.
What just happened?
- Each dot had three numbers, so it lived in 3-D. A page only has room for fewer numbers.
- Shining a torch makes a shadow: one number per dot. Some torch directions squash dots on top of each other; others keep them nicely spread out.
- The widest shadow keeps the most information. Robo found it by itself, then found the next-widest direction at right angles to the first.
- With the pancake, fruit and pencil, one or two directions kept almost everything, so the flat picture still shows the real pattern (you can even see the three kinds of fruit apart).
- The ball is round, so every shadow is about as wide. Squashing it always loses a lot. PCA helps most when the numbers move together.
How it works
Find the middle
Robo slides the whole cloud so its middle sits at zero.
Measure the stretch
It makes a little table of how much the cloud stretches in each direction, and how the numbers move together.
Swing the arrow
It starts from your torch and keeps nudging the arrow towards the stretchiest way, until it stops moving.
Squash
Keep the widest one or two directions, drop the rest, and draw the flat picture.
For grown-ups: what's really going on
This is principal component analysis (PCA). With centred data X (n × 3), the sample covariance matrix is C = XᵀX / (n − 1). Projecting onto a unit vector u gives a 1-D "shadow" whose variance is uᵀCu. The first principal component maximises that, and by the Rayleigh quotient it is the eigenvector of C with the largest eigenvalue λ₁.
- "Your shadow keeps X%" is
uᵀCu / tr(C). The bars are the explained variance ratiosλᵢ / Σλ. The dashed line shows that your torch can never beat bar 1, nor go below bar 3. - Robo's animated search is power iteration,
v ← Cv / ‖Cv‖, started from your torch direction. It converges to the top eigenvector at a rate set byλ₂/λ₁, which is why the ball (nearly equal eigenvalues) wanders. - All three components come from a cyclic Jacobi eigen decomposition of the symmetric 3 × 3 covariance matrix. They are orthogonal. In practice libraries use the SVD of
X, which is more stable. - "Squash it flat" removes the third component: each point becomes
x − (x·v₃)v₃. The mean squared error of that reconstruction equals the dropped variance,λ₃(up to the n − 1 factor). - PCA is linear and depends on units: on real data with mixed units (cm, grams) you usually standardise each feature first. Curved structure needs non-linear methods such as kernel PCA, t-SNE or UMAP.
Every cloud is generated from a seeded random generator (mulberry32), so the same seed always gives the same dots.