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
#best, #best_quality_value, #best_sub_quality_values, #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
#initialize, #log_end_of_optimization, #optimization_step, #optimize, #time_per_step, #update_best
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.
154 155 156 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 154 def population @population end |
Instance Method Details
#get_candidate(index) ⇒ Object
Get candidate from population at given index.
199 200 201 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 199 def get_candidate(index) @population[index] end |
#get_candidates_with_indices(indices) ⇒ Object
Get candidates from population at given indices.
194 195 196 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 194 def get_candidates_with_indices(indices) indices.map {|i| @population[i]} end |
#initialize_options(options) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 156 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.
164 165 166 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 164 def initialize_population(sizeOfPopulation) @population = Array.new(sizeOfPopulation).map {search_space.gen_candidate()} end |
#population_size ⇒ Object
184 185 186 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 184 def population_size @population_size end |
#re_initialize_population(percentageOfPopulation = 0.50) ⇒ Object
Re-initialize parts of the population.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 169 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.
189 190 191 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 189 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.
204 205 206 |
# File 'lib/feldtruby/optimize/optimizer.rb', line 204 def update_candidate_in_population(index, candidate) @population[index] = candidate end |