Giter VIP home page Giter VIP logo

ranola's Introduction

ranola

Build Status Codacy Badge

ranola is a library for low-rank matrix approximations by randomized algorithms (Randomized Numerical Linear Algebra aka RandNLA). Compared with standard deterministic algorithms, the randomized methods are often faster and produce accurate results. Empirical results show that a corresponding implementation can be faster than LAPACK on dense matrices.

At the moment the simplest direct scheme is implemented. It allows to ensure a minimal error in the final approximation of decompositions:

  • Singular value decomposition
  • Eigen value decomposition

Getting ranola

If you're using SBT, add the following line to your build file:

resolvers += "jitpack" at "https://jitpack.io"

libraryDependencies += "com.github.nikdon" % "ranola" % "v0.2.0"

For Maven:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.nikdon</groupId>
    <artifactId>ranola</artifactId>
    <version>v0.2.0</version>
</dependency>

Randomized schemes

  1. Generic scheme (§4.1) is designed for solving the fixed-rank problem, where the target rank of the input matrix is specified in advance. This algorithm works well for matrices whose singular values exhibit some decay, but they may produce a poor basis when the input matrix has a flat singular spectrum or when the input matrix is very large.

    val EigSym(lambda, evs) = EVDR.generic(A_dense, k = 3, nOverSamples = 2)
      
    val SVD(ur, sr, vr) = SVDR.generic(M, k = 3, nOverSamples = 10)
    
  2. Adaptive scheme (§4.2) can handle the fixed-precision problem with predifined computational tolerance. The CPU time requirements of schemes 1 and 2 are essentially identical.

    not implemented in v 0.2.0
  3. Power Iteration scheme (§4.3) requires 2*nIter + 1 times as many matrix–vector multiplies as scheme 1, but is far more accurate in situations where the singular values of matrix to decompose decay slowly. Scheme 3 targets the fixed-rank problem. In situations where it is critical to achieve nearoptimal approximation errors, one can increase the oversampling beyond standard recommendation overSamples = 5 all the way to overSamples = k without changing the scaling of the asymptotic computational cost. This procedure is vulnerable to round-off errors. The recommended implementation appears as scheme 4.

    val SVD(ur, sr, vr) = SVDR.viaPowerIteration(M, k = 3, nIter = 5, nOverSamples = 2)
      
    val EigSym(lambda, evs) = EVDR.viaPowerIteration(M, k = 3, nIter = 5, nOverSamples = 2)
    
  4. Subspace Iteration scheme (§4.4) is designed for solving the fixed-rank problem, where the target rank of the input matrix is specified in advance. This procedure is invulnerable to round-off errors in opposite to Power Iteration algorithm (§4.3).

    val SVD(ur, sr, vr) = SVDR.viaSubspaceIterations(M, k = 3, nIter = 5, nOverSamples = 2)
      
    val EigSym(lambda, evs) = EVDR.viaSubspaceIterations(M, k = 3, nIter = 5, nOverSamples = 2)
    
  5. Fast Generic scheme (§4.5) uses subsampled random Fourier transform (SRFT) that can be used to identify a nearoptimal basis for a rank-k matrix using l = (k + log(M.cols)) log(k) samples (overSamples = (k + log(M.cols)) log(k) - k). In practice, setting overSamples = 10 or overSamples = 20 is typically more than adequate. It allows to compute an approximate rank-(l) factorization of a general dense m-by-n matrix in roughly O(mn log(k + overSamples)) flops.

    not implemented in v 0.2.0
    

Number of oversamples

Number of oversamples depends on:

  • Matrix dimensions. Very large matrices may require more oversampling.

  • Singular spectrum. The more rapid the decay of the singular values, the less oversampling is needed. In the extreme case that the matrix has exact rank k, it is not necessary to oversample.

  • Random test matrix. Gaussian matrices succeed with very little oversampling, such as overSamples = 5 or overSamples = 10. There is rarely any advantage to select overSamples > k.

Add support of other math libraries

Anyone is welcome to customize ranola. The simplest way to it is add support of different math libraries. To do this find in MatrixOp.scala implicit values for custom matrix operations and add yours. For example, currently implemented the one one based on scala breeze:

implicit val BreezeDoubleMatrixOps = new MatrixOps[Double, breeze.linalg.DenseMatrix, breeze.linalg.DenseVector] {
    ...
}

Next step is to implement implicits in SVDR.scala and EVDR.scala:

implicit val breezeDoubleMatrixSVDR = new Decomposition[Double, DenseMatrix, DenseVector, DenseSVD] {
    ...
}

implicit val breezeDoubleMatrixEVDR = new Decomposition[Double, DenseMatrix, DenseVector, DenseEigSym] {
...
}

To use the custom implementation simply import related implicits:

import ranola.EVDR.Implicits._

import ranola.SVDR.Implicits._

And that is it, enjoy.

Analytics

ranola's People

Contributors

nikdon avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

ranola's Issues

Implement randomized subspace iteration algorithm

See algorithm 4.4 of "Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions" Halko, et al., 2009 (arXiv:909) [[http://arxiv.org/pdf/0909.4061]]

Implement fast randomized range finder algorithm

See algorithm 4.5 of "Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions" Halko, et al., 2009 (arXiv:909) [[http://arxiv.org/pdf/0909.4061]]

Implement adaptive randomized range finder

See algorithm 4.2 of "Finding structure with randomness: Stochastic algorithms for constructing approximate matrix decompositions" Halko, et al., 2009 (arXiv:909) [[http://arxiv.org/pdf/0909.4061]]

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.