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.
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.
pub fn dim(&self) -> usize
pub fn qd_dim(&self) -> usize
pub fn capacity(&self) -> usize
pub fn occupied(&self) -> usize
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).
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.
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.
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).
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.
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.
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).
pub fn best_y(&self) -> f64
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.
pub fn ys(&self) -> &[f64]
pub fn xs(&self) -> &[Vec<f64>]
pub fn descriptors(&self) -> &[Vec<f64>]
pub fn counts(&self) -> &[u64]
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.