Class: FeldtRuby::Optimize::SearchSpace::Sampler
- Defined in:
- lib/feldtruby/optimize/search_space.rb
Overview
A sampler generates a new candidate (or set of candidates) that is (are) within a search space. This default sampler does uniform random sampling over the whole search space.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#search_space ⇒ Object
Returns the value of attribute search_space.
Instance Method Summary collapse
-
#initialize(searchSpace = nil) ⇒ Sampler
constructor
A new instance of Sampler.
-
#sample_candidate ⇒ Object
Sample one candidate within the space.
-
#sample_candidates(numCandidates) ⇒ Object
Sample multiple candidates from the search space.
-
#sample_value_for_dimension(index) ⇒ Object
Random uniform sampling of a valid value for a given dimension index in the search space.
Constructor Details
#initialize(searchSpace = nil) ⇒ Sampler
Returns a new instance of Sampler.
87 88 89 |
# File 'lib/feldtruby/optimize/search_space.rb', line 87 def initialize(searchSpace = nil) self.search_space = searchSpace end |
Instance Attribute Details
#search_space ⇒ Object
Returns the value of attribute search_space.
85 86 87 |
# File 'lib/feldtruby/optimize/search_space.rb', line 85 def search_space @search_space end |
Instance Method Details
#sample_candidate ⇒ Object
Sample one candidate within the space. Default is to do random uniform sampling.
98 99 100 101 |
# File 'lib/feldtruby/optimize/search_space.rb', line 98 def sample_candidate num_vars = search_space.num_variables (0...num_vars).map {|i| sample_value_for_dimension(i)} end |
#sample_candidates(numCandidates) ⇒ Object
Sample multiple candidates from the search space. The default is just to call the method sampling one candidate mutliple times. But subclasses can implement more sophisticated schemes.
105 106 107 |
# File 'lib/feldtruby/optimize/search_space.rb', line 105 def sample_candidates(numCandidates) Array.new(numCandidates) { sample_candidate() } end |
#sample_value_for_dimension(index) ⇒ Object
Random uniform sampling of a valid value for a given dimension index in the search space.
92 93 94 95 |
# File 'lib/feldtruby/optimize/search_space.rb', line 92 def sample_value_for_dimension(index) min, delta = search_space.min_values[index], search_space.deltas[index] min + delta * rand() end |