distribution 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +13 -0
- data/.yardopts +5 -0
- data/Gemfile +5 -0
- data/History.txt +24 -8
- data/LICENCE.md +26 -0
- data/README.md +155 -0
- data/Rakefile +15 -19
- 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/data/template/spec.erb +7 -6
- data/distribution.gemspec +25 -0
- data/lib/distribution.rb +79 -124
- data/lib/distribution/beta.rb +6 -8
- data/lib/distribution/beta/gsl.rb +14 -9
- data/lib/distribution/beta/java.rb +1 -1
- data/lib/distribution/beta/ruby.rb +41 -7
- data/lib/distribution/binomial.rb +10 -11
- data/lib/distribution/binomial/gsl.rb +6 -5
- data/lib/distribution/binomial/java.rb +1 -1
- data/lib/distribution/binomial/ruby.rb +22 -15
- 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 +60 -55
- 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 +17 -11
- data/lib/distribution/f.rb +10 -11
- data/lib/distribution/f/gsl.rb +26 -22
- data/lib/distribution/f/java.rb +1 -1
- data/lib/distribution/f/ruby.rb +104 -105
- 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 +5 -6
- data/lib/distribution/hypergeometric/java.rb +1 -1
- data/lib/distribution/hypergeometric/ruby.rb +34 -35
- data/lib/distribution/logistic.rb +6 -9
- data/lib/distribution/logistic/ruby.rb +14 -9
- data/lib/distribution/lognormal.rb +37 -0
- data/lib/distribution/lognormal/gsl.rb +21 -0
- data/lib/distribution/lognormal/ruby.rb +16 -0
- data/lib/distribution/math_extension.rb +187 -231
- data/lib/distribution/math_extension/chebyshev_series.rb +281 -272
- data/lib/distribution/math_extension/erfc.rb +28 -31
- 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 +30 -1
- data/lib/distribution/normal/ruby.rb +69 -59
- data/lib/distribution/normal/statistics2.rb +5 -2
- data/lib/distribution/normalmultivariate.rb +64 -64
- data/lib/distribution/poisson.rb +12 -14
- data/lib/distribution/poisson/gsl.rb +7 -7
- data/lib/distribution/poisson/java.rb +26 -0
- data/lib/distribution/poisson/ruby.rb +38 -9
- data/lib/distribution/shorthand.rb +17 -0
- data/lib/distribution/t.rb +16 -16
- 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 +3 -0
- data/lib/distribution/weibull.rb +10 -0
- data/lib/distribution/weibull/gsl.rb +21 -0
- data/lib/distribution/weibull/ruby.rb +34 -0
- data/spec/beta_spec.rb +48 -50
- data/spec/binomial_spec.rb +80 -84
- data/spec/bivariatenormal_spec.rb +28 -35
- data/spec/chisquare_spec.rb +49 -52
- data/spec/distribution_spec.rb +11 -11
- data/spec/exponential_spec.rb +48 -39
- data/spec/f_spec.rb +73 -71
- data/spec/gamma_spec.rb +50 -53
- data/spec/hypergeometric_spec.rb +63 -69
- data/spec/logistic_spec.rb +31 -37
- data/spec/lognormal_spec.rb +54 -0
- data/spec/math_extension_spec.rb +192 -209
- data/spec/normal_spec.rb +80 -73
- data/spec/poisson_spec.rb +78 -36
- data/spec/shorthand_spec.rb +19 -22
- data/spec/spec_helper.rb +31 -6
- data/spec/t_spec.rb +63 -77
- data/spec/uniform_spec.rb +154 -0
- data/spec/weibull_spec.rb +17 -0
- data/vendor/java/commons-math-2.2.jar +0 -0
- metadata +91 -111
- data.tar.gz.sig +0 -0
- data/.autotest +0 -23
- data/.gemtest +0 -0
- data/Manifest.txt +0 -95
- data/README.txt +0 -100
- metadata.gz.sig +0 -0
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
|
data/spec/logistic_spec.rb
CHANGED
@@ -1,68 +1,62 @@
|
|
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::Logistic do
|
4
|
-
|
5
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
49
|
+
describe 'singleton' do
|
54
50
|
before do
|
55
|
-
@engine=Distribution::Logistic
|
51
|
+
@engine = Distribution::Logistic
|
56
52
|
end
|
57
|
-
it_should_behave_like
|
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
|
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
|