Class: Biopsy::ParameterSweeper
- Inherits:
-
Object
- Object
- Biopsy::ParameterSweeper
- Defined in:
- lib/biopsy/optimisers/parameter_sweeper.rb
Overview
options - is a hash of two hashes, :settings and :parameters
:ranges are arrays to be parameter sweeped
---(single values may be present, these are also remain unchanged
but are accessible within the parameters hash to the constructor)
Instance Attribute Summary collapse
-
#best ⇒ Object
readonly
Returns the value of attribute best.
-
#combinations ⇒ Object
readonly
Returns the value of attribute combinations.
-
#combinator ⇒ Object
readonly
Returns the value of attribute combinator.
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(ranges) ⇒ ParameterSweeper
constructor
A new instance of ParameterSweeper.
-
#knows_starting_point? ⇒ Boolean
True if this algorithm chooses its own starting point.
- #next ⇒ Object
- #random_start_point ⇒ Object
-
#run_one_iteration(parameters, score) ⇒ Object
return the next parameter set to evaluate.
- #select_starting_point ⇒ Object
- #setup(*_args) ⇒ Object
- #update_best? ⇒ Boolean
Constructor Details
#initialize(ranges) ⇒ ParameterSweeper
Returns a new instance of ParameterSweeper.
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 59 def initialize(ranges) @ranges = ranges # convert all options to an array so it can be handled by the # generate_combinations() method # ..this is for users entering single values e.g 4 as a parameter @ranges.each_value{ |value| value = [value] unless value.kind_of? Array } # restrict to a subsample? @combinations = 1 @ranges.each { |r| @combinations *= r[1].size } @is_finished = false @combinator = (Combinator.new @ranges).to_enum end |
Instance Attribute Details
#best ⇒ Object (readonly)
Returns the value of attribute best.
57 58 59 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 57 def best @best end |
#combinations ⇒ Object (readonly)
Returns the value of attribute combinations.
57 58 59 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 57 def combinations @combinations end |
#combinator ⇒ Object (readonly)
Returns the value of attribute combinator.
57 58 59 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 57 def combinator @combinator end |
Instance Method Details
#finished? ⇒ Boolean
114 115 116 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 114 def finished? @is_finished end |
#knows_starting_point? ⇒ Boolean
True if this algorithm chooses its own starting point
119 120 121 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 119 def knows_starting_point? true end |
#next ⇒ Object
96 97 98 99 100 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 96 def next @combinator.next rescue nil end |
#random_start_point ⇒ Object
110 111 112 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 110 def random_start_point @combinator.next end |
#run_one_iteration(parameters, score) ⇒ Object
return the next parameter set to evaluate
80 81 82 83 84 85 86 87 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 80 def run_one_iteration(parameters, score) @current = { :parameters => parameters, :score => score } self.update_best? return @combinator.next rescue @is_finished = true return nil end |
#select_starting_point ⇒ Object
106 107 108 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 106 def select_starting_point @combinator.next end |
#setup(*_args) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 72 def setup(*_args) @best = { :parameters => nil, :score => nil } end |
#update_best? ⇒ Boolean
89 90 91 92 93 94 |
# File 'lib/biopsy/optimisers/parameter_sweeper.rb', line 89 def update_best? raise "best is nil. should run setup first" if @best.nil? if @best[:score].nil? || @current[:score] > @best[:score] @best = @current.clone end end |