numo-linalg-randsvd 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/lib/numo/linalg/randsvd.rb +10 -8
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13231de1b8ebda4466ffc207054984fb294ee73653dcd7c954089e2739d75ea0
4
- data.tar.gz: f09bf78c3de2598053be56ce84083fdd293f3d4609c277ac6642c18a0ff3843f
3
+ metadata.gz: 6124cfa5d92e207e25176f5a76c10edf7efe094c7467b38bedaef3221ebf1125
4
+ data.tar.gz: c38604617b8dc031414205bd2359ecf54ceeac3d496cdd6c28b1e35b049baf88
5
5
  SHA512:
6
- metadata.gz: 5349bfc846c6ac5a52139747db1c8261a2d0d3ba2ac1b2e25b958deaf8cc3283f2786401ba9def1aa8d2210fb39483bc5d1d0d2a90ef6cfd2b1f3e36d58efb87
7
- data.tar.gz: 5add7d6b98a45739ab2c35f2c57e6d92bdcb210fa43327c913b59a3761816a0fca12090adc9fbea795fbad151fb58434c2a80a7b2674ac9ba4c99959efd787d9
6
+ metadata.gz: '04126899d6e0fdf582778a435d027380eaaff1eb6826614220dce3533f8e055ed518e3128e7bf822fe52e766858ea45ab08badb57d3f6ae83d92911e55abd056'
7
+ data.tar.gz: be04847c850344d151508bcd5a6051da2bd373480fdc8a2c91fd9e4403b41e8bc2ede31932aefa29f8271c7c3b1f4786f4a164593d04e773d63e041d1fce2aa9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [0.2.1] - 2022-11-2022
2
+
3
+ - Fix dependent version of numo-random.
4
+
5
+ ## [0.2.0] - 2022-11-12
6
+
7
+ **Breaking Changes**
8
+
9
+ - Change to use numo-random gem for generating random matrix.
10
+
1
11
  ## [0.1.1] - 2022-10-23
2
12
 
3
13
  - Fix documentation uri.
@@ -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
- def randsvd(a, k, t = 0, driver: 'svd', job: 'A')
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
- a = dtype.new(shape).rand
29
- b = dtype.new(shape).rand
30
- ((Numo::NMath.sqrt(Numo::NMath.log(a) * -2.0) * Numo::NMath.sin(b * 2.0 * Math::PI)) * sigma) + mu
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.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-23 00:00:00.000000000 Z
11
+ date: 2022-11-20 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'
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'
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.