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 +4 -4
- data/lib/random_multivariate_normal.rb +9 -5
- data/lib/random_multivariate_normal/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf03666931f89046e6db874909e81b25049e3af9500e338662e4052395b9893a
|
4
|
+
data.tar.gz: 488720985847dccb6883cde1285645d8c092563b39c4f3b124b90816a736f5a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|
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
|
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
|
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
|
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.
|
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-
|
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
|
-
|
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.
|