pub struct DifferentialEvolution<B: Backend> { /* private fields */ }Expand description
Classical DE/rand/1/bin (and friends).
§Example
use burn::backend::Flex;
use rlevo_evolution::algorithms::de::{DeConfig, DeVariant, DifferentialEvolution};
let strategy = DifferentialEvolution::<Flex>::new();
let mut params = DeConfig::default_for(30, 10);
params.variant = DeVariant::Rand1Bin;
let _ = (strategy, params);Implementations§
Trait Implementations§
Source§impl<B: Clone + Backend> Clone for DifferentialEvolution<B>
impl<B: Clone + Backend> Clone for DifferentialEvolution<B>
Source§fn clone(&self) -> DifferentialEvolution<B>
fn clone(&self) -> DifferentialEvolution<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 DifferentialEvolution<B>
Source§impl<B: Default + Backend> Default for DifferentialEvolution<B>
impl<B: Default + Backend> Default for DifferentialEvolution<B>
Source§fn default() -> DifferentialEvolution<B>
fn default() -> DifferentialEvolution<B>
Source§impl<B: Backend> Strategy<B> for DifferentialEvolution<B>
impl<B: Backend> Strategy<B> for DifferentialEvolution<B>
Source§fn init(
&self,
params: &DeConfig,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> DeState<B>
fn init( &self, params: &DeConfig, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> DeState<B>
Samples the initial population uniformly within params.bounds
and returns a DeState with an empty fitness cache, signalling
that the first ask/tell cycle should evaluate the initial
population rather than generate trial vectors.
Initial sampling goes through seed_stream rather than
B::seed + Tensor::random to keep results reproducible across
parallel test threads.
Source§fn ask(
&self,
params: &DeConfig,
state: &DeState<B>,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> (Tensor<B, 2>, DeState<B>)
fn ask( &self, params: &DeConfig, state: &DeState<B>, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (Tensor<B, 2>, DeState<B>)
Proposes the next population of candidate solutions.
First call (fitness cache empty): returns the initial
population from DeState::population unchanged so the caller
can evaluate it before any mutation/crossover step.
Subsequent calls: for each individual i in 0..pop_size:
- Sample the required number of distinct random indices
(excluding
i) viaseed_streamwithSeedPurpose::Trial. - Compute the mutant vector
v_iaccording toDeConfig::variant. - Apply binomial or exponential crossover (also seeded through
seed_streamwithSeedPurpose::Crossover) to blendv_iwith the current individual, ensuring at least one gene comes fromv_i(j_randguarantee). - Clamp the trial genome to
params.bounds.
The returned state is a clone of the input state; no fitness
update occurs here — that happens in Strategy::tell.
Source§fn tell(
&self,
_params: &DeConfig,
trial: Tensor<B, 2>,
fitness: Tensor<B, 1>,
state: DeState<B>,
_rng: &mut dyn Rng,
) -> (DeState<B>, StrategyMetrics)
fn tell( &self, _params: &DeConfig, trial: Tensor<B, 2>, fitness: Tensor<B, 1>, state: DeState<B>, _rng: &mut dyn Rng, ) -> (DeState<B>, StrategyMetrics)
Consumes the evaluated trial population and advances the state.
First call (fitness cache empty): stores the initial
population’s fitness, initializes best_genome/best_fitness,
and increments the generation counter. No replacement occurs
because there are no previous individuals to compare against.
Subsequent calls: applies greedy per-slot replacement — each
trial individual replaces its corresponding current individual if
and only if trial_fitness[i] >= state.fitness[i]. The best-ever
genome and fitness are updated if the new generation improves on
state.best_fitness.
Returns the updated DeState and a StrategyMetrics snapshot
covering the current generation’s fitness distribution.
Auto Trait Implementations§
impl<B> Freeze for DifferentialEvolution<B>
impl<B> RefUnwindSafe for DifferentialEvolution<B>
impl<B> Send for DifferentialEvolution<B>
impl<B> Sync for DifferentialEvolution<B>
impl<B> Unpin for DifferentialEvolution<B>
impl<B> UnsafeUnpin for DifferentialEvolution<B>
impl<B> UnwindSafe for DifferentialEvolution<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