Class: Glicko2::Rating

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

Overview

A Rating of a player.

Constant Summary collapse

GLICKO_GRADIENT =
173.7178
GLICKO_INTERCEPT =
DEFAULT_GLICKO_RATING

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mean, sd, volatility = nil) ⇒ Rating



9
10
11
12
13
# File 'lib/glicko2/rating.rb', line 9

def initialize(mean, sd, volatility=nil)
  @mean = mean
  @sd = sd
  @volatility = volatility || DEFAULT_VOLATILITY
end

Instance Attribute Details

#meanObject (readonly)

Returns the value of attribute mean.



7
8
9
# File 'lib/glicko2/rating.rb', line 7

def mean
  @mean
end

#sdObject (readonly)

Returns the value of attribute sd.



7
8
9
# File 'lib/glicko2/rating.rb', line 7

def sd
  @sd
end

#volatilityObject (readonly)

Returns the value of attribute volatility.



7
8
9
# File 'lib/glicko2/rating.rb', line 7

def volatility
  @volatility
end

Class Method Details

.from_glicko_rating(r, rd, volatility = nil) ⇒ Object

Creates a Rating from the Glicko scale.



16
17
18
# File 'lib/glicko2/rating.rb', line 16

def self.from_glicko_rating(r, rd, volatility=nil)
  new((r - GLICKO_INTERCEPT) / GLICKO_GRADIENT, rd / GLICKO_GRADIENT, volatility)
end

Instance Method Details

#gravity_expected_score(other_mean) ⇒ Object

Calculate ‘g(phi)` and `E(mu, mu_j, phi_j)` as defined in the Glicko2 paper



26
27
28
29
# File 'lib/glicko2/rating.rb', line 26

def gravity_expected_score(other_mean)
  g = 1 / Math.sqrt(1 + 3 * sd**2 / Math::PI**2)
  [g, 1 / (1 + Math.exp(-g * (other_mean - mean)))]
end

#to_glicko_ratingObject

Converts to the Glicko scale.



21
22
23
# File 'lib/glicko2/rating.rb', line 21

def to_glicko_rating
  [GLICKO_GRADIENT * mean + GLICKO_INTERCEPT, GLICKO_GRADIENT * sd]
end

#to_sObject



31
32
33
# File 'lib/glicko2/rating.rb', line 31

def to_s
  "#<Rating mean=#{mean}, sd=#{sd}, volatility=#{volatility}>"
end