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
@@ -0,0 +1,154 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/spec_helper.rb")
|
2
|
+
require 'distribution/uniform'
|
3
|
+
|
4
|
+
describe Distribution::Uniform do
|
5
|
+
|
6
|
+
shared_examples_for "uniform engine" do
|
7
|
+
|
8
|
+
it ".rng should generate sequences with the right mean & variance" do
|
9
|
+
skip("This method is very innacurrate due to the low convergence rate")
|
10
|
+
# samples = 100_000
|
11
|
+
# sum = 0
|
12
|
+
# ss = 0
|
13
|
+
# lower = 0
|
14
|
+
# upper = 20
|
15
|
+
|
16
|
+
# # Expectations
|
17
|
+
# exp_mean = (upper + lower) / 2
|
18
|
+
# exp_variance = ((upper - lower) ** 2) / 12
|
19
|
+
# rng = @engine.rng(lower, upper)
|
20
|
+
|
21
|
+
# samples.times do
|
22
|
+
# v = rng.call
|
23
|
+
# sum += v
|
24
|
+
# ss += (v - exp_mean) ** 2
|
25
|
+
# end
|
26
|
+
|
27
|
+
# mean = sum.to_f / samples
|
28
|
+
# variance = ss.to_f / samples
|
29
|
+
# mean.should be_within(1e-5).of(exp_mean)
|
30
|
+
# variance.should be_within(1e-5).of(exp_variance)
|
31
|
+
end
|
32
|
+
|
33
|
+
it ".rng with a specified seed should be reproducible" do
|
34
|
+
seed = Random.new_seed.modulo 100000007
|
35
|
+
gen_a = @engine.rng(0, 1, seed)
|
36
|
+
gen_b = @engine.rng(0, 1, seed)
|
37
|
+
|
38
|
+
expect((gen_a.call)).to eq(gen_b.call)
|
39
|
+
end
|
40
|
+
|
41
|
+
it ".pdf should return correct pdf for values within the defined range" do
|
42
|
+
if @engine.respond_to? :pdf
|
43
|
+
10.times do
|
44
|
+
low, width = rand, rand
|
45
|
+
x = low + rand * width
|
46
|
+
epdf = 1.0 / width
|
47
|
+
expect(@engine.pdf(x, low, low + width)).to be_within(1e-10).of(epdf)
|
48
|
+
end
|
49
|
+
|
50
|
+
else
|
51
|
+
pending("No #{@engine}.pdf")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it ".pdf should return 0 for values outside the defined range" do
|
56
|
+
if @engine.respond_to? :pdf
|
57
|
+
10.times do
|
58
|
+
low, width = rand, rand
|
59
|
+
# x lies just outside of where the pdf exists as a non-zero value
|
60
|
+
# A small amount (1e-10) is removed from bad_x to ensure no overlap
|
61
|
+
x = low - (1 + rand) * width - 1e-10
|
62
|
+
expect(@engine.pdf(x, low, low + width)).to be_within(1e-10).of(0.0)
|
63
|
+
end
|
64
|
+
|
65
|
+
else
|
66
|
+
pending("No #{@engine}.pdf")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
it ".cdf should return 0 for values smaller than the lower bound" do
|
72
|
+
if @engine.respond_to? :cdf
|
73
|
+
low, width = rand, rand
|
74
|
+
x = low - rand * width
|
75
|
+
expect(@engine.cdf(x, low, low + width)).to be_within(1e-10).of(0.0)
|
76
|
+
else
|
77
|
+
pending("No #{@engine}.cdf")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it ".cdf should return correct cdf for x within defined range" do
|
82
|
+
if @engine.respond_to? :cdf
|
83
|
+
low, width = rand, rand
|
84
|
+
x = low + rand * width
|
85
|
+
ecdf = (x - low) / width
|
86
|
+
expect(@engine.cdf(x, low, low + width)).to be_within(1e-10).of(ecdf)
|
87
|
+
else
|
88
|
+
pending("No #{@engine}.cdf")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it ".cdf should return 1 for values greater than the upper bound" do
|
93
|
+
if @engine.respond_to? :cdf
|
94
|
+
low, width = rand, rand
|
95
|
+
x = low + (1 + rand) * (width)
|
96
|
+
expect(@engine.cdf(x, low, low + width)).to be_within(1e-10).of(1.0)
|
97
|
+
else
|
98
|
+
pending("No #{@engine}.cdf")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it ".quantile should return correct inverse cdf" do
|
103
|
+
if @engine.respond_to? :quantile
|
104
|
+
low, width = rand, rand
|
105
|
+
scale = rand
|
106
|
+
x = low + scale * width
|
107
|
+
qn = (x - low) / width
|
108
|
+
expect(@engine.quantile(qn, low, low + width)).to be_within(1e-10).of(x)
|
109
|
+
else
|
110
|
+
pending("No #{@engine}.quantile")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it ".p_value should return same result as .quantile" do
|
115
|
+
if @engine.respond_to? :p_value and @engine.respond_to? :quantile
|
116
|
+
low, width = rand, rand
|
117
|
+
scale = rand
|
118
|
+
x = low + scale * width
|
119
|
+
qn = (x - low) / width
|
120
|
+
|
121
|
+
expect(@engine.quantile(qn, low, low + width)).to eq(@engine.p_value(qn, low, low + width))
|
122
|
+
else
|
123
|
+
pending("No #{@engine}.p_value")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
describe "singleton" do
|
130
|
+
before do
|
131
|
+
@engine = Distribution::Uniform
|
132
|
+
end
|
133
|
+
it_should_behave_like "uniform engine"
|
134
|
+
end
|
135
|
+
|
136
|
+
describe Distribution::Uniform::Ruby_ do
|
137
|
+
before do
|
138
|
+
@engine = Distribution::Uniform::Ruby_
|
139
|
+
end
|
140
|
+
it_should_behave_like "uniform engine"
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
if Distribution.has_gsl?
|
145
|
+
describe Distribution::Uniform::GSL_ do
|
146
|
+
before do
|
147
|
+
@engine = Distribution::Uniform::GSL_
|
148
|
+
end
|
149
|
+
it_should_behave_like "uniform engine"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
end
|
data/spec/weibull_spec.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)+
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
|
2
2
|
|
3
3
|
include ExampleWithGSL
|
4
4
|
|
5
5
|
describe Distribution::Weibull do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
6
|
+
# shared_examples for "Weibull engine" do
|
7
|
+
it 'should return correct pdf' do
|
8
|
+
expect(Distribution::Weibull.pdf(2, 1, 1)).to be_within(1e-3).of(0.13533)
|
9
|
+
end
|
10
|
+
it 'should return correct cdf' do
|
11
|
+
expect(Distribution::Weibull.cdf(2, 1, 1)).to be_within(1e-3).of(0.86466)
|
12
|
+
end
|
13
|
+
it 'should return correct p-value' do
|
14
|
+
expect(Distribution::Weibull.p_value(0.86466, 1, 1)).to be_within(1e-3).of(2.0)
|
15
|
+
end
|
16
|
+
# end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distribution
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claudio Bustos
|
8
|
-
|
8
|
+
- Carlos Agarie
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-07-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -52,9 +53,11 @@ dependencies:
|
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '3.2'
|
55
|
-
description: Distribution
|
56
|
+
description: Distribution is a gem with several probabilistic distributions. Pure
|
57
|
+
Ruby is used by default, C (GSL) or Java extensions are used if available
|
56
58
|
email:
|
57
59
|
- clbustos@gmail.com
|
60
|
+
- carlos.agarie@gmail.com
|
58
61
|
executables:
|
59
62
|
- distribution
|
60
63
|
extensions: []
|
@@ -62,6 +65,7 @@ extra_rdoc_files: []
|
|
62
65
|
files:
|
63
66
|
- ".gitignore"
|
64
67
|
- ".travis.yml"
|
68
|
+
- ".yardopts"
|
65
69
|
- Gemfile
|
66
70
|
- History.txt
|
67
71
|
- LICENCE.md
|
@@ -100,6 +104,7 @@ files:
|
|
100
104
|
- lib/distribution/chisquare/java.rb
|
101
105
|
- lib/distribution/chisquare/ruby.rb
|
102
106
|
- lib/distribution/chisquare/statistics2.rb
|
107
|
+
- lib/distribution/distributable.rb
|
103
108
|
- lib/distribution/exponential.rb
|
104
109
|
- lib/distribution/exponential/gsl.rb
|
105
110
|
- lib/distribution/exponential/ruby.rb
|
@@ -140,11 +145,15 @@ files:
|
|
140
145
|
- lib/distribution/poisson/gsl.rb
|
141
146
|
- lib/distribution/poisson/java.rb
|
142
147
|
- lib/distribution/poisson/ruby.rb
|
148
|
+
- lib/distribution/shorthand.rb
|
143
149
|
- lib/distribution/t.rb
|
144
150
|
- lib/distribution/t/gsl.rb
|
145
151
|
- lib/distribution/t/java.rb
|
146
152
|
- lib/distribution/t/ruby.rb
|
147
153
|
- lib/distribution/t/statistics2.rb
|
154
|
+
- lib/distribution/uniform.rb
|
155
|
+
- lib/distribution/uniform/gsl.rb
|
156
|
+
- lib/distribution/uniform/ruby.rb
|
148
157
|
- lib/distribution/version.rb
|
149
158
|
- lib/distribution/weibull.rb
|
150
159
|
- lib/distribution/weibull/gsl.rb
|
@@ -167,12 +176,13 @@ files:
|
|
167
176
|
- spec/spec.opts
|
168
177
|
- spec/spec_helper.rb
|
169
178
|
- spec/t_spec.rb
|
179
|
+
- spec/uniform_spec.rb
|
170
180
|
- spec/weibull_spec.rb
|
171
181
|
- vendor/java/commons-math-2.2.jar
|
172
182
|
homepage: https://github.com/sciruby/distribution
|
173
183
|
licenses: []
|
174
184
|
metadata: {}
|
175
|
-
post_install_message:
|
185
|
+
post_install_message:
|
176
186
|
rdoc_options: []
|
177
187
|
require_paths:
|
178
188
|
- lib
|
@@ -187,9 +197,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
197
|
- !ruby/object:Gem::Version
|
188
198
|
version: '0'
|
189
199
|
requirements: []
|
190
|
-
|
191
|
-
|
192
|
-
signing_key:
|
200
|
+
rubygems_version: 3.1.2
|
201
|
+
signing_key:
|
193
202
|
specification_version: 4
|
194
203
|
summary: Distribution
|
195
204
|
test_files: []
|