Class: Fast::ExperimentCombinations

Inherits:
Object
  • Object
show all
Defined in:
lib/fast/experiment.rb

Overview

Suggest possible combinations of occurrences to replace.

Check for #generate_combinations to understand the strategy of each round.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(round:, occurrences_count:, ok_experiments:, fail_experiments:) ⇒ ExperimentCombinations

Returns a new instance of ExperimentCombinations.



148
149
150
151
152
153
# File 'lib/fast/experiment.rb', line 148

def initialize(round:, occurrences_count:, ok_experiments:, fail_experiments:)
  @round = round
  @ok_experiments = ok_experiments
  @fail_experiments = fail_experiments
  @occurrences_count = occurrences_count
end

Instance Attribute Details

#combinationsObject (readonly)

Returns the value of attribute combinations.



146
147
148
# File 'lib/fast/experiment.rb', line 146

def combinations
  @combinations
end

Instance Method Details

#all_ok_replacements_combinedObject

After identifying all individual replacements that work, try combining all of them.



178
179
180
# File 'lib/fast/experiment.rb', line 178

def all_ok_replacements_combined
  [@ok_experiments.uniq.sort]
end

#generate_combinationsObject

Generate different combinations depending on the current round.



159
160
161
162
163
164
165
166
167
168
# File 'lib/fast/experiment.rb', line 159

def generate_combinations
  case @round
  when 1
    individual_replacements
  when 2
    all_ok_replacements_combined
  else
    ok_replacements_pair_combinations
  end
end

#individual_replacementsObject

Replace a single occurrence at each iteration and identify which individual replacements work.



172
173
174
# File 'lib/fast/experiment.rb', line 172

def individual_replacements
  (1..@occurrences_count).to_a
end

#ok_replacements_pair_combinationsObject

Divide and conquer combining all successful individual replacements.



183
184
185
186
187
188
# File 'lib/fast/experiment.rb', line 183

def ok_replacements_pair_combinations
  @ok_experiments
    .combination(2)
    .map { |e| e.flatten.uniq.sort }
    .uniq - @fail_experiments - @ok_experiments
end