distribution 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -6
- data/.yardopts +5 -0
- data/History.txt +3 -0
- data/README.md +87 -44
- data/benchmark/binomial_coefficient.rb +19 -23
- data/benchmark/binomial_coefficient/experiment.rb +33 -36
- data/benchmark/factorial_hash.rb +7 -8
- data/benchmark/factorial_method.rb +4 -6
- data/benchmark/odd.rb +6 -7
- data/benchmark/power.rb +11 -11
- data/bin/distribution +26 -26
- data/distribution.gemspec +3 -4
- data/lib/distribution.rb +55 -96
- data/lib/distribution/beta/gsl.rb +10 -5
- data/lib/distribution/beta/ruby.rb +3 -1
- data/lib/distribution/binomial/ruby.rb +5 -2
- data/lib/distribution/bivariatenormal.rb +4 -5
- data/lib/distribution/bivariatenormal/gsl.rb +2 -2
- data/lib/distribution/bivariatenormal/java.rb +1 -1
- data/lib/distribution/bivariatenormal/ruby.rb +245 -254
- data/lib/distribution/chisquare.rb +8 -10
- data/lib/distribution/chisquare/gsl.rb +24 -19
- data/lib/distribution/chisquare/java.rb +1 -1
- data/lib/distribution/chisquare/ruby.rb +25 -25
- data/lib/distribution/chisquare/statistics2.rb +16 -13
- data/lib/distribution/distributable.rb +40 -0
- data/lib/distribution/exponential.rb +4 -5
- data/lib/distribution/exponential/gsl.rb +13 -9
- data/lib/distribution/exponential/ruby.rb +14 -9
- data/lib/distribution/f.rb +1 -1
- data/lib/distribution/f/gsl.rb +26 -22
- data/lib/distribution/f/java.rb +1 -1
- data/lib/distribution/f/ruby.rb +16 -19
- data/lib/distribution/f/statistics2.rb +22 -19
- data/lib/distribution/gamma.rb +5 -7
- data/lib/distribution/gamma/gsl.rb +13 -9
- data/lib/distribution/gamma/java.rb +1 -1
- data/lib/distribution/gamma/ruby.rb +5 -11
- data/lib/distribution/hypergeometric.rb +5 -8
- data/lib/distribution/hypergeometric/gsl.rb +4 -5
- data/lib/distribution/hypergeometric/java.rb +1 -1
- data/lib/distribution/hypergeometric/ruby.rb +34 -35
- data/lib/distribution/logistic.rb +5 -8
- data/lib/distribution/logistic/ruby.rb +13 -8
- data/lib/distribution/lognormal.rb +5 -7
- data/lib/distribution/lognormal/gsl.rb +8 -6
- data/lib/distribution/lognormal/ruby.rb +5 -9
- data/lib/distribution/math_extension.rb +6 -15
- data/lib/distribution/math_extension/chebyshev_series.rb +281 -272
- data/lib/distribution/math_extension/erfc.rb +26 -29
- data/lib/distribution/math_extension/exponential_integral.rb +17 -17
- data/lib/distribution/math_extension/gammastar.rb +19 -20
- data/lib/distribution/math_extension/gsl_utilities.rb +12 -12
- data/lib/distribution/math_extension/incomplete_beta.rb +52 -61
- data/lib/distribution/math_extension/incomplete_gamma.rb +166 -168
- data/lib/distribution/math_extension/log_utilities.rb +20 -22
- data/lib/distribution/normal.rb +11 -13
- data/lib/distribution/normal/gsl.rb +13 -10
- data/lib/distribution/normal/java.rb +14 -13
- data/lib/distribution/normal/ruby.rb +68 -58
- data/lib/distribution/normal/statistics2.rb +5 -2
- data/lib/distribution/normalmultivariate.rb +64 -64
- data/lib/distribution/poisson.rb +11 -13
- data/lib/distribution/poisson/gsl.rb +7 -7
- data/lib/distribution/poisson/java.rb +19 -24
- data/lib/distribution/poisson/ruby.rb +38 -9
- data/lib/distribution/shorthand.rb +17 -0
- data/lib/distribution/t.rb +13 -15
- data/lib/distribution/t/gsl.rb +27 -24
- data/lib/distribution/t/java.rb +1 -1
- data/lib/distribution/t/ruby.rb +99 -100
- data/lib/distribution/t/statistics2.rb +19 -19
- data/lib/distribution/uniform.rb +26 -0
- data/lib/distribution/uniform/gsl.rb +36 -0
- data/lib/distribution/uniform/ruby.rb +91 -0
- data/lib/distribution/version.rb +1 -1
- data/lib/distribution/weibull.rb +6 -7
- data/lib/distribution/weibull/gsl.rb +16 -16
- data/lib/distribution/weibull/ruby.rb +30 -23
- data/spec/beta_spec.rb +45 -47
- data/spec/binomial_spec.rb +77 -85
- data/spec/bivariatenormal_spec.rb +28 -35
- data/spec/chisquare_spec.rb +48 -52
- data/spec/distribution_spec.rb +10 -10
- data/spec/exponential_spec.rb +44 -49
- data/spec/f_spec.rb +4 -4
- data/spec/gamma_spec.rb +50 -53
- data/spec/hypergeometric_spec.rb +63 -69
- data/spec/logistic_spec.rb +32 -37
- data/spec/lognormal_spec.rb +25 -31
- data/spec/math_extension_spec.rb +192 -210
- data/spec/normal_spec.rb +80 -73
- data/spec/poisson_spec.rb +63 -41
- data/spec/shorthand_spec.rb +19 -22
- data/spec/spec_helper.rb +8 -9
- data/spec/t_spec.rb +63 -77
- data/spec/uniform_spec.rb +154 -0
- data/spec/weibull_spec.rb +13 -14
- metadata +17 -8
data/spec/exponential_spec.rb
CHANGED
@@ -1,39 +1,37 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)+
|
2
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
|
2
|
+
|
3
3
|
describe Distribution::Exponential do
|
4
|
-
|
5
|
-
|
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).
|
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
|
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).
|
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
|
36
|
-
@engine.p_value(pr,l).
|
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,54 +39,51 @@ describe Distribution::Exponential do
|
|
41
39
|
end
|
42
40
|
end
|
43
41
|
end
|
44
|
-
|
45
42
|
|
46
|
-
describe
|
43
|
+
describe 'singleton' do
|
47
44
|
before do
|
48
|
-
@engine=Distribution::Exponential
|
45
|
+
@engine = Distribution::Exponential
|
49
46
|
end
|
50
|
-
it_should_behave_like
|
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
|
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
|
-
|
62
|
+
it_should_behave_like 'exponential engine'
|
67
63
|
end
|
68
64
|
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
|
-
describe
|
80
|
-
it
|
81
|
-
Random.
|
82
|
-
Random.should_receive(:rand).and_return(0.5)
|
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)
|
83
78
|
rng = Distribution::Exponential.rng 1.0
|
84
|
-
rng.call
|
79
|
+
rng.call
|
85
80
|
end
|
86
81
|
|
87
|
-
it
|
88
|
-
random = double(
|
89
|
-
random.
|
90
|
-
rng = Distribution::Exponential
|
91
|
-
rng.call
|
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
|
92
87
|
end
|
93
|
-
end
|
88
|
+
end
|
94
89
|
end
|
data/spec/f_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Distribution::F do
|
|
15
15
|
[0.1, 0.5, 1, 2, 10, 20, 30].each do |x|
|
16
16
|
[2, 5, 10].product([2, 5, 10]).each do |n, m|
|
17
17
|
expected_value = GSL::Ran.fdist_pdf(x, n, m)
|
18
|
-
@engine.pdf(x, n, m).
|
18
|
+
expect(@engine.pdf(x, n, m)).to be_within(1e-4).of(expected_value)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
else
|
@@ -30,7 +30,7 @@ describe Distribution::F do
|
|
30
30
|
[0.1, 0.5, 1, 2, 10, 20, 30].each do |f|
|
31
31
|
[2, 5, 10].each do |n2|
|
32
32
|
[2, 5, 10].each do |n1|
|
33
|
-
@engine.cdf(f, n1, n2).
|
33
|
+
expect(@engine.cdf(f, n1, n2)).to be_within(1e-4).of(GSL::Cdf.fdist_P(f, n1, n2))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -43,7 +43,7 @@ describe Distribution::F do
|
|
43
43
|
if @engine.respond_to? :p_value
|
44
44
|
|
45
45
|
expected_value = GSL::Cdf.fdist_Pinv(0.975, 5, 4.189092917592713)
|
46
|
-
@engine.p_value(0.975, 5, 4.189092917592713).
|
46
|
+
expect(@engine.p_value(0.975, 5, 4.189092917592713)).to be_within(1e-4).of(expected_value)
|
47
47
|
|
48
48
|
[0.1, 0.5, 1, 2, 10, 20, 30].each do |f|
|
49
49
|
[2, 5, 10].each do |n2|
|
@@ -51,7 +51,7 @@ describe Distribution::F do
|
|
51
51
|
area = @engine.cdf(f, n1, n2)
|
52
52
|
expected_value = GSL::Cdf.fdist_Pinv(area, n1, n2)
|
53
53
|
|
54
|
-
@engine.p_value(area, n1, n2).
|
54
|
+
expect(@engine.p_value(area, n1, n2)).to be_within(1e-4).of(expected_value)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
data/spec/gamma_spec.rb
CHANGED
@@ -1,85 +1,82 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)+
|
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).
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
53
|
+
describe 'singleton' do
|
56
54
|
before do
|
57
|
-
@engine=Distribution::Gamma
|
55
|
+
@engine = Distribution::Gamma
|
58
56
|
end
|
59
|
-
it_should_behave_like
|
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
|
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
|
-
|
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
|
-
|
82
|
-
end
|
79
|
+
it_should_behave_like 'Gamma engine'
|
80
|
+
end
|
83
81
|
end
|
84
|
-
|
85
82
|
end
|
data/spec/hypergeometric_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)+
|
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
|
-
|
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
|
17
|
-
|
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
|
-
|
22
|
-
@engine.cdf(k, 80, 100,
|
23
|
-
|
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
|
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).
|
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
|
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,
|
60
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
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
|
96
|
-
@engine.p_value(ac, m, n, total).
|
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.
|
105
|
-
it {@engine.
|
106
|
-
it {@engine.
|
107
|
-
it
|
108
|
-
@engine.exact_pdf(1,1,1,1).
|
109
|
-
@engine.exact_pdf(16, 80, 100,
|
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
|