distribution 0.6.0 → 0.8.0

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.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.travis.yml +13 -0
  4. data/.yardopts +5 -0
  5. data/Gemfile +5 -0
  6. data/History.txt +24 -8
  7. data/LICENCE.md +26 -0
  8. data/README.md +155 -0
  9. data/Rakefile +15 -19
  10. data/benchmark/binomial_coefficient.rb +19 -23
  11. data/benchmark/binomial_coefficient/experiment.rb +33 -36
  12. data/benchmark/factorial_hash.rb +7 -8
  13. data/benchmark/factorial_method.rb +4 -6
  14. data/benchmark/odd.rb +6 -7
  15. data/benchmark/power.rb +11 -11
  16. data/bin/distribution +26 -26
  17. data/data/template/spec.erb +7 -6
  18. data/distribution.gemspec +25 -0
  19. data/lib/distribution.rb +79 -124
  20. data/lib/distribution/beta.rb +6 -8
  21. data/lib/distribution/beta/gsl.rb +14 -9
  22. data/lib/distribution/beta/java.rb +1 -1
  23. data/lib/distribution/beta/ruby.rb +41 -7
  24. data/lib/distribution/binomial.rb +10 -11
  25. data/lib/distribution/binomial/gsl.rb +6 -5
  26. data/lib/distribution/binomial/java.rb +1 -1
  27. data/lib/distribution/binomial/ruby.rb +22 -15
  28. data/lib/distribution/bivariatenormal.rb +4 -5
  29. data/lib/distribution/bivariatenormal/gsl.rb +2 -2
  30. data/lib/distribution/bivariatenormal/java.rb +1 -1
  31. data/lib/distribution/bivariatenormal/ruby.rb +245 -254
  32. data/lib/distribution/chisquare.rb +8 -10
  33. data/lib/distribution/chisquare/gsl.rb +24 -19
  34. data/lib/distribution/chisquare/java.rb +1 -1
  35. data/lib/distribution/chisquare/ruby.rb +60 -55
  36. data/lib/distribution/chisquare/statistics2.rb +16 -13
  37. data/lib/distribution/distributable.rb +40 -0
  38. data/lib/distribution/exponential.rb +4 -5
  39. data/lib/distribution/exponential/gsl.rb +13 -9
  40. data/lib/distribution/exponential/ruby.rb +17 -11
  41. data/lib/distribution/f.rb +10 -11
  42. data/lib/distribution/f/gsl.rb +26 -22
  43. data/lib/distribution/f/java.rb +1 -1
  44. data/lib/distribution/f/ruby.rb +104 -105
  45. data/lib/distribution/f/statistics2.rb +22 -19
  46. data/lib/distribution/gamma.rb +5 -7
  47. data/lib/distribution/gamma/gsl.rb +13 -9
  48. data/lib/distribution/gamma/java.rb +1 -1
  49. data/lib/distribution/gamma/ruby.rb +5 -11
  50. data/lib/distribution/hypergeometric.rb +5 -8
  51. data/lib/distribution/hypergeometric/gsl.rb +5 -6
  52. data/lib/distribution/hypergeometric/java.rb +1 -1
  53. data/lib/distribution/hypergeometric/ruby.rb +34 -35
  54. data/lib/distribution/logistic.rb +6 -9
  55. data/lib/distribution/logistic/ruby.rb +14 -9
  56. data/lib/distribution/lognormal.rb +37 -0
  57. data/lib/distribution/lognormal/gsl.rb +21 -0
  58. data/lib/distribution/lognormal/ruby.rb +16 -0
  59. data/lib/distribution/math_extension.rb +187 -231
  60. data/lib/distribution/math_extension/chebyshev_series.rb +281 -272
  61. data/lib/distribution/math_extension/erfc.rb +28 -31
  62. data/lib/distribution/math_extension/exponential_integral.rb +17 -17
  63. data/lib/distribution/math_extension/gammastar.rb +19 -20
  64. data/lib/distribution/math_extension/gsl_utilities.rb +12 -12
  65. data/lib/distribution/math_extension/incomplete_beta.rb +52 -61
  66. data/lib/distribution/math_extension/incomplete_gamma.rb +166 -168
  67. data/lib/distribution/math_extension/log_utilities.rb +20 -22
  68. data/lib/distribution/normal.rb +11 -13
  69. data/lib/distribution/normal/gsl.rb +13 -10
  70. data/lib/distribution/normal/java.rb +30 -1
  71. data/lib/distribution/normal/ruby.rb +69 -59
  72. data/lib/distribution/normal/statistics2.rb +5 -2
  73. data/lib/distribution/normalmultivariate.rb +64 -64
  74. data/lib/distribution/poisson.rb +12 -14
  75. data/lib/distribution/poisson/gsl.rb +7 -7
  76. data/lib/distribution/poisson/java.rb +26 -0
  77. data/lib/distribution/poisson/ruby.rb +38 -9
  78. data/lib/distribution/shorthand.rb +17 -0
  79. data/lib/distribution/t.rb +16 -16
  80. data/lib/distribution/t/gsl.rb +27 -24
  81. data/lib/distribution/t/java.rb +1 -1
  82. data/lib/distribution/t/ruby.rb +99 -100
  83. data/lib/distribution/t/statistics2.rb +19 -19
  84. data/lib/distribution/uniform.rb +26 -0
  85. data/lib/distribution/uniform/gsl.rb +36 -0
  86. data/lib/distribution/uniform/ruby.rb +91 -0
  87. data/lib/distribution/version.rb +3 -0
  88. data/lib/distribution/weibull.rb +10 -0
  89. data/lib/distribution/weibull/gsl.rb +21 -0
  90. data/lib/distribution/weibull/ruby.rb +34 -0
  91. data/spec/beta_spec.rb +48 -50
  92. data/spec/binomial_spec.rb +80 -84
  93. data/spec/bivariatenormal_spec.rb +28 -35
  94. data/spec/chisquare_spec.rb +49 -52
  95. data/spec/distribution_spec.rb +11 -11
  96. data/spec/exponential_spec.rb +48 -39
  97. data/spec/f_spec.rb +73 -71
  98. data/spec/gamma_spec.rb +50 -53
  99. data/spec/hypergeometric_spec.rb +63 -69
  100. data/spec/logistic_spec.rb +31 -37
  101. data/spec/lognormal_spec.rb +54 -0
  102. data/spec/math_extension_spec.rb +192 -209
  103. data/spec/normal_spec.rb +80 -73
  104. data/spec/poisson_spec.rb +78 -36
  105. data/spec/shorthand_spec.rb +19 -22
  106. data/spec/spec_helper.rb +31 -6
  107. data/spec/t_spec.rb +63 -77
  108. data/spec/uniform_spec.rb +154 -0
  109. data/spec/weibull_spec.rb +17 -0
  110. data/vendor/java/commons-math-2.2.jar +0 -0
  111. metadata +91 -111
  112. data.tar.gz.sig +0 -0
  113. data/.autotest +0 -23
  114. data/.gemtest +0 -0
  115. data/Manifest.txt +0 -95
  116. data/README.txt +0 -100
  117. metadata.gz.sig +0 -0
