Skip to content

Japanese-Maple/SVD-PCA

Repository files navigation

PCA, Custom C-Optimized SVD

This project provides a high-performance implementation of Single Value Decomposition (SVD), followed by the PCA itself. It bridges the gap between low-level efficiency and high-level data science by utilizing a custom-compiled C shared library for Eigendecomposition while maintaining the flexibility of Python (NumPy/PyTorch) for data manipulation.


Key Features

  • Custom C Backend: Implements the QL Algorithm with Wilkinson shifts for fast and numerically stable Eigendecomposition.
  • Performance Optimized: Compiled with -O3 and -fPIC to leverage CPU-level optimizations via a shared library (libqr.so).
  • Advanced Visualization: Support for 2D/3D density projections, variance analysis, and image compression.
  • Hybrid Architecture: Seamlessly integrates C-based math helpers with modern Python data stacks like PyTorch and Matplotlib.

Project Structure

  • qr.c: The core C source file containing the Wilkinson Symmetric QR/QL algorithms.
  • libqr.so: Shared library
  • PCA_via_SVD.ipynb: Demonstration of PCA on synthetic 2D and real datasets and high-dimensional variance visualization.
  • svd.ipynb: Practical application of SVD for image processing and reconstruction.
  • utilities.py: Helper functions, featuring visualizations and computation.

Visualizations

1. Principal Component Projections

Here I show how the algorithm identifies the axes of maximum variance in a synthetic dataset. Principal Component Projections

2. SVD-Based Image Reconstruction

Comparing original images against reconstructed versions using varying numbers of principal components. Image Reconstruction Example

Releases

No releases published

Packages

 
 
 

Contributors

Languages