Class: RandSVD

Inherits:
Object
  • Object
show all
Defined in:
lib/randsvd.rb,
lib/randsvd/version.rb

Overview

RandSVD is a class that performs truncated singular value decomposition using a randomized algorithm.

Constant Summary collapse

VERSION =
'0.2.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.seedObject (readonly)

Returns the value of attribute seed.



10
11
12
# File 'lib/randsvd.rb', line 10

def seed
  @seed
end

Class Method Details

.gesdd(mat, k, t = 0, seed = nil) ⇒ Array<NMatrix>

Compute the randomized singular value decompostion using NMatrix::LAPACK.gesdd method.

Parameters:

  • mat (NMatrix)

    The m-by-n input matrix to be decomposed.

  • k (Integer)

    The number of singular values.

  • t (Integer) (defaults to: 0)

    The number of iterations for orthogonalization.

  • seed (Integer) (defaults to: nil)

    The random seed used to generate the random matrix.

Returns:

  • (Array<NMatrix>)

    Returns array containing the m-by-k matrix of left-singular vectors, the k-by-1 matrix containing the singular values in decreasing order, and the k-by-n transposed matrix of right-singular vectors.



42
43
44
45
46
# File 'lib/randsvd.rb', line 42

def gesdd(mat, k, t = 0, seed = nil)
  seed ||= srand
  @seed = seed
  rsvd(mat, k, t, 1)
end

.gesvd(mat, k, t = 0, seed = nil) ⇒ Array<NMatrix>

Compute the randomized singular value decompostion using NMatrix::LAPACK.gesvd method.

Parameters:

  • mat (NMatrix)

    The m-by-n input matrix to be decomposed.

  • k (Integer)

    The number of singular values.

  • t (Integer) (defaults to: 0)

    The number of iterations for orthogonalization.

  • seed (Integer) (defaults to: nil)

    The random seed used to generate the random matrix.

Returns:

  • (Array<NMatrix>)

    Returns array containing the m-by-k matrix of left-singular vectors, the k-by-1 matrix containing the singular values in decreasing order, and the k-by-n transposed matrix of right-singular vectors.



24
25
26
27
28
# File 'lib/randsvd.rb', line 24

def gesvd(mat, k, t = 0, seed = nil)
  seed ||= srand
  @seed = seed
  rsvd(mat, k, t, 0)
end