Kernel PCA
Implement Kernel PCA using the RBF kernel.
Standard PCA finds linear projections. Kernel PCA applies the kernel trick to find nonlinear projections:
- Compute the RBF kernel matrix:
- Center the kernel matrix: where is the matrix with all entries
- Compute eigenvalues/eigenvectors of
- Return the top eigenvector columns scaled by
For simplicity, this problem uses points and . Return the projected values rounded to 4 decimal places.
Note: Use power iteration to find the dominant eigenvector.
Example
X = [[0], [1], [2]] sigma = 1.0 k = 1
[[-0.6575], [0.0], [0.6575]]
- The RBF kernel matrix is computed using the formula , resulting in a matrix.
- The kernel matrix is then centered to obtain , where is a matrix with all entries .
- Using power iteration, the dominant eigenvector of is found, and its components are scaled by the square root of the corresponding eigenvalue .
- The resulting vector is then rounded to 4 decimal places, yielding the projected values .
Constraints
- X: 2D list of data points (n x d)
- sigma: RBF kernel width
- k: number of components (1)
- Return 2D list (n x k) of projected values, rounded to 4 decimal places