pub struct FloatCodec<T = f32> { /* private fields */ }
Expand description
A Codec for a Genotype of FloatGenes
. The encode
function creates a Genotype with num_chromosomes
chromosomes
and num_genes
genes per chromosome. The decode
function creates a Vec<Vec<f32>>
from the Genotype where the inner Vec
contains the alleles of the FloatGenes
in the chromosome - the f32
values.
The lower and upper bounds of the FloatGenes
can be set with the with_bounds
function.
The default bounds are equal to min
and max
values.
Implementations§
Source§impl<T> FloatCodec<T>
impl<T> FloatCodec<T>
Sourcepub fn with_bounds(self, range: Range<f32>) -> Self
pub fn with_bounds(self, range: Range<f32>) -> Self
Set the bounds of the FloatGenes
in the Genotype. The default bounds
are equal to the min and max values.
Source§impl FloatCodec<Vec<f32>>
impl FloatCodec<Vec<f32>>
Trait Implementations§
Source§impl<T: Clone> Clone for FloatCodec<T>
impl<T: Clone> Clone for FloatCodec<T>
Source§fn clone(&self) -> FloatCodec<T>
fn clone(&self) -> FloatCodec<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Codec<FloatChromosome, Vec<Vec<f32>>> for FloatCodec<Vec<Vec<f32>>>
Implement the Codec
trait for a FloatCodec
with a Vec<Vec<f32>>
type.
This will decode to a matrix of f32
values.
The encode
function creates a Genotype with num_chromosomes
chromosomes
and num_genes
genes per chromosome.
impl Codec<FloatChromosome, Vec<Vec<f32>>> for FloatCodec<Vec<Vec<f32>>>
Implement the Codec
trait for a FloatCodec
with a Vec<Vec<f32>>
type.
This will decode to a matrix of f32
values.
The encode
function creates a Genotype with num_chromosomes
chromosomes
and num_genes
genes per chromosome.
- Example:
use radiate_core::*;
// Create a new FloatCodec with 3 chromosomes and 4 genes
// per chromosome - a 3x4 matrix of f32 values.
let codec = FloatCodec::matrix(3, 4, 0.0..1.0);
let genotype: Genotype<FloatChromosome> = codec.encode();
let decoded: Vec<Vec<f32>> = codec.decode(&genotype);
assert_eq!(decoded.len(), 3);
assert_eq!(decoded[0].len(), 4);
Source§impl Codec<FloatChromosome, Vec<f32>> for FloatCodec<Vec<f32>>
Implement the Codec
trait for a FloatCodec
with a Vec<f32>
type.
This will decode to a vector of f32
values.
The encode
function creates a Genotype with a single chromosomes
and num_genes
genes per chromosome.
impl Codec<FloatChromosome, Vec<f32>> for FloatCodec<Vec<f32>>
Implement the Codec
trait for a FloatCodec
with a Vec<f32>
type.
This will decode to a vector of f32
values.
The encode
function creates a Genotype with a single chromosomes
and num_genes
genes per chromosome.
§Example
use radiate_core::*;
// Create a new FloatCodec with 3 genes
// per chromosome - a vector with 3 f32 values.
let codec = FloatCodec::vector(3, 0.0..1.0);
let genotype: Genotype<FloatChromosome> = codec.encode();
let decoded: Vec<f32> = codec.decode(&genotype);
assert_eq!(decoded.len(), 3);
Source§impl Codec<FloatChromosome, f32> for FloatCodec<f32>
Implement the Codec
trait for a FloatCodec
with a f32
type.
This will decode to a single f32
value.
The encode
function creates a Genotype with a single chromosomes
and a single gene per chromosome.
impl Codec<FloatChromosome, f32> for FloatCodec<f32>
Implement the Codec
trait for a FloatCodec
with a f32
type.
This will decode to a single f32
value.
The encode
function creates a Genotype with a single chromosomes
and a single gene per chromosome.
§Example
use radiate_core::*;
// Create a new FloatCodec with a single gene
// per chromosome - a single f32 value.
let codec = FloatCodec::scalar(0.0..1.0);
let genotype: Genotype<FloatChromosome> = codec.encode();
let decoded: f32 = codec.decode(&genotype);