Sparse Matrices & Iterative Methods
Efficient storage and solution techniques for large-scale systems where zeros dominate.
Application: Latent Semantic Analysis
Consider document analysis (NLP). We map terms to documents.
D1: "I love numerical analysis"
D2: "I do not love numerical analysis, but I love linear algebra."
| I | love | numerical | linear | algebra | |
|---|---|---|---|---|---|
| D1 | 1 | 1 | 1 | 0 | 0 |
| D2 | 1 | 2 | 0 | 1 | 1 |
In real world applications, this matrix $X$ is massive and mostly zeros.
Sparse Matrices
Definition
An $m \times n$ matrix is sparse if it has $\mathcal{O}(\min(m, n))$ nonzero entries. Roughly a constant number of nonzeros per row.
"Matrices that allow special techniques to take advantage of the large number of zero elements." — J. Wilkinson
The Economic Goal
Perform standard matrix computations without storing the zeros.
Sparse Add: $\mathcal{O}(nnz(A) + nnz(B))$
Storage Formats
COO (Coordinate Format)
Store $(row, col, value)$ tuples. Simple, good for entry.
JR = [ 1, 1, ... ]
JC = [ 1, 4, ... ]
CSR (Compressed Sparse Row)
Compress the row indices. Fast row access.
JA = [ col_indices ... ]
IA = [ row_offsets ... ]
Diagonal
Ellpack
Linked List
Skyline
Interactive Example
Consider Matrix $A$:
CSR Representation
AA: [7, 1, 2, 2, 2, 2, 5, 5, 6, 4]
JA: [1, 2, 3, 2, 4, 4, 5, 5, 6]
IA: [1, 2, 4, 6, 7, 9]
Sparse Operations
Matrix-Vector ($z = Ax$)
Cost: $\mathcal{O}(nnz)$
Matrix-Matrix ($Z = AB$)
Problem: $Z$ is sparse but structure is unknown beforehand.
Iterative Methods
Instead of direct factorization (like LU), we iteratively improve an approximate solution $x_k$.
Basic Idea
Split $A = N + M$. Then $Ax = b \Rightarrow (N+M)x = b \Rightarrow Nx = b - Mx$.
Careful choice of $N$ and $M$ makes this effective.
🧠 Final Challenge +20 XP
In Compressed Sparse Row (CSR) format, what does the `IA` array store?