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

Source

pub fn try_generate<R: Rng>( rng: &mut R, bounds: &MultiBounds, ) -> Result<Self, GenomeError>

Fallibly generate a random variable-length vector from bounds.

bounds.dimension() is interpreted as the maximum length (minimum length 1) and the per-dimension [min, max] intervals bound the sampled gene values. Returns Err(GenomeError::InvalidStructure) for empty (0-dimension) bounds, which cannot yield a valid non-empty genome — this replaces the previous panic on the inverted range 1..=0.

Source

pub fn generate_with_len<R: Rng>( rng: &mut R, min_length: usize, max_length: usize, value_bounds: &MultiBounds, ) -> Result<Self, GenomeError>

Generate a random variable-length vector with explicit length bounds.

This is the honest constructor for random generation: the length is sampled uniformly from [min_length, max_length] and each gene is sampled from the corresponding entry of value_bounds (falling back to the first entry when the sampled length exceeds the number of provided bounds). Unlike EvolutionaryGenome::generate, it does not overload a MultiBounds’ dimension as a length.

Trait Implementations§

Source§

impl Clone for DynamicRealVector

Source§

fn clone(&self) -> DynamicRealVector

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self

Generate a random variable-length vector.

bounds.dimension() is interpreted as the maximum length (minimum length 1); the per-dimension [min, max] intervals bound the sampled gene values. For empty (0-dimension) bounds there is nothing to sample, so this degrades gracefully to an empty genome instead of panicking on an inverted gen_range(1..=0). Use try_generate if you want that degenerate case reported as an error, or generate_with_len for explicit length bounds.

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 distance(&self, other: &Self) -> f64

Distance metric between two genomes. Read more
Source§

fn try_distance(&self, other: &Self) -> Result<f64, GenomeError>

Fallible distance metric. Read more
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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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

Source§

impl TraceGenome for DynamicRealVector

Available on crate feature ppl only.
Source§

fn to_trace(&self) -> Trace

Convert DynamicRealVector to Fugue trace.

Stores genes at "<trace_prefix()>#i" and metadata at “meta#min_length”, “meta#max_length” and “meta#length”. The gene address prefix is taken from trace_prefix so that the prefix advertised by the trait and the prefix actually written can never diverge.

Source§

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

Reconstruct DynamicRealVector from Fugue trace.

Source§

fn trace_prefix() -> &'static str

Get the address prefix used for trace storage (default: "gene").

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

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

§

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