pub struct BatAlgorithm<B: Backend> { /* private fields */ }Expand description
Bat Algorithm strategy.
§Example
use burn::backend::Flex;
use rlevo_evolution::algorithms::metaheuristic::bat::{BatAlgorithm, BatConfig};
let strategy = BatAlgorithm::<Flex>::new();
let params = BatConfig::default_for(32, 10);
let _ = (strategy, params);Implementations§
Trait Implementations§
Source§impl<B: Clone + Backend> Clone for BatAlgorithm<B>
impl<B: Clone + Backend> Clone for BatAlgorithm<B>
Source§fn clone(&self) -> BatAlgorithm<B>
fn clone(&self) -> BatAlgorithm<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 BatAlgorithm<B>
Source§impl<B: Default + Backend> Default for BatAlgorithm<B>
impl<B: Default + Backend> Default for BatAlgorithm<B>
Source§fn default() -> BatAlgorithm<B>
fn default() -> BatAlgorithm<B>
Source§impl<B: Backend> Strategy<B> for BatAlgorithm<B>
impl<B: Backend> Strategy<B> for BatAlgorithm<B>
Source§fn init(
&self,
params: &BatConfig,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> BatState<B>
fn init( &self, params: &BatConfig, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> BatState<B>
Build the initial colony by host-sampling pop_size positions
uniformly in [bounds.lo, bounds.hi].
Velocities are zeroed, loudness is set to params.a0, pulse rate
to params.r0, and fitness left empty so that the first
ask → tell pair initialises
those fields before any acceptance logic runs. Positions are drawn
from a deterministic seed_stream; the process-wide Flex RNG is
never touched.
Source§fn ask(
&self,
params: &BatConfig,
state: &BatState<B>,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> (Tensor<B, 2>, BatState<B>)
fn ask( &self, params: &BatConfig, state: &BatState<B>, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (Tensor<B, 2>, BatState<B>)
Propose candidate positions for the current generation.
On the first call (state.fitness is empty) returns the initial
positions unchanged so the caller can evaluate generation zero.
On subsequent calls the update proceeds in three host/device steps:
- Frequency — sample
f_i = f_min + (f_max − f_min)·β_i,β_i ∈ U[0,1]. - Global move —
v_i ← v_i + (x_i − x_best)·f_i,x'_i = x_i + v_i. - Local walk (when
rand > r_i) — override withx'_i = x_best + ε·mean(A),ε ∈ U[−1,1].
All random draws are host-sampled through seed_stream for
bit-stable reproduction across thread schedules. The
per-bat acceptance decisions (pending_accept) are recorded in the
returned state and consumed by tell.
§Panics
Panics if called when state.best_genome is None after the first
generation has been evaluated (i.e. if state.fitness is non-empty
but state.best_genome was not set by a preceding tell call).
Source§fn tell(
&self,
params: &BatConfig,
candidates: Tensor<B, 2>,
fitness: Tensor<B, 1>,
state: BatState<B>,
_rng: &mut dyn Rng,
) -> (BatState<B>, StrategyMetrics)
fn tell( &self, params: &BatConfig, candidates: Tensor<B, 2>, fitness: Tensor<B, 1>, state: BatState<B>, _rng: &mut dyn Rng, ) -> (BatState<B>, StrategyMetrics)
Ingest candidate fitness values, apply the acceptance gate, and advance the generation counter.
On the first call (generation zero bootstrap) all candidates are unconditionally accepted and loudness/pulse-rate updates are skipped.
On subsequent calls candidate i replaces position i iff
pending_accept[i] (drawn in ask) and
fitness[i] ≥ state.fitness[i]. On acceptance, loudness decays
(A_i *= α) and pulse rate grows
(r_i = r₀·(1 − exp(−γ·t))).
Auto Trait Implementations§
impl<B> Freeze for BatAlgorithm<B>
impl<B> RefUnwindSafe for BatAlgorithm<B>
impl<B> Send for BatAlgorithm<B>
impl<B> Sync for BatAlgorithm<B>
impl<B> Unpin for BatAlgorithm<B>
impl<B> UnsafeUnpin for BatAlgorithm<B>
impl<B> UnwindSafe for BatAlgorithm<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