Numo::Linalg.randsvd

Numo::Linalg.randsvd is a module function on Numo::Linalg for truncated singular value decomposition with randomized algorithm.
This gem re-implements RandSVD using Numo::NArray and
Numo::Linalg instead of NMatrix.
Note: Since v0.4.0, this gem uses Numo::NArray Alternative instead of Numo::NArray as a dependency.
References:
- P.-G. Martinsson, A. Szlam, M. Tygert, "Normalized power iterations for the computation of SVD," Proc. of NIPS Workshop on Low-Rank Methods for Large-Scale Machine Learning, 2011.
- P.-G. Martinsson, V. Rokhlin, M. Tygert, "A randomized algorithm for the approximation of matrices," Tech. Rep., 1361, Yale University Department of Computer Science, 2006.
Installation
Add this line to your application's Gemfile:
gem 'numo-linalg-randsvd'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install numo-linalg-randsvd
Usage
require 'numo/linalg/randsvd'
x = Numo::DFloat.new(100, 20).rand
y = Numo::DFloat.new(20, 50).rand
z = x.dot(y)
p z
n_singular_values = 20
s, u, vt = Numo::Linalg.randsvd(z, n_singular_values)
p s
p u
p vt
zz = u.dot(s.diag).dot(vt)
p zz
p (z - zz).abs.max
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-linalg-randsvd.
This project is intended to be a safe, welcoming space for collaboration,
and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the BSD-3-Clause License