rubystats 0.2.3 → 0.4.1
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.
- checksums.yaml +7 -0
- data/.github/workflows/test.yml +21 -0
- data/.gitignore +20 -0
- data/Gemfile +3 -0
- data/History.txt +34 -0
- data/{README.txt → README.rdoc} +18 -7
- data/Rakefile +11 -44
- data/examples/uniform.rb +14 -0
- data/lib/rubystats/beta_distribution.rb +4 -0
- data/lib/rubystats/binomial_distribution.rb +42 -131
- data/lib/rubystats/cauchy_distribution.rb +50 -0
- data/lib/rubystats/exponential_distribution.rb +2 -2
- data/lib/rubystats/fishers_exact_test.rb +9 -9
- data/lib/rubystats/gamma_distribution.rb +70 -0
- data/lib/rubystats/lognormal_distribution.rb +59 -0
- data/lib/rubystats/modules.rb +57 -48
- data/lib/rubystats/multivariate_normal_distribution.rb +73 -0
- data/lib/rubystats/normal_distribution.rb +4 -3
- data/lib/rubystats/poisson_distribution.rb +78 -0
- data/lib/rubystats/probability_distribution.rb +4 -4
- data/lib/rubystats/student_t_distribution.rb +62 -0
- data/lib/rubystats/uniform_distribution.rb +70 -0
- data/lib/rubystats/version.rb +3 -0
- data/lib/rubystats/weibull_distribution.rb +56 -0
- data/lib/rubystats.rb +39 -5
- data/rubystats.gemspec +28 -0
- data/test/tc_beta.rb +90 -69
- data/test/tc_binomial.rb +30 -16
- data/test/tc_cauchy.rb +39 -0
- data/test/tc_exponential.rb +13 -3
- data/test/tc_fisher.rb +15 -15
- data/test/tc_gamma.rb +39 -0
- data/test/tc_lnorm.rb +45 -0
- data/test/tc_multivariate_normal.rb +53 -0
- data/test/tc_norm.rb +35 -6
- data/test/tc_poisson.rb +35 -0
- data/test/tc_require_all.rb +5 -5
- data/test/tc_studentt.rb +43 -0
- data/test/tc_unif.rb +48 -0
- data/test/tc_weibull.rb +51 -0
- data/test/ts_stats.rb +1 -1
- metadata +115 -47
data/test/tc_poisson.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'rubystats/poisson_distribution'
|
4
|
+
|
5
|
+
class TestPoisson < MiniTest::Unit::TestCase
|
6
|
+
def test_simple
|
7
|
+
rate = 3.5
|
8
|
+
k = 6
|
9
|
+
|
10
|
+
pois = Rubystats::PoissonDistribution.new(rate)
|
11
|
+
cdf = pois.cdf(k)
|
12
|
+
pmf = pois.pmf(k)
|
13
|
+
pdf = pois.pdf(k)
|
14
|
+
mean = pois.mean
|
15
|
+
inv_cdf = pois.icdf(cdf)
|
16
|
+
|
17
|
+
assert_equal pmf, pdf
|
18
|
+
assert_in_delta(0.0770984, pdf, 0.0000001 )
|
19
|
+
assert_in_delta(0.9347119, cdf, 0.0000001)
|
20
|
+
assert_equal(k,inv_cdf)
|
21
|
+
assert_equal(3.5,mean)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_rng
|
25
|
+
rate = 3.5
|
26
|
+
pois = Rubystats::PoissonDistribution.new(rate)
|
27
|
+
|
28
|
+
rngs = []
|
29
|
+
n = 1000
|
30
|
+
n.times { rngs << pois.rng.to_f }
|
31
|
+
avg = rngs.reduce(:+) / rngs.size
|
32
|
+
|
33
|
+
assert_in_delta(avg, pois.mean, 0.5)
|
34
|
+
end
|
35
|
+
end
|
data/test/tc_require_all.rb
CHANGED
@@ -4,17 +4,17 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
|
4
4
|
# test that we can use old api that wasn't namespaced
|
5
5
|
#
|
6
6
|
|
7
|
-
require '
|
7
|
+
require 'minitest/autorun'
|
8
8
|
require 'rubystats'
|
9
9
|
|
10
|
-
class TestNormal <
|
10
|
+
class TestNormal < MiniTest::Unit::TestCase
|
11
11
|
def test_simple
|
12
12
|
norm = NormalDistribution.new(10,2)
|
13
13
|
cdf = norm.cdf(11)
|
14
14
|
|
15
|
-
assert_equal("0.
|
16
|
-
|
15
|
+
assert_equal("0.6914624612740131",cdf.to_s)
|
16
|
+
refute_nil(norm.rng)
|
17
17
|
|
18
|
-
|
18
|
+
ExponentialDistribution.new(2)
|
19
19
|
end
|
20
20
|
end
|
data/test/tc_studentt.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'rubystats/student_t_distribution'
|
4
|
+
|
5
|
+
class TestStudentT < MiniTest::Unit::TestCase
|
6
|
+
def test_pdf
|
7
|
+
t = Rubystats::StudentTDistribution.new(8)
|
8
|
+
|
9
|
+
pdf = t.pdf(0.0)
|
10
|
+
assert_in_epsilon pdf, 0.386699, 0.000001, "pdf"
|
11
|
+
|
12
|
+
pdf = t.pdf(1.0)
|
13
|
+
assert_in_epsilon pdf, 0.2276076, 0.000001, "pdf"
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_properties
|
17
|
+
t = Rubystats::StudentTDistribution.new(8)
|
18
|
+
assert_in_epsilon t.mean, 0.0, 0.01, "mean"
|
19
|
+
assert_in_epsilon t.variance, 1.333, 0.01, "variance"
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_rng
|
23
|
+
t = Rubystats::StudentTDistribution.new(8)
|
24
|
+
|
25
|
+
total = 100000
|
26
|
+
values = Array.new(total).map{t.rng}
|
27
|
+
|
28
|
+
mean = values.inject(0.0) {|sum, v| sum + v} / values.size
|
29
|
+
assert_in_delta mean, 0.0, 0.1, "rng mean"
|
30
|
+
|
31
|
+
var = values.inject(0.0) {|sum, v| sum + (v - mean)**2} / values.size
|
32
|
+
assert_in_delta var, 8.0/(8.0-2.0), 0.1, "rng mean"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_integer_input
|
36
|
+
dfi, dff = 8, 8.0
|
37
|
+
xi,xf = 1, 1.0
|
38
|
+
dti = Rubystats::StudentTDistribution.new(dfi).pdf(xi)
|
39
|
+
dtf = Rubystats::StudentTDistribution.new(dff).pdf(xf)
|
40
|
+
assert_in_delta dti, dtf, 0.000001
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/test/tc_unif.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'rubystats/uniform_distribution'
|
4
|
+
|
5
|
+
class TestUnif < MiniTest::Unit::TestCase
|
6
|
+
def test_cdf
|
7
|
+
|
8
|
+
unif = Rubystats::UniformDistribution.new(1,6)
|
9
|
+
cdf = unif.cdf(2.5)
|
10
|
+
|
11
|
+
assert_equal 0.3, cdf
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_pdf
|
15
|
+
unif = Rubystats::UniformDistribution.new(1.0, 6.0)
|
16
|
+
|
17
|
+
pdf = unif.pdf(2.5)
|
18
|
+
assert_equal 0.2, pdf
|
19
|
+
|
20
|
+
pdf_out_of_lower_bounds = unif.pdf(0.0)
|
21
|
+
assert_equal 0.0, pdf_out_of_lower_bounds
|
22
|
+
|
23
|
+
pdf_out_of_upper_bounds = unif.pdf(8.0)
|
24
|
+
assert_equal 0.0, pdf_out_of_upper_bounds
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_rng
|
28
|
+
lower, upper = 1,6
|
29
|
+
unif = Rubystats::UniformDistribution.new(lower,upper)
|
30
|
+
|
31
|
+
total = 10000
|
32
|
+
values = Array.new(total).map{unif.rng}
|
33
|
+
|
34
|
+
assert_equal values.min >= lower, true
|
35
|
+
assert_equal values.max <= upper, true
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_integer_input
|
39
|
+
loweri, upperi = 1, 6
|
40
|
+
lowerf, upperf = 1.0, 6.0
|
41
|
+
xi = 3
|
42
|
+
xf = 3.0
|
43
|
+
dunifi = Rubystats::NormalDistribution.new(loweri,upperi).pdf(xi)
|
44
|
+
duniff = Rubystats::NormalDistribution.new(lowerf,upperf).pdf(xf)
|
45
|
+
assert_in_delta dunifi, duniff, 0.00000001
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/test/tc_weibull.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'rubystats/weibull_distribution'
|
4
|
+
|
5
|
+
class TestWeibull < MiniTest::Unit::TestCase
|
6
|
+
def test_simple
|
7
|
+
scale = 6.0
|
8
|
+
shape = 4.0
|
9
|
+
wbd = Rubystats::WeibullDistribution.new(scale,shape)
|
10
|
+
assert_in_delta(5.438415, wbd.mean, 0.000001)
|
11
|
+
assert_in_delta(2.327813, wbd.variance, 0.000001)
|
12
|
+
assert_in_delta(0.0243884, wbd.pdf(2.0), 0.000001)
|
13
|
+
assert_in_delta(0.2381909, wbd.pdf(5.0), 0.000001)
|
14
|
+
assert_in_delta(0.3826092, wbd.cdf(5.0), 0.000001)
|
15
|
+
# make sure the mean of RNG values is close to the expected mean
|
16
|
+
rngs = []
|
17
|
+
n = 10000
|
18
|
+
n.times {|i| rngs << wbd.rng }
|
19
|
+
avg = rngs.inject(0.0) {|sum,x|sum + x} / rngs.size
|
20
|
+
assert_in_delta(avg, 5.438415, 0.1)
|
21
|
+
|
22
|
+
x_vals = [0.5, 1, 1.5, 2, 2.5, 3, 3.5]
|
23
|
+
|
24
|
+
p_vals = wbd.pdf(x_vals)
|
25
|
+
c_vals = wbd.cdf(x_vals)
|
26
|
+
|
27
|
+
expected_pvals = [0.00038578, 0.00308404, 0.01037606, 0.02438840, 0.04679345, 0.07828442, 0.11786168]
|
28
|
+
expected_cvals = [0.00004822, 0.00077131, 0.00389863, 0.01226978, 0.02969111, 0.06058694, 0.10933684]
|
29
|
+
|
30
|
+
x_vals.size.times do |i|
|
31
|
+
assert_in_delta expected_pvals[i], p_vals[i], 0.000001
|
32
|
+
assert_in_delta expected_cvals[i], c_vals[i], 0.000001
|
33
|
+
end
|
34
|
+
|
35
|
+
x_vals.each do |x|
|
36
|
+
cdf = wbd.cdf(x)
|
37
|
+
inv_cdf = wbd.icdf(cdf)
|
38
|
+
assert_in_delta(x, inv_cdf, 0.00000001)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_integer_input
|
43
|
+
scalei,shapei = 6, 4
|
44
|
+
scalef,shapef = 6.0, 4.0
|
45
|
+
xi = 3
|
46
|
+
xf = 3.0
|
47
|
+
dwbi = Rubystats::WeibullDistribution.new(scalei,shapei).pdf(xi)
|
48
|
+
dwbf = Rubystats::WeibullDistribution.new(scalef,shapef).pdf(xf)
|
49
|
+
assert_in_delta dwbi, dwbf, 0.000001
|
50
|
+
end
|
51
|
+
end
|
data/test/ts_stats.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubystats
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
|
+
- Ilya Scharrenbroich
|
7
8
|
- Bryan Donovan - http://www.bryandonovan.com
|
9
|
+
- Phillip Baker
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
date: 2023-05-21 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: minitest
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '4.2'
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '5.0'
|
25
|
+
type: :development
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '4.2'
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '5.0'
|
35
|
+
- !ruby/object:Gem::Dependency
|
16
36
|
name: hoe
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.7.0
|
17
42
|
type: :development
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
21
46
|
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
47
|
+
- !ruby/object:Gem::Version
|
23
48
|
version: 1.7.0
|
24
|
-
|
25
|
-
|
26
|
-
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: matrix
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
description: Ruby Stats is a port of the statistics libraries from PHPMath. Probability
|
64
|
+
distributions include binomial, beta, and normal distributions with PDF, CDF and
|
65
|
+
inverse CDF as well as Fisher's Exact Test.
|
66
|
+
email:
|
27
67
|
executables: []
|
28
|
-
|
29
68
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
files:
|
69
|
+
extra_rdoc_files: []
|
70
|
+
files:
|
71
|
+
- ".github/workflows/test.yml"
|
72
|
+
- ".gitignore"
|
73
|
+
- Gemfile
|
36
74
|
- History.txt
|
37
75
|
- Manifest.txt
|
38
|
-
- README.
|
76
|
+
- README.rdoc
|
39
77
|
- Rakefile
|
40
78
|
- examples/beta.rb
|
41
79
|
- examples/binomial.rb
|
@@ -43,47 +81,77 @@ files:
|
|
43
81
|
- examples/failrate_vs_goal.rb
|
44
82
|
- examples/fisher.rb
|
45
83
|
- examples/norm.rb
|
84
|
+
- examples/uniform.rb
|
46
85
|
- lib/rubystats.rb
|
47
86
|
- lib/rubystats/beta_distribution.rb
|
48
87
|
- lib/rubystats/binomial_distribution.rb
|
88
|
+
- lib/rubystats/cauchy_distribution.rb
|
49
89
|
- lib/rubystats/exponential_distribution.rb
|
50
90
|
- lib/rubystats/fishers_exact_test.rb
|
91
|
+
- lib/rubystats/gamma_distribution.rb
|
92
|
+
- lib/rubystats/lognormal_distribution.rb
|
51
93
|
- lib/rubystats/modules.rb
|
94
|
+
- lib/rubystats/multivariate_normal_distribution.rb
|
52
95
|
- lib/rubystats/normal_distribution.rb
|
96
|
+
- lib/rubystats/poisson_distribution.rb
|
53
97
|
- lib/rubystats/probability_distribution.rb
|
98
|
+
- lib/rubystats/student_t_distribution.rb
|
99
|
+
- lib/rubystats/uniform_distribution.rb
|
100
|
+
- lib/rubystats/version.rb
|
101
|
+
- lib/rubystats/weibull_distribution.rb
|
102
|
+
- rubystats.gemspec
|
54
103
|
- test/tc_beta.rb
|
55
104
|
- test/tc_binomial.rb
|
105
|
+
- test/tc_cauchy.rb
|
56
106
|
- test/tc_exponential.rb
|
57
107
|
- test/tc_fisher.rb
|
108
|
+
- test/tc_gamma.rb
|
109
|
+
- test/tc_lnorm.rb
|
110
|
+
- test/tc_multivariate_normal.rb
|
58
111
|
- test/tc_norm.rb
|
112
|
+
- test/tc_poisson.rb
|
59
113
|
- test/tc_require_all.rb
|
114
|
+
- test/tc_studentt.rb
|
115
|
+
- test/tc_unif.rb
|
116
|
+
- test/tc_weibull.rb
|
60
117
|
- test/ts_stats.rb
|
61
|
-
|
62
|
-
|
118
|
+
homepage: https://github.com/phillbaker/rubystats
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
63
122
|
post_install_message:
|
64
|
-
rdoc_options:
|
65
|
-
|
66
|
-
- README.txt
|
67
|
-
require_paths:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
68
125
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
71
128
|
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version:
|
74
|
-
|
75
|
-
|
76
|
-
requirements:
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 1.9.3
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
77
133
|
- - ">="
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version:
|
80
|
-
version:
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
81
136
|
requirements: []
|
82
|
-
|
83
|
-
|
84
|
-
rubygems_version: 1.2.0
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.3
|
85
139
|
signing_key:
|
86
|
-
specification_version:
|
87
|
-
summary:
|
88
|
-
test_files:
|
89
|
-
|
140
|
+
specification_version: 4
|
141
|
+
summary: ''
|
142
|
+
test_files:
|
143
|
+
- test/tc_beta.rb
|
144
|
+
- test/tc_binomial.rb
|
145
|
+
- test/tc_cauchy.rb
|
146
|
+
- test/tc_exponential.rb
|
147
|
+
- test/tc_fisher.rb
|
148
|
+
- test/tc_gamma.rb
|
149
|
+
- test/tc_lnorm.rb
|
150
|
+
- test/tc_multivariate_normal.rb
|
151
|
+
- test/tc_norm.rb
|
152
|
+
- test/tc_poisson.rb
|
153
|
+
- test/tc_require_all.rb
|
154
|
+
- test/tc_studentt.rb
|
155
|
+
- test/tc_unif.rb
|
156
|
+
- test/tc_weibull.rb
|
157
|
+
- test/ts_stats.rb
|