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 +4 -4
- data/lib/glicko2/rater.rb +13 -11
- data/lib/glicko2/version.rb +1 -1
- data/spec/rater_spec.rb +23 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b36e18b907d4edc5ea6cec402c3d800bd2727e03
|
4
|
+
data.tar.gz: 26eb8e5feb31138e0fc63fe195913eccd950d0dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45efeb808b62315d5bd8bca8dc21c3ea5aa76ec6acd1158e4393add484f85fb80648f7e8ded2ae770d522449f1f5b20816c3baf5d2fe83ac914fc725a2e0a2f5
|
7
|
+
data.tar.gz: 05dbc7c297933d55ec4738d5880908bb9f4a104bab787f9f9f6b0f2d0eb4390bd03f563446a773130a716c6c3727eba11bae21a55f0d3b012295af32ee6c88ce
|
data/lib/glicko2/rater.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
27
|
-
|
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)
|
data/lib/glicko2/version.rb
CHANGED
data/spec/rater_spec.rb
CHANGED
@@ -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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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.
|
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-
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|