Class: EvoSynth::Evolvers::AdaptiveES

Inherits:
Object
  • Object
show all
Includes:
Evolver
Defined in:
lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb

Overview

ES-ADAPTIV (Weicker Page 135)

TODO: rdoc (mutation and adjustment are fixed!)

Constant Summary collapse

DEFAULT_SIGMA =
0.1
DEFAULT_CHILD_FACTOR =
5
DEFAULT_MODIFICATION_FREQUENCY =
10
DEFAULT_MUTATION =
EvoSynth::Mutations::GaussMutation.new(DEFAULT_SIGMA)
DEFAULT_PARENT_SELECTION =
EvoSynth::Selections::RandomSelection.new
DEFAULT_ENV_SELECTION =
EvoSynth::Selections::SelectBest.new
DEFAULT_ADJUSTMENT =
EvoSynth::Adjustments::AdaptiveAdjustment.new

Instance Attribute Summary collapse

Attributes included from RunnableEvolver

#generations_computed

Instance Method Summary collapse

Methods included from ProfileUsingEvolver

#init_profile, #use_profile

Methods included from RunnableEvolver

#run_until, #run_until_fitness_reached, #run_until_generations_reached

Constructor Details

#initialize(profile) ⇒ AdaptiveES

Returns a new instance of AdaptiveES.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb', line 48

def initialize(profile)
  init_profile :population,
      :evaluator,
    :sigma          => DEFAULT_SIGMA,
      :child_factor      => DEFAULT_CHILD_FACTOR,
      :modification_frequency => DEFAULT_MODIFICATION_FREQUENCY,
      :enviromental_selection => DEFAULT_ENV_SELECTION,
      :parent_selection    => DEFAULT_PARENT_SELECTION

  use_profile profile
  @adjustment = DEFAULT_ADJUSTMENT
  @mutation = DEFAULT_MUTATION
  @success = 0

  @population.each { |individual| @evaluator.calculate_and_set_initial_fitness(individual) }
end

Instance Attribute Details

#successObject (readonly)

Returns the value of attribute success.



38
39
40
# File 'lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb', line 38

def success
  @success
end

Instance Method Details

#best_solutionObject



69
70
71
# File 'lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb', line 69

def best_solution
  @population.best
end

#next_generationObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb', line 81

def next_generation
  child_population = EvoSynth::Population.new

  (@child_factor * @population.size).times do
    parent = @parent_selection.select(@population, 1).first
    @mutation.sigma = @sigma
    child = @mutation.mutate(parent)
 
    @evaluator.calculate_and_set_fitness(child)
    @success += 1 if child > parent
    child_population << child
  end

  @population = @enviromental_selection.select(child_population, @population.size)
  if @generations_computed % @modification_frequency == 0
    success_rate =  @success / (@modification_frequency - (@child_factor * @population.size))
    @sigma = @adjustment.adjust(@sigma, success_rate)
    @success = 0
  end
end

#return_resultObject



77
78
79
# File 'lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb', line 77

def return_result
  @population
end

#to_sObject



65
66
67
# File 'lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb', line 65

def to_s
  "adaptive ES <sigma: #{@sigma}, success: #{@success}, mutation: #{@mutation}, parent selection: #{@parent_selection}, enviromental selection: #{@enviromental_selection}>"
end

#worst_solutionObject



73
74
75
# File 'lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb', line 73

def worst_solution
  @population.worst
end