class Olympic::Rating::Glicko::Formula

Constants

CERTAINTY_DECAY

This is the “certainty decay,” or the constant value that is used in Step 1 of the Glicko rating system. It denotes the decay of certainty of a player's rating over a given time (see {Glicko} for a definition of time). The default chosen here expects a typical RD of 50, with 10 time units before a decay to 350. The formula would be (in LaTeX):

c = \sqrt{\frac{350^2-50^2}{10}}

However, in order to optimize operations, this is c^2. So the actual value of this would be:

c = \frac{350^2-50^2}{10}
DEFAULT_RATING

The default rating. Glicko states to use 1500 as the default.

DEFAULT_RATING_DERIVATION

The default RD. Glicko states to use 350 as the default.

Q
Q2

Public Class Methods

new(unit, matches) click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 35
def initialize(unit, matches)
  @unit = unit
  @matches = matches
end

Public Instance Methods

call() click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 40
def call
  flush_cache
  @unit.rating = new_rating
  @unit.derivation = new_derivation
end
derivation() click to toggle source

This returns the current rating derivation of the unit. It clamps the rating derivation to between 30 and 350. The Glicko system states that it must be less than or equal to 350, but later recommends not letting the rating derivation drop below 30.

@return [Numeric]

# File lib/olympic/rating/glicko/formula.rb, line 53
def derivation
  if @unit.unrated?
    350
  elsif @unit.time_passed == 0
    @unit.derivation
  else
    a = [
      30,
      Math.sqrt((@unit.derivation) ** 2 + CERTAINTY_DECAY * @unit.time_passed),
      350
    ].sort[1]
  end
end

Private Instance Methods

delta() click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 91
def delta
  1.0.fdiv(Q2 * delta_summation)
end
delta_summation() click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 96
def delta_summation
  @matches.inject(0) do |memo, value|
    e = epsilon(value[:rating], value[:derivation])
    g = gamma(value[:derivation])
    memo + (g ** 2) * e * (1 - e)
  end
end
epsilon(rating, derivation) click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 110
def epsilon(rating, derivation)
  1.0.fdiv(1 + 10 **
    (gamma(derivation) * (@unit.rating - rating)).fdiv(-400))
end
gamma(derivation) click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 105
def gamma(derivation)
  1.0.fdiv Math.sqrt(1 + (3 * Q2 * (derivation ** 2)).fdiv(Math::PI ** 2))
end
new_derivation() click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 76
def new_derivation
  Math.sqrt(1.0.fdiv(
    1.0.fdiv(derivation ** 2) + 1.0.fdiv(delta)))
end
new_rating() click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 70
def new_rating
  @unit.rating +
    Q.fdiv(1.0.fdiv(derivation ** 2) + 1.0.fdiv(delta)) * summation
end
summation() click to toggle source
# File lib/olympic/rating/glicko/formula.rb, line 82
def summation
  @matches.inject(0) do |memo, value|
    e = epsilon(value[:rating], value[:derivation])
    g = gamma(value[:derivation])
    memo + g * (value[:outcome] - e)
  end
end