Finding Groups

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

Challenges

Beat Robo: on the pancake, fruit or pencil, turn your torch until your shadow keeps at least 95% of the widest one, before Robo looks.
Thinnest shadow: on the pancake, aim your torch so its shadow keeps less than 3% of the spread. Hint: shine it straight through the flat side.
No best side: ask Robo to study the ball. See that no direction is much better than the others (the top bar stays under 50%).

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?

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.