pub struct FloatCodec<F: Float, T = F> { /* 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<F: Float, T> FloatCodec<F, T>
impl<F: Float, T> FloatCodec<F, T>
Sourcepub fn with_bounds(self, range: Range<F>) -> Self
pub fn with_bounds(self, range: Range<F>) -> Self
Set the bounds of the FloatGenes in the Genotype. The default bounds
are equal to the min and max values.
Source§impl<F: Float> FloatCodec<F, Vec<F>>
impl<F: Float> FloatCodec<F, Vec<F>>
Trait Implementations§
Source§impl<F: Clone + Float, T: Clone> Clone for FloatCodec<F, T>
impl<F: Clone + Float, T: Clone> Clone for FloatCodec<F, T>
Source§fn clone(&self) -> FloatCodec<F, T>
fn clone(&self) -> FloatCodec<F, T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Float> Codec<FloatChromosome<F>, F> for FloatCodec<F, F>
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<F: Float> Codec<FloatChromosome<F>, F> for FloatCodec<F, F>
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_f32..1.0_f32);
let genotype: Genotype<FloatChromosome<f32>> = codec.encode();
let decoded: f32 = codec.decode(&genotype);fn encode(&self) -> Genotype<FloatChromosome<F>>
fn decode(&self, genotype: &Genotype<FloatChromosome<F>>) -> F
Source§impl<F: Float> Codec<FloatChromosome<F>, Vec<F>> for FloatCodec<F, Vec<F>>
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<F: Float> Codec<FloatChromosome<F>, Vec<F>> for FloatCodec<F, Vec<F>>
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_f32..1.0_f32);
let genotype: Genotype<FloatChromosome<f32>> = codec.encode();
let decoded: Vec<f32> = codec.decode(&genotype);
assert_eq!(decoded.len(), 3);Source§impl<F: Float> Codec<FloatChromosome<F>, Vec<Vec<F>>> for FloatCodec<F, Vec<Vec<F>>>
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<F: Float> Codec<FloatChromosome<F>, Vec<Vec<F>>> for FloatCodec<F, Vec<Vec<F>>>
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_f32..1.0_f32);
let genotype: Genotype<FloatChromosome<f32>> = codec.encode();
let decoded: Vec<Vec<f32>> = codec.decode(&genotype);
assert_eq!(decoded.len(), 3);
assert_eq!(decoded[0].len(), 4);Source§impl<F: Float> Codec<FloatChromosome<F>, Vec<Vec<Vec<F>>>> for FloatCodec<F, Vec<Vec<Vec<F>>>>
Implement the Codec for a FloatCodec with a Vec<Vec<Vec<f32>>> type.
Unlike the other impls, this will decode to a 3D tensor of f32 values.
impl<F: Float> Codec<FloatChromosome<F>, Vec<Vec<Vec<F>>>> for FloatCodec<F, Vec<Vec<Vec<F>>>>
Implement the Codec for a FloatCodec with a Vec<Vec<Vec<f32>>> type.
Unlike the other impls, this will decode to a 3D tensor of f32 values.
§Example
use radiate_core::*;
// Create a new FloatCodec with 2 layers:
// - First layer: 2 rows and 3 columns
// - Second layer: 3 rows and 4 columns
let codec = FloatCodec::tensor(vec![(2, 3), (3, 4)], 0.0_f32..1.0_f32);
let genotype: Genotype<FloatChromosome<f32>> = codec.encode();
let decoded: Vec<Vec<Vec<f32>>> = codec.decode(&genotype);
assert_eq!(decoded.len(), 2);
assert_eq!(decoded[0].len(), 2);
assert_eq!(decoded[0][0].len(), 3);
assert_eq!(decoded[1].len(), 3);
assert_eq!(decoded[1][0].len(), 4);