abstract class Talgene::Genome(T)
- Talgene::Genome(T)
- Reference
- Object
Overview
A convenience abstract class to avoid some boilerplate over the implementation of a
#fitness
method.
require "talgene"
class Model < Talgene::Genome(Int32)
def fitness : Float64
genes.each.slice(2).sum 0.0 do |(x, y)|
y - x
end
end
end
model = Model.new [0, 1, 2, 3, 4, 5]
model.fitness # => 3.0
Included Modules
- Indexable(T)
- Talgene::Fittable
Defined in:
models/genome.crConstructors
-
.new(genes : Array(T))
Creates a new
Talgene::Genome
instance with supplied array of genes.
Instance Method Summary
-
#genes : Array(T)
Returns the underlying array of genes of this genetic representation.
-
#size
Returns the number of elements in this container.
-
#unsafe_fetch(index : Int)
Returns the element at the given index, without doing any bounds check.
Instance methods inherited from module Talgene::Fittable
<=>(other : Fittable)
<=>,
fitness : Float64
fitness
Constructor Detail
Creates a new Talgene::Genome
instance with supplied array of genes.
Instance Method Detail
Returns the number of elements in this container.
Returns the element at the given index, without doing any bounds check.
Indexable
makes sure to invoke this method with index in 0...size
,
so converting negative indices to positive ones is not needed here.
Clients never invoke this method directly. Instead, they access
elements with #[](index)
and #[]?(index)
.
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.