Class: EvoSynth::Evolvers::DerandomizedES

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

Overview

DERANDOMISIERTE-ES (Weicker Page 139)

TODO: rdoc

Constant Summary collapse

DEFAULT_SIGMA =
0.1
DEFAULT_ALPHA =
0.2
DEFAULT_TAU =

Math.sqrt(genome.size) is a common value

4
DEFAULT_CHILD_FACTOR =
5
DEFAULT_MUTATION =
EvoSynth::Mutations::GaussMutation.new(DEFAULT_SIGMA)
DEFAULT_RECOMBINATION =
EvoSynth::GlobalRecombinations::GlobalArithmeticCrossover.new
DEFAULT_ENV_SELECTION =
EvoSynth::Selections::SelectBest.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) ⇒ DerandomizedES

Returns a new instance of DerandomizedES.



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

def initialize(profile)
  init_profile :population,
      :evaluator,
    :sigma          => DEFAULT_SIGMA,
    :alpha          => DEFAULT_ALPHA,
    :tau          => DEFAULT_TAU,
      :child_factor      => DEFAULT_CHILD_FACTOR,
      :enviromental_selection => DEFAULT_ENV_SELECTION

  use_profile profile
  @mutation = DEFAULT_MUTATION
  @recombination = DEFAULT_RECOMBINATION

  genome_length = 0;
  @population.each do |individual|
    @evaluator.calculate_and_set_initial_fitness(individual)
    genome_length = individual.genome.size if individual.genome.size > genome_length
  end
  @s = [0.0] * genome_length
end

Instance Attribute Details

#sObject (readonly)

Returns the value of attribute s.



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

def s
  @s
end

Instance Method Details

#best_solutionObject



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

def best_solution
  @population.best
end

#next_generationObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/evosynth/evolvers/evolution_strategies/derandomized_es.rb', line 85

def next_generation
  z = []
  child_population = EvoSynth::Population.new
  child = @recombination.recombine(@population)

  (@child_factor * @population.size).times do
    mutated_child = @mutation.mutate(child)
    child_population << mutated_child

    z = []
    mutated_child.genome.each_with_index { |gene, index| z << gene - child.genome[index] }
  end

  child_population.each { |individual| @evaluator.calculate_and_set_fitness(individual) }
  @population = @enviromental_selection.select(child_population, @population.size)

  adjust_parameters(z)
end

#return_resultObject



81
82
83
# File 'lib/evosynth/evolvers/evolution_strategies/derandomized_es.rb', line 81

def return_result
  @population
end

#to_sObject



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

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

#worst_solutionObject



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

def worst_solution
  @population.worst
end