@@ -1,85 +1,82 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
2
  include ExampleWithGSL
3
3
  describe Distribution::Gamma do
4
-
5
-
6
- shared_examples_for "Gamma engine" do
7
- it_only_with_gsl "should return correct pdf" do
4
+ shared_examples_for 'Gamma engine' do
5
+ it_only_with_gsl 'should return correct pdf' do
8
6
  if @engine.respond_to? :pdf
9
7
  1.upto(101) do |x|
10
- a=rand * x
11
- b=1 + rand * 5
12
- g=GSL::Ran.gamma_pdf(x,a,b)
13
- @engine.pdf(x,a,b).should be_within(1e-10).of(g)
8
+ a = rand * x
9
+ b = 1 + rand * 5
10
+ g = GSL::Ran.gamma_pdf(x, a, b)
11
+ expect(@engine.pdf(x, a, b)).to be_within(1e-10).of(g)
14
12
  end
15
13
  else
16
14
  pending("No #{@engine}.pdf")
17
15
  end
18
16
  end
19
- it_only_with_gsl "should return correct cdf" do
20
- if @engine.respond_to? :cdf
21
- # From GSL-1.9.
22
- TOL = 1048576.0*Float::EPSILON
23
- @engine.cdf(0.0, 1.0, 1.0).should eq(0.0)
24
- @engine.cdf(1e-100, 1.0, 1.0).should be_within(TOL).of(1e-100)
25
- @engine.cdf(0.001, 1.0, 1.0).should be_within(TOL).of(9.99500166625008332e-4)
26
- @engine.cdf(0.01, 1.0, 1.0).should be_within(TOL).of(9.95016625083194643e-3)
27
- @engine.cdf(0.1, 1.0, 1.0).should be_within(TOL).of(9.51625819640404268e-2)
28
- @engine.cdf(0.325, 1.0, 1.0).should be_within(TOL).of(2.77472646357927811e-1)
29
- @engine.cdf(1.0, 1.0, 1.0).should be_within(TOL).of(6.32120558828557678e-1)
30
- @engine.cdf(1.5, 1.0, 1.0).should be_within(TOL).of(7.76869839851570171e-1)
31
- @engine.cdf(2.0, 1.0, 1.0).should be_within(TOL).of(8.64664716763387308e-1)
32
- @engine.cdf(10.0, 1.0, 1.0).should be_within(TOL).of(9.99954600070237515e-1)
33
- @engine.cdf(20.0, 1.0, 1.0).should be_within(TOL).of(9.99999997938846378e-1)
34
- @engine.cdf(100.0, 1.0, 1.0).should be_within(TOL).of(1e0)
35
- @engine.cdf(1000.0, 1.0, 1.0).should be_within(TOL).of(1e0)
36
- @engine.cdf(10000.0, 1.0, 1.0).should be_within(TOL).of(1e0)
37
- else
38
- pending("No #{@engine}.cdf")
17
+ it_only_with_gsl 'should return correct cdf' do
18
+ if @engine.respond_to? :cdf
19
+ # From GSL-1.9.
20
+ tol = 1_048_576.0 * Float::EPSILON
21
+ expect(@engine.cdf(0.0, 1.0, 1.0)).to eq(0.0)
22
+ expect(@engine.cdf(1e-100, 1.0, 1.0)).to be_within(tol).of(1e-100)
23
+ expect(@engine.cdf(0.001, 1.0, 1.0)).to be_within(tol).of(9.99500166625008332e-4)
24
+ expect(@engine.cdf(0.01, 1.0, 1.0)).to be_within(tol).of(9.95016625083194643e-3)
25
+ expect(@engine.cdf(0.1, 1.0, 1.0)).to be_within(tol).of(9.51625819640404268e-2)
26
+ expect(@engine.cdf(0.325, 1.0, 1.0)).to be_within(tol).of(2.77472646357927811e-1)
27
+ expect(@engine.cdf(1.0, 1.0, 1.0)).to be_within(tol).of(6.32120558828557678e-1)
28
+ expect(@engine.cdf(1.5, 1.0, 1.0)).to be_within(tol).of(7.76869839851570171e-1)
29
+ expect(@engine.cdf(2.0, 1.0, 1.0)).to be_within(tol).of(8.64664716763387308e-1)
30
+ expect(@engine.cdf(10.0, 1.0, 1.0)).to be_within(tol).of(9.99954600070237515e-1)
31
+ expect(@engine.cdf(20.0, 1.0, 1.0)).to be_within(tol).of(9.99999997938846378e-1)
32
+ expect(@engine.cdf(100.0, 1.0, 1.0)).to be_within(tol).of(1e0)
33
+ expect(@engine.cdf(1000.0, 1.0, 1.0)).to be_within(tol).of(1e0)
34
+ expect(@engine.cdf(10_000.0, 1.0, 1.0)).to be_within(tol).of(1e0)
35
+ else
36
+ pending("No #{@engine}.cdf")
37
+ end
39
38
  end
