Class: EvoSynth::Mutations::SelfAdaptiveGaussMutation

Inherits:
Object
  • Object
show all
Defined in:
lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb

Overview

SELBSTADAPTIVE-GAUSS-MUTATION (Weicker page 114)

TODO: needs rdoc

Constant Summary collapse

DEFAULT_INITIAL_SIGMA =
1.0
DEFAULT_LOWER_BOUND =
-1 * Float::MAX
DEFAULT_UPPER_BOUND =
Float::MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_sigma = DEFAULT_INITIAL_SIGMA, lower_bound = DEFAULT_LOWER_BOUND, upper_bound = DEFAULT_UPPER_BOUND) ⇒ SelfAdaptiveGaussMutation

Returns a new instance of SelfAdaptiveGaussMutation.



39
40
41
42
43
# File 'lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb', line 39

def initialize(initial_sigma = DEFAULT_INITIAL_SIGMA, lower_bound = DEFAULT_LOWER_BOUND, upper_bound = DEFAULT_UPPER_BOUND)
  @initial_sigma = initial_sigma
  @lower_bound = lower_bound
  @upper_bound = upper_bound
end

Instance Attribute Details

#initial_sigmaObject

Returns the value of attribute initial_sigma.



33
34
35
# File 'lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb', line 33

def initial_sigma
  @initial_sigma
end

#lower_boundObject

Returns the value of attribute lower_bound.



33
34
35
# File 'lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb', line 33

def lower_bound
  @lower_bound
end

#upper_boundObject

Returns the value of attribute upper_bound.



33
34
35
# File 'lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb', line 33

def upper_bound
  @upper_bound
end

Instance Method Details

#add_sigma(individual) ⇒ Object



65
66
67
68
# File 'lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb', line 65

def add_sigma(individual)
  individual.instance_eval("def sigma; @sigma end; def sigma=(value); @sigma = value end")
  individual.sigma = @initial_sigma
end

#mutate(individual) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb', line 45

def mutate(individual)
  mutated = individual.deep_clone
  add_sigma(mutated) unless defined? mutated.sigma

  mutated.sigma *= Math.exp( (1 / Math.sqrt(mutated.genome.size)) * EvoSynth.nrand)

  mutated.genome.map! do |gene|
    gene += EvoSynth.nrand(0.0, mutated.sigma)
    gene = @lower_bound if gene < @lower_bound
    gene = @upper_bound if gene > @upper_bound
    gene
  end

  mutated
end

#to_sObject



61
62
63
# File 'lib/evosynth/operators/mutations/self_adaptive_gauss_mutation.rb', line 61

def to_s
  "self adaptive gauss mutation <sigma: #{@sigma}, lower bound: #{@lower_bound}, upper_bound: #{@upper_bound}>"
end