v9.1.1
Menu

Power Iteration

mediumFREEEigenvalues & EigenvectorsLinear Algebra, Numerical MethodsCV: Mathematical Foundations

Implement the power iteration method to find the dominant eigenvector of a matrix. This task involves understanding the underlying concept of eigenvalues and eigenvectors, which are crucial in linear algebra and have numerous applications in computer vision and machine learning.

The power iteration method is an iterative algorithm that finds the eigenvector corresponding to the largest eigenvalue of a matrix AA. The process involves starting with a random vector v0\mathbf{v}_0 and iteratively updating it using the matrix AA. The key idea is to repeatedly apply the matrix AA to the current vector and normalize the result.

Here are the general steps:

  1. Initialize a random vector v0\mathbf{v}_0
  2. Iterate: update the vector using the matrix AA and normalize the result
  3. Repeat until convergence
vk+1=Avk∣∣Avk∣∣\mathbf{v}_{k+1} = \frac{A\mathbf{v}_k}{||A\mathbf{v}_k||}

This technique is widely used in principal component analysis (PCA).

Example

Input
power_iteration([[2, 0], [0, 1]], [1, 1], 10)
Output
[1.0, 0.001]
Reasoning
  • Inputs: A=[2001]A = \begin{bmatrix}2 & 0\\ 0 & 1\end{bmatrix} is diagonal, so its eigenvalues are λ1=2\lambda_1 = 2 (eigenvector [1,0][1, 0]) and λ2=1\lambda_2 = 1 (eigenvector [0,1][0, 1]). The start vector v0=[1,1]\mathbf{v}_0 = [1, 1] mixes both equally, and iterations is 10.
  • Step 1: Av0=[2,1]A\mathbf{v}_0 = [2, 1], with length 22+12=5\sqrt{2^2 + 1^2} = \sqrt{5}, so v1≈[0.8944,0.4472]\mathbf{v}_1 \approx [0.8944, 0.4472].
  • Step 2: Av1A\mathbf{v}_1 is proportional to [4,1][4, 1]; dividing by 17\sqrt{17} gives v2≈[0.9701,0.2425]\mathbf{v}_2 \approx [0.9701, 0.2425]. The first component doubles relative to the second every step.
  • After 10 steps: the direction is [210,1]=[1024,1][2^{10}, 1] = [1024, 1], and dividing by 10242+1\sqrt{1024^2 + 1} gives ≈[0.9999995, 0.000977]\approx [0.9999995,\ 0.000977], which rounds to [1.0, 0.001] at 4 decimal places.
  • Notice: the leftover second component shrinks by the factor λ2/λ1=12\lambda_2 / \lambda_1 = \tfrac{1}{2} per iteration, so a larger eigenvalue gap converges faster. Every iterate has length 1, which is why the output sits on the unit circle near [1,0][1, 0].

Constraints

  • A is a square matrix (n×n) where 2 ≤ n ≤ 10
  • Perform exactly the specified number of iterations
  • Normalize the vector after each iteration
  • Return the final vector rounded to 4 decimal places

Learn this in

More from CV: Mathematical Foundations

solution.py

Test results

Sign in to run your code against the test cases.