40
- end
41
- it "should return correct p_value" do
42
- if @engine.respond_to? :p_value
43
- 1.upto(20) do |x|
44
- a=rand()*0.5
45
- b=1 + rand() * 5
46
- pr=@engine.cdf(x,a,b)
47
- @engine.p_value(pr,a,b).should be_within(1e-3).of(x)
48
- end
49
- else
50
- pending("No #{@engine}.p_value")
39
+ it 'should return correct p_value' do
40
+ if @engine.respond_to? :p_value
41
+ 1.upto(20) do |x|
42
+ a = rand * 0.5
43
+ b = 1 + rand * 5
44
+ pr = @engine.cdf(x, a, b)
45
+ expect(@engine.p_value(pr, a, b)).to be_within(1e-3).of(x)
46
+ end
47
+ else
48
+ skip("No #{@engine}.p_value")
49
+ end
51
50
  end
52
51
  end
53
- end
54
52
 
55
- describe "singleton" do
53
+ describe 'singleton' do
56
54
  before do
57
- @engine=Distribution::Gamma
55
+ @engine = Distribution::Gamma
58
56
  end
59
- it_should_behave_like "Gamma engine"
57
+ it_should_behave_like 'Gamma engine'
60
58
  end
61
-
59
+
62
60
  describe Distribution::Gamma::Ruby_ do
