Class: EvoSynth::Mutations::UniformRealMutation
- Inherits:
-
Object
- Object
- EvoSynth::Mutations::UniformRealMutation
- Defined in:
- lib/evosynth/operators/mutations/uniform_real_mutation.rb
Overview
GLEICHVERTEILTE-REELWERTIGE-MUTATION (Weicker page 131) TODO: needs rdoc
Constant Summary collapse
- DEFAULT_PROBABILITY =
0.1
- DEFAULT_STEP_SIZE =
0.1
Instance Method Summary collapse
-
#initialize(probability = DEFAULT_PROBABILITY, step_size = DEFAULT_STEP_SIZE) ⇒ UniformRealMutation
constructor
A new instance of UniformRealMutation.
- #mutate(individual) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(probability = DEFAULT_PROBABILITY, step_size = DEFAULT_STEP_SIZE) ⇒ UniformRealMutation
Returns a new instance of UniformRealMutation.
36 37 38 39 |
# File 'lib/evosynth/operators/mutations/uniform_real_mutation.rb', line 36 def initialize(probability = DEFAULT_PROBABILITY, step_size = DEFAULT_STEP_SIZE) @probability = probability @step_size = step_size end |
Instance Method Details
#mutate(individual) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/evosynth/operators/mutations/uniform_real_mutation.rb', line 41 def mutate(individual) mutated = individual.deep_clone genome = mutated.genome genome.size.times do |index| genome[index] += @step_size - 2 * EvoSynth.rand * @step_size if EvoSynth.rand <= @probability end mutated end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/evosynth/operators/mutations/uniform_real_mutation.rb', line 52 def to_s "uniform real mutation <probability: #{@probability}>" end |