Tutorials › High-Dimensional Genomic Data Analysis › Rank-K Reconstruction and PCA Compression

Dimension Reduction and Clustering · Tutorial 602 of 795

Rank-K Reconstruction and PCA Compression

Learn how PCA truncation reconstructs profiles, how to calculate the resulting squared error, and how to weigh compression against information loss.

Intermediate 10 min read

What You'll Learn

  • Express PCA reconstruction as a rank-k approximation using scores and loadings.
  • Derive why truncating the singular value decomposition minimizes squared error.
  • Calculate total and profile-specific reconstruction errors from discarded components.
  • Compare reconstruction error and storage needs across choices of k.
  • Identify how preprocessing and the error metric shape what a reconstruction preserves.

From PCA Coordinates to Reconstructed Profiles

PCA can represent each profile using a smaller set of component scores, but those scores are useful for compression only if we can reconstruct an approximation to the original measurements. In genomic data, a profile might be a sample measured on many features. Retaining fewer components means storing fewer numbers, at the cost of losing some variation in those profiles.

Let \(X\) be an \(n\times p\) data matrix after the chosen centering and scaling steps: rows are profiles, columns are features, and \(x_{ij}\) is the processed value for profile \(i\) and feature \(j\). As in the earlier material on centering and scaling, the chosen preprocessing determines the scale on which PCA operates. Write the singular value decomposition as \(X=UDV^\mathsf{T}\), with singular values \(d_1\ge d_2\ge\cdots\ge d_r>0\), where \(r\) is the rank of \(X\). The columns of \(U\) and \(V\) are orthonormal.

Definition: The rank-\(k\) PCA reconstruction of \(X\), for \(0\le k\le r\), is \(X_k=U_kD_kV_k^\mathsf{T}\), where \(U_k,D_k,V_k\) retain the first \(k\) singular components. Equivalently, \(X_k=T_kV_k^\mathsf{T}\), where \(T_k=XV_k=U_kD_k\) contains the \(k\) component scores. The squared reconstruction error is \(\|X-X_k\|_F^2=\sum_{i=1}^{n}\sum_{j=1}^{p}(x_{ij}-(X_k)_{ij})^2\), the total squared error across all matrix entries.

Each row of \(X_k\) is a reconstructed profile. Its values are obtained by taking that profile’s \(k\) scores and combining them with the corresponding feature loadings. With \(k=r\), the reconstruction is exact. With fewer components, the omitted directions contribute to the reconstruction error.

Why Truncation Minimizes Squared Error

The rank-\(k\) reconstruction is not just one convenient way to compress the matrix: among all matrices of rank at most \(k\), it has the smallest total squared error measured by the Frobenius norm. This result applies to a fixed, finite matrix and the stated squared-error objective. It does not say that this objective is the right one for every scientific purpose.

Theorem: If \(A\) is any \(n\times p\) matrix with rank at most \(k\), then \(\|X-A\|_F^2\ge\sum_{j=k+1}^{r}d_j^2\). The truncated SVD \(X_k\) attains equality, so it minimizes squared reconstruction error over all rank-at-most-\(k\) matrices.

A short derivation explains both the optimality and the error formula. Let \(P\) be the orthogonal projection onto the row space of \(A\). Because every row of \(A\) lies in this space, \(A(I-P)=0\). Right multiplication by an orthogonal projection cannot increase the Frobenius norm, so

$$ \|X-A\|_F^2\ge \|(X-A)(I-P)\|_F^2=\|X(I-P)\|_F^2. $$

The eigenvectors of \(X^\mathsf{T}X\) are the right singular vectors \(v_j\), with eigenvalues \(d_j^2\). If the projection space has dimension at most \(k\), the greatest possible squared length retained by projecting onto it is \(\sum_{j=1}^{k}d_j^2\): a \(k\)-dimensional subspace captures most squared length by spanning the eigenvectors with the largest eigenvalues. Since \(\|X\|_F^2=\sum_{j=1}^{r}d_j^2\), the least possible squared residual is therefore \(\sum_{j=k+1}^{r}d_j^2\). The row space spanned by \(v_1,\ldots,v_k\) achieves this bound, and projecting \(X\) onto that space gives \(X_k\). Thus

$$ \|X-X_k\|_F^2=\sum_{j=k+1}^{r}d_j^2. $$

This formula also connects truncation to explained variance. The total squared magnitude of the processed matrix is \(\sum_{j=1}^{r}d_j^2\), and the fraction retained by the first \(k\) components is \(\sum_{j=1}^{k}d_j^2/\sum_{j=1}^{r}d_j^2\). The remaining fraction is the squared reconstruction error divided by the total squared magnitude. This is a statement about the chosen matrix scale and squared-error measure, not a guarantee that every feature or profile is reconstructed equally well.

Worked Reconstructions for Hypothetical Profiles

Worked Example: Reconstructing Four Profiles With Two Components

Consider this hypothetical centered matrix with four profiles and three features:

$$ X= \begin{bmatrix} 3&2&1\\ -3&2&-1\\ 3&-2&-1\\ -3&-2&1 \end{bmatrix}. $$

Its columns are mutually orthogonal and have lengths \(6\), \(4\), and \(2\), respectively. Hence its singular values are \(d_1=6,d_2=4,d_3=2\), with right singular vectors aligned with the three feature axes. Keeping \(k=2\) components retains the first two columns and replaces the third with zero:

$$ X_2= \begin{bmatrix} 3&2&0\\ -3&2&0\\ 3&-2&0\\ -3&-2&0 \end{bmatrix}. $$