63
61
  before do
64
- @engine=Distribution::Gamma::Ruby_
62
+ @engine = Distribution::Gamma::Ruby_
65
63
  end
66
- it_should_behave_like "Gamma engine"
64
+ it_should_behave_like 'Gamma engine'
67
65
  end
68
66
  if Distribution.has_gsl?
69
67
  describe Distribution::Gamma::GSL_ do
70
68
  before do
71
- @engine=Distribution::Gamma::GSL_
69
+ @engine = Distribution::Gamma::GSL_
72
70
  end
73
- it_should_behave_like "Gamma engine"
71
+ it_should_behave_like 'Gamma engine'
74
72
  end
75
73
  end
76
74
  if Distribution.has_java?
77
75
  describe Distribution::Gamma::Java_ do
78
76
  before do
79
- @engine=Distribution::Gamma::Java_
77
+ @engine = Distribution::Gamma::Java_
80
78
  end
81
- it_should_behave_like "Gamma engine"
82
- end
79
+ it_should_behave_like 'Gamma engine'
80
+ end
83
81
  end
84
-
85
82
  end
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
2
  include ExampleWithGSL
3
- #require 'ruby-prof'
3
+ # require 'ruby-prof'
4
4
 
5
5
  # Need to test:
6
6
  # * that Fixnum fast_choose returns same as choose
@@ -9,105 +9,99 @@ include ExampleWithGSL
9
9
 
10
10
  describe Distribution::Hypergeometric do
11
11
  describe Distribution::Hypergeometric::GSL_ do
12
- before do
13
- @ruby=Distribution::Hypergeometric::Ruby_
14
- @engine=Distribution::Hypergeometric::GSL_
12
+ before do
13
+ @ruby = Distribution::Hypergeometric::Ruby_
14
+ @engine = Distribution::Hypergeometric::GSL_
15
15
  end
16
- it_only_with_gsl "cdf should return values near to exact Ruby calculations" do
17
- #RubyProf.start
18
-
16
+ it_only_with_gsl 'cdf should return values near to exact Ruby calculations' do
17
+ # RubyProf.start
18
+
19
19
  if @engine.respond_to? :cdf
