pub struct ArchNasStrategy<B: Backend> { /* private fields */ }Expand description
Custom NAS harness. Does not implement
Strategy — see the module docs.
The strategy is stateless; all evolving state lives in NasState. Drive
it with the same ask/tell loop as a Strategy:
let strat = ArchNasStrategy::<B>::new();
let mut state = strat.init(¶ms, &mut rng, &device);
for _ in 0..generations {
let (genome, next) = strat.ask(¶ms, &state, &mut rng, &device);
let fitness = fitness_fn.evaluate(&genome, &device);
state = strat.tell(¶ms, genome, fitness, next, &mut rng);
}
let (arch_id, weights, fitness) = strat.best(&state).unwrap();Implementations§
Source§impl<B: Backend> ArchNasStrategy<B>
impl<B: Backend> ArchNasStrategy<B>
Sourcepub fn init(
&self,
params: &NasParams,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> NasState<B>
pub fn init( &self, params: &NasParams, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> NasState<B>
Sourcepub fn ask(
&self,
params: &NasParams,
state: &NasState<B>,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> (NasGenome<B>, NasState<B>)
pub fn ask( &self, params: &NasParams, state: &NasState<B>, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (NasGenome<B>, NasState<B>)
Propose the next population.
Before the first tell (resident fitness still empty) the
unchanged resident population is returned for evaluation. Afterwards the
method produces offspring: elite_count best residents carried over
unmutated, then tournament selection, same-architecture blend crossover
(single-parent copy when parents’ architectures differ), and either a
per-child architecture mutation (re-initializing the child’s active
weights) at arch_mutation_rate or an isotropic Gaussian weight
perturbation. Five independent host substreams are derived from rng:
selection, crossover, mutation, architecture (re)assignment, and weight
re-initialization.
The returned NasGenome is freshly allocated (no struct-level clone).
§Panics
Panics if weight_init_std or weight_mutation_std is non-finite
(+∞ or NaN), or if the resident weight tensor cannot be read back to
the host as f32.
Sourcepub fn tell(
&self,
params: &NasParams,
population: NasGenome<B>,
fitness: Tensor<B, 1>,
state: NasState<B>,
_rng: &mut dyn Rng,
) -> NasState<B>
pub fn tell( &self, params: &NasParams, population: NasGenome<B>, fitness: Tensor<B, 1>, state: NasState<B>, _rng: &mut dyn Rng, ) -> NasState<B>
Consume a population’s fitness and produce the next state.
Records the told population as the new residents, updates the best-ever
(arch_id, weights, fitness) triple, and increments the generation.
fitness follows the canonical maximise convention (higher is better).
§Fitness hygiene
This is the ArchNasStrategy driver chokepoint (ADR 0034): the
strategy is its own driver and does not run through
EvolutionaryHarness, so there is
no harness above it. tell applies
sanitize_fitness to the host fitness
vector (NaN → −∞, +∞ → f32::MAX, −∞ and finite pass through)
before update_best and before it is stored as state.fitness, so
a non-finite fitness can never become an immortal champion nor win the
next ask’s elite carry or tournament.
§Panics
Panics if the fitness tensor cannot be read back to the host as f32.
Trait Implementations§
Source§impl<B: Clone + Backend> Clone for ArchNasStrategy<B>
impl<B: Clone + Backend> Clone for ArchNasStrategy<B>
Source§fn clone(&self) -> ArchNasStrategy<B>
fn clone(&self) -> ArchNasStrategy<B>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<B: Copy + Backend> Copy for ArchNasStrategy<B>
Auto Trait Implementations§
impl<B> Freeze for ArchNasStrategy<B>
impl<B> RefUnwindSafe for ArchNasStrategy<B>
impl<B> Send for ArchNasStrategy<B>
impl<B> Sync for ArchNasStrategy<B>
impl<B> Unpin for ArchNasStrategy<B>
impl<B> UnsafeUnpin for ArchNasStrategy<B>
impl<B> UnwindSafe for ArchNasStrategy<B>
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<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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