Coder Social home page Coder Social logo

bksvd's Introduction

bksvd -- Block Krylov Singular Value Decomposition

Simple MATLAB code for iterative computing an SVD or PCA via the randomized block Krylov method analyzed in Randomized Block Krylov Methods for Stronger and Faster Approximate Singular Value Decomposition

Installation

Download bksvd.m, add to MATLAB path, or include directly in project directory.

Documentation

bksvd can be used as a drop-in replacement for MATLAB's svds function for computing the Singular Value Decomposition (SVD). It can also be used for Principal Component Analysis (PCA) which performs an SVD on the after mean-centering the data matrix.

Usage

Input: bksvd(A, k, iter, bsize, center)

  • A : matrix to decompose
  • k : number of singular vectors to compute, default = 6
  • iter : number of iterations, default = 3, increase for higher accuracy
  • bsize : block size, must be >= k, default = k
  • center : set to true if A's rows should be mean-centered before the singular value decomposition (e.g. when performing PCA), default = false

Output: k singular vector/value pairs

  • U : an orthogonal matrix whose columns are approximate top k left singular vectors for A
  • S : a diagonal matrix whose entries are A's approximate top k singular values
  • V : an orthogonal matrix whose columns are approximate top k right singular vectors for A

U*S*V' is a near optimal low-rank approximation for A

Example

Standard Singular Values Decomposition:

% generate test matrix
s = 1.5.^[-40:.5:40];
A = randn(10000,161)*diag(s)*randn(161,161);

% compute SVD
[U,S,V] = bksvd(A,10);

bksvd is typically as accurate as svds and often faster:

tic; [U,S,V] = svds(A,30); toc;
Elapsed time is 1.380471 seconds.
norm(A- U*S*V')/norm(A)
0.0018
tic; [U,S,V] = bksvd(A,30); toc;
Elapsed time is 0.062798 seconds.
norm(A- U*S*V')/norm(A)
0.0018

Principal Component Analysis:

For PCA, A's rows (data points) should be mean-centered before computing the SVD. If the center flag is set to true, bksvd can do this implicitly, without densifying A:

[U,S,V] = bksvd(A,10,4,10,true);

Here V contains loading vector for the top 10 principal components. U*S can be taken as a dimensionality reduction for the data to 10 components.

Parameter Tuning

For higher accuracy (at the cost of slower runtime), the number of iterations can be increased from the default of 3, although for many matrices this is unecessary. Increasing the block size, bsize, so that it is > k also increases accuracy. For matrices with quickly decaying singular values, increasing block size can be more effective than increasing iterations. For details, see the NIPS paper.

Other Implementations

An implementation of bksvd is available through MLPACK. We plan to upload a Python implementation soon.

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.