Class: Glicko2::Rating
- Inherits:
-
Object
- Object
- Glicko2::Rating
- 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
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#sd ⇒ Object
readonly
Returns the value of attribute sd.
-
#volatility ⇒ Object
readonly
Returns the value of attribute volatility.
Class Method Summary collapse
-
.from_glicko_rating(r, rd, volatility = nil) ⇒ Object
Creates a Rating from the Glicko scale.
Instance Method Summary collapse
-
#gravity_expected_score(other_mean) ⇒ Object
Calculate ‘g(phi)` and `E(mu, mu_j, phi_j)` as defined in the Glicko2 paper.
-
#initialize(mean, sd, volatility = nil) ⇒ Rating
constructor
A new instance of Rating.
-
#to_glicko_rating ⇒ Object
Converts to the Glicko scale.
- #to_s ⇒ Object
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
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
7 8 9 |
# File 'lib/glicko2/rating.rb', line 7 def mean @mean end |
#sd ⇒ Object (readonly)
Returns the value of attribute sd.
7 8 9 |
# File 'lib/glicko2/rating.rb', line 7 def sd @sd end |
#volatility ⇒ Object (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.(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_rating ⇒ Object
Converts to the Glicko scale.
21 22 23 |
# File 'lib/glicko2/rating.rb', line 21 def [GLICKO_GRADIENT * mean + GLICKO_INTERCEPT, GLICKO_GRADIENT * sd] end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/glicko2/rating.rb', line 31 def to_s "#<Rating mean=#{mean}, sd=#{sd}, volatility=#{volatility}>" end |