20
- #[2].each do |k|
21
- [0,1,2,4,8,16].each do |k|
22
- @engine.cdf(k, 80, 100, 10000).should be_within(1e-10).of(@ruby.cdf(k, 80, 100, 10000))
23
- end
24
- #result = RubyProf.stop
25
-
20
+ # [2].each do |k|
21
+ [0, 1, 2, 4, 8, 16].each do |k|
22
+ expect(@engine.cdf(k, 80, 100, 10_000)).to be_within(1e-10).of(@ruby.cdf(k, 80, 100, 10_000))
23
+ end
24
+ # result = RubyProf.stop
25
+
26
26
  # Print a flat profile to text
27
- #printer = RubyProf::FlatPrinter.new(result)
28
- #printer.print(STDOUT)
29
-
27
+ # printer = RubyProf::FlatPrinter.new(result)
28
+ # printer.print(STDOUT)
29
+
30
30
  else
31
31
  pending("No #{@engine}.pdf")
32
32
  end
33
33
  end
34
-
35
34
  end
36
35
  describe Distribution::Hypergeometric::Ruby_ do
37
-
38
36
  before do
39
- @engine=Distribution::Hypergeometric::Ruby_
37
+ @engine = Distribution::Hypergeometric::Ruby_
40
38
  end
41
- it_only_with_gsl "pdf_fast should return same as pdf" do
39
+ it_only_with_gsl 'pdf_fast should return same as pdf' do
42
40
  pending("Aprox. factorial doesn't work right")
43
41
  if @engine.respond_to? :pdf
44
- [0,1,2,4,8,16].each do |k|
45
- @engine.pdf_aprox(k, 80, 100, 1000).should be_within(1e-8).of(GSL::Ran::hypergeometric_pdf(k, 80, 920, 100))
42
+ [0, 1, 2, 4, 8, 16].each do |k|
43
+ expect(@engine.pdf_aprox(k, 80, 100, 1000)).to be_within(1e-8).of(GSL::Ran.hypergeometric_pdf(k, 80, 920, 100))
46
44
  end
47
45
  else
48
46
  pending("No #{@engine}.pdf")
49
47
  end
50
48
  end
51
-
52
- it_only_with_gsl "should return correct pdf" do
53
- #RubyProf.start
54
-
49
+
50
+ it_only_with_gsl 'should return correct pdf' do
51
+ # RubyProf.start
52
+
55
53
  if @engine.respond_to? :pdf
56
- #[2].each do |k|
57
- [0,1,2,4,8,16].each do |k|
58
- #puts "k:#{k}->#{@engine.pdf(k, 80, 100, 10000).to_f}"
59
- @engine.pdf(k, 80, 100, 10000).to_f.should be_within(1e-8).of(GSL::Ran::hypergeometric_pdf(k, 80, 9920, 100))
60
- end
61
- #result = RubyProf.stop
62
-
54
+ # [2].each do |k|
55
+ [0, 1, 2, 4, 8, 16].each do |k|
56
+ # puts "k:#{k}->#{@engine.pdf(k, 80, 100, 10000).to_f}"
57
+ expect(@engine.pdf(k, 80, 100, 10_000).to_f).to be_within(1e-8).of(GSL::Ran.hypergeometric_pdf(k, 80, 9920, 100))
58
+ end
59
+ # result = RubyProf.stop
60
+
63
61
  # Print a flat profile to text
64
- #printer = RubyProf::FlatPrinter.new(result)
65
- #printer.print(STDOUT)
66
-
62
+ # printer = RubyProf::FlatPrinter.new(result)
63
+ # printer.print(STDOUT)
64
+
67
65
  else
68
66
  pending("No #{@engine}.pdf")
69
67
  end
70
68
  end
