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
impl DynamicRealVector
Sourcepub fn new(
genes: Vec<f64>,
min_length: usize,
max_length: usize,
) -> Result<Self, GenomeError>
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
Sourcepub fn with_defaults(genes: Vec<f64>) -> Self
pub fn with_defaults(genes: Vec<f64>) -> Self
Create with default length constraints (1 to usize::MAX)
Sourcepub fn zeros(
dimension: usize,
min_length: usize,
max_length: usize,
) -> Result<Self, GenomeError>
pub fn zeros( dimension: usize, min_length: usize, max_length: usize, ) -> Result<Self, GenomeError>
Create a zero-filled vector of the given dimension
Sourcepub fn min_length(&self) -> usize
pub fn min_length(&self) -> usize
Get the minimum allowed length
Sourcepub fn max_length(&self) -> usize
pub fn max_length(&self) -> usize
Get the maximum allowed length
Sourcepub fn into_inner(self) -> Vec<f64>
pub fn into_inner(self) -> Vec<f64>
Get the underlying vector
Sourcepub fn norm_squared(&self) -> f64
pub fn norm_squared(&self) -> f64
Calculate squared Euclidean norm
Sourcepub fn push(&mut self, gene: f64) -> Result<(), GenomeError>
pub fn push(&mut self, gene: f64) -> Result<(), GenomeError>
Add a gene to the end (if within bounds)
Sourcepub fn pop(&mut self) -> Result<f64, GenomeError>
pub fn pop(&mut self) -> Result<f64, GenomeError>
Remove the last gene (if within bounds)
Sourcepub fn insert(&mut self, index: usize, gene: f64) -> Result<(), GenomeError>
pub fn insert(&mut self, index: usize, gene: f64) -> Result<(), GenomeError>
Insert a gene at a specific position
Sourcepub fn remove(&mut self, index: usize) -> Result<f64, GenomeError>
pub fn remove(&mut self, index: usize) -> Result<f64, GenomeError>
Remove a gene at a specific position
Sourcepub fn can_shrink(&self) -> bool
pub fn can_shrink(&self) -> bool
Check if a gene can be removed
Sourcepub fn add(&self, other: &Self) -> Result<Self, GenomeError>
pub fn add(&self, other: &Self) -> Result<Self, GenomeError>
Element-wise addition (requires same length)
Sourcepub fn sub(&self, other: &Self) -> Result<Self, GenomeError>
pub fn sub(&self, other: &Self) -> Result<Self, GenomeError>
Element-wise subtraction (requires same length)
Trait Implementations§
Source§impl Clone for DynamicRealVector
impl Clone for DynamicRealVector
Source§fn clone(&self) -> DynamicRealVector
fn clone(&self) -> DynamicRealVector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DynamicRealVector
impl Debug for DynamicRealVector
Source§impl<'de> Deserialize<'de> for DynamicRealVector
impl<'de> Deserialize<'de> for DynamicRealVector
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl EvolutionaryGenome for DynamicRealVector
impl EvolutionaryGenome for DynamicRealVector
Source§fn to_trace(&self) -> Trace
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>
fn from_trace(trace: &Trace) -> Result<Self, GenomeError>
Reconstruct DynamicRealVector from Fugue trace.
Source§fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
fn generate<R: Rng>(rng: &mut R, bounds: &MultiBounds) -> Self
Source§fn trace_prefix() -> &'static str
fn trace_prefix() -> &'static str
Source§fn as_slice(&self) -> Option<&[Self::Allele]>
fn as_slice(&self) -> Option<&[Self::Allele]>
Source§fn as_mut_slice(&mut self) -> Option<&mut [Self::Allele]>
fn as_mut_slice(&mut self) -> Option<&mut [Self::Allele]>
Source§impl PartialEq for DynamicRealVector
impl PartialEq for DynamicRealVector
Source§impl RealValuedGenome for DynamicRealVector
impl RealValuedGenome for DynamicRealVector
Source§fn from_genes(genes: Vec<f64>) -> Result<Self, GenomeError>
fn from_genes(genes: Vec<f64>) -> Result<Self, GenomeError>
Source§fn apply_bounds(&mut self, bounds: &MultiBounds)
fn apply_bounds(&mut self, bounds: &MultiBounds)
Source§impl Serialize for DynamicRealVector
impl Serialize for DynamicRealVector
impl StructuralPartialEq for DynamicRealVector
Auto Trait Implementations§
impl Freeze for DynamicRealVector
impl RefUnwindSafe for DynamicRealVector
impl Send for DynamicRealVector
impl Sync for DynamicRealVector
impl Unpin for DynamicRealVector
impl UnsafeUnpin for DynamicRealVector
impl UnwindSafe for DynamicRealVector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.