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,63 +1,56 @@
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::BivariateNormal do
4
- shared_examples_for "all pdf normal capables engines" do
5
- it_only_with_gsl "should return correct pdf" do
4
+ shared_examples_for 'all pdf normal capables engines' do
5
+ it_only_with_gsl 'should return correct pdf' do
6
6
  if @engine.respond_to? :pdf
7
- [0.2,0.4,0.6,0.8,0.9, 0.99,0.999,0.999999].each {|rho|
8
- @engine.pdf(0,0, rho , 1,1).should be_within(1e-8).of(GSL::Ran::bivariate_gaussian_pdf(0, 0, 1,1,rho))
7
+ [0.2, 0.4, 0.6, 0.8, 0.9, 0.99, 0.999, 0.999999].each {|rho|
8
+ expect(@engine.pdf(0, 0, rho, 1, 1)).to be_within(1e-8).of(GSL::Ran.bivariate_gaussian_pdf(0, 0, 1, 1, rho))
9
9
  }
10
10
  else
11
11
  pending("No #{@engine}.pdf")
12
12
  end
13
13
  end
14
14
  end
15
-
16
- shared_examples_for "all cdf normal capables engines" do
17
- it "should return correct cdf" do
15
+
16
+ shared_examples_for 'all cdf normal capables engines' do
17
+ it 'should return correct cdf' do
18
18
  if @engine.respond_to? :cdf
19
- @engine.cdf(2,0.5,0.5).should be_within(1e-3).of(0.686)
20
- @engine.cdf(2,0.0,0.5).should be_within(1e-3).of(0.498)
21
- @engine.cdf(1.5,0.5,0.5).should be_within(1e-3).of(0.671)
22
- v=rand
23
- @engine.cdf(10,0,v).should be_within(1e-3).of(Distribution::Normal.cdf(0))
19
+ expect(@engine.cdf(2, 0.5, 0.5)).to be_within(1e-3).of(0.686)
20
+ expect(@engine.cdf(2, 0.0, 0.5)).to be_within(1e-3).of(0.498)
21
+ expect(@engine.cdf(1.5, 0.5, 0.5)).to be_within(1e-3).of(0.671)
22
+ v = rand
23
+ expect(@engine.cdf(10, 0, v)).to be_within(1e-3).of(Distribution::Normal.cdf(0))
24
24
  else
25
- pending("No #{@engine}.cdf")
26
-
25
+ pending("No #{@engine}.cdf")
26
+
27
27
  end
28
28
  end
29
-
30
29
  end
31
- describe "singleton" do
30
+ describe 'singleton' do
32
31
  before do
33
- @engine=Distribution::BivariateNormal
32
+ @engine = Distribution::BivariateNormal
34
33
  end
35
- it_should_behave_like "all pdf normal capables engines"
36
- it_should_behave_like "all cdf normal capables engines"
37
-
34
+ it_should_behave_like 'all pdf normal capables engines'
35
+ it_should_behave_like 'all cdf normal capables engines'
38
36
  end
39
-
37
+
40
38
  describe Distribution::Normal::Ruby_ do
41
39
  before do
42
- @engine=Distribution::BivariateNormal::Ruby_
40
+ @engine = Distribution::BivariateNormal::Ruby_
43
41
  end
44
- it_should_behave_like "all pdf normal capables engines"
45
- it_should_behave_like "all cdf normal capables engines"
46
- it "Ganz method should return similar method to Hull one" do
47
- [-3,-2,-1,0,1,1.5].each {|x|
48
- @engine.cdf_hull(x,x,0.5).should be_within(0.001).of(@engine.cdf_genz(x,x,0.5))
49
-
42
+ it_should_behave_like 'all pdf normal capables engines'
43
+ it_should_behave_like 'all cdf normal capables engines'
44
+ it 'Ganz method should return similar method to Hull one' do
45
+ [-3, -2, -1, 0, 1, 1.5].each {|x|
46
+ expect(@engine.cdf_hull(x, x, 0.5)).to be_within(0.001).of(@engine.cdf_genz(x, x, 0.5))
50
47
  }
51
48
  end
52
-
53
49
  end
54
50
  describe Distribution::Normal::GSL_ do
55
51
  before do
56
- @engine=Distribution::BivariateNormal::GSL_
52
+ @engine = Distribution::BivariateNormal::GSL_
57
53
  end
58
- it_should_behave_like "all pdf normal capables engines"
59
-
54
+ it_should_behave_like 'all pdf normal capables engines'
60
55
  end
61
-
62
-
63
56
  end
@@ -1,89 +1,86 @@
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::ChiSquare do
4
-
5
- shared_examples_for "Chi-square engine(with pdf)" do
6
- it_only_with_gsl "should return correct pdf" do
4
+ shared_examples_for 'Chi-square engine(with pdf)' do
5
+ it_only_with_gsl 'should return correct pdf' do
7
6
  if @engine.respond_to? :pdf
8
7
  1.upto(10) do |k|
9
- v=1+rand(5)
10
- chi=GSL::Ran.chisq_pdf(v,k)
11
- @engine.pdf(v,k).should be_within(10e-10).of(chi)
8
+ v = 1 + rand(5)
9
+ chi = GSL::Ran.chisq_pdf(v, k)
10
+ expect(@engine.pdf(v, k)).to be_within(10e-10).of(chi)
12
11
  end
13
12
  else
14
- pending("No #{@engine}.pdf")
13
+ skip("No #{@engine}.pdf")
15
14
  end
16
15
  end
16
+ end
17
17
 
18
- end
19
-
20
- shared_examples_for "Chi-square engine" do
18
+ shared_examples_for 'Chi-square engine' do
19
+ it_only_with_gsl 'should return correct cdf' do
20
+ if @engine.respond_to? :cdf
21
+ 1.upto(10) do |k|
22
+ v = 1 + rand(5)
23
+ chi = GSL::Cdf.chisq_P(v, k)
24
+ expect(@engine.cdf(v, k)).to be_within(10e-10).of(chi)
25
+ end
26
+ else
27
+ skip("No #{@engine}.cdf")
28
+ end
29
+ end
21
30
 
22
- it_only_with_gsl "should return correct cdf" do
23
- if @engine.respond_to? :cdf
24
- 1.upto(10) do |k|
25
- v=1+rand(5)
26
- chi=GSL::Cdf::chisq_P(v,k)
27
- @engine.cdf(v,k).should be_within(10e-10).of(chi)
31
+ it 'should return correct p_value' do
32
+ if @engine.respond_to? :p_value
33
+ 1.upto(10) do |k|
34
+ v = 1 + rand(5)
35
+ pr = @engine.cdf(v, k)
36
+ expect(@engine.p_value(pr, k)).to be_within(10e-4).of(v)
37
+ end
38
+ else
39
+ skip("No #{@engine}.p_value")
28
40
  end
29
- else
30
- pending("No #{@engine}.cdf")
31
- end
32
- end
33
- it "should return correct p_value" do
34
- if @engine.respond_to? :p_value
35
- 1.upto(10) do |k|
36
- v=1+rand(5)
37
- pr=@engine.cdf(v,k)
38
- @engine.p_value(pr,k).should be_within(10e-4).of(v)
39
- end
40
- else
41
- pending("No #{@engine}.p_value")
42
41
  end
43
42
  end
44
- end
45
43
 
46
- describe "singleton" do
44
+ describe 'singleton' do
47
45
  before do
48
- @engine=Distribution::ChiSquare
46
+ @engine = Distribution::ChiSquare
49
47
  end
50
- it_should_behave_like "Chi-square engine"
51
- it_should_behave_like "Chi-square engine(with pdf)"
48
+ it_should_behave_like 'Chi-square engine'
49
+ it_should_behave_like 'Chi-square engine(with pdf)'
52
50
  end
53
-
51
+
54
52
  describe Distribution::ChiSquare::Ruby_ do
55
53
  before do
56
- @engine=Distribution::ChiSquare::Ruby_
54
+ @engine = Distribution::ChiSquare::Ruby_
57
55
  end
58
- it_should_behave_like "Chi-square engine"
59
- it_should_behave_like "Chi-square engine(with pdf)"
56
+ it_should_behave_like 'Chi-square engine'
57
+ it_should_behave_like 'Chi-square engine(with pdf)'
60
58
  end
61
59
  if Distribution.has_gsl?
62
60
  describe Distribution::ChiSquare::GSL_ do
63
61
  before do
64
- @engine=Distribution::ChiSquare::GSL_
62
+ @engine = Distribution::ChiSquare::GSL_
65
63
  end
66
- it_should_behave_like "Chi-square engine"
67
- it_should_behave_like "Chi-square engine(with pdf)"
64
+ it_should_behave_like 'Chi-square engine'
65
+ it_should_behave_like 'Chi-square engine(with pdf)'
68
66
  end
69
- end
67
+ end
70
68
  if Distribution.has_statistics2?
71
69
  describe Distribution::ChiSquare::Statistics2_ do
72
70
  before do
73
- @engine=Distribution::ChiSquare::Statistics2_
71
+ @engine = Distribution::ChiSquare::Statistics2_
74
72
  end
75
- it_should_behave_like "Chi-square engine"
76
- end
73
+ it_should_behave_like 'Chi-square engine'
74
+ end
77
75
  end
78
-
76
+
79
77
  if Distribution.has_java?
80
78
  describe Distribution::ChiSquare::Java_ do
81
79
  before do
82
- @engine=Distribution::ChiSquare::Java_
80
+ @engine = Distribution::ChiSquare::Java_
83
81
  end
84
- it_should_behave_like "Chi-square engine"
85
- it_should_behave_like "Chi-square engine(with pdf)"
86
- end
82
+ it_should_behave_like 'Chi-square engine'
83
+ it_should_behave_like 'Chi-square engine(with pdf)'
84
+ end
87
85
  end
88
-
89
86
  end
@@ -1,19 +1,19 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
2
  describe Distribution do
3
- it "should respond to has_gsl?" do
4
- lambda {Distribution.has_gsl?}.should_not raise_exception
3
+ it 'should respond to has_gsl?' do
4
+ lambda { Distribution.has_gsl? }.should_not raise_exception
5
5
  if Distribution.has_gsl?
6
- defined?(GSL).should be_true
6
+ expect(defined?(GSL)).to be
7
7
  else
8
- defined?(GSL).should be_false
9
- end
8
+ expect(defined?(GSL)).to be_nil
9
+ end
10
10
  end
11
- it "should respond to has_statistics2?" do
12
- lambda {Distribution.has_statistics2?}.should_not raise_exception
11
+ it 'should respond to has_statistics2?' do
12
+ lambda { Distribution.has_statistics2? }.should_not raise_exception
13
13
  if Distribution.has_statistics2?
14
- defined?(Statistics2).should be_true
14
+ expect(defined?(Statistics2)).to be
15
15
  else
16
- defined?(Statistics2).should be_false
17
- end
16
+ expect(defined?(Statistics2)).to be_nil
17
+ end
18
18
  end
19
19
  end
@@ -1,39 +1,37 @@
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::Exponential do
4
-
5
- shared_examples_for "exponential engine" do
6
- it "should return correct pdf" do
4
+ shared_examples_for 'exponential engine' do
5
+ it 'should return correct pdf' do
7
6
  if @engine.respond_to? :pdf
8
- [0.5,1,1.5].each {|l|
7
+ [0.5, 1, 1.5].each {|l|
9
8
  1.upto(5) {|x|
10
- @engine.pdf(x,l).should be_within(1e-10).of(l*Math.exp(-l*x))
9
+ expect(@engine.pdf(x, l)).to be_within(1e-10).of(l * Math.exp(-l * x))
11
10
  }
12
11
  }
13
12
  else
14
13
  pending("No #{@engine}.pdf")
15
14
  end
16
15
  end
17
-
18
- it "should return correct cdf" do
16
+
17
+ it 'should return correct cdf' do
19
18
  if @engine.respond_to? :cdf
20
- [0.5,1,1.5].each {|l|
19
+ [0.5, 1, 1.5].each {|l|
21
20
  1.upto(5) {|x|
22
- @engine.cdf(x,l).should be_within(1e-10).of(1-Math.exp(-l*x))
21
+ expect(@engine.cdf(x, l)).to be_within(1e-10).of(1 - Math.exp(-l * x))
23
22
  }
24
23
  }
25
24
  else
26
25
  pending("No #{@engine}.cdf")
27
26
  end
28
27
  end
29
-
30
-
31
- it "should return correct p_value" do
28
+
29
+ it 'should return correct p_value' do
32
30
  if @engine.respond_to? :p_value
33
- [0.5,1,1.5].each {|l|
31
+ [0.5, 1, 1.5].each {|l|
34
32
  1.upto(5) {|x|
35
- pr=@engine.cdf(x,l)
36
- @engine.p_value(pr,l).should be_within(1e-10).of(x)
33
+ pr = @engine.cdf(x, l)
34
+ expect(@engine.p_value(pr, l)).to be_within(1e-10).of(x)
37
35
  }
38
36
  }
39
37
  else
@@ -41,40 +39,51 @@ describe Distribution::Exponential do
41
39
  end
42
40
  end
43
41
  end
44
-
45
42
 
46
- describe "singleton" do
43
+ describe 'singleton' do
47
44
  before do
48
- @engine=Distribution::Exponential
45
+ @engine = Distribution::Exponential
49
46
  end
50
- it_should_behave_like "exponential engine"
47
+ it_should_behave_like 'exponential engine'
51
48
  end
52
-
49
+
53
50
  describe Distribution::Exponential::Ruby_ do
54
51
  before do
55
- @engine=Distribution::Exponential::Ruby_
52
+ @engine = Distribution::Exponential::Ruby_
56
53
  end
57
- it_should_behave_like "exponential engine"
58
-
54
+ it_should_behave_like 'exponential engine'
59
55
  end
60
-
56
+
61
57
  if Distribution.has_gsl?
62
58
  describe Distribution::Exponential::GSL_ do
63
59
  before do
64
- @engine=Distribution::Exponential::GSL_
60
+ @engine = Distribution::Exponential::GSL_
65
61
  end
66
- it_should_behave_like "exponential engine"
62
+ it_should_behave_like 'exponential engine'
63
+ end
64
+ end
65
+
66
+ # if Distribution.has_java?
67
+ # describe Distribution::Exponential::Java_ do
68
+ # before do
69
+ # @engine=Distribution::Exponential::Java_
70
+ # end
71
+ # it_should_behave_like "exponential engine"
72
+ #
73
+ # end
74
+ # end
75
+ describe 'rng' do
76
+ it 'should default to Kernel#rand if no :random is given' do
77
+ allow(Random).to receive(:rand).and_return(0.5)
78
+ rng = Distribution::Exponential.rng 1.0
79
+ rng.call
80
+ end
81
+
82
+ it 'should use a given rng if one is passed during construction' do
83
+ random = double('random')
84
+ allow(random).to receive(:rand).and_return(0.5)
85
+ rng = Distribution::Exponential.rng 1.0, random: random
86
+ rng.call
67
87
  end
68
88
  end
69
-
70
- # if Distribution.has_java?
71
- # describe Distribution::Exponential::Java_ do
72
- # before do
73
- # @engine=Distribution::Exponential::Java_
74
- # end
75
- # it_should_behave_like "exponential engine"
76
- #
77
- # end
78
- # end
79
-
80
89
  end
@@ -1,107 +1,109 @@
1
- require File.expand_path(File.dirname(__FILE__)+"/spec_helper.rb")
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
2
 
3
3
  include ExampleWithGSL
4
4
 
5
5
  describe Distribution::F do
6
- shared_examples_for "F engine(with rng)" do
7
- it "should return correct rng" do
8
- pending()
6
+ shared_examples_for 'F engine (with rng)' do
7
+ it 'should return correct rng' do
8
+ pending
9
+ end
9
10
  end
10
- end
11
11
 
12
- shared_examples_for "F engine(with pdf)" do
13
- it_only_with_gsl "should return correct pdf" do
14
- if @engine.respond_to? :pdf
15
- [0.1,0.5,1,2,10,20,30].each{|f|
16
- [2,5,10].each{|n2|
17
- [2,5,10].each{|n1|
18
- @engine.pdf(f,n1,n2).should be_within(1e-4).of(GSL::Ran.fdist_pdf(f,n1,n2))
19
- }
20
- }
21
- }
22
- else
23
- pending("No #{@engine}.pdf")
12
+ shared_examples_for 'F engine (with pdf)' do
13
+ it_only_with_gsl 'should return correct pdf' do
14
+ if @engine.respond_to? :pdf
15
+ [0.1, 0.5, 1, 2, 10, 20, 30].each do |x|
16
+ [2, 5, 10].product([2, 5, 10]).each do |n, m|
17
+ expected_value = GSL::Ran.fdist_pdf(x, n, m)
18
+ expect(@engine.pdf(x, n, m)).to be_within(1e-4).of(expected_value)
19
+ end
20
+ end
21
+ else
22
+ pending("No #{@engine}.pdf")
23
+ end
24
24
  end
25
25
  end
26
- end
27
26
 
28
- shared_examples_for "F engine" do
29
-
30
- it_only_with_gsl "should return correct cdf" do
31
- if @engine.respond_to? :cdf
32
- [0.1,0.5,1,2,10,20,30].each{|f|
33
- [2,5,10].each{|n2|
34
- [2,5,10].each{|n1|
35
- @engine.cdf(f,n1,n2).should be_within(1e-4).of(GSL::Cdf.fdist_P(f,n1,n2))
36
-
37
- }
38
- }
39
- }
40
- else
41
- pending("No #{@engine}.cdf")
27
+ shared_examples_for 'F engine' do
28
+ it_only_with_gsl 'should return correct cdf' do
29
+ if @engine.respond_to? :cdf
30
+ [0.1, 0.5, 1, 2, 10, 20, 30].each do |f|
31
+ [2, 5, 10].each do |n2|
32
+ [2, 5, 10].each do |n1|
33
+ expect(@engine.cdf(f, n1, n2)).to be_within(1e-4).of(GSL::Cdf.fdist_P(f, n1, n2))
34
+ end
35
+ end
36
+ end
37
+ else
38
+ pending("No #{@engine}.cdf")
39
+ end
42
40
  end
43
-
44
- end
45
- it_only_with_gsl "should return correct p_value" do
46
- if @engine.respond_to? :p_value
47
-
48
- [0.1,0.5,1,2,10,20,30].each{|f|
49
- [2,5,10].each{|n2|
50
- [2,5,10].each{|n1|
51
- area=@engine.cdf(f,n1,n2)
52
- @engine.p_value(area,n1,n2).should be_within(1e-4).of(GSL::Cdf.fdist_Pinv(area,n1,n2))
53
- }
54
- }
55
- }
56
-
57
-
58
- else
59
- pending("No #{@engine}.p_value")
41
+
42
+ it_only_with_gsl 'should return correct p_value', focus: true do
43
+ if @engine.respond_to? :p_value
44
+
45
+ expected_value = GSL::Cdf.fdist_Pinv(0.975, 5, 4.189092917592713)
46
+ expect(@engine.p_value(0.975, 5, 4.189092917592713)).to be_within(1e-4).of(expected_value)
47
+
48
+ [0.1, 0.5, 1, 2, 10, 20, 30].each do |f|
49
+ [2, 5, 10].each do |n2|
50
+ [2, 5, 10].each do |n1|
51
+ area = @engine.cdf(f, n1, n2)
52
+ expected_value = GSL::Cdf.fdist_Pinv(area, n1, n2)
53
+
54
+ expect(@engine.p_value(area, n1, n2)).to be_within(1e-4).of(expected_value)
55
+ end
56
+ end
57
+ end
58
+ else
59
+ pending("No #{@engine}.p_value")
60
+ end
60
61
  end
61
62
  end
62
- end
63
63
 
64
- describe "singleton" do
64
+ describe 'singleton' do
65
65
  before do
66
- @engine=Distribution::F
66
+ @engine = Distribution::F
67
67
  end
68
- it_should_behave_like "F engine"
69
- it_should_behave_like "F engine(with pdf)"
68
+
69
+ it_should_behave_like 'F engine'
70
+ it_should_behave_like 'F engine (with pdf)'
70
71
  end
71
-
72
+
72
73
  describe Distribution::F::Ruby_ do
73
74
  before do
74
- @engine=Distribution::F::Ruby_
75
+ @engine = Distribution::F::Ruby_
75
76
  end
76
- it_should_behave_like "F engine"
77
- it_should_behave_like "F engine(with pdf)"
77
+ it_should_behave_like 'F engine'
78
+ it_should_behave_like 'F engine (with pdf)'
78
79
  end
80
+
79
81
  if Distribution.has_gsl?
80
82
  describe Distribution::F::GSL_ do
81
83
  before do
82
- @engine=Distribution::F::GSL_
84
+ @engine = Distribution::F::GSL_
83
85
  end
84
- it_should_behave_like "F engine"
85
- it_should_behave_like "F engine(with pdf)"
86
+ it_should_behave_like 'F engine'
87
+ it_should_behave_like 'F engine (with pdf)'
86
88
  end
87
- end
89
+ end
90
+
88
91
  if Distribution.has_statistics2?
89
92
  describe Distribution::F::Statistics2_ do
90
93
  before do
91
- @engine=Distribution::F::Statistics2_
94
+ @engine = Distribution::F::Statistics2_
92
95
  end
93
- it_should_behave_like "F engine"
94
- end
96
+ it_should_behave_like 'F engine'
97
+ end
95
98
  end
96
-
99
+
97
100
  if Distribution.has_java?
98
101
  describe Distribution::F::Java_ do
99
102
  before do
100
- @engine=Distribution::F::Java_
103
+ @engine = Distribution::F::Java_
101
104
  end
102
- it_should_behave_like "F engine"
103
- it_should_behave_like "F engine(with pdf)"
104
- end
105
+ it_should_behave_like 'F engine'
106
+ it_should_behave_like 'F engine (with pdf)'
107
+ end
105
108
  end
106
-
107
109
  end