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.
153 154 155 156 157 158 |
# File 'lib/fast/experiment.rb', line 153 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.
151 152 153 |
# File 'lib/fast/experiment.rb', line 151 def combinations @combinations end |
Instance Method Details
#all_ok_replacements_combined ⇒ Object
After identifying all individual replacements that work, try combining all of them.
183 184 185 |
# File 'lib/fast/experiment.rb', line 183 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
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/fast/experiment.rb', line 164 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.
177 178 179 |
# File 'lib/fast/experiment.rb', line 177 def individual_replacements (1..@occurrences_count).to_a end |
#ok_replacements_pair_combinations ⇒ Object
Divide and conquer combining all successful individual replacements.
188 189 190 191 192 193 |
# File 'lib/fast/experiment.rb', line 188 def ok_replacements_pair_combinations @ok_experiments .combination(2) .map { |e| e.flatten.uniq.sort } .uniq - @fail_experiments - @ok_experiments end |