erv 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2c01ff8ee7e228352bd7e91cf37398ac1c9a4599
4
- data.tar.gz: 1df36e92cac62835249f6b3be46e6b15ee23609c
2
+ SHA256:
3
+ metadata.gz: 603f059bcc653dec48f6f20f7f451d63fa1a56cfc3bcc13dd425e7af9074ea85
4
+ data.tar.gz: cf66f1926b9417926f8cae463606171c7e42866b1069e53d0f9bd88a8c10d2c7
5
5
  SHA512:
6
- metadata.gz: 61281fab1ea61ce27f999075719b1ad7a4cd955ab2cc5d48ec8d790eee445024a880329e3fea1f2d65e0d3eb014dc1d41e289533e2caec05a815b0b554c18916
7
- data.tar.gz: b6db99c3a1a4babc7fdbb56028b16e9b865eadb95159269a5e63e8c6618a99a5950932c75e02fae7046c22523a40a33393bad5d02e8fb378567e597c0c3c11cc
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']
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ERV
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
@@ -4,7 +4,7 @@ require 'erv/discrete_uniform_distribution'
4
4
 
5
5
  describe ERV::DiscreteUniformDistribution do
6
6
 
7
- let :num_samples { 10000 }
7
+ let (:num_samples) { 10000 }
8
8
 
9
9
  it 'should require at least a maximum parameter' do
10
10
  lambda do
@@ -4,7 +4,7 @@ require 'erv/exponential_distribution'
4
4
 
5
5
  describe ERV::ExponentialDistribution do
6
6
 
7
- let :num_samples { 10000 }
7
+ let (:num_samples) { 10000 }
8
8
 
9
9
  it 'should require the rate parameter' do
10
10
  lambda do
@@ -4,7 +4,7 @@ require 'erv/gamma_distribution'
4
4
 
5
5
  describe ERV::GammaDistribution do
6
6
 
7
- let :num_samples { 10000 }
7
+ let (:num_samples) { 10000 }
8
8
 
9
9
  it 'should require the scale and shape parameters' do
10
10
  lambda do
@@ -4,7 +4,7 @@ require 'erv/gaussian_distribution'
4
4
 
5
5
  describe ERV::GaussianDistribution do
6
6
 
7
- let :num_samples { 10000 }
7
+ let (:num_samples) { 10000 }
8
8
 
9
9
  it 'should require the scale and shape parameters' do
10
10
  lambda do
@@ -4,7 +4,7 @@ require 'erv/generalized_pareto_distribution'
4
4
 
5
5
  describe ERV::GpdDistribution do
6
6
 
7
- let :num_samples { 200000 }
7
+ let (:num_samples) { 200000 }
8
8
 
9
9
  it 'should require scale and shape parameters' do
10
10
  lambda do
@@ -4,7 +4,7 @@ require 'erv/geometric_distribution'
4
4
 
5
5
  describe ERV::GeometricDistribution do
6
6
 
7
- let :num_samples { 10000 }
7
+ let (:num_samples) { 10000 }
8
8
 
9
9
  it 'should require at least a probability of success parameter' do
10
10
  lambda do
@@ -4,7 +4,7 @@ require 'erv/mixture_distribution'
4
4
 
5
5
  describe ERV::MixtureDistribution do
6
6
 
7
- let :num_samples { 10000 }
7
+ let (:num_samples) { 10000 }
8
8
 
9
9
  it 'should require at least two distributions' do
10
10
  lambda do
@@ -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.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: 2017-08-24 00:00:00.000000000 Z
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.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.11
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