simple-random 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -25,29 +25,6 @@ Rake::TestTask.new(:test) do |test|
25
25
  test.verbose = true
26
26
  end
27
27
 
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
28
  task :test => :check_dependencies
42
29
 
43
30
  task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "simple-random #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.10.0
@@ -42,6 +42,19 @@ class SimpleRandom
42
42
  raise 'Mean must be positive' if mean <= 0
43
43
  -1.0 * mean * Math.log(uniform)
44
44
  end
45
+
46
+ # Get triangular random sample with specified lower limit, mode, upper limit
47
+ def triangular(lower, mode, upper)
48
+ raise 'Upper limit must be larger than lower limit' if upper < lower
49
+ raise 'Mode must lie between the upper and lower limits' if (mode < lower || mode > upper)
50
+ f_c = (mode - lower) / (upper - lower)
51
+ uniform_rand_num = uniform
52
+ if uniform_rand_num < f_c
53
+ lower + Math.sqrt(uniform_rand_num * (upper - lower) * (mode - lower))
54
+ else
55
+ upper - Math.sqrt((1 - uniform_rand_num) * (upper - lower) * (upper - mode))
56
+ end
57
+ end
45
58
 
46
59
  # Implementation based on "A Simple Method for Generating Gamma Variables"
47
60
  # by George Marsaglia and Wai Wan Tsang. ACM Transactions on Mathematical Software
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple-random}
8
- s.version = "0.9.3"
8
+ s.version = "0.10.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{John D. Cook}, %q{Jason Adams}]
12
- s.date = %q{2011-09-17}
12
+ s.date = %q{2014-03-31}
13
13
  s.description = %q{Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential, Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform, and Weibull. Ported from John D. Cook's C# Code.}
14
14
  s.email = %q{jasonmadams@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.require_paths = [%q{lib}]
32
32
  s.rubygems_version = %q{1.8.6}
33
33
  s.summary = %q{Simple Random Number Generator}
34
+ s.license = "Code Project Open License"
34
35
 
35
36
  if s.respond_to? :specification_version then
36
37
  s.specification_version = 3
@@ -69,6 +69,36 @@ class TestSimpleRandom < Test::Unit::TestCase
69
69
 
70
70
  assert epsilon < MAXIMUM_EPSILON
71
71
  end
72
+
73
+ should "generate random numbers from triangular(0, 1, 1) in the range [0, 1]" do
74
+ SAMPLE_SIZE.times do
75
+ t = @r.triangular(0.0, 1.0, 1.0)
76
+ assert t <= 1.0
77
+ assert t >= 0.0
78
+ end
79
+ end
80
+
81
+ should "generate random numbers from triangular(0, 1, 1) with mean approximately 0.66" do
82
+ a = 0.0
83
+ c = 1.0
84
+ b = 1.0
85
+ numbers = generate_numbers(@r, :triangular, a, c, b)
86
+ mean = (a + b + c) / 3
87
+ epsilon = (mean - numbers.mean).abs
88
+
89
+ assert epsilon < MAXIMUM_EPSILON
90
+ end
91
+
92
+ should "generate random numbers from triangular(0, 1, 1) with standard deviation approximately 0.23" do
93
+ a = 0.0
94
+ c = 1.0
95
+ b = 1.0
96
+ numbers = generate_numbers(@r, :triangular, a, c, b)
97
+ std_dev = Math.sqrt((a**2 + b**2 + c**2 - a*b - a*c - b*c) / 18)
98
+ epsilon = (std_dev - numbers.standard_deviation).abs
99
+
100
+ assert epsilon < MAXIMUM_EPSILON
101
+ end
72
102
 
73
103
  should "generate a random number sampled from a gamma distribution" do
74
104
  assert @r.gamma(5, 2.3)
metadata CHANGED
@@ -1,38 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: simple-random
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 55
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 10
9
+ - 0
10
+ version: 0.10.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - John D. Cook
9
14
  - Jason Adams
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2011-09-17 00:00:00.000000000Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
18
+
19
+ date: 2014-03-31 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: shoulda
17
- requirement: &23585180 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
23
33
  type: :development
24
- prerelease: false
25
- version_requirements: *23585180
26
- description: Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential,
27
- Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform,
28
- and Weibull. Ported from John D. Cook's C# Code.
34
+ version_requirements: *id001
35
+ description: Simple Random Number Generator including Beta, Cauchy, Chi square, Exponential, Gamma, Inverse Gamma, Laplace (double exponential), Normal, Student t, Uniform, and Weibull. Ported from John D. Cook's C# Code.
29
36
  email: jasonmadams@gmail.com
30
37
  executables: []
38
+
31
39
  extensions: []
32
- extra_rdoc_files:
40
+
41
+ extra_rdoc_files:
33
42
  - LICENSE
34
43
  - README.rdoc
35
- files:
44
+ files:
36
45
  - .document
37
46
  - LICENSE
38
47
  - README.rdoc
@@ -43,27 +52,37 @@ files:
43
52
  - test/helper.rb
44
53
  - test/test_simple_random.rb
45
54
  homepage: http://github.com/ealdent/simple-random
46
- licenses: []
55
+ licenses:
56
+ - Code Project Open License
47
57
  post_install_message:
48
58
  rdoc_options: []
49
- require_paths:
59
+
60
+ require_paths:
50
61
  - lib
51
- required_ruby_version: !ruby/object:Gem::Requirement
62
+ required_ruby_version: !ruby/object:Gem::Requirement
52
63
  none: false
53
- requirements:
54
- - - ! '>='
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
72
  none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
63
80
  requirements: []
81
+
64
82
  rubyforge_project:
65
- rubygems_version: 1.8.6
83
+ rubygems_version: 1.8.15
66
84
  signing_key:
67
85
  specification_version: 3
68
86
  summary: Simple Random Number Generator
69
87
  test_files: []
88
+