RandSVD is a class that performs truncated singular value decomposition using a randomized algorithm. To implement, I referred to the following papers:
- 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.
Note: Since NMatrix does not support Ruby 3, the author recommends using numo-linalg-randsvd instead.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install randsvd
require 'randsvd' # Initialize some variables. input_matrix = NMatrix.rand([1000, 100]) nb_singular_values = 10 # Perform the randomized singular value decomposition. u, s, vt = RandSVD.gesvd(input_matrix, nb_singular_values) # Reconstruct the matrix with the singular values and vectors. reconstructed_matrix = u.dot(NMatrix.diag(s).dot(vt))
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/randsvd. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.