more_math 0.3.3 → 0.4.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 -2
- data/VERSION +1 -1
- data/lib/more_math/linear_regression.rb +11 -3
- data/lib/more_math/sequence.rb +1 -1
- data/lib/more_math/version.rb +1 -1
- data/more_math.gemspec +4 -4
- data/tests/sequence_test.rb +18 -12
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f0225a838150eb806c43ab9f127a48d4e3413a112d790c471a30a523a9ba232a
|
4
|
+
data.tar.gz: 280a109a31687d7d1206a4242b70d45c569109104a806f12a76335d469571cef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28d4b17002c51d638cac2df07f1e183c507f27dc963c18579fd0ba6a6796f3ae119fd4c1ffc77bfa7125dfb69b00d5d6fac48b90f9449d9596a36c2f139e4bd8
|
7
|
+
data.tar.gz: 2ebdea2b609ada67acd58764c1983dd5ec773866f94bd3900213ea73e7119b758467fdff7b576a7552669cf4dbb5431462b9321a40393e7d89564acb11bcffd0
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
@@ -32,9 +32,9 @@ module MoreMath
|
|
32
32
|
t.abs <= td.inverse_probability(1 - alpha.abs / 2.0).abs
|
33
33
|
end
|
34
34
|
|
35
|
-
# Returns the
|
35
|
+
# Returns the residuals of this linear regression in relation to the given
|
36
36
|
# domain and image.
|
37
|
-
def
|
37
|
+
def residuals
|
38
38
|
result = []
|
39
39
|
@domain.zip(@image) do |x, y|
|
40
40
|
result << y - (@a * x + @b)
|
@@ -42,13 +42,21 @@ module MoreMath
|
|
42
42
|
result
|
43
43
|
end
|
44
44
|
|
45
|
+
def r2
|
46
|
+
image_seq = MoreMath::Sequence.new(@image)
|
47
|
+
sum_res = residuals.inject(0.0) { |s, r| s + r ** 2 }
|
48
|
+
[
|
49
|
+
1.0 - sum_res / image_seq.sum_of_squares,
|
50
|
+
0.0,
|
51
|
+
].max
|
52
|
+
end
|
53
|
+
|
45
54
|
private
|
46
55
|
|
47
56
|
def compute
|
48
57
|
size = @image.size
|
49
58
|
sum_xx = sum_xy = sum_x = sum_y = 0.0
|
50
59
|
@domain.zip(@image) do |x, y|
|
51
|
-
x += 1
|
52
60
|
sum_xx += x ** 2
|
53
61
|
sum_xy += x * y
|
54
62
|
sum_x += x
|
data/lib/more_math/sequence.rb
CHANGED
@@ -289,7 +289,7 @@ module MoreMath
|
|
289
289
|
# Returns the d-value for the Durbin-Watson statistic. The value is d << 2
|
290
290
|
# for positive, d >> 2 for negative and d around 2 for no autocorrelation.
|
291
291
|
def durbin_watson_statistic
|
292
|
-
e = linear_regression.
|
292
|
+
e = linear_regression.residuals
|
293
293
|
e.size <= 1 and return 2.0
|
294
294
|
(1...e.size).inject(0.0) { |s, i| s + (e[i] - e[i - 1]) ** 2 } /
|
295
295
|
e.inject(0.0) { |s, x| s + x ** 2 }
|
data/lib/more_math/version.rb
CHANGED
data/more_math.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: more_math 0.
|
2
|
+
# stub: more_math 0.4.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "more_math".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.4.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "
|
11
|
+
s.date = "2019-06-13"
|
12
12
|
s.description = "Library that provides more mathematical functions/algorithms than standard Ruby.".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.extra_rdoc_files = ["README.rdoc".freeze, "lib/more_math.rb".freeze, "lib/more_math/cantor_pairing_function.rb".freeze, "lib/more_math/constants/functions_constants.rb".freeze, "lib/more_math/continued_fraction.rb".freeze, "lib/more_math/distributions.rb".freeze, "lib/more_math/entropy.rb".freeze, "lib/more_math/exceptions.rb".freeze, "lib/more_math/functions.rb".freeze, "lib/more_math/histogram.rb".freeze, "lib/more_math/linear_regression.rb".freeze, "lib/more_math/newton_bisection.rb".freeze, "lib/more_math/numberify_string_function.rb".freeze, "lib/more_math/permutation.rb".freeze, "lib/more_math/ranking_common.rb".freeze, "lib/more_math/sequence.rb".freeze, "lib/more_math/sequence/moving_average.rb".freeze, "lib/more_math/sequence/refinement.rb".freeze, "lib/more_math/string_numeral.rb".freeze, "lib/more_math/subset.rb".freeze, "lib/more_math/version.rb".freeze]
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.licenses = ["MIT".freeze]
|
18
18
|
s.rdoc_options = ["--title".freeze, "MoreMath -- More Math in Ruby".freeze, "--main".freeze, "README.rdoc".freeze]
|
19
19
|
s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
|
20
|
-
s.rubygems_version = "
|
20
|
+
s.rubygems_version = "3.0.3".freeze
|
21
21
|
s.summary = "Library that provides more mathematics.".freeze
|
22
22
|
s.test_files = ["tests/cantor_pairing_function_test.rb".freeze, "tests/continued_fraction_test.rb".freeze, "tests/distribution_test.rb".freeze, "tests/entropy_test.rb".freeze, "tests/functions_test.rb".freeze, "tests/histogram_test.rb".freeze, "tests/newton_bisection_test.rb".freeze, "tests/numberify_string_function_test.rb".freeze, "tests/permutation_test.rb".freeze, "tests/sequence_moving_average_test.rb".freeze, "tests/sequence_test.rb".freeze, "tests/string_numeral_test.rb".freeze, "tests/subset_test.rb".freeze, "tests/test_helper.rb".freeze]
|
23
23
|
|
data/tests/sequence_test.rb
CHANGED
@@ -126,8 +126,8 @@ class SequenceTest < Test::Unit::TestCase
|
|
126
126
|
3, 94, 5, 79, 11, 16, 0, 90, 81, 42, 64, 76, 92, 25,
|
127
127
|
3, 90, 51, 15, 0, 74, 98, 93, 90, 14, 81, 85, 28, 30,
|
128
128
|
73, 32, 88])
|
129
|
-
@rand_up = Sequence.new(Array.new(rand.size) { |i| rand[i]
|
130
|
-
@rand_down = Sequence.new(Array.new(rand.size) { |i| rand[i]
|
129
|
+
@rand_up = Sequence.new(Array.new(rand.size) { |i| rand[i] + 10 * i })
|
130
|
+
@rand_down = Sequence.new(Array.new(rand.size) { |i| rand[i] - 10 * i })
|
131
131
|
@rasi = Sequence.new(
|
132
132
|
[ 0.0, 11.7813239550446, 23.8742291678261, 0.368124552684678,
|
133
133
|
20.233654312272, 7.64120827980215, 61.609239533582, 69.346191849821,
|
@@ -186,7 +186,8 @@ class SequenceTest < Test::Unit::TestCase
|
|
186
186
|
assert_in_delta 0.3, @flat.median, 1E-8
|
187
187
|
assert_in_delta 0.3, @flat.percentile(75), 1E-8
|
188
188
|
assert_equal 100, @flat.histogram(10).each_bin.first.count
|
189
|
-
assert @flat.linear_regression.
|
189
|
+
assert @flat.linear_regression.residuals.all? { |r| r.abs <= 1E-6 }
|
190
|
+
assert_in_delta 0.0, @flat.linear_regression.r2, 1E-8
|
190
191
|
end
|
191
192
|
|
192
193
|
def test_half
|
@@ -207,7 +208,8 @@ class SequenceTest < Test::Unit::TestCase
|
|
207
208
|
assert_in_delta 37.375, @half.percentile(75), 1E-8
|
208
209
|
assert_equal [10] * 10, counts = @half.histogram(10).counts
|
209
210
|
assert_equal 100, counts.inject { |s, x| s + x }
|
210
|
-
assert @half.linear_regression.
|
211
|
+
assert @half.linear_regression.residuals.all? { |r| r.abs <= 0.5 }
|
212
|
+
assert_in_delta 1.0, @half.linear_regression.r2, 1E-8
|
211
213
|
end
|
212
214
|
|
213
215
|
def test_rand
|
@@ -227,13 +229,15 @@ class SequenceTest < Test::Unit::TestCase
|
|
227
229
|
assert_in_delta 50.0, @rand.median, 1E-8
|
228
230
|
assert_in_delta 81, @rand.percentile(75), 1E-8
|
229
231
|
assert_in_delta 0.05660, @rand.linear_regression.a, 1E-4
|
230
|
-
assert_in_delta
|
232
|
+
assert_in_delta 48.0378, @rand.linear_regression.b, 1E-4
|
231
233
|
assert @rand.linear_regression.slope_zero?
|
232
|
-
assert_in_delta(-
|
233
|
-
assert_in_delta
|
234
|
+
assert_in_delta(-9.9433, @rand_down.linear_regression.a, 1E-4)
|
235
|
+
assert_in_delta 48.0378, @rand_down.linear_regression.b, 1E-4
|
236
|
+
assert_in_delta 0.9883, @rand_down.linear_regression.r2, 1E-4
|
234
237
|
assert !@rand_down.linear_regression.slope_zero?
|
235
|
-
assert_in_delta
|
236
|
-
assert_in_delta
|
238
|
+
assert_in_delta 10.0566, @rand_up.linear_regression.a, 1E-4
|
239
|
+
assert_in_delta 48.0378, @rand_up.linear_regression.b, 1E-4
|
240
|
+
assert_in_delta 0.98857, @rand_up.linear_regression.r2, 1E-4
|
237
241
|
assert !@rand_up.linear_regression.slope_zero?
|
238
242
|
assert_nil @rand.detect_outliers
|
239
243
|
assert !@rand.detect_autocorrelation[:detected]
|
@@ -258,7 +262,8 @@ class SequenceTest < Test::Unit::TestCase
|
|
258
262
|
assert_in_delta 0.0, @rasi.median, 1E-2
|
259
263
|
assert_in_delta 30.58, @rasi.percentile(75), 1E-2
|
260
264
|
assert_in_delta(-0.41, @rasi.linear_regression.a, 1E-2)
|
261
|
-
assert_in_delta(
|
265
|
+
assert_in_delta(23.94, @rasi.linear_regression.b, 1E-2)
|
266
|
+
assert_in_delta 0.0887, @rasi.linear_regression.r2, 1E-4
|
262
267
|
assert !@rasi.linear_regression.slope_zero?
|
263
268
|
assert_equal 13, @rasi.detect_outliers[:high]
|
264
269
|
assert @rasi.detect_autocorrelation[:detected]
|
@@ -284,8 +289,9 @@ class SequenceTest < Test::Unit::TestCase
|
|
284
289
|
assert_in_delta 51.5, @book.median, 1E-2
|
285
290
|
assert_in_delta 58.25, @book.percentile(75), 1E-2
|
286
291
|
assert_in_delta(-0.0952, @book.linear_regression.a, 1E-4)
|
287
|
-
assert_in_delta(54.
|
292
|
+
assert_in_delta(54.5420, @book.linear_regression.b, 1E-4)
|
288
293
|
assert @book.linear_regression.slope_zero?
|
294
|
+
assert_in_delta 0.0249, @book.linear_regression.r2, 1E-4
|
289
295
|
assert_equal 7, @book.detect_outliers[:high]
|
290
296
|
ought = [1.0, -0.39, 0.3, -0.17, 0.07, -0.10, 0.05, 0.04, -0.04, -0.01,
|
291
297
|
0.01, 0.11, -0.07, 0.15, 0.04, -0.01
|
@@ -297,7 +303,7 @@ class SequenceTest < Test::Unit::TestCase
|
|
297
303
|
assert_equal [3, 4, 9, 12, 18, 14, 4, 5, 0, 1],
|
298
304
|
counts = @book.histogram(10).counts
|
299
305
|
assert_equal 70, counts.inject { |s, x| s + x }
|
300
|
-
assert @flat.linear_regression.
|
306
|
+
assert @flat.linear_regression.residuals.all? { |r| r.abs <= 1E-6 }
|
301
307
|
end
|
302
308
|
|
303
309
|
def test_cover
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: more_math
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -204,8 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
- !ruby/object:Gem::Version
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
|
-
|
208
|
-
rubygems_version: 2.6.11
|
207
|
+
rubygems_version: 3.0.3
|
209
208
|
signing_key:
|
210
209
|
specification_version: 4
|
211
210
|
summary: Library that provides more mathematics.
|