71
-
72
-
73
-
74
-
75
- it "should return correct cdf" do
76
- total=rand(5)+3000
77
- n=rand(10)+15
78
- m=rand(10)+5
79
- ac=0
80
- 0.upto(m) do |i|
81
- ac+=@engine.pdf(i,m,n,total)
82
- @engine.cdf(i,m,n,total).should eq(ac)
69
+
70
+ it 'should return correct cdf' do
71
+ total = rand(5) + 3000
72
+ n = rand(10) + 15
73
+ m = rand(10) + 5
74
+ ac = 0
75
+ 0.upto(m) do |i|
76
+ ac += @engine.pdf(i, m, n, total)
77
+ expect(@engine.cdf(i, m, n, total)).to eq(ac)
83
78
  end
84
79
  end
85
-
86
- it "should return correct p_value" do
87
- #0.upto(10) do |i|
80
+
81
+ it 'should return correct p_value' do
82
+ # 0.upto(10) do |i|
88
83
  # puts "#{i}:#{@engine.pdf(i,5,7,10)}"
89
- #end
90
- total=rand(5)+3000
91
- n=rand(10)+15
92
- m=rand(10)+5
93
- ac=0
84
+ # end
85
+ total = rand(5) + 3000
86
+ n = rand(10) + 15
87
+ m = rand(10) + 5
88
+ ac = 0
94
89
  0.upto(m) do |k|
95
- ac+=@engine.pdf(k,m,n,total)
96
- @engine.p_value(ac, m, n, total).should eq(k)
90
+ ac += @engine.pdf(k, m, n, total)
91
+ expect(@engine.p_value(ac, m, n, total)).to eq(k)
97
92
  end
98
- end
93
+ end
99
94
  end
100
95
  describe Distribution::Hypergeometric do
101
96
  before do
102
- @engine=Distribution::Hypergeometric
97
+ @engine = Distribution::Hypergeometric
103
98
  end
104
- it {@engine.should respond_to(:exact_pdf) }
105
- it {@engine.should respond_to(:exact_cdf) }
106
- it {@engine.should respond_to(:exact_p_value) }
107
- it "exact pdf should return a Rational" do
108
- @engine.exact_pdf(1,1,1,1).should_not be_a(Float)
109
- @engine.exact_pdf(16, 80, 100, 10000).should_not be_a(Float)
99
+ it { expect(@engine).to respond_to(:exact_pdf) }
100
+ it { expect(@engine).to respond_to(:exact_cdf) }
101
+ it { expect(@engine).to respond_to(:exact_p_value) }
102
+ it 'exact pdf should return a Rational' do
103
+ expect(@engine.exact_pdf(1, 1, 1, 1)).not_to be_a(Float)
104
+ expect(@engine.exact_pdf(16, 80, 100, 10_000)).not_to be_a(Float)
110
105
  end
111
-
112
106
  end
113
- end
107
+ end
@@ -1,68 +1,62 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
2
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
+
3
3
  describe Distribution::Logistic do
4
-
5
- shared_examples_for "logistic engine" do
6
- it "should return correct pdf" do
4
+ shared_examples_for 'logistic engine' do
5
+ it 'should return correct pdf' do
7
6
  if @engine.respond_to? :pdf
8
7
  1.upto(10) {
9
- u=rand()
10
- s=rand()+1
11
- x=rand()*100-50
12
- exp=Math.exp(-(x-u) / s) / (s*(1+Math.exp(-(x-u) / s)**2))
13
- @engine.pdf(x,u,s).should eq(exp)
8
+ u = rand
9
+ s = rand + 1
10
+ x = rand * 100 - 50
11
+ exp = Math.exp(-(x - u) / s) / (s * (1 + Math.exp(-(x - u) / s)**2))
12
+ expect(@engine.pdf(x, u, s)).to eq(exp)
14
13
  }
15
14
  else
16
15
  pending("No #{@engine}.pdf")
17
16
  end
18
17
  end
19
-
20
- it "should return correct cdf" do
21
- if @engine.respond_to? :cdf
22
-
23
18
 
