Class: Operator::MutationRipple
- Inherits:
-
Object
- Object
- Operator::MutationRipple
- Defined in:
- ../lib/mutation_ripple.rb
Overview
Simple codon-level mutation. It assumes the source genotype has the form of the Array of numbers.
Instance Attribute Summary (collapse)
-
- (Object) magnitude
The maximal possible value of the mutaton plus 1.
-
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
Instance Method Summary (collapse)
-
- (MutationRipple) initialize(dummy = nil, magnitude = nil)
constructor
Create the mutation operator with default settings.
-
- (Object) mutation(orig, dummy = nil)
Select the random position within the orig vector and mutate it.
Constructor Details
- (MutationRipple) initialize(dummy = nil, magnitude = nil)
Create the mutation operator with default settings.
48 49 50 51 |
# File '../lib/mutation_ripple.rb', line 48 def initialize dummy=nil, magnitude=nil @random = Kernel @magnitude = magnitude end |
Instance Attribute Details
- (Object) magnitude
The maximal possible value of the mutaton plus 1. If not specified, the maximal value over the original genotype values is used.
58 59 60 |
# File '../lib/mutation_ripple.rb', line 58 def magnitude @magnitude end |
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
54 55 56 |
# File '../lib/mutation_ripple.rb', line 54 def random @random end |
Instance Method Details
- (Object) mutation(orig, dummy = nil)
Select the random position within the orig vector and mutate it. The resultant value (of a mutated codon) is a random number in the range 0..magnitude. Return the mutated copy of the orig. genotype.
63 64 65 66 67 68 69 |
# File '../lib/mutation_ripple.rb', line 63 def mutation( orig, dummy=nil ) mutant = orig.clone max = @magnitude.nil? ? mutant.max+1 : @magnitude where = @random.rand( orig.size ) mutant[ where ] = @random.rand( max ) mutant end |