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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8592c5f27e6c601ae312bf1870259967e7763b28
4
- data.tar.gz: b1e23ffdfc15ee89ff25f8cf7d0a3f9ca8f27aa5
2
+ SHA256:
3
+ metadata.gz: f0225a838150eb806c43ab9f127a48d4e3413a112d790c471a30a523a9ba232a
4
+ data.tar.gz: 280a109a31687d7d1206a4242b70d45c569109104a806f12a76335d469571cef
5
5
  SHA512:
6
- metadata.gz: 0a0bf6510034861d95b94abbe7bc6d13d38fa5c5db9d5eb62dec371b8b6a846a76e15de6fd0a1a8151d6459cdb0819fe85ea5503025c4cf49e331a39f7dcd8a8
7
- data.tar.gz: f841cbc883d82f78a834044e84857bc25d212c54da766085e5ea7fe0f7dcebf44044896a5009565a09e6d6183ad6fc991fab166a688f6ec2db57daf1ee9a48c2
6
+ metadata.gz: 28d4b17002c51d638cac2df07f1e183c507f27dc963c18579fd0ba6a6796f3ae119fd4c1ffc77bfa7125dfb69b00d5d6fac48b90f9449d9596a36c2f139e4bd8
7
+ data.tar.gz: 2ebdea2b609ada67acd58764c1983dd5ec773866f94bd3900213ea73e7119b758467fdff7b576a7552669cf4dbb5431462b9321a40393e7d89564acb11bcffd0
@@ -1,6 +1,8 @@
1
1
  rvm:
2
2
  - 2.1
3
3
  - 2.2
4
- - 2.3.3
5
- - 2.4.0
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
6
8
  sudo: false
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
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 residues of this linear regression in relation to the given
35
+ # Returns the residuals of this linear regression in relation to the given
36
36
  # domain and image.
37
- def residues
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
@@ -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.residues
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 }
@@ -1,6 +1,6 @@
1
1
  module MoreMath
2
2
  # MoreMath version
3
- VERSION = '0.3.3'
3
+ VERSION = '0.4.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: more_math 0.3.3 ruby lib
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.3.3"
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 = "2017-07-04"
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 = "2.6.11".freeze
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
 
@@ -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] * (1 - 4.0 / (i + 1)) })
130
- @rand_down = Sequence.new(Array.new(rand.size) { |i| rand[i] * (1 + 4.0 / (i + 1)) })
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.residues.all? { |r| r.abs <= 1E-6 }
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.residues.all? { |r| r.abs <= 0.5 }
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 47.9812, @rand.linear_regression.b, 1E-4
232
+ assert_in_delta 48.0378, @rand.linear_regression.b, 1E-4
231
233
  assert @rand.linear_regression.slope_zero?
232
- assert_in_delta(-0.4019, @rand_down.linear_regression.a, 1E-4)
233
- assert_in_delta 82.7303, @rand_down.linear_regression.b, 1E-4
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 0.5151, @rand_up.linear_regression.a, 1E-4
236
- assert_in_delta(13.2320, @rand_up.linear_regression.b, 1E-4)
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(24.35, @rasi.linear_regression.b, 1E-2)
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.6372, @book.linear_regression.b, 1E-4)
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.residues.all? { |r| r.abs <= 1E-6 }
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.3.3
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: 2017-07-04 00:00:00.000000000 Z
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
- rubyforge_project:
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.