Skip to main content

RealVector

Struct RealVector 

Source
pub struct RealVector { /* private fields */ }
Expand description

Fixed-length real-valued vector genome

This genome type represents continuous optimization problems where solutions are vectors of real numbers.

Implementations§

Source§

impl RealVector

Source

pub fn new(genes: Vec<f64>) -> Self

Create a new real vector with the given genes

Source

pub fn zeros(dimension: usize) -> Self

Create a zero-filled vector of the given dimension

Source

pub fn filled(dimension: usize, value: f64) -> Self

Create a vector filled with a constant value

Source

pub fn collect_from<I: IntoIterator<Item = f64>>(iter: I) -> Self

Create from an iterator

Source

pub fn into_inner(self) -> Vec<f64>

Get the underlying vector

Source

pub fn as_vec(&self) -> &Vec<f64>

Get a reference to the genes

Source

pub fn norm(&self) -> f64

Calculate Euclidean norm

Source

pub fn norm_squared(&self) -> f64

Calculate squared Euclidean norm

Source

pub fn add(&self, other: &Self) -> Result<Self, GenomeError>

Element-wise addition

Source

pub fn sub(&self, other: &Self) -> Result<Self, GenomeError>

Element-wise subtraction

Source

pub fn scale(&self, scalar: f64) -> Self

Scalar multiplication

Trait Implementations§

Source§

impl BoundedCrossoverOperator<RealVector> for SbxCrossover

Source§

fn crossover_bounded<R: Rng>( &self, parent1: &RealVector, parent2: &RealVector, bounds: &MultiBounds, rng: &mut R, ) -> OperatorResult<(RealVector, RealVector)>

Apply bounded crossover to two parents
Source§

impl BoundedMutationOperator<RealVector> for GaussianMutation

Source§

fn mutate_bounded<R: Rng>( &self, genome: &mut RealVector, bounds: &MultiBounds, rng: &mut R, )

Apply bounded mutation to a genome
Source§

impl BoundedMutationOperator<RealVector> for PolynomialMutation

Source§

fn mutate_bounded<R: Rng>( &self, genome: &mut RealVector, bounds: &MultiBounds, rng: &mut R, )

Apply bounded mutation to a genome
Source§

impl BoundedMutationOperator<RealVector> for UniformMutation

Source§

fn mutate_bounded<R: Rng>( &self, genome: &mut RealVector, bounds: &MultiBounds, rng: &mut R, )

Apply bounded mutation to a genome
Source§

impl Clone for RealVector

Source§

fn clone(&self) -> RealVector

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 CrossoverOperator<RealVector> for ArithmeticCrossover

Source§

fn crossover<R: Rng>( &self, parent1: &RealVector, parent2: &RealVector, _rng: &mut R, ) -> OperatorResult<(RealVector, RealVector)>

Apply crossover to two parents and produce two offspring
Source§

fn crossover_probability(&self) -> f64

Get the probability of crossover being applied
Source§

impl CrossoverOperator<RealVector> for BlxAlphaCrossover

Source§

fn crossover<R: Rng>( &self, parent1: &RealVector, parent2: &RealVector, rng: &mut R, ) -> OperatorResult<(RealVector, RealVector)>

Apply crossover to two parents and produce two offspring
Source§

fn crossover_probability(&self) -> f64

Get the probability of crossover being applied
Source§

impl CrossoverOperator<RealVector> for SbxCrossover

Source§

fn crossover<R: Rng>( &self, parent1: &RealVector, parent2: &RealVector, rng: &mut R, ) -> OperatorResult<(RealVector, RealVector)>

Apply crossover to two parents and produce two offspring
Source§

fn crossover_probability(&self) -> f64

Get the probability of crossover being applied
Source§

impl Debug for RealVector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RealVector

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl EvolutionaryGenome for RealVector

Source§

fn to_trace(&self) -> Trace

Convert RealVector to Fugue trace.

Each gene is stored at address “gene#i” where i is the index.

Source§

fn from_trace(trace: &Trace) -> Result<Self, GenomeError>

Reconstruct RealVector from Fugue trace.

Reads genes from addresses “gene#0”, “gene#1”, … until no more are found.

Source§

type Allele = f64

The allele type for individual genes
Source§

type Phenotype = Vec<f64>

The phenotype or decoded solution type
Source§

fn decode(&self) -> Self::Phenotype

Decode genome into phenotype for fitness evaluation
Source§

fn dimension(&self) -> usize

Compute dimensionality for adaptive operators
Source§

fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self

Generate a random genome within the given bounds
Source§

fn as_slice(&self) -> Option<&[f64]>

Get the genome’s genes as a slice (for numeric genomes)
Source§

fn as_mut_slice(&mut self) -> Option<&mut [f64]>

Get the genome’s genes as a mutable slice (for numeric genomes)
Source§

fn distance(&self, other: &Self) -> f64

Distance metric between two genomes (default: 0.0)
Source§

fn trace_prefix() -> &'static str

Get the address prefix used for trace storage (default: “gene”)
Source§

impl<const N: usize> From<[f64; N]> for RealVector

Source§

fn from(arr: [f64; N]) -> Self

Converts to this type from the input type.
Source§

impl From<RealVector> for Vec<f64>

Source§

fn from(genome: RealVector) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for RealVector

Source§

fn from(genes: Vec<f64>) -> Self

Converts to this type from the input type.
Source§

impl Index<usize> for RealVector

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for RealVector

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a RealVector

Source§

type Item = &'a f64

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, f64>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for RealVector

Source§

type Item = f64

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<f64>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl MutationOperator<RealVector> for GaussianMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut RealVector, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl MutationOperator<RealVector> for PolynomialMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut RealVector, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl MutationOperator<RealVector> for ScrambleMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut RealVector, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl MutationOperator<RealVector> for SwapMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut RealVector, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl MutationOperator<RealVector> for UniformMutation

Source§

fn mutate<R: Rng>(&self, genome: &mut RealVector, rng: &mut R)

Apply mutation to a genome in place
Source§

fn mutation_probability(&self) -> f64

Get the mutation probability per gene
Source§

impl PartialEq for RealVector

Source§

fn eq(&self, other: &RealVector) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RealValuedGenome for RealVector

Source§

fn genes(&self) -> &[f64]

Get the genes as a slice of f64 values
Source§

fn genes_mut(&mut self) -> &mut [f64]

Get the genes as a mutable slice of f64 values
Source§

fn from_genes(genes: Vec<f64>) -> Result<Self, GenomeError>

Create from a vector of genes
Source§

fn apply_bounds(&mut self, bounds: &MultiBounds)

Apply bounds to all genes
Source§

impl Serialize for RealVector

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RealVector

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

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

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,