Class: Biopsy::Combinator
- Inherits:
-
Object
- Object
- Biopsy::Combinator
- Includes:
- Enumerable
- Defined in:
- lib/biopsy/optimisers/parameter_sweeper.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #generate_combinations(index, opts, &block) ⇒ Object
-
#initialize(parameters) ⇒ Combinator
constructor
A new instance of Combinator.
Constructor Details
#initialize(parameters) ⇒ Combinator
Returns a new instance of Combinator.
28 29 30 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 28 def initialize parameters @parameters = parameters end |
Instance Method Details
#each(&block) ⇒ Object
45 46 47 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 45 def each &block generate_combinations(0, {}, &block) end |
#generate_combinations(index, opts, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 32 def generate_combinations(index, opts, &block) if index == @parameters.length block.call opts.clone return end # recurse key = @parameters.keys[index] @parameters[key].each do |value| opts[key] = value generate_combinations(index + 1, opts, &block) end end |