erv 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +5 -5
- data/erv.gemspec +1 -1
- data/lib/erv/random_variable.rb +8 -1
- data/lib/erv/version.rb +1 -1
- data/test/erv/discrete_uniform_distribution_test.rb +1 -1
- data/test/erv/exponential_distribution_test.rb +1 -1
- data/test/erv/gamma_distribution_test.rb +1 -1
- data/test/erv/gaussian_distribution_test.rb +1 -1
- data/test/erv/generalized_pareto_distribution_test.rb +1 -1
- data/test/erv/geometric_distribution_test.rb +1 -1
- data/test/erv/mixture_distribution_test.rb +1 -1
- data/test/erv/random_variable_test.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 603f059bcc653dec48f6f20f7f451d63fa1a56cfc3bcc13dd425e7af9074ea85
|
4
|
+
data.tar.gz: cf66f1926b9417926f8cae463606171c7e42866b1069e53d0f9bd88a8c10d2c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ee227008ef4b7ac84d956cc93a5b0e637146a579df9700f6f74fc0cabaec451e0a0bcd7205b8b9a576bb95c4bc77fdd3f55c222fda8fb7bc251ae539b9fc5e2
|
7
|
+
data.tar.gz: 560c161b2809c89adcb0348df4b778e5fa9656923e47dfe6efb8165e20b7cc01e9c117530255266c0da0f9a7cf007f5f7e1380c76b8d81958fc8b5b57a0d9478
|
data/README.md
CHANGED
@@ -29,12 +29,12 @@ require 'erv'
|
|
29
29
|
|
30
30
|
# Gaussian random variable with mean 10 and standard deviation 2
|
31
31
|
gaussian_rv = ERV::RandomVariable.new(distribution: :gaussian,
|
32
|
-
mean: 10, sd: 2)
|
32
|
+
args: { mean: 10, sd: 2 })
|
33
33
|
s1 = gaussian_rv.sample
|
34
34
|
|
35
35
|
# Geometric random variable with probability of success 0.3
|
36
36
|
geometric_rv = ERV::RandomVariable.new(distribution: :geometric,
|
37
|
-
probability_of_success: 0.3)
|
37
|
+
args: { probability_of_success: 0.3 })
|
38
38
|
s2 = geometric_rv.sample
|
39
39
|
```
|
40
40
|
|
@@ -45,9 +45,9 @@ distribution:
|
|
45
45
|
```ruby
|
46
46
|
require 'erv'
|
47
47
|
|
48
|
-
emd = ERV::MixtureDistribution.new([ { distribution: :exponential, rate: 1.0, weight: 100.0 },
|
49
|
-
{ distribution: :exponential, rate: 2.0, weight: 200.0 },
|
50
|
-
{ distribution: :exponential, rate: 3.0, weight: 300.0 } ])
|
48
|
+
emd = ERV::MixtureDistribution.new([ { distribution: :exponential, args: { rate: 1.0 }, weight: 100.0 },
|
49
|
+
{ distribution: :exponential, args: { rate: 2.0 }, weight: 200.0 },
|
50
|
+
{ distribution: :exponential, args: { rate: 3.0 }, weight: 300.0 } ])
|
51
51
|
s3 = emd.sample
|
52
52
|
```
|
53
53
|
|
data/erv.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = 'https://github.com/mtortonesi/ruby-erv'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split($/).reject{|x| x == '.gitignore' }
|
16
|
+
spec.files = `git ls-files`.split($/).reject{|x| x == '.gitignore' or x == '.projections.json' }
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
data/lib/erv/random_variable.rb
CHANGED
@@ -26,16 +26,20 @@ module ERV
|
|
26
26
|
klass_name = dist_name.split('_').push('distribution').map(&:capitalize).join
|
27
27
|
|
28
28
|
# create distribution object
|
29
|
-
@dist = ERV.const_get(klass_name).new(args)
|
29
|
+
@dist = ERV.const_get(klass_name).new(args[:args])
|
30
30
|
end
|
31
31
|
|
32
32
|
def next
|
33
33
|
@dist.sample
|
34
34
|
end
|
35
|
+
|
36
|
+
alias_method :sample, :next
|
37
|
+
|
35
38
|
end
|
36
39
|
|
37
40
|
|
38
41
|
class SequentialRandomVariable
|
42
|
+
|
39
43
|
def initialize(args={})
|
40
44
|
first = args.delete(:first_value)
|
41
45
|
raise ArgumentError, "First value must be provided!" if first.nil?
|
@@ -46,6 +50,9 @@ module ERV
|
|
46
50
|
def next
|
47
51
|
@most_recent += @var.next
|
48
52
|
end
|
53
|
+
|
54
|
+
alias_method :sample, :next
|
55
|
+
|
49
56
|
end
|
50
57
|
|
51
58
|
end
|
data/lib/erv/version.rb
CHANGED
@@ -12,13 +12,13 @@ describe ERV::SequentialRandomVariable do
|
|
12
12
|
|
13
13
|
it 'should consider starting value' do
|
14
14
|
first = 1.0
|
15
|
-
srv = ERV::SequentialRandomVariable.new(first_value: first, distribution: :exponential, rate: 2.0)
|
15
|
+
srv = ERV::SequentialRandomVariable.new(first_value: first, distribution: :exponential, args: { rate: 2.0 })
|
16
16
|
srv.next.must_be :>, first
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should consider previous sample' do
|
20
20
|
first = 1.0
|
21
|
-
srv = ERV::SequentialRandomVariable.new(first_value: first, distribution: :exponential, rate: 2.0)
|
21
|
+
srv = ERV::SequentialRandomVariable.new(first_value: first, distribution: :exponential, args: { rate: 2.0 })
|
22
22
|
previous_sample = srv.next
|
23
23
|
10.times do
|
24
24
|
new_sample = srv.next
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mauro Tortonesi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.0.3
|
83
|
-
description: erv-0.3.
|
83
|
+
description: erv-0.3.4
|
84
84
|
email:
|
85
85
|
- mauro.tortonesi@unife.it
|
86
86
|
executables: []
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.6
|
141
|
+
rubygems_version: 2.7.6
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
144
|
summary: Easy/elegant Ruby library providing support for random variable generation
|