Singular Value Decomposition

October 26th, 2009  |  Published in Machine Learning, Programming  |  3 Comments

Singular Value Decomposition is something I’ve been wanting to wrap my head around for a while now that I am getting really into Machine Learning. Unfortunately, a lot of the material out there is often hard to understand and believe it or not there are few libraries that are available in .NET.

So what is singular value decomposition (SVD)? Probabably, the best description I’ve run across is:

Singular Value Decomposition is a way of factoring matrices into a series of linear approximations that expose the underlying structure of the matrix. SVD is extraordinarily useful and has many applications such as data analysis, signal processing, pattern recognition, image compression, weather prediction, and Latent Semantic Analysis. [iMetaSearch]

SVD formula is:

M=U∑V*

M is simply a m-by-n matrix, U form a set of orthonormal “output” basis vector directions for M, Σ are the singular values, which can be thought of as scalar “gain controls” by which each corresponding input is multiplied to give a corresponding output and V* form a set of orthonormal “input” or “analysing” basis vector directions for M. The best walk through I’ve come across is over at iMetaSearch here.

A lack of good .NET Libraries.

I tried out four different libraries: SmartMathLibrary, LatoolNet, ALGLIB and DotNetMatrix. Out of these four I could only get two of them completely working and I ultimately came to the conclusion that SmartMathLibrary was the best for doing SVD.

The Code

Here is the code to replicate this tutorial over at MIT.

using System;
using SmartMathLibrary;

namespace MatrixTest2
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            SVDTest();
            Console.ReadLine();
        }

        private static void SVDTest()
        {
            // Create/load array
            var holeDifficulty = new double[,]
                                     {
                                         {2, 1, 0, 0},
                                         {4, 3, 0, 0}
                                     };

            // Load in to Matrix
            var a = new Matrix(holeDifficulty);

            // Singular Value Decomposition
            var SVD = new SingularValueDecomposition(a);
            SVD.ExecuteDecomposition();

            // Get the general vector
            GeneralVector s = SVD.S;

            // Display results
            Console.WriteLine(a.Transpose().ToString());
            Console.WriteLine();
            Console.WriteLine(s.ToString());
            Console.WriteLine();
            Console.WriteLine(SVD.U.ToString());
            Console.WriteLine();
            Console.WriteLine(SVD.V.ToString());
        }
    }
}

Additional Resources

iMetaSearch

IR Math with Java : TF, IDF and LSI

SVD Tutorial

Responses

  1. Ririz says:

    August 15th, 2011at 7:55 am(#)

    how to calculate inverse matrix using SmartMathLibrary?
    please help…

  2. Latent Semantic Indexing « Wiki says:

    August 30th, 2011at 6:53 am(#)

    [...] commonly described as a “indexing and retrieval method that uses a mathematical technique called Singular Value Decomposition (SVD) to identify patterns in the relationships between the terms and concepts contained in an [...]

  3. Plotting Documents & Words: Using Latent Semantic Indexing « Wiki says:

    August 31st, 2011at 2:48 am(#)

    [...] the last blog post we looked over a couple of great papers talking about using Singular Value Decomposition (SVD) to do Latent Semantic Indexing (LSI) using the SmartMathLibrary. Now that we have the results [...]

Leave a Response


Archives

Calendar

February 2012
S M T W T F S
« Aug    
 1234
567891011
12131415161718
19202122232425
26272829