19
+ it 'should return correct cdf' do
20
+ if @engine.respond_to? :cdf
24
21
  1.upto(100) {
25
- u=rand()
26
- s=rand()+1
27
- x=rand()*100-50
28
- exp=1/(1+Math.exp(-(x-u)/s))
29
- @engine.cdf(x,u,s).should eq(exp)
22
+ u = rand
23
+ s = rand * 100
24
+ x = rand * 100 - 50
25
+ exp = 1 / (1 + Math.exp(-(x - u) / s))
26
+
27
+ expect(@engine.cdf(x, u, s)).to eq(exp)
30
28
  }
31
-
29
+
32
30
  else
33
31
  pending("No #{@engine}.cdf")
34
32
  end
35
33
  end
36
-
37
-
38
- it "should return correct p_value" do
34
+
35
+ it 'should return correct p_value' do
39
36
  if @engine.respond_to? :p_value
40
- 1.upto(9) {|i|
41
- u=rand()
42
- s=rand()+1
43
- x=@engine.p_value(i/10,u,s)
44
- @engine.cdf(x,u,s).should eq i/10
37
+ 1.upto(9) {|i|
38
+ u = rand
39
+ s = rand * 100
40
+ x = @engine.p_value(i / 10.0, u, s)
41
+ expect(@engine.cdf(x, u, s)).to be_within(1e-10).of(i / 10.0)
45
42
  }
46
43
  else
47
44
  pending("No #{@engine}.cdf")
48
45
  end
49
46
  end
50
47
  end
51
-
52
48
 
53
- describe "singleton" do
49
+ describe 'singleton' do
54
50
  before do
55
- @engine=Distribution::Logistic
51
+ @engine = Distribution::Logistic
56
52
  end
57
- it_should_behave_like "logistic engine"
53
+ it_should_behave_like 'logistic engine'
58
54
  end
59
-
55
+
60
56
  describe Distribution::Logistic::Ruby_ do
61
57
  before do
62
- @engine=Distribution::Logistic::Ruby_
58
+ @engine = Distribution::Logistic::Ruby_
63
59
  end
64
- it_should_behave_like "logistic engine"
65
-
60
+ it_should_behave_like 'logistic engine'
66
61
  end
67
-
68
62
  end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
+
3
+ describe Distribution::LogNormal do
4
+ shared_examples_for 'log-normal engine' do
5
+ it 'should return correct pdf' do
6
+ if @engine.respond_to? :pdf
7
+ 1.upto(10) {
8
+ u = rand
9
+ s = rand * 100
10
+ x = rand * 50
11
+ exp = (1.0 / (x * s * Math.sqrt(2 * Math::PI))) * Math.exp(-((Math.log(x) - u)**2 / (2 * s**2)))
12
+ expect(@engine.pdf(x, u, s)).to be_within(1e-10).of(exp)
13
+ }
14
+ else
15
+ pending("No #{@engine}.pdf")
16
+ end
17
+ end
18
+ it 'should return correct cdf' do
19
+ if @engine.respond_to? :cdf
20
+ 1.upto(10) {
21
+ u = rand
22
+ s = rand * 100
23
+ x = rand * 50
24
+ exp = Distribution::Normal.cdf((Math.log(x) - u) / s)
25
+ expect(@engine.cdf(x, u, s)).to be_within(1e-10).of(exp)
26
+ }
27
+ else
28
+ pending("No #{@engine}.cdf")
29
+ end
30
+ end
31
+ end
32
+
33
+ describe 'singleton' do
34
+ before do
35
+ @engine = Distribution::LogNormal
36
+ end
37
+ it_should_behave_like 'log-normal engine'
38
+ end
39
+
40
+ describe Distribution::LogNormal::Ruby_ do
41
+ before do
42
+ @engine = Distribution::LogNormal::Ruby_
43
+ end
44
+ it_should_behave_like 'log-normal engine'
45
+ end
46
+ if Distribution.has_gsl?
47
+ describe Distribution::LogNormal::GSL_ do
48
+ before do
49
+ @engine = Distribution::LogNormal::GSL_
50
+ end
51
+ it_should_behave_like 'log-normal engine'
52
+ end
53
+ end
54
+ end