Class: FeldtRuby::Optimize::PopulationBasedOptimizer
- Defined in:
- lib/feldtruby/optimize/optimizer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#population ⇒ Object
readonly
Returns the value of attribute population.
Attributes inherited from Optimizer
#archive, #num_optimization_steps, #objective, #options, #search_space, #termination_criterion
Attributes included from Logging
Instance Method Summary collapse
-
#get_candidate(index) ⇒ Object
Get candidate from population at given index.
-
#get_candidates_with_indices(indices) ⇒ Object
Get candidates from population at given indices.
- #initialize_options(options) ⇒ Object
-
#initialize_population(sizeOfPopulation) ⇒ Object
Create a population of a given size by randomly sampling candidates from the search space.
- #population_size ⇒ Object
-
#re_initialize_population(percentageOfPopulation = 0.50) ⇒ Object
Re-initialize parts of the population.
-
#sample_population_indices_without_replacement(numSamples) ⇒ Object
Sample indices from the population without replacement.
-
#update_candidate_in_population(index, candidate) ⇒ Object
Update population with candidate at given index.
Methods inherited from Optimizer
#best, #init_archive, #initialize, #log_end_of_optimization, #optimization_step, #optimize, #time_per_step, #update_archive
Methods included from Logging
#__find_logger_set_on_instance_vars, #new_default_logger, #setup_logger_and_distribute_to_instance_variables
Constructor Details
This class inherits a constructor from FeldtRuby::Optimize::Optimizer
Instance Attribute Details
#population ⇒ Object (readonly)
Returns the value of attribute population.
172 173 174 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 172 def population @population end |
Instance Method Details
#get_candidate(index) ⇒ Object
Get candidate from population at given index.
217 218 219 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 217 def get_candidate(index) @population[index] end |
#get_candidates_with_indices(indices) ⇒ Object
Get candidates from population at given indices.
212 213 214 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 212 def get_candidates_with_indices(indices) indices.map {|i| @population[i]} end |
#initialize_options(options) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 174 def () super @population_size = @options[:populationSize] initialize_population(@population_size) @sampler = [:samplerClass].new(self, ) end |
#initialize_population(sizeOfPopulation) ⇒ Object
Create a population of a given size by randomly sampling candidates from the search space.
182 183 184 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 182 def initialize_population(sizeOfPopulation) @population = Array.new(sizeOfPopulation).map {search_space.gen_candidate()} end |
#population_size ⇒ Object
202 203 204 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 202 def population_size @population_size end |
#re_initialize_population(percentageOfPopulation = 0.50) ⇒ Object
Re-initialize parts of the population.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 187 def re_initialize_population(percentageOfPopulation = 0.50) if percentageOfPopulation >= 1.00 initialize_population(@population_size) else num_to_replace = (percentageOfPopulation * @population_size).to_i # We must use a PopulationSampler here instead of just calling sample_population_indices_without_replacement # since we do not know which sampler is installed. sampler = PopulationSampler.new(self, self.) indices = sampler.sample_population_indices_without_replacement(num_to_replace) indices.each do |i| @population[i] = search_space.gen_candidate() end end end |
#sample_population_indices_without_replacement(numSamples) ⇒ Object
Sample indices from the population without replacement.
207 208 209 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 207 def sample_population_indices_without_replacement(numSamples) @sampler.sample_population_indices_without_replacement(numSamples) end |
#update_candidate_in_population(index, candidate) ⇒ Object
Update population with candidate at given index.
222 223 224 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 222 def update_candidate_in_population(index, candidate) @population[index] = candidate end |