numo-linalg-randsvd 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -1
- data/README.md +5 -0
- data/lib/numo/linalg/randsvd.rb +10 -8
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71312ec59a5898236280d11b100f6b43c7e42c4851e69198dc105d71745aef67
|
4
|
+
data.tar.gz: d95416e7779f463e7017d119e701fd232280d2da98767b4c58940b0582174b9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c1b847a52683c315bbea34e4b685d03332719a1b9b198318c41d55990cb7502b67fcec1e33ac4d8ab13fbf34abf92721e0633e3fd06182603658bf39fd60b0e
|
7
|
+
data.tar.gz: be658a95443b24be18f82f2895ee49b07133c5ef12355d0d3fcffe49f5b5501af2bead44dde05701df51989e0cd01d41cb427921aec87cd53960b01ba23ac7c6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Numo::Linalg.randsvd
|
2
2
|
|
3
|
+
[](https://github.com/yoshoku/numo-linalg-randsvd/actions/workflows/main.yml)
|
4
|
+
[](https://badge.fury.io/rb/numo-linalg-randsvd)
|
5
|
+
[](https://github.com/yoshoku/numo-linalg-randsvd/blob/main/LICENSE.txt)
|
6
|
+
[](https://yoshoku.github.io/numo-linalg-randsvd/doc/)
|
7
|
+
|
3
8
|
Numo::Linalg.randsvd is a module function on Numo::Linalg for truncated singular value decomposition with randomized algorithm.
|
4
9
|
This gem re-implements [RandSVD](https://github.com/yoshoku/randsvd) using [Numo::NArray](https://github.com/ruby-numo/numo-narray) and
|
5
10
|
[Numo::Linalg](https://github.com/ruby-numo/numo-linalg) instead of [NMatrix](https://github.com/SciRuby/nmatrix).
|
data/lib/numo/linalg/randsvd.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'numo/narray'
|
4
|
+
require 'numo/random'
|
4
5
|
|
5
6
|
# Ruby/Numo (NUmerical MOdules)
|
6
7
|
module Numo
|
@@ -15,24 +16,25 @@ module Numo
|
|
15
16
|
# @param t [Integer] The number of iterations for orthogonalization.
|
16
17
|
# @param driver [String] The driver parameter of Numo::Linalg.svd.
|
17
18
|
# @param job [String] The job parameter of Numo::Linalg.svd.
|
18
|
-
|
19
|
+
# @param seed [Integer] The seed of random number generator.
|
20
|
+
def randsvd(a, k, t = 0, driver: 'svd', job: 'A', seed: nil)
|
19
21
|
n = a.shape[1]
|
20
|
-
q = _orthonormal_mat(a, [k + 10, n].min, t)
|
22
|
+
q = _orthonormal_mat(a, [k + 10, n].min, t, seed)
|
21
23
|
b = a.dot(q)
|
22
24
|
s, u, vt = Numo::Linalg.svd(b, driver: driver, job: job)
|
23
25
|
vtqt = vt.dot(q.transpose)
|
24
26
|
_truncated_mat(s, u, vtqt, k)
|
25
27
|
end
|
26
28
|
|
27
|
-
def _rand_normal(shape, dtype = Numo::DFloat, mu = 0.0, sigma = 1.0)
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def _rand_normal(shape, dtype = Numo::DFloat, seed = nil, mu = 0.0, sigma = 1.0)
|
30
|
+
Numo::Random::Generator.new(seed: seed).normal(
|
31
|
+
shape: shape, dtype: dtype.name.split('::')[-1].downcase.to_sym, loc: mu, scale: sigma
|
32
|
+
)
|
31
33
|
end
|
32
34
|
|
33
|
-
def _orthonormal_mat(a, l, t)
|
35
|
+
def _orthonormal_mat(a, l, t, seed)
|
34
36
|
m = a.shape[0]
|
35
|
-
r = _rand_normal([m, l], a.class)
|
37
|
+
r = _rand_normal([m, l], a.class, seed)
|
36
38
|
q, = Numo::Linalg.qr(a.transpose.dot(r), mode: 'economic')
|
37
39
|
t.times do
|
38
40
|
r, = Numo::Linalg.qr(a.dot(q), mode: 'economic')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-linalg-randsvd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-linalg
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.9.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: numo-random
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.4.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.0
|
41
55
|
description: |
|
42
56
|
Numo::Linalg.randsvd is a module function on Numo::Linalg for
|
43
57
|
truncated singular value decomposition with randomized algorithm.
|
@@ -59,7 +73,7 @@ metadata:
|
|
59
73
|
homepage_uri: https://github.com/yoshoku/numo-linalg-randsvd
|
60
74
|
source_code_uri: https://github.com/yoshoku/numo-linalg-randsvd
|
61
75
|
changelog_uri: https://github.com/yoshoku/numo-linalg-randsvd/blob/main/CHANGELOG.md
|
62
|
-
documentation_uri: https://
|
76
|
+
documentation_uri: https://yoshoku.github.io/numo-linalg-randsvd/doc/
|
63
77
|
rubygems_mfa_required: 'true'
|
64
78
|
post_install_message:
|
65
79
|
rdoc_options: []
|
@@ -76,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
90
|
- !ruby/object:Gem::Version
|
77
91
|
version: '0'
|
78
92
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
93
|
+
rubygems_version: 3.3.7
|
80
94
|
signing_key:
|
81
95
|
specification_version: 4
|
82
96
|
summary: Numo::Linalg.randsvd is a module function on Numo::Linalg for truncated singular
|