Giter Club home page Giter Club logo

svd-python-implementation's Introduction

SVD-python-implementation

An implementation of Single Value Decomposition(SVD) in python

What is SVD

SVD is a kind of decomposition technique that can be used on matrix in any size even non-square matrix.

image
If A matrix is a mxn matrix, then U matrix is a mxm orthogonal matrix and V is also a nxn orthogonal matrix.
Sigma is a mxn matrix, and the non-zero value inside sigma is called the singular values of this matrix.
U and V are also known as the left and right singular vectors of A.

How to compute SVD

Step 1. Calculate U or V

U and V can be computed by the following equation
image

The equations are the eigen-decomposition of AA_T and A_TA.
Because AA_T and A_TA are symmetric matrix, the eigenvalues are guaranteed to be real value.
The square root of the eigenvalues here are the singular value mentioned in above.
And U and V are the eigenvectors which will be orthogonal to each other for each distinct eigenvalue.

Step 2. Calculate the other one

However, the computed U and V cannot form the A we want, because the sign of U and V can be arbitrary in eigen-decomposition of A.
The final U and V are coupled in a special way, so the above equation cannot pick out both U and V at the same time.
Therefore, the formal way is to calculate either U or V first then decide the other one with the following equations
image

Step 3. Finalize the matrix and make them orthognoal matrix

Sometimes the U or V calculated through the above steps will contain non-orthogonal vectors or zero column vectors.
This is due to the fact that mxn matrix can only provide a maximum amount of orthognal vectors of min(m, n).

For example, if A is a 2x4 matrix, and U is calculated through step1. When V is calculated through step 2, two columns of V will become zero. Even if the V is calculated first, the first step cannot guarantee the orthognoality of V because of two zero eignevalues.

Therefore the last step is to make U or V orthogonal. This can be done through calculating a system of linear equations. If U is 2x2 and V is 4x4, and we assume that V has two non-orthogonal vectors witch is the last two vectors. These two vectors can be calculated by finding the solution of equations that makes the dot product with the first two vector zero.

Assuem V looks like this
image
Two equations can be found by calculating the dot product with the first two vectors
image
From two equations four variables, we can assign arbitrary value to the free variables. Here we assign the free variables to be 1.
image
Normalize this vector, and place it back to V
image
Continue with the same process again, then the last vector can also be found.

Simpler flow of calculating SVD

  1. Calculate U or V with the Step 1 equation
  2. Calculate the other matrix with the Step 2 equation
  3. Make all matrices orthognal by solving the system of equations as Step 3

svd-python-implementation's People

Contributors

longhongc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.