pub struct WhaleOptimization<B: Backend> { /* private fields */ }Expand description
Whale Optimization Algorithm strategy.
§Panics
Strategy::ask panics if called a second time without an intervening
Strategy::tell — specifically, if state.best_genome is None after
the first generation. In normal harness-driven usage this cannot happen:
ask on the first call returns the initial positions unevaluated;
tell then sets best_genome; and every subsequent ask finds it
populated. Bypassing the harness and calling ask twice in a row without
a tell in between will trigger the assert.
§Example
use burn::backend::Flex;
use rlevo_evolution::algorithms::metaheuristic::woa::{WhaleOptimization, WoaConfig};
let strategy = WhaleOptimization::<Flex>::new();
let params = WoaConfig::default_for(32, 10);
let _ = (strategy, params);Implementations§
Trait Implementations§
Source§impl<B: Clone + Backend> Clone for WhaleOptimization<B>
impl<B: Clone + Backend> Clone for WhaleOptimization<B>
Source§fn clone(&self) -> WhaleOptimization<B>
fn clone(&self) -> WhaleOptimization<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 WhaleOptimization<B>
Source§impl<B: Default + Backend> Default for WhaleOptimization<B>
impl<B: Default + Backend> Default for WhaleOptimization<B>
Source§fn default() -> WhaleOptimization<B>
fn default() -> WhaleOptimization<B>
Source§impl<B: Backend> Strategy<B> for WhaleOptimization<B>
impl<B: Backend> Strategy<B> for WhaleOptimization<B>
Source§fn init(
&self,
params: &WoaConfig,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> WoaState<B>
fn init( &self, params: &WoaConfig, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> WoaState<B>
Samples the initial whale positions uniformly within
WoaConfig::bounds using the host-RNG convention and sets the
generation counter to zero.
Source§fn ask(
&self,
params: &WoaConfig,
state: &WoaState<B>,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> (Tensor<B, 2>, WoaState<B>)
fn ask( &self, params: &WoaConfig, state: &WoaState<B>, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (Tensor<B, 2>, WoaState<B>)
Proposes the next whale positions.
On the first call returns the initial positions unchanged. On
subsequent calls, each whale independently selects one of three
moves based on host-sampled scalars p and |A|:
p < 0.5, |A| < 1— encircle the current best,p < 0.5, |A| ≥ 1— search toward a random other whale,p ≥ 0.5— spiral toward the current best.
The three candidate tensors are computed in parallel and composed
with boolean masks; no divergent kernel paths are used. Results are
clamped to WoaConfig::bounds.
Source§fn tell(
&self,
_params: &WoaConfig,
population: Tensor<B, 2>,
fitness: Tensor<B, 1>,
state: WoaState<B>,
_rng: &mut dyn Rng,
) -> (WoaState<B>, StrategyMetrics)
fn tell( &self, _params: &WoaConfig, population: Tensor<B, 2>, fitness: Tensor<B, 1>, state: WoaState<B>, _rng: &mut dyn Rng, ) -> (WoaState<B>, StrategyMetrics)
Records evaluated fitness, updates the best-so-far (food source), and increments the generation counter.
Returns the updated WoaState and a StrategyMetrics snapshot
for the completed generation.
Auto Trait Implementations§
impl<B> Freeze for WhaleOptimization<B>
impl<B> RefUnwindSafe for WhaleOptimization<B>
impl<B> Send for WhaleOptimization<B>
impl<B> Sync for WhaleOptimization<B>
impl<B> Unpin for WhaleOptimization<B>
impl<B> UnsafeUnpin for WhaleOptimization<B>
impl<B> UnwindSafe for WhaleOptimization<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