Module: FeldtRuby::Optimize

Defined in:
lib/feldtruby/optimize.rb,
lib/feldtruby/optimize/archive.rb,
lib/feldtruby/optimize/objective.rb,
lib/feldtruby/optimize/optimizer.rb,
lib/feldtruby/optimize/search_space.rb,
lib/feldtruby/optimize/differential_evolution.rb,
lib/feldtruby/optimize/sub_qualities_comparators.rb

Defined Under Namespace

Modules: DE_BoundingStrategy_RandomWithinSearchSpace, DE_CrossoverStrategy_Binomial, DE_MutationStrategy_Best_1, DE_MutationStrategy_Best_2, DE_MutationStrategy_Rand_1, DE_UpdateStrategy_NoFeedbackUpdates Classes: Archive, DEOptimizerBase, DEOptimizer_Best_1_Bin, DEOptimizer_Best_2_Bin, DEOptimizer_Rand_1_Bin, DiversityObjective, EpsilonNonDominance, EuclideanDistanceToBest, EvolutionaryOptimizer, MaxStepsTerminationCriterion, Objective, ObjectiveMaximizeBlock, ObjectiveMinimizeBlock, Optimizer, PercentageQualityValue, PopulationBasedOptimizer, PopulationSampler, QualityValue, RadiusLimitedPopulationSampler, RandomSearcher, SearchSpace, StdOutLogger, SubQualitiesComparator, TerminationCriterion

Constant Summary collapse

DefaultOptimizationOptions =
{
	:terminationCriterionClass => FeldtRuby::Optimize::MaxStepsTerminationCriterion,
	:verbose => true,
	:populationSize => 100,
	:samplerClass => FeldtRuby::Optimize::RadiusLimitedPopulationSampler,
	:samplerRadius => 8, # Max distance between individuals selected in same tournament.
	:archive => nil, # If this is set it takes precedence over archiveClass.
	:archiveClass => FeldtRuby::Optimize::Archive,
	:archiveDiversityObjective => nil, # If this is set it takes precedence over the class in archiveDiversityObjectiveClass
	:archiveDiversityObjectiveClass => FeldtRuby::Optimize::EuclideanDistanceToBest,
}
DefaultSearchSpace =
SearchSpace.new_symmetric(2, 1)
DEOptimizer =

DE/rand/1/bin is the default DE optimizer since it does not converge too quickly but is generally good. For many problems the DEOptimizer_Best_1_Bin gives better results faster though.

DEOptimizer_Rand_1_Bin

Class Method Summary collapse

Class Method Details

.maximize(min, max, options = {}, &costFunction) ⇒ Object

Short hand wrapper for function maximization.



231
232
233
# File 'lib/feldtruby/optimize/differential_evolution.rb', line 231

def self.maximize(min, max, options = {}, &costFunction)
	optimize(min, max, options, FeldtRuby::Optimize::ObjectiveMaximizeBlock, &costFunction)
end

.minimize(min, max, options = {}, &costFunction) ⇒ Object

Short hand wrapper for function minimization.



226
227
228
# File 'lib/feldtruby/optimize/differential_evolution.rb', line 226

def self.minimize(min, max, options = {}, &costFunction)
	optimize(min, max, options, &costFunction)
end

.optimize(min, max, options = {:verbose => true}, objectiveFuncClass = FeldtRuby::Optimize::ObjectiveMinimizeBlock, &costFunction) ⇒ Object

Optimize the numVariables between the min and max values given costFunction. Default is to minimize.



215
216
217
218
219
220
221
222
223
# File 'lib/feldtruby/optimize/differential_evolution.rb', line 215

def self.optimize(min, max, options = {:verbose => true}, 
	objectiveFuncClass = FeldtRuby::Optimize::ObjectiveMinimizeBlock, &costFunction)
	objective = objectiveFuncClass.new(&costFunction)
	num_vars = costFunction.arity
	search_space = SearchSpace.new_from_min_max(num_vars, min, max)
	optimizer = DEOptimizer.new(objective, search_space, options)
	optimizer.optimize()
	optimizer.best.to_a
end

.override_default_options_with(options) ⇒ Object



239
240
241
242
243
# File 'lib/feldtruby/optimize/optimizer.rb', line 239

def self.override_default_options_with(options)
	o = DefaultOptimizationOptions.clone.update(options)
	o[:terminationCriterion] = o[:terminationCriterionClass].new(o[:maxNumSteps])
	o
end