For the first profile, the reconstruction is \((3,2,0)\) rather than \((3,2,1)\), so its squared error is \((3-3)^2+(2-2)^2+(1-0)^2=1\). Each of the other three profiles also has squared error \(1\), giving total error \(4\). The singular-value formula gives the same result: \(d_3^2=2^2=4\). The total squared magnitude is \(6^2+4^2+2^2=56\), so the retained fraction is \(52/56\approx0.9286\), or \(92.86\%\).

Worked Example: A Rank-One Reconstruction From Two Features

Suppose three hypothetical profiles have a centered two-feature matrix

$$ X= \begin{bmatrix} 1&1\\ -1&1\\ 0&-2 \end{bmatrix}. $$

The first column has squared length \(2\), the second has squared length \(6\), and their inner product is \(1(1)+(-1)(1)+0(-2)=0\). Thus the singular values are \(\sqrt{6}\) and \(\sqrt{2}\), and the leading right singular vector is the second feature axis. For \(k=1\), the reconstruction keeps the second column and sets the first to zero:

$$ X_1= \begin{bmatrix} 0&1\\ 0&1\\ 0&-2 \end{bmatrix}. $$

The squared errors for the three profiles are \(1,1,0\), so the total is \(2\). This also follows from the discarded singular value: \((\sqrt{2})^2=2\). The total squared magnitude is \(2+6=8\); therefore this reconstruction retains \(6/8=0.75\), or \(75\%\), of the total squared magnitude. In this example, the retained component reproduces the second feature exactly but not the first.

Worked Example: Choosing a Component Count for Compression

Use the four-profile matrix in the first example, and suppose the goal is to store the scores and loadings rather than all \(np\) matrix entries. Storing the original \(4\times3\) matrix requires \(np=12\) values. A rank-\(k\) representation requires \(nk+pk=k(n+p)\) values, not counting means, scales, or other metadata.

For \(k=1\), the representation requires \(1(4+3)=7\) values, fewer than the 12 original entries. Its error is \(d_2^2+d_3^2=4^2+2^2=20\), which is \(20/56\approx0.3571\) of the total squared magnitude. For \(k=2\), it requires \(2(4+3)=14\) values, more than the original matrix, while reducing error to \(d_3^2=4\). Thus \(k=2\) gives a better reconstruction but is not a storage saving under this simple count. In real applications, whether the representation saves space also depends on metadata and how values are stored.

Assumptions, Diagnostics, and Alternatives

The optimality result is exact for the chosen matrix, rank constraint, and unweighted sum of squared entrywise errors. It does not require that the entries follow a probability distribution. Its practical interpretation, however, depends on how the matrix was constructed. Centering, feature scaling, transformations, and the presence of missing values affect which differences count as large. The examples above use complete, centered matrices; PCA reconstruction of a matrix with missing entries requires a different treatment.

When inspecting a proposed compression, check the singular values and calculate the tail sum for the chosen \(k\). Also examine errors by profile or feature: a modest total error can conceal a large error for one profile or a particular feature. These checks do not change the theorem; they help establish whether its overall squared-error summary matches the intended use. Detailed analysis of reconstruction residual patterns is a distinct diagnostic task.

PCA truncation is one option among several. Keeping selected original features preserves their direct interpretation but does not generally minimize total squared error at a fixed number of retained features. Lossless storage preserves all recorded values but does not reduce the information in the matrix. Rank-\(k\) PCA instead uses dense linear combinations of features and gives the best rank-at-most-\(k\) approximation under Frobenius loss. Those components need not correspond to single genes or biological processes, and the result is not evidence of a causal or biological mechanism.

  • Changing scale changes the target. If features are standardized before PCA, squared error is measured on that standardized scale. Transforming a reconstruction back to the original units does not make its errors comparable across features in the same way.
  • A small total error is not a per-feature guarantee. The theorem minimizes the sum across all entries. It does not minimize the largest individual error or ensure equal accuracy across profiles.
  • Compression and reconstruction quality can conflict. Increasing \(k\) cannot increase the truncated-SVD squared error, but may increase storage and may provide little practical benefit.
  • Components are not always uniquely oriented. If singular values are repeated, different orthonormal bases can span the same optimal subspace. The reconstruction can be well-defined even when individual component directions are not unique.
Key takeaway: For a fixed preprocessed matrix and a rank limit \(k\), truncated PCA retains the directions with the largest singular values. Its total squared reconstruction error is exactly the sum of the squared singular values that were discarded.

Check Your Understanding

Use the singular-value error formula and the stated storage convention. Solutions follow the questions.

  1. A matrix has singular values \(7\) and \(3\). What is the squared reconstruction error for \(k=1\), and what fraction of the total squared magnitude is retained?
  2. A matrix has total squared magnitude \(100\). A chosen truncation discards components whose squared singular values sum to \(25\). What is its squared error and what fraction of total squared magnitude is lost?
  3. A matrix has \(n=20\) profiles and \(p=10\) features. Ignoring metadata, how many values are stored using \(k=2\), and what percentage fewer values is that than storing all matrix entries?
  4. Why can a rank-\(k\) approximation minimize squared error for the processed matrix without necessarily minimizing error in each feature’s original measurement units?

Solutions. (1) The error is \(3^2=9\). Total squared magnitude is \(7^2+3^2=58\), so the retained fraction is \(49/58\approx0.8448\), or \(84.48\%\). (2) The error is \(25\), and the fraction lost is \(25/100=0.25\), or \(25\%\). (3) The compressed representation stores \(k(n+p)=2(20+10)=60\) values, compared with \(np=200\). It stores \(140/200=70\%\) fewer values. (4) The error is measured on the scale of the processed matrix. Centering or scaling changes the scale and relative weighting of feature differences, so minimizing squared error there does not necessarily minimize error measured in each feature’s original units.

Clinical Biostats