rubystats 0.2.6 → 0.4.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.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +21 -0
- data/History.txt +31 -0
- data/README.rdoc +17 -6
- 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/gamma_distribution.rb +70 -0
- data/lib/rubystats/lognormal_distribution.rb +59 -0
- data/lib/rubystats/modules.rb +6 -0
- data/lib/rubystats/multivariate_normal_distribution.rb +73 -0
- data/lib/rubystats/normal_distribution.rb +2 -2
- data/lib/rubystats/poisson_distribution.rb +78 -0
- data/lib/rubystats/probability_distribution.rb +3 -3
- data/lib/rubystats/student_t_distribution.rb +62 -0
- data/lib/rubystats/uniform_distribution.rb +70 -0
- data/lib/rubystats/version.rb +1 -1
- data/lib/rubystats/weibull_distribution.rb +56 -0
- data/lib/rubystats.rb +29 -0
- data/rubystats.gemspec +6 -0
- data/test/tc_beta.rb +21 -0
- data/test/tc_binomial.rb +14 -0
- data/test/tc_cauchy.rb +39 -0
- data/test/tc_exponential.rb +10 -0
- 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 +11 -1
- data/test/tc_poisson.rb +35 -0
- data/test/tc_studentt.rb +43 -0
- data/test/tc_unif.rb +48 -0
- data/test/tc_weibull.rb +51 -0
- metadata +28 -3
- data/.travis.yml +0 -12
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubystats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Scharrenbroich
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
@@ -54,8 +54,8 @@ executables: []
|
|
54
54
|
extensions: []
|
55
55
|
extra_rdoc_files: []
|
56
56
|
files:
|
57
|
+
- ".github/workflows/test.yml"
|
57
58
|
- ".gitignore"
|
58
|
-
- ".travis.yml"
|
59
59
|
- Gemfile
|
60
60
|
- History.txt
|
61
61
|
- Manifest.txt
|
@@ -67,22 +67,39 @@ files:
|
|
67
67
|
- examples/failrate_vs_goal.rb
|
68
68
|
- examples/fisher.rb
|
69
69
|
- examples/norm.rb
|
70
|
+
- examples/uniform.rb
|
70
71
|
- lib/rubystats.rb
|
71
72
|
- lib/rubystats/beta_distribution.rb
|
72
73
|
- lib/rubystats/binomial_distribution.rb
|
74
|
+
- lib/rubystats/cauchy_distribution.rb
|
73
75
|
- lib/rubystats/exponential_distribution.rb
|
74
76
|
- lib/rubystats/fishers_exact_test.rb
|
77
|
+
- lib/rubystats/gamma_distribution.rb
|
78
|
+
- lib/rubystats/lognormal_distribution.rb
|
75
79
|
- lib/rubystats/modules.rb
|
80
|
+
- lib/rubystats/multivariate_normal_distribution.rb
|
76
81
|
- lib/rubystats/normal_distribution.rb
|
82
|
+
- lib/rubystats/poisson_distribution.rb
|
77
83
|
- lib/rubystats/probability_distribution.rb
|
84
|
+
- lib/rubystats/student_t_distribution.rb
|
85
|
+
- lib/rubystats/uniform_distribution.rb
|
78
86
|
- lib/rubystats/version.rb
|
87
|
+
- lib/rubystats/weibull_distribution.rb
|
79
88
|
- rubystats.gemspec
|
80
89
|
- test/tc_beta.rb
|
81
90
|
- test/tc_binomial.rb
|
91
|
+
- test/tc_cauchy.rb
|
82
92
|
- test/tc_exponential.rb
|
83
93
|
- test/tc_fisher.rb
|
94
|
+
- test/tc_gamma.rb
|
95
|
+
- test/tc_lnorm.rb
|
96
|
+
- test/tc_multivariate_normal.rb
|
84
97
|
- test/tc_norm.rb
|
98
|
+
- test/tc_poisson.rb
|
85
99
|
- test/tc_require_all.rb
|
100
|
+
- test/tc_studentt.rb
|
101
|
+
- test/tc_unif.rb
|
102
|
+
- test/tc_weibull.rb
|
86
103
|
- test/ts_stats.rb
|
87
104
|
homepage: https://github.com/phillbaker/rubystats
|
88
105
|
licenses:
|
@@ -111,8 +128,16 @@ summary: ''
|
|
111
128
|
test_files:
|
112
129
|
- test/tc_beta.rb
|
113
130
|
- test/tc_binomial.rb
|
131
|
+
- test/tc_cauchy.rb
|
114
132
|
- test/tc_exponential.rb
|
115
133
|
- test/tc_fisher.rb
|
134
|
+
- test/tc_gamma.rb
|
135
|
+
- test/tc_lnorm.rb
|
136
|
+
- test/tc_multivariate_normal.rb
|
116
137
|
- test/tc_norm.rb
|
138
|
+
- test/tc_poisson.rb
|
117
139
|
- test/tc_require_all.rb
|
140
|
+
- test/tc_studentt.rb
|
141
|
+
- test/tc_unif.rb
|
142
|
+
- test/tc_weibull.rb
|
118
143
|
- test/ts_stats.rb
|
data/.travis.yml
DELETED