Class: Operator::Shorten
- Inherits:
-
Object
- Object
- Operator::Shorten
- Defined in:
- ../lib/shorten.rb
Overview
Cut off the unused tail of the chromozome. This operator is typically applied after the GE mapping (see Mapping::Base) when there is an information about the numbers of codons used for the phenotype creation. There are two modes of the operation: stochastic and deterministic.
Instance Attribute Summary (collapse)
-
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
-
- (Object) stochastic
The mode of the operation:.
Instance Method Summary (collapse)
-
- (Shorten) initialize
constructor
Use the default Kernel.rand and deterministic mode.
-
- (Object) shorten(gen, max)
Reduce the size of the genotype gen, specifying the max point.
Constructor Details
- (Shorten) initialize
Use the default Kernel.rand and deterministic mode.
12 13 14 15 |
# File '../lib/shorten.rb', line 12 def initialize @random = Kernel @stochastic = false end |
Instance Attribute Details
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
18 19 20 |
# File '../lib/shorten.rb', line 18 def random @random end |
- (Object) stochastic
The mode of the operation:
true .. the genotype is shortened at the precisely specified cutting index.
false .. the genotype is shortened at the random point after the specified index.
23 24 25 |
# File '../lib/shorten.rb', line 23 def stochastic @stochastic end |
Instance Method Details
- (Object) shorten(gen, max)
Reduce the size of the genotype gen, specifying the max point. See stochastic attribute for meaning of the argument max.
27 28 29 30 31 |
# File '../lib/shorten.rb', line 27 def shorten( gen, max ) return gen.clone if gen.size <= max point = @stochastic ? (@random.rand( gen.size+1-max ) + max) : max gen.clone[0...point] end |