Class: OpenSkill::Models::PlackettLuce::Rating

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



279
280
281
282
283
284
# File 'lib/openskill/models/plackett_luce.rb', line 279

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.



277
278
279
# File 'lib/openskill/models/plackett_luce.rb', line 277

def id
  @id
end

#muObject

Returns the value of attribute mu.



276
277
278
# File 'lib/openskill/models/plackett_luce.rb', line 276

def mu
  @mu
end

#nameObject

Returns the value of attribute name.



276
277
278
# File 'lib/openskill/models/plackett_luce.rb', line 276

def name
  @name
end

#sigmaObject

Returns the value of attribute sigma.



276
277
278
# File 'lib/openskill/models/plackett_luce.rb', line 276

def sigma
  @sigma
end

Instance Method Details

#<(other) ⇒ Object

Raises:

  • (ArgumentError)


302
303
304
305
306
# File 'lib/openskill/models/plackett_luce.rb', line 302

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

  ordinal < other.ordinal
end

#<=(other) ⇒ Object

Raises:

  • (ArgumentError)


314
315
316
317
318
# File 'lib/openskill/models/plackett_luce.rb', line 314

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

  ordinal <= other.ordinal
end

#<=>(other) ⇒ Object



296
297
298
299
300
# File 'lib/openskill/models/plackett_luce.rb', line 296

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

  ordinal <=> other.ordinal
end

#==(other) ⇒ Object



326
327
328
329
330
# File 'lib/openskill/models/plackett_luce.rb', line 326

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

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

#>(other) ⇒ Object

Raises:

  • (ArgumentError)


308
309
310
311
312
# File 'lib/openskill/models/plackett_luce.rb', line 308

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

  ordinal > other.ordinal
end

#>=(other) ⇒ Object

Raises:

  • (ArgumentError)


320
321
322
323
324
# File 'lib/openskill/models/plackett_luce.rb', line 320

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

  ordinal >= other.ordinal
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


336
337
338
# File 'lib/openskill/models/plackett_luce.rb', line 336

def eql?(other)
  self == other
end

#hashObject



332
333
334
# File 'lib/openskill/models/plackett_luce.rb', line 332

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

#inspectObject



344
345
346
# File 'lib/openskill/models/plackett_luce.rb', line 344

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



292
293
294
# File 'lib/openskill/models/plackett_luce.rb', line 292

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

#to_sObject



340
341
342
# File 'lib/openskill/models/plackett_luce.rb', line 340

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