grand 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: 604eb3589910ee75d906a58184b84079d11a84ca
4
- data.tar.gz: e24dfd64c89afe88864a117ed9cae17386cdb13a
3
+ metadata.gz: 3586405a397dae7cf09dedc1cdcf61af9d38a1d6
4
+ data.tar.gz: f5292580efcfbbd668943f52c75dbb1b0d003927
5
5
  SHA512:
6
- metadata.gz: d8c221d0439199c75c280642b5fe249152207d32e7be9c62779979e3ada82acee4d86bfe850e1b4e28c3ac9ed5d38b07c311b5a063800a71df51b9fc633ce48c
7
- data.tar.gz: 0534e83ef507485a5a0b0a49b2213c50eb87433e20a664069636b3ea93717ecac91a4979d61e37d1ea9abedb0ad079c20458df55a42f8e4ee929aa9a1d2dfc60
6
+ metadata.gz: b971c7b1225a2fa0f038f21200533cf6f1306968be069004e861ca6c3494d5d34870c79ff37b1d9692f54944795fbd2694e0412b1b0a1fd356c6e0a37a1cb885
7
+ data.tar.gz: 407cb1ee1815c078c10266d80ee6191543434e4745b6fc076dab4eb5a0b260f0a9d7bc40a32a19e81f2bf7b835f0b79de3d622b8be460da9befb791ad525dbc4
data/README.md CHANGED
@@ -22,15 +22,15 @@ Or install it yourself as:
22
22
 
23
23
  > require 'grand'
24
24
  => true
25
- > GRand::randn
25
+ > GRand.randn
26
26
  => 0.8459468356387407
27
- > GRand::randn(1, 2)
27
+ > GRand.randn(1, 2)
28
28
  => [[-0.5259311445434742, 0.5058339155942712]]
29
- > GRand::rand(n3, 2)
29
+ > GRand.rand(n3, 2)
30
30
  => [[1.0015454079393156, -0.2544992806165275], [-0.7978337095145441, -1.7813946216288779], [0.9631364295796622, 2.157358119782299]]
31
- > GRand::randn(2, 1)
31
+ > GRand.randn(2, 1)
32
32
  => [[-0.634759160869425], [0.549004503513128]]
33
- > GRand::randn(3, 3, 3)
33
+ > GRand.randn(3, 3, 3)
34
34
  => [[[-1.689589847133065, -0.41054654640696786, 0.36381728856120105], [-0.9437196021569799, 1.19558636009585, -1.1605453269136559], [1.0837506708104712, -1.1395537425254014, 0.5925022408229144]], [[-1.7133014088074843, -0.805051352081152, 0.3746241803203248], [0.3642622933280586, 0.5843943798812012, 1.141236536447513], [-0.25543269419159714, 1.1743836190357984, -0.5161554049975062]], [[-0.03303459622587511, -3.5547854922416438, 0.17581738567933877], [-0.979119743081027, 1.397273496753393, 0.18670646583239753], [-0.26985128879011183, -0.5662975999343106, 0.46600852896034334]]]
35
35
 
36
36
  ## Development
@@ -0,0 +1,15 @@
1
+ unless Enumerable.instance_methods.include? :shape
2
+
3
+ module Enumerable
4
+ def shape
5
+ total = []
6
+ a = self
7
+ while a.respond_to?(:count)
8
+ total << a.count
9
+ a = a.first
10
+ end
11
+ total
12
+ end
13
+ end
14
+
15
+ end
data/lib/grand.rb CHANGED
@@ -1,15 +1,31 @@
1
1
  require 'grand/version'
2
2
  require 'rubystats'
3
+ require 'matrix'
4
+ require 'core_ext/enumerable'
3
5
 
4
6
  module GRand
7
+ def self.array_randn(*d)
8
+ return normal_distribution.rng if d.size == 0
9
+
10
+ x = d.shift
11
+ x.times.map{ self.array_randn(*d) }
12
+ end
13
+
5
14
  def self.randn(*d)
6
15
  return normal_distribution.rng if d.size == 0
7
16
 
8
17
  x = d.shift
9
- x.times.map{ self.randn(*d) }
18
+ Vector[*x.times.map{ self.randn(*d) }]
10
19
  end
11
20
 
12
21
  def self.normal_distribution
13
22
  @@nd ||= Rubystats::NormalDistribution.new(0, 1)
14
23
  end
24
+
25
+ def self.zeros(*d)
26
+ return 0 if d.size == 0
27
+
28
+ x = d.shift
29
+ Vector[*x.times.map{ self.zeros(*d) } ]
30
+ end
15
31
  end
data/lib/grand/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module GRand
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Ostermayr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-27 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubystats
@@ -83,6 +83,7 @@ files:
83
83
  - bin/console
84
84
  - bin/setup
85
85
  - grand.gemspec
86
+ - lib/core_ext/enumerable.rb
86
87
  - lib/grand.rb
87
88
  - lib/grand/version.rb
88
89
  homepage: https://github.com/gregors/grand
@@ -104,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  version: '0'
105
106
  requirements: []
106
107
  rubyforge_project:
107
- rubygems_version: 2.6.11
108
+ rubygems_version: 2.4.5
108
109
  signing_key:
109
110
  specification_version: 4
110
111
  summary: I needed randn from numpy in ruby.