Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

numo-linalg-randsvd

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

numo-linalg-randsvd

bundlerRubygems
Version
0.4.0
Version published
Maintainers
1
Created
Source

Numo::Linalg.randsvd

Build Status Gem Version BSD 3-Clause License Documentation

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'

# An example of matrix decomposition is as follows:
x = Numo::DFloat.new(100, 20).rand
y = Numo::DFloat.new(20, 50).rand
z = x.dot(y)
p z
# Numo::DFloat#shape=[100,50]
# ...

# Performing the randomized singular value decomposition with specified the number of singular values.
n_singular_values = 20
s, u, vt = Numo::Linalg.randsvd(z, n_singular_values)
p s
# Numo::DFloat#shape=[20]
# ...
p u
# Numo::DFloat#shape=[100,20]
# ...
p vt
# Numo::DFloat#shape=[20,50]
# ...

# Reconstructing the matrix with the singular values and singular vectors.
zz = u.dot(s.diag).dot(vt)
p zz
# Numo::DFloat#shape=[100,50]
# ...
p (z - zz).abs.max
# 5.5067062021407764e-14

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

FAQs

Package last updated on 02 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts