Class: Glicko2::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/glicko2.rb

Overview

Collection of helper methods

Class Method Summary collapse

Class Method Details

.illinois_method(a, b) ⇒ Object

Illinois method is a version of the regula falsi method for solving an equation with one unknown



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/glicko2.rb', line 25

def self.illinois_method(a, b)
  fa = yield a
  fb = yield b
  while (b - a).abs > TOLERANCE
    c = a + (a - b) * fa / (fb - fa)
    fc = yield c
    if fc * fb < 0
      a = b
      fa = fb
    else
      fa /= 2.0
    end
    b = c
    fb = fc
  end
  a
end

.ranks_to_score(rank, other) ⇒ Object

Convert from a rank, where lower numbers win against higher numbers, into Glicko scores where wins are ‘1`, draws are `0.5` and losses are `0`.



14
15
16
17
18
19
20
21
22
# File 'lib/glicko2.rb', line 14

def self.ranks_to_score(rank, other)
  if rank < other
    1.0
  elsif rank == other
    0.5
  else
    0.0
  end
end