Class: OpenSkill::Models::BradleyTerryPart::Rating

Inherits:
Object
  • Object
show all
Defined in:
lib/openskill/models/bradley_terry_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.



281
282
283
284
285
286
# File 'lib/openskill/models/bradley_terry_part.rb', line 281

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.



279
280
281
# File 'lib/openskill/models/bradley_terry_part.rb', line 279

def id
  @id
end

#muObject

Returns the value of attribute mu.



278
279
280
# File 'lib/openskill/models/bradley_terry_part.rb', line 278

def mu
  @mu
end

#nameObject

Returns the value of attribute name.



278
279
280
# File 'lib/openskill/models/bradley_terry_part.rb', line 278

def name
  @name
end

#sigmaObject

Returns the value of attribute sigma.



278
279
280
# File 'lib/openskill/models/bradley_terry_part.rb', line 278

def sigma
  @sigma
end

Instance Method Details

#<(other) ⇒ Object

Raises:

  • (ArgumentError)


304
305
306
307
308
# File 'lib/openskill/models/bradley_terry_part.rb', line 304

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

  ordinal < other.ordinal
end

#<=(other) ⇒ Object

Raises:

  • (ArgumentError)


316
317
318
319
320
# File 'lib/openskill/models/bradley_terry_part.rb', line 316

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

  ordinal <= other.ordinal
end

#<=>(other) ⇒ Object



298
299
300
301
302
# File 'lib/openskill/models/bradley_terry_part.rb', line 298

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

  ordinal <=> other.ordinal
end

#==(other) ⇒ Object



328
329
330
331
332
# File 'lib/openskill/models/bradley_terry_part.rb', line 328

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

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

#>(other) ⇒ Object

Raises:

  • (ArgumentError)


310
311
312
313
314
# File 'lib/openskill/models/bradley_terry_part.rb', line 310

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

  ordinal > other.ordinal
end

#>=(other) ⇒ Object

Raises:

  • (ArgumentError)


322
323
324
325
326
# File 'lib/openskill/models/bradley_terry_part.rb', line 322

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

  ordinal >= other.ordinal
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


338
339
340
# File 'lib/openskill/models/bradley_terry_part.rb', line 338

def eql?(other)
  self == other
end

#hashObject



334
335
336
# File 'lib/openskill/models/bradley_terry_part.rb', line 334

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

#inspectObject



346
347
348
# File 'lib/openskill/models/bradley_terry_part.rb', line 346

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



294
295
296
# File 'lib/openskill/models/bradley_terry_part.rb', line 294

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

#to_sObject



342
343
344
# File 'lib/openskill/models/bradley_terry_part.rb', line 342

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