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.



410
411
412
# File 'lib/feldtruby/optimize/objective.rb', line 410

def objective
  @objective
end

Instance Method Details

#hat_compare(c1, c2) ⇒ Object



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

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)


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

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

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

Returns:

  • (Boolean)


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

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.



414
415
416
# File 'lib/feldtruby/optimize/objective.rb', line 414

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