Module: Numo::Linalg

Defined in:
lib/numo/linalg/randsvd.rb

Overview

Numo::Linalg : Linear Algebra library with BLAS/LAPACK binding to Numo::NArray

Class Method Summary collapse

Class Method Details

.randsvd(a, k, t = 0, driver: 'svd', job: 'A', seed: nil) ⇒ Object

Compute the randomized singular value decompostion.

Parameters:

  • a (Numo::NArray)

    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.

  • driver (String) (defaults to: 'svd')

    The driver parameter of Numo::Linalg.svd.

  • job (String) (defaults to: 'A')

    The job parameter of Numo::Linalg.svd.

  • seed (Integer) (defaults to: nil)

    The seed of random number generator.



20
21
22
23
24
25
26
27
# File 'lib/numo/linalg/randsvd.rb', line 20

def randsvd(a, k, t = 0, driver: 'svd', job: 'A', seed: nil)
  n = a.shape[1]
  q = _orthonormal_mat(a, [k + 10, n].min, t, seed)
  b = a.dot(q)
  s, u, vt = Numo::Linalg.svd(b, driver: driver, job: job)
  vtqt = vt.dot(q.transpose)
  _truncated_mat(s, u, vtqt, k)
end