pub struct Archive { /* private fields */ }Expand description
CVT quality-diversity archive: capacity niches, each holding the best
solution found for it.
Implementations§
Source§impl Archive
impl Archive
Sourcepub fn try_new(
dim: usize,
qd_lb: &[f64],
qd_ub: &[f64],
capacity: usize,
samples_per_niche: usize,
rng: &mut Rng,
) -> Result<Self, &'static str>
pub fn try_new( dim: usize, qd_lb: &[f64], qd_ub: &[f64], capacity: usize, samples_per_niche: usize, rng: &mut Rng, ) -> Result<Self, &'static str>
Construct a validated CVT archive.
§Errors
Returns an error if dim or capacity is zero, if the descriptor
bound slices are empty or of unequal length, or if any bound pair is
non-finite or does not satisfy lower < upper.
Sourcepub fn new(
dim: usize,
qd_lb: &[f64],
qd_ub: &[f64],
capacity: usize,
samples_per_niche: usize,
rng: &mut Rng,
) -> Self
pub fn new( dim: usize, qd_lb: &[f64], qd_ub: &[f64], capacity: usize, samples_per_niche: usize, rng: &mut Rng, ) -> Self
Construct a CVT archive, panicking on invalid configuration. Prefer
Archive::try_new for user-supplied inputs.
§Panics
Panics on any configuration Archive::try_new rejects.
Sourcepub fn seed_uniform(&mut self, lower: &[f64], upper: &[f64], rng: &mut Rng)
pub fn seed_uniform(&mut self, lower: &[f64], upper: &[f64], rng: &mut Rng)
Seed all niche solutions with uniform random samples in [lower, upper]
(never evaluated — they serve as the initial SBX/Iso parent pool, as the
Python original documents).
§Panics
Panics if lower.len() or upper.len() differs from the archive’s
decision dimension.
Sourcepub fn index_of_niche(&self, d: &[f64]) -> usize
pub fn index_of_niche(&self, d: &[f64]) -> usize
Index of the niche whose center is nearest the (encoded) descriptor.
§Panics
Panics if d.len() differs from the archive’s descriptor dimension.
Sourcepub fn set(&mut self, i: usize, y: f64, d: &[f64], x: &[f64])
pub fn set(&mut self, i: usize, y: f64, d: &[f64], x: &[f64])
Add a solution to niche i if it improves it.
§Panics
Panics if i is not below the archive capacity, or if d or x do
not match the descriptor and decision dimensions.
Sourcepub fn update(
&mut self,
xs: &[Vec<f64>],
fitness: &mut dyn QdFitness,
) -> (Vec<f64>, Vec<f64>)
pub fn update( &mut self, xs: &[Vec<f64>], fitness: &mut dyn QdFitness, ) -> (Vec<f64>, Vec<f64>)
Evaluate xs, add to the archive, and return (improvements, real_ys)
where improvement = fitness - niche's previous fitness (negative is an
improvement — the objective the Diversifier’s optimizer minimizes).
§Panics
Panics if fitness returns a descriptor whose length differs from the
archive’s descriptor dimension.
Sourcepub fn update_evaluated(
&mut self,
xs: &[Vec<f64>],
evaluations: &[(f64, Vec<f64>)],
) -> Result<(Vec<f64>, Vec<f64>), &'static str>
pub fn update_evaluated( &mut self, xs: &[Vec<f64>], evaluations: &[(f64, Vec<f64>)], ) -> Result<(Vec<f64>, Vec<f64>), &'static str>
Apply already evaluated (fitness, descriptor) values in input order.
Keeping this step separate lets callers parallelize expensive objective
functions without concurrently mutating the archive.
§Errors
Returns an error if evaluated does not have the same length as xs.
Sourcepub fn update_batch(
&mut self,
xs: &[Vec<f64>],
fitness: &mut dyn QdBatchFitness,
) -> Result<(Vec<f64>, Vec<f64>), &'static str>
pub fn update_batch( &mut self, xs: &[Vec<f64>], fitness: &mut dyn QdBatchFitness, ) -> Result<(Vec<f64>, Vec<f64>), &'static str>
Evaluate and apply a complete batch. Evaluation may be parallel inside
fitness; archive updates are deterministic and retain input order.
§Errors
Returns an error if fitness does not return exactly one
(fitness, descriptor) pair per candidate.
Sourcepub fn random_xs(
&self,
best_n: usize,
chunk: usize,
rng: &mut Rng,
) -> Vec<Vec<f64>>
pub fn random_xs( &self, best_n: usize, chunk: usize, rng: &mut Rng, ) -> Vec<Vec<f64>>
Sample chunk solutions from the best best_n niches (by fitness).
Sourcepub fn random_x_one(&self, best_n: usize, rng: &mut Rng) -> (Vec<f64>, f64)
pub fn random_x_one(&self, best_n: usize, rng: &mut Rng) -> (Vec<f64>, f64)
A random solution from the best best_n niches (with fitness).
Sourcepub fn best_y(&self) -> f64
pub fn best_y(&self) -> f64
Lowest finite quality currently stored, or infinity for an empty archive.
Sourcepub fn qd_score(&self) -> f64
pub fn qd_score(&self) -> f64
QD-score matching Python Archive.get_qd_score: for an all-positive
archive, sum reciprocal fitness; otherwise sum the negated negative
fitness values. Higher is better in both cases.
Sourcepub fn descriptors(&self) -> &[Vec<f64>]
pub fn descriptors(&self) -> &[Vec<f64>]
Per-niche behavior descriptors.
Auto Trait Implementations§
impl Freeze for Archive
impl RefUnwindSafe for Archive
impl Send for Archive
impl Sync for Archive
impl Unpin for Archive
impl UnsafeUnpin for Archive
impl UnwindSafe for Archive
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.