numo-linalg-randsvd 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/numo/linalg/randsvd.rb +10 -8
- metadata +16 -2
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/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.
|