glicko2 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b475b65a53c6af5c404f010b22a616f3f645617
4
- data.tar.gz: d837d51c7cbc959b810140ea1139d4c654109a22
3
+ metadata.gz: b36e18b907d4edc5ea6cec402c3d800bd2727e03
4
+ data.tar.gz: 26eb8e5feb31138e0fc63fe195913eccd950d0dd
5
5
  SHA512:
6
- metadata.gz: 560eba41bcbcc66ee5036a91be810b3916575c08d9ee5f03fa22514f42e779932ad3c41ecaa6b073f626eae8c36a8fdc07da9dc360a71797ec4ac8845dca2063
7
- data.tar.gz: bf6ea3797d64d7735917ae1d25de400db48222ef581d40358e0e921138298edad882d79cc8d358445a7287d9e08b692f7fe3ab287253a3ee9b2b5c78095ed75b
6
+ metadata.gz: 45efeb808b62315d5bd8bca8dc21c3ea5aa76ec6acd1158e4393add484f85fb80648f7e8ded2ae770d522449f1f5b20816c3baf5d2fe83ac914fc725a2e0a2f5
7
+ data.tar.gz: 05dbc7c297933d55ec4738d5880908bb9f4a104bab787f9f9f6b0f2d0eb4390bd03f563446a773130a716c6c3727eba11bae21a55f0d3b012295af32ee6c88ce
@@ -22,18 +22,20 @@ module Glicko2
22
22
  delta2 = @delta_pre**2
23
23
  sd2 = rating.sd**2
24
24
  a = Math.log(rating.volatility**2)
25
- f = lambda do |x|
26
- expX = Math.exp(x)
27
- (expX * (delta2 - sd2 - v - expX)) / (2 * (sd2 + v + expX)**2) - (x - a) / tau**2
25
+ if v.finite?
26
+ f = lambda do |x|
27
+ expX = Math.exp(x)
28
+ (expX * (delta2 - sd2 - v - expX)) / (2 * (sd2 + v + expX)**2) - (x - a) / tau**2
29
+ end
30
+ if delta2 > sd2 + v
31
+ b = Math.log(delta2 - sd2 - v)
32
+ else
33
+ k = 1
34
+ k += 1 while f.call(a - k * tau) < 0
35
+ b = a - k * tau
36
+ end
37
+ a = Util.illinois_method(a, b, &f)
28
38
  end
29
- if delta2 > sd2 + v
30
- b = Math.log(delta2 - sd2 - v)
31
- else
32
- k = 1
33
- k += 1 while f.call(a - k * tau) < 0
34
- b = a - k * tau
35
- end
36
- a = Util.illinois_method(a, b, &f)
37
39
  volatility = Math.exp(a / 2.0)
38
40
  sd_pre = Math.sqrt(sd2 + volatility**2)
39
41
  sd = 1 / Math.sqrt(1.0 / sd_pre**2 + 1 / v)
@@ -1,3 +1,3 @@
1
1
  module Glicko2
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'bigdecimal'
1
2
  require 'minitest_helper'
2
3
 
3
4
  class TestRater < Minitest::Test
@@ -6,17 +7,34 @@ class TestRater < Minitest::Test
6
7
  @rating1 = Glicko2::Rating.from_glicko_rating(1400, 30)
7
8
  @rating2 = Glicko2::Rating.from_glicko_rating(1550, 100)
8
9
  @rating3 = Glicko2::Rating.from_glicko_rating(1700, 300)
9
- @rater = Glicko2::Rater.new(@rating)
10
10
  end
11
11
 
12
12
  def test_rate_matches_example
13
- @rater.add(@rating1, 1.0)
14
- @rater.add(@rating2, 0.0)
15
- @rater.add(@rating3, 0.0)
16
- rating = @rater.rate(0.5)
13
+ rater = Glicko2::Rater.new(@rating)
14
+ rater.add(@rating1, 1.0)
15
+ rater.add(@rating2, 0.0)
16
+ rater.add(@rating3, 0.0)
17
+ rating = rater.rate(0.5)
17
18
 
18
19
  assert_in_delta(-0.2069, rating.mean, 0.00005)
19
20
  assert_in_delta(0.8722, rating.sd, 0.00005)
20
21
  assert_in_delta(0.05999, rating.volatility, 0.00005)
21
22
  end
23
+
24
+ def test_rate_no_games
25
+ rating = Glicko2::Rater.new(@rating).rate(0.5)
26
+
27
+ assert_in_delta(@rating.mean, rating.mean, 0.00005)
28
+ assert_in_delta(Math.sqrt(@rating.sd**2 + @rating.volatility**2), rating.sd, 0.00005)
29
+ assert_in_delta(Glicko2::DEFAULT_VOLATILITY, rating.volatility, 0.00005)
30
+ end
31
+
32
+ def test_rate_no_games_big_decimal
33
+ @rating = Glicko2::Rating.from_glicko_rating(BigDecimal.new(1500), BigDecimal.new(200))
34
+ rating = Glicko2::Rater.new(@rating).rate(0.5)
35
+
36
+ assert_in_delta(@rating.mean, rating.mean, 0.00005)
37
+ assert_in_delta(Math.sqrt(@rating.sd**2 + @rating.volatility**2), rating.sd, 0.00005)
38
+ assert_in_delta(Glicko2::DEFAULT_VOLATILITY, rating.volatility, 0.00005)
39
+ end
22
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glicko2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Fargher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler