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, id) ⇒ Combinator
constructor
A new instance of Combinator.
Constructor Details
#initialize(parameters, id) ⇒ Combinator
Returns a new instance of Combinator.
28 29 30 31 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 28 def initialize(parameters, id) @parameters = parameters @id = id end |
Instance Method Details
#each(&block) ⇒ Object
46 47 48 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 46 def each &block generate_combinations(0, {}, &block) end |
#generate_combinations(index, opts, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 33 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 |