Skip to content

These are the code implementation of the random SVD based on Cpp. It is tested using Python.

License

Notifications You must be signed in to change notification settings

doloMing/random-singular-value-decomposition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random SVD Principle and CMake Usage Guide

1. Random SVD Principle

1.1 Overview

Random Singular Value Decomposition (Random SVD) is a dimensionality reduction technique used for high-dimensional data. It approximates the singular value decomposition of a matrix through random projections, making it effective for handling large-scale datasets.

1.2 Mathematical Principle

Given a matrix ( A \in \mathbb{R}^{m \times n} ), its Singular Value Decomposition (SVD) can be expressed as:

[ A = U \Sigma V^T ]

where:

  • ( U ) is an ( m \times m ) orthogonal matrix containing the left singular vectors.
  • ( \Sigma ) is an ( m \times n ) diagonal matrix containing the singular values.
  • ( V ) is an ( n \times n ) orthogonal matrix containing the right singular vectors.

1.3 Random Projection

The core idea of Random SVD is to reduce computational complexity through random projection. The specific steps are as follows:

  1. Generate a Random Matrix: Generate a random matrix ( \Omega \in \mathbb{R}^{n \times k} ), where ( k ) is the desired number of features.

  2. Compute Projection: Compute ( Y = A \Omega ), resulting in a smaller matrix ( Y \in \mathbb{R}^{m \times k} ).

  3. QR Decomposition: Perform QR decomposition on ( Y ) to obtain the orthogonal matrix ( Q ) and the upper triangular matrix ( R ):

[ Y = QR ]

  1. Compute Matrix B: Compute ( B = Q^T A ), and then perform SVD on ( B ):

[ B = U_B \Sigma_B V_B^T ]

  1. Recover U Matrix: Finally, the left singular vectors ( U ) can be obtained as ( U = Q U_B ).

1.4 Summary of Formulas

The steps of Random SVD can be summarized as:

[ Y = A \Omega ] [ Q, R = \text{QR}(Y) ] [ B = Q^T A ] [ B = U_B \Sigma_B V_B^T ] [ U = Q U_B ]

2. CMake Usage Guide

2.1 Download CMake

  1. Visit the CMake official website.
  2. Choose the appropriate installation package for your operating system.
  3. Follow the installation wizard to complete the installation.

2.2 Modify CMakeLists.txt

Create or modify the CMakeLists.txt file in the project root directory with the following content:

2.3 Compile Files Using CMake

  1. Open a terminal (command prompt or terminal).

  2. Navigate to the project root directory.

  3. Create a build directory:

    mkdir build
    cd build
  4. Run CMake to generate build files:

    cmake ..
  5. Compile the project:

    cmake --build .

2.4 Run Tests

  1. In the build directory, find random_svd.dll and load it via Python. Then, run the test file:

    python test.py
  2. Check the output to ensure the program runs correctly.

3. Conclusion

Through the above steps, you can understand the principles of Random SVD based on its C++ version. Random SVD is an efficient dimensionality reduction technique suitable for handling large-scale datasets.

About

These are the code implementation of the random SVD based on Cpp. It is tested using Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published