Class: EvoSynth::Mutations::GaussMutation
- Inherits:
-
Object
- Object
- EvoSynth::Mutations::GaussMutation
- Defined in:
- lib/evosynth/operators/mutations/gauss_mutation.rb
Overview
GAUSS-MUTATION (Weicker page 60)
TODO: needs rdoc
Constant Summary collapse
- DEFAULT_SIGMA =
1.0
- DEFAULT_LOWER_BOUND =
-1 * Float::MAX
- DEFAULT_UPPER_BOUND =
Float::MAX
Instance Attribute Summary collapse
-
#lower_bound ⇒ Object
Returns the value of attribute lower_bound.
-
#sigma ⇒ Object
Returns the value of attribute sigma.
-
#upper_bound ⇒ Object
Returns the value of attribute upper_bound.
Instance Method Summary collapse
-
#initialize(sigma = DEFAULT_SIGMA, lower_bound = DEFAULT_LOWER_BOUND, upper_bound = DEFAULT_UPPER_BOUND) ⇒ GaussMutation
constructor
A new instance of GaussMutation.
- #mutate(individual) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(sigma = DEFAULT_SIGMA, lower_bound = DEFAULT_LOWER_BOUND, upper_bound = DEFAULT_UPPER_BOUND) ⇒ GaussMutation
Returns a new instance of GaussMutation.
39 40 41 42 43 |
# File 'lib/evosynth/operators/mutations/gauss_mutation.rb', line 39 def initialize(sigma = DEFAULT_SIGMA, lower_bound = DEFAULT_LOWER_BOUND, upper_bound = DEFAULT_UPPER_BOUND) @sigma = sigma @lower_bound = lower_bound @upper_bound = upper_bound end |
Instance Attribute Details
#lower_bound ⇒ Object
Returns the value of attribute lower_bound.
33 34 35 |
# File 'lib/evosynth/operators/mutations/gauss_mutation.rb', line 33 def lower_bound @lower_bound end |
#sigma ⇒ Object
Returns the value of attribute sigma.
33 34 35 |
# File 'lib/evosynth/operators/mutations/gauss_mutation.rb', line 33 def sigma @sigma end |
#upper_bound ⇒ Object
Returns the value of attribute upper_bound.
33 34 35 |
# File 'lib/evosynth/operators/mutations/gauss_mutation.rb', line 33 def upper_bound @upper_bound end |
Instance Method Details
#mutate(individual) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/evosynth/operators/mutations/gauss_mutation.rb', line 45 def mutate(individual) mutated = individual.deep_clone mutated.genome.map! do |gene| gene += EvoSynth.nrand(0.0, @sigma) gene = @lower_bound if gene < @lower_bound gene = @upper_bound if gene > @upper_bound gene end mutated end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/evosynth/operators/mutations/gauss_mutation.rb', line 58 def to_s "gauss mutation <sigma: #{@sigma}, lower bound: #{@lower_bound}, upper_bound: #{@upper_bound}>" end |