pub struct FireflyAlgorithm<B: Backend> { /* private fields */ }Expand description
Firefly Algorithm strategy.
When the custom-kernels feature is off, FireflyConfig enforces a
pop_size <= FIREFLY_PURE_TENSOR_CAP (= 128) cap through
Validate::validate at the harness chokepoint, since the pure-tensor path
materializes an (N, N, D) pairwise tensor. With the feature on the same
cap is surfaced via a debug_assert! in Strategy::init, because the
fused kernel super::kernels::pairwise_attract_cube is still designed-only
and the strategy keeps using the pure-tensor path in the meantime.
§Example
use burn::backend::Flex;
use rlevo_evolution::algorithms::metaheuristic::firefly::{FireflyAlgorithm, FireflyConfig};
let strategy = FireflyAlgorithm::<Flex>::new();
let params = FireflyConfig::default_for(32, 10);
let _ = (strategy, params);Implementations§
Trait Implementations§
Source§impl<B: Clone + Backend> Clone for FireflyAlgorithm<B>
impl<B: Clone + Backend> Clone for FireflyAlgorithm<B>
Source§fn clone(&self) -> FireflyAlgorithm<B>
fn clone(&self) -> FireflyAlgorithm<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 FireflyAlgorithm<B>
Source§impl<B: Default + Backend> Default for FireflyAlgorithm<B>
impl<B: Default + Backend> Default for FireflyAlgorithm<B>
Source§fn default() -> FireflyAlgorithm<B>
fn default() -> FireflyAlgorithm<B>
Source§impl<B: Backend> Strategy<B> for FireflyAlgorithm<B>
impl<B: Backend> Strategy<B> for FireflyAlgorithm<B>
Source§fn init(
&self,
params: &FireflyConfig,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> FireflyState<B>
fn init( &self, params: &FireflyConfig, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> FireflyState<B>
Build the initial swarm by host-sampling pop_size positions
uniformly in [bounds.lo, bounds.hi].
Positions are drawn from a deterministic seed_stream so
initialisation is bit-stable regardless of core count or test
ordering; the process-wide Flex RNG is never touched.
The pop_size <= FIREFLY_PURE_TENSOR_CAP cap (without custom-kernels)
is enforced by FireflyConfig’s Validate impl at the harness
chokepoint.
Source§fn ask(
&self,
params: &FireflyConfig,
state: &FireflyState<B>,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> (Tensor<B, 2>, FireflyState<B>)
fn ask( &self, params: &FireflyConfig, state: &FireflyState<B>, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (Tensor<B, 2>, FireflyState<B>)
Propose the next swarm positions.
On the first call (state.fitness is empty) returns the initial
positions unchanged so the caller can evaluate generation zero.
On subsequent calls, computes the pairwise attractiveness update
via pure_tensor_attract and clips positions to
params.bounds. The noise seed is derived from the host RNG
through seed_stream, keeping draws reproducible.
Source§fn tell(
&self,
_params: &FireflyConfig,
population: Tensor<B, 2>,
fitness: Tensor<B, 1>,
state: FireflyState<B>,
_rng: &mut dyn Rng,
) -> (FireflyState<B>, StrategyMetrics)
fn tell( &self, _params: &FireflyConfig, population: Tensor<B, 2>, fitness: Tensor<B, 1>, state: FireflyState<B>, _rng: &mut dyn Rng, ) -> (FireflyState<B>, StrategyMetrics)
Ingest fitness values, update the swarm, and advance the generation counter.
Pulls fitness to host, updates state.positions and
state.fitness, then refreshes the best-so-far genome if the
current generation contains a new maximum. Returns the updated
state and a StrategyMetrics snapshot for the completed
generation.
Source§fn best(&self, state: &FireflyState<B>) -> Option<(Tensor<B, 2>, f32)>
fn best(&self, state: &FireflyState<B>) -> Option<(Tensor<B, 2>, f32)>
Returns the best-so-far (genome, fitness) pair, or None before
the first tell call.
Source§type Params = FireflyConfig
type Params = FireflyConfig
Source§type State = FireflyState<B>
type State = FireflyState<B>
Auto Trait Implementations§
impl<B> Freeze for FireflyAlgorithm<B>
impl<B> RefUnwindSafe for FireflyAlgorithm<B>
impl<B> Send for FireflyAlgorithm<B>
impl<B> Sync for FireflyAlgorithm<B>
impl<B> Unpin for FireflyAlgorithm<B>
impl<B> UnsafeUnpin for FireflyAlgorithm<B>
impl<B> UnwindSafe for FireflyAlgorithm<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