FloatCodec

Struct FloatCodec 

Source
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>

Source

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<Vec<f32>>>

Source

pub fn matrix(rows: usize, cols: usize, range: Range<f32>) -> Self

Create a new FloatCodec with the given number of chromosomes, genes, min, and max values. The f_32 values for each FloatGene will be randomly generated between the min and max values.

Source§

impl FloatCodec<Vec<f32>>

Source

pub fn vector(count: usize, range: Range<f32>) -> Self

Create a new FloatCodec with the given number of chromosomes, genes, min, and max values. The f_32 values for each FloatGene will be randomly generated between the min and max values.

Source§

impl FloatCodec<f32>

Source

pub fn scalar(range: Range<f32>) -> Self

Create a new FloatCodec with the given number of chromosomes, genes, min, and max values. The f_32 values for each FloatGene will be randomly generated between the min and max values.

Trait Implementations§

Source§

impl<T: Clone> Clone for FloatCodec<T>

Source§

fn clone(&self) -> FloatCodec<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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.

§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.

§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);

Auto Trait Implementations§

§

impl<T> Freeze for FloatCodec<T>

§

impl<T> RefUnwindSafe for FloatCodec<T>
where T: RefUnwindSafe,

§

impl<T> Send for FloatCodec<T>
where T: Send,

§

impl<T> Sync for FloatCodec<T>
where T: Sync,

§

impl<T> Unpin for FloatCodec<T>
where T: Unpin,

§

impl<T> UnwindSafe for FloatCodec<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V