Class: Fast::ExperimentCombinations
- Inherits:
-
Object
- Object
- Fast::ExperimentCombinations
- 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
-
#combinations ⇒ Object
readonly
Returns the value of attribute combinations.
Instance Method Summary collapse
-
#all_ok_replacements_combined ⇒ Object
After identifying all individual replacements that work, try combining all of them.
-
#generate_combinations ⇒ Object
Generate different combinations depending on the current round.
-
#individual_replacements ⇒ Object
Replace a single occurrence at each iteration and identify which individual replacements work.
-
#initialize(round:, occurrences_count:, ok_experiments:, fail_experiments:) ⇒ ExperimentCombinations
constructor
A new instance of ExperimentCombinations.
-
#ok_replacements_pair_combinations ⇒ Object
Divide and conquer combining all successful individual replacements.
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
#combinations ⇒ Object (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_combined ⇒ Object
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_combinations ⇒ Object
Generate different combinations depending on the current round.
-
Round 1: Use #individual_replacements
-
Round 2: Tries #all_ok_replacements_combined
-
Round 3+: Follow #ok_replacements_pair_combinations
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_replacements ⇒ Object
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_combinations ⇒ Object
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 |