pub struct AntColonyReal<B: Backend> { /* private fields */ }Expand description
Ant Colony Optimization (continuous domains).
The archive_size >= 2 (the σ computation needs at least two archive
solutions to take a pairwise distance) and m >= 1 invariants are enforced
by Validate::validate at the harness chokepoint.
§Example
use burn::backend::Flex;
use rlevo_evolution::algorithms::metaheuristic::aco_r::{AcoRConfig, AntColonyReal};
let strategy = AntColonyReal::<Flex>::new();
let params = AcoRConfig::default_for(50, 10, 10);
let _ = (strategy, params);Implementations§
Trait Implementations§
Source§impl<B: Clone + Backend> Clone for AntColonyReal<B>
impl<B: Clone + Backend> Clone for AntColonyReal<B>
Source§fn clone(&self) -> AntColonyReal<B>
fn clone(&self) -> AntColonyReal<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 AntColonyReal<B>
Source§impl<B: Default + Backend> Default for AntColonyReal<B>
impl<B: Default + Backend> Default for AntColonyReal<B>
Source§fn default() -> AntColonyReal<B>
fn default() -> AntColonyReal<B>
Source§impl<B: Backend> Strategy<B> for AntColonyReal<B>
impl<B: Backend> Strategy<B> for AntColonyReal<B>
Source§fn init(
&self,
params: &AcoRConfig,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> AcoRState<B>
fn init( &self, params: &AcoRConfig, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> AcoRState<B>
Initialises the archive by host-sampling archive_size × genome_dim
values uniformly from params.bounds.
All random draws go through seed_stream derived from rng rather
than B::seed + Tensor::random; this keeps draws reproducible across
thread schedules when multiple tests or harnesses share the same
process-wide Burn RNG state.
Source§fn ask(
&self,
params: &AcoRConfig,
state: &AcoRState<B>,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> (Tensor<B, 2>, AcoRState<B>)
fn ask( &self, params: &AcoRConfig, state: &AcoRState<B>, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (Tensor<B, 2>, AcoRState<B>)
Proposes the next population.
First call (state.archive_fitness.is_empty()): returns the
initial archive as-is so the harness scores it before any generation
update occurs.
Subsequent calls: draws m offspring by, for each dimension d
of each offspring i:
- Selecting an archive index
lby CDF-weighted roulette fromstate.weights(host-side, viaseed_stream). - Computing
σ_{l,d} = ξ · mean_e |archive_{e,d} − archive_{l,d}|on-device. - Sampling
x_{i,d} ~ N(archive_{l,d}, σ_{l,d})host-side viarand_distr::Normaland a secondseed_stream.
Offspring are clamped to params.bounds before upload to the device.
The returned state is the same object passed in (no mutation occurs in
ask; all state changes are deferred to tell).
Source§fn tell(
&self,
params: &AcoRConfig,
population: Tensor<B, 2>,
fitness: Tensor<B, 1>,
state: AcoRState<B>,
_rng: &mut dyn Rng,
) -> (AcoRState<B>, StrategyMetrics)
fn tell( &self, params: &AcoRConfig, population: Tensor<B, 2>, fitness: Tensor<B, 1>, state: AcoRState<B>, _rng: &mut dyn Rng, ) -> (AcoRState<B>, StrategyMetrics)
Merges population with the current archive and updates state.
First tell (state.archive_fitness.is_empty()): population is
the initial archive returned verbatim by the first ask; this call
sorts it by fitness and records best_genome and best_fitness.
Steady-state tell: concatenates state.archive (shape (k, D))
with population (shape (m, D)), sorts the combined k + m rows by
fitness, and retains only the top k. Updates best_genome if the new
archive leader improves on state.best_fitness.
Returns the updated state and a StrategyMetrics snapshot built from
fitness (the offspring scores, not the full archive).
Source§fn best(&self, state: &AcoRState<B>) -> Option<(Tensor<B, 2>, f32)>
fn best(&self, state: &AcoRState<B>) -> Option<(Tensor<B, 2>, f32)>
Returns the best genome seen across all generations, or None before
the first tell call.
The returned tensor has shape (1, genome_dim).
Source§type Params = AcoRConfig
type Params = AcoRConfig
Auto Trait Implementations§
impl<B> Freeze for AntColonyReal<B>
impl<B> RefUnwindSafe for AntColonyReal<B>
impl<B> Send for AntColonyReal<B>
impl<B> Sync for AntColonyReal<B>
impl<B> Unpin for AntColonyReal<B>
impl<B> UnsafeUnpin for AntColonyReal<B>
impl<B> UnwindSafe for AntColonyReal<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