random_multivariate_normal 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9a5940c9b6a4b6c14d1e06e8531c12999401281d9fc14d8b8684bc1cbaf9d8b
4
- data.tar.gz: d39c3aed5c244503888850057fa970c6b687aa8f2aac8398443a6b2fe996ac72
3
+ metadata.gz: bf03666931f89046e6db874909e81b25049e3af9500e338662e4052395b9893a
4
+ data.tar.gz: 488720985847dccb6883cde1285645d8c092563b39c4f3b124b90816a736f5a9
5
5
  SHA512:
6
- metadata.gz: 986a4dc89b5f28aec02060d64c57223f22459234bf6e931acde74d85806b464c65eb1e7d81d28046f61a7bf5a3c87500ced4a077958c990ac185c3232e462ab2
7
- data.tar.gz: cde52b4a852773f45395923e22b73af88006595e05885de6e169514fd4c72688b7152d85ef674bf177b535bdc7431849f88949998fbd85dcd6f474e18a163476
6
+ metadata.gz: 544f8eb3a66499431a9a052aaa5dbc5ca2afcef8a9e5601af0396ff2a62fe29992ffc963f9b0c18205a4d97a7e0e9bebda4cb18cc89ffb9b1dcdd4cc4143b16e
7
+ data.tar.gz: 390a4ba56a069c3c90c3ab89d798baf0d0b41d733eac59763dc5f289280b8a838e4c041a33b0ea19e35e42bb671edf6bd3f6aecba6f5a8b2264f511c20644fe1
@@ -32,17 +32,21 @@ class RandomMultivariateNormal
32
32
  raise ArgumentError.new('Not symmetric matrix') unless mat.symmetric?
33
33
  raise ArgumentError.new('Not positive definite matrix') unless mat.eigen.d.each(:diagonal).all?{|d| d > 0.0}
34
34
 
35
- l = Matrix.zero(mat.row_size)
35
+ l = array_as_zero_matrix(mat.row_size)
36
36
  mat.each_with_index do |e, row, col|
37
37
  lij = if row == col
38
- Math.sqrt(mat[col, col] - col.times.inject(0){|sum, j| sum + (l[col, j] ** 2)})
38
+ Math.sqrt(mat[col, col] - col.times.inject(0){|sum, j| sum + (l[col][j] ** 2)})
39
39
  elsif row > col
40
- (1.0/l[col, col]) * (mat[row, col] - col.times.inject(0){|sum, j| sum + l[row, j] * l[col, j]})
40
+ (1.0/l[col][col]) * (mat[row, col] - col.times.inject(0){|sum, j| sum + l[row][j] * l[col][j]})
41
41
  else
42
42
  0.0
43
43
  end
44
- l[row, col] = lij
44
+ l[row][col] = lij
45
45
  end
46
- l
46
+ Matrix[*l]
47
+ end
48
+
49
+ def array_as_zero_matrix(size)
50
+ Array.new(size) { Array.new(size, 0) }
47
51
  end
48
52
  end
@@ -1,3 +1,3 @@
1
1
  class RandomMultivariateNormal
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random_multivariate_normal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - monochromegane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-14 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,7 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
- rubygems_version: 3.0.3
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.6.2
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Random number generator from a multivariate normal distribution.