pub struct CompactGenetic;Expand description
Compact Genetic Algorithm for binary spaces (cGA).
Implements ProbabilityModel with a per-gene probability vector updated
by winner/loser competition from the truncation-selected subset. Samples
are raw {0, 1} f32 values; EdaParams::bounds
clamps are no-ops for this model.
See the module docs for the update rule, the deviation from classic cGA, and the reference.
Trait Implementations§
Source§impl Clone for CompactGenetic
impl Clone for CompactGenetic
Source§fn clone(&self) -> CompactGenetic
fn clone(&self) -> CompactGenetic
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CompactGenetic
Source§impl Debug for CompactGenetic
impl Debug for CompactGenetic
Source§impl Default for CompactGenetic
impl Default for CompactGenetic
Source§fn default() -> CompactGenetic
fn default() -> CompactGenetic
Source§impl<B: Backend> ProbabilityModel<B> for CompactGenetic
impl<B: Backend> ProbabilityModel<B> for CompactGenetic
Source§fn fit(
&self,
params: &Self::Params,
prev: Option<&Self::State>,
population: Tensor<B, 2>,
fitness: Tensor<B, 1>,
device: &<B as BackendTypes>::Device,
) -> Self::State
fn fit( &self, params: &Self::Params, prev: Option<&Self::State>, population: Tensor<B, 2>, fitness: Tensor<B, 1>, device: &<B as BackendTypes>::Device, ) -> Self::State
Update the per-gene probability vector by winner/loser competition.
When prev = None returns the uniform-0.5 prior; population and
fitness are ignored on that path. Otherwise finds the argmax (winner)
and argmin (loser) of the fitness vector (canonical maximise: higher is
better), then nudges each gene where winner and loser disagree by
±1 / virtual_pop_size (toward the winner), clamped to [0, 1].
§Panics
Panics if the population or fitness tensor cannot be read back as
f32 (.expect("population tensor must be readable as f32") /
.expect("fitness tensor must be readable as f32")). Also panics with an
out-of-bounds index if the population column count d exceeds
prev.prob.len() (the per-gene probability vector carried in prev).
Source§fn sample(
&self,
state: &Self::State,
n: usize,
rng: &mut dyn Rng,
device: &<B as BackendTypes>::Device,
) -> Tensor<B, 2>
fn sample( &self, state: &Self::State, n: usize, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> Tensor<B, 2>
Draw n binary genomes from the per-gene Bernoulli probabilities.
Each gene is sampled independently as 1.0 with probability prob[j],
0.0 otherwise, using the supplied host RNG (never Tensor::random /
B::seed). The returned tensor has shape (n, D) and contains only
0.0 and 1.0 values.
§Panics
Panics if the n * d element count overflows allocation or TensorData
capacity (Vec::with_capacity(n * d) / the (n, D) TensorData).
Source§type Params = CompactGeneticParams
type Params = CompactGeneticParams
Source§type State = CompactGeneticState
type State = CompactGeneticState
Auto Trait Implementations§
impl Freeze for CompactGenetic
impl RefUnwindSafe for CompactGenetic
impl Send for CompactGenetic
impl Sync for CompactGenetic
impl Unpin for CompactGenetic
impl UnsafeUnpin for CompactGenetic
impl UnwindSafe for CompactGenetic
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