Skip to main content

DynamicRealVector

Struct DynamicRealVector 

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

Variable-length real-valued vector genome

This genome type represents optimization problems where the solution dimension can vary. Useful for problems like:

  • Neural network architecture search (variable hidden layer sizes)
  • Variable-length feature selection
  • Adaptive-dimensional optimization

Implementations§

Source§

impl DynamicRealVector

Source

pub fn new( genes: Vec<f64>, min_length: usize, max_length: usize, ) -> Result<Self, GenomeError>

Create a new dynamic real vector with the given genes and length constraints

Source

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

Create with default length constraints (1 to usize::MAX)

Source

pub fn zeros( dimension: usize, min_length: usize, max_length: usize, ) -> Result<Self, GenomeError>

Create a zero-filled vector of the given dimension

Source

pub fn min_length(&self) -> usize

Get the minimum allowed length

Source

pub fn max_length(&self) -> usize

Get the maximum allowed length

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 push(&mut self, gene: f64) -> Result<(), GenomeError>

Add a gene to the end (if within bounds)

Source

pub fn pop(&mut self) -> Result<f64, GenomeError>

Remove the last gene (if within bounds)

Source

pub fn insert(&mut self, index: usize, gene: f64) -> Result<(), GenomeError>

Insert a gene at a specific position

Source

pub fn remove(&mut self, index: usize) -> Result<f64, GenomeError>

Remove a gene at a specific position

Source

pub fn can_grow(&self) -> bool

Check if a gene can be added

Source

pub fn can_shrink(&self) -> bool

Check if a gene can be removed

Source

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

Element-wise addition (requires same length)

Source

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

Element-wise subtraction (requires same length)

Source

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

Scalar multiplication

Trait Implementations§

Source§

impl Clone for DynamicRealVector

Source§

fn clone(&self) -> DynamicRealVector

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 Debug for DynamicRealVector

Source§

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

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

impl<'de> Deserialize<'de> for DynamicRealVector

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 DynamicRealVector

Source§

fn to_trace(&self) -> Trace

Convert DynamicRealVector to Fugue trace.

Stores genes at “gene#i” and metadata at “meta#min_length” and “meta#max_length”.

Source§

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

Reconstruct DynamicRealVector from Fugue trace.

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

fn as_slice(&self) -> Option<&[Self::Allele]>

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

fn as_mut_slice(&mut self) -> Option<&mut [Self::Allele]>

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

impl PartialEq for DynamicRealVector

Source§

fn eq(&self, other: &DynamicRealVector) -> 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 DynamicRealVector

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 DynamicRealVector

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 DynamicRealVector

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,