C.W.K.
Stream
Lesson 08 of 08 · published

Eigen Applications: PCA, PageRank, Quantum

~10 min · pca, pagerank, svd, quantum

Level 0Math Novice
0 XP0/59 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

Three Worlds, One Idea

Eigen-decomposition is the same operation appearing in three radically different contexts. Each is worth 30 seconds.

PCA — Finding the Big Directions in Data

You have a dataset where each row is a sample and each column is a feature. The covariance matrix tells you how features co-vary. PCA computes its eigenvectors: those eigenvectors are the directions in which your data has the most variation, ranked by eigenvalue size. Project the data onto the top eigenvectors and you've reduced 100-dim data to -dim with minimal information loss.

This is how you visualize 1000-dim embeddings on a 2D scatter plot. PCA picks the 2 directions that preserve as much "shape" of the data as possible.

PageRank — Finding the Important Pages

Google's original ranking algorithm models the web as a graph: each page is a node, each link is an edge. You build a matrix where is the probability of jumping from page to page . The dominant eigenvector of (the eigenvector with the largest eigenvalue) gives you a stationary probability distribution: "if a random surfer clicked links forever, what fraction of time would they spend on each page?" That distribution is the importance score.

The web has billions of pages. Computing the eigenvector exactly is impossible, but iterative algorithms (power iteration) converge to it surprisingly fast. That's PageRank.

Quantum Mechanics — States and Observations

In quantum mechanics, a physical system's state is a vector in a complex vector space. Observable quantities (energy, momentum, position) are operators (matrices). When you measure an observable, you get an eigenvalue of the operator, and the system's state collapses to the corresponding eigenvector. This is the math underneath "the cat is alive AND dead until you look" — superposition is a sum of eigenstates; measurement projects onto one.

SVD — Eigen for Rectangular Matrices

Eigenvalues only exist for square matrices. The Singular Value Decomposition generalizes: it factors any matrix where the singular values in play the role of eigenvalues. SVD powers recommender systems, latent semantic analysis, and image compression.

If a system has structure, that structure usually has a name and the name is "eigen-something." Spotting the eigen-decomposition under the hood of a method tells you what's actually being computed.

Track Reward

You walked through the eigen-dungeons and lived. Matrices are transformations. The identity is the do-nothing. The inverse is the undo. Determinants are souls. Eigenvectors are favorite directions. From here on, when someone says "transformer attention" or "covariance projection" or "spectral method," you'll know the chassis underneath.

Code

PCA in 4 lines·python
import numpy as np

# Tiny PCA — 2D data with strong correlation, find the principal axes
np.random.seed(0)
X = np.random.randn(200, 2)
X[:, 1] = 0.7 * X[:, 0] + 0.3 * X[:, 1]   # induce correlation

# 1) Center the data
X = X - X.mean(axis=0)

# 2) Covariance matrix
C = (X.T @ X) / (len(X) - 1)

# 3) Eigendecomposition
eigvals, eigvecs = np.linalg.eigh(C)       # use eigh for symmetric matrices
print("eigenvalues:", eigvals)             # smaller, larger
print("first principal direction:", eigvecs[:, -1])  # largest-eigenvalue eigenvector
PageRank in 4 lines·python
import numpy as np

# Toy PageRank — 4-page web
M = np.array([[0,   0.5, 0.5, 0  ],
              [0.5, 0,   0,   1  ],
              [0.5, 0,   0,   0  ],
              [0,   0.5, 0.5, 0  ]])

# Power iteration — converges to the dominant eigenvector
rank = np.ones(4) / 4
for _ in range(50):
    rank = M @ rank
    rank = rank / rank.sum()
print("PageRank scores:", rank)

External links

Exercise

Take any 100×5 dataset (random or real). Standardize each column. Compute PCA via eigendecomposition of the covariance matrix. Plot the first two principal components against each other and notice how the data spreads.
Hint
X = (X - X.mean(axis=0)) / X.std(axis=0), then C = X.T @ X / (len-1), then eigvals, eigvecs = np.linalg.eigh(C). The first two principal axes are eigvecs[:, -1] and eigvecs[:, -2].

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue
💛 by Pippahappy

Comments 2

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.
  1. Elechemist
    Elechemist

    아직 완전히 와닿진 않지만 eigen을 이렇게 쓰는거구나. pagerank알고리즘은 천재적이다

    import numpy as np import matplotlib.pyplot as plt

    rng = np.random.default_rng(42)

    잠재 구조가 있는 100x5 데이터: 두 숨은 요인이 5개 열을 만든다

    n = 100 f1 = rng.standard_normal(n) f2 = rng.standard_normal(n) X = np.column_stack([ f1 + 0.3rng.standard_normal(n), f1 + 0.3rng.standard_normal(n), f2 + 0.3rng.standard_normal(n), f2 + 0.3rng.standard_normal(n), 0.5f1 + 0.5f2 + 0.3*rng.standard_normal(n), ])

    1) 열별 표준화 (평균 0, 표준편차 1)

    Xs = (X - X.mean(axis=0)) / X.std(axis=0)

    2) 공분산 행렬

    C = (Xs.T @ Xs) / (n - 1)

    3) 대칭행렬 고유분해

    vals, vecs = np.linalg.eigh(C)

    4) 큰 고유값 순으로 정렬

    order = np.argsort(vals)[::-1] vals = vals[order] vecs = vecs[:, order]

    5) 처음 두 주성분으로 사영

    PC = Xs @ vecs[:, :2]

    print("고유값:", np.round(vals, 4)) print("분산 설명 비율:", np.round(vals / vals.sum(), 4)) print("누적:", np.round(np.cumsum(vals / vals.sum()), 4))

    6) PC1 vs PC2 산점도

    fig, ax = plt.subplots(figsize=(7, 6)) ax.scatter(PC[:, 0], PC[:, 1], s=40, alpha=0.7, edgecolor='white', linewidth=0.5) ax.axhline(0, color='gray', lw=0.5) ax.axvline(0, color='gray', lw=0.5) ax.set_xlabel(f"PC1 ({vals[0]/vals.sum()*100:.1f}%)") ax.set_ylabel(f"PC2 ({vals[1]/vals.sum()*100:.1f}%)") ax.set_title("PCA: first two principal components") ax.set_aspect('equal', adjustable='datalim') plt.tight_layout() plt.savefig('pca_scatter.png', dpi=130)

    💛 by Pippahappy
    1. Pippa
      Pippa· warmElechemistElechemist

      맞아요, 아직 손에 완전히 잡히지 않아도 PCA 코드가 eigen의 쓰임을 아주 잘 보여줘요. 공분산 행렬의 eigenvector가 “데이터가 가장 많이 퍼지는 방향”이고, 큰 eigenvalue가 “그 방향에 실린 정보량”이라고 보면 됩니다. PageRank도 같은 뿌리예요: 연결 구조 행렬에서 오래 남는 방향을 찾는 거니까요.