Class: OpenSkill::Models::ThurstoneMostellerPart::Rating

Inherits:
Object
  • Object
show all
Defined in:
lib/openskill/models/thurstone_mosteller_part.rb

Overview

Rating class for individual players

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mu:, sigma:, name: nil) ⇒ Rating

Returns a new instance of Rating.



284
285
286
287
288
289
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 284

def initialize(mu:, sigma:, name: nil)
  @id = SecureRandom.hex
  @mu = mu.to_f
  @sigma = sigma.to_f
  @name = name
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



282
283
284
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 282

def id
  @id
end

#muObject

Returns the value of attribute mu.



281
282
283
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 281

def mu
  @mu
end

#nameObject

Returns the value of attribute name.



281
282
283
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 281

def name
  @name
end

#sigmaObject

Returns the value of attribute sigma.



281
282
283
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 281

def sigma
  @sigma
end

Instance Method Details

#<(other) ⇒ Object

Raises:

  • (ArgumentError)


307
308
309
310
311
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 307

def <(other)
  raise ArgumentError, 'comparison with non-Rating' unless other.is_a?(Rating)

  ordinal < other.ordinal
end

#<=(other) ⇒ Object

Raises:

  • (ArgumentError)


319
320
321
322
323
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 319

def <=(other)
  raise ArgumentError, 'comparison with non-Rating' unless other.is_a?(Rating)

  ordinal <= other.ordinal
end

#<=>(other) ⇒ Object



301
302
303
304
305
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 301

def <=>(other)
  return nil unless other.is_a?(Rating)

  ordinal <=> other.ordinal
end

#==(other) ⇒ Object



331
332
333
334
335
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 331

def ==(other)
  return false unless other.is_a?(Rating)

  @mu == other.mu && @sigma == other.sigma
end

#>(other) ⇒ Object

Raises:

  • (ArgumentError)


313
314
315
316
317
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 313

def >(other)
  raise ArgumentError, 'comparison with non-Rating' unless other.is_a?(Rating)

  ordinal > other.ordinal
end

#>=(other) ⇒ Object

Raises:

  • (ArgumentError)


325
326
327
328
329
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 325

def >=(other)
  raise ArgumentError, 'comparison with non-Rating' unless other.is_a?(Rating)

  ordinal >= other.ordinal
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


341
342
343
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 341

def eql?(other)
  self == other
end

#hashObject



337
338
339
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 337

def hash
  [@id, @mu, @sigma].hash
end

#inspectObject



349
350
351
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 349

def inspect
  to_s
end

#ordinal(z: 3.0, alpha: 1.0, target: 0.0) ⇒ Float

Calculate display rating (conservative estimate)

Parameters:

  • z (Float) (defaults to: 3.0)

    number of standard deviations

  • alpha (Float) (defaults to: 1.0)

    scaling factor

  • target (Float) (defaults to: 0.0)

    target adjustment

Returns:

  • (Float)

    the ordinal rating



297
298
299
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 297

def ordinal(z: 3.0, alpha: 1.0, target: 0.0)
  alpha * ((@mu - z * @sigma) + (target / alpha))
end

#to_sObject



345
346
347
# File 'lib/openskill/models/thurstone_mosteller_part.rb', line 345

def to_s
  "Rating(mu=#{@mu}, sigma=#{@sigma}#{", name=#{@name}" if @name})"
end