A Cloud With No Favourite Direction — hard Dimensionality Reduction & Embeddings problem | Incognition
A Cloud With No Favourite Direction
30 pts · 30 coins
Dimensionality Reduction & EmbeddingsHard
A Cloud With No Favourite Direction
The dimensionality-reduction pipeline — centre the data, build the covariance matrix, find its eigenvectors, project onto them — hands you new coordinates that are no longer correlated with each other. But they still have very different spreads: the coordinate along PC1 varies a lot, the one along PC2 far less.
Whitening adds one last move. Divide each new coordinate by its own standard deviation, so that every direction ends up with variance exactly 1. The cloud comes out round, with no direction more stretched than any other.
Task: write whiten(points) for 2D data. points is a list of [x,y] pairs. Return the whitened pair for every point, in the same order, with each number rounded to 4 decimal places.
Centre. Subtract the mean point from every point, giving centred pairs (dx,dy).
Covariance. With n points, and dividing by n:
C=[abbc],a=n1∑dx2,b=n1∑dxdy,c=n1∑dy2
Eigenvectors. Find the eigenvalues of C, λ1>λ2, and a unit eigenvector for each: u1 for λ1 and u2 for λ2. Flipping an eigenvector gives another eigenvector, so to make the answer unique, orient each one so that its first component is positive — or, if its first component is 0, so that its second component is positive.
Rotate, then rescale. A centred point d becomes
[λ1d⋅u1,λ2d⋅u2]
You may assume there are at least three points, they don't all lie on one straight line, and the two eigenvalues are different — so both are positive, and each has a single eigenvector direction.
Example.
Here C=[5445], with eigenvalues 9 and 1. Whatever the input, each output coordinate should come out with mean 0 and variance 1 — a handy check on your own work.