Class: FeldtRuby::Optimize::Objective::LowerAggregateQualityIsBetterComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/feldtruby/optimize/objective.rb

Overview

A Comparator ranks a set of candidates based on their sub-qualities. This default comparator just uses the quality value to sort the candidates, with lower values indicating better quality.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectiveObject

Returns the value of attribute objective.



417
418
419
# File 'lib/feldtruby/optimize/objective.rb', line 417

def objective
  @objective
end

Instance Method Details

#hat_compare(c1, c2) ⇒ Object



433
434
435
436
# File 'lib/feldtruby/optimize/objective.rb', line 433

def hat_compare(c1, c2)
  # We change the order since smaller values indicates higher quality
  objective.quality_of(c2).value <=> objective.quality_of(c1).value
end

#is_better_than?(c1, c2) ⇒ Boolean

Returns:

  • (Boolean)


425
426
427
# File 'lib/feldtruby/optimize/objective.rb', line 425

def is_better_than?(c1, c2)
  hat_compare(c1, c2) == 1
end

#is_better_than_for_goal?(index, c1, c2) ⇒ Boolean

Returns:

  • (Boolean)


429
430
431
# File 'lib/feldtruby/optimize/objective.rb', line 429

def is_better_than_for_goal?(index, c1, c2)
  objective.quality_of(c1).sub_quality(index, true) < objective.quality_of(c2).sub_quality(index, true)
end

#rank_candidates(candidates, weights) ⇒ Object

Return an array with the candidates ranked from best to worst. Candidates that cannot be distinghuished from each other are randomly ranked.



421
422
423
# File 'lib/feldtruby/optimize/objective.rb', line 421

def rank_candidates candidates, weights
  candidates.sort_by {|c| objective.quality_of(c, weights).value}
end