Skip to main content

EdaStrategy

Struct EdaStrategy 

Source
pub struct EdaStrategy<B: Backend, M> { /* private fields */ }
Expand description

Generic estimation-of-distribution strategy.

Drives the fitsample loop of any ProbabilityModel. The strategy itself is stateless (the model is held by value; all mutable generation state lives in the returned EdaState), so it slots straight into EvolutionaryHarness.

Type parameter M must implement ProbabilityModel<B>; in practice this is one of UnivariateGaussian, UnivariateBernoulli, CompactGenetic, DependencyChain, or BayesianNetwork.

§Example

use burn::backend::Flex;
use rlevo_evolution::algorithms::eda::{EdaParams, EdaStrategy, UnivariateGaussian};
use rlevo_evolution::algorithms::eda::univariate_gaussian::UnivariateGaussianParams;
use rlevo_core::bounds::Bounds;

let strategy = EdaStrategy::<Flex, _>::new(UnivariateGaussian);
let params = EdaParams {
    pop_size: 32,
    selection_ratio: 0.5,
    bounds: Some(Bounds::new(-5.12, 5.12)),
    model: UnivariateGaussianParams::default_for(8),
};
let _ = (strategy, params);

Implementations§

Source§

impl<B: Backend, M> EdaStrategy<B, M>

Source

pub fn new(model: M) -> Self

Build a new EDA strategy around model.

Trait Implementations§

Source§

impl<B: Backend, M: Debug> Debug for EdaStrategy<B, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B: Backend, M: ProbabilityModel<B>> Strategy<B> for EdaStrategy<B, M>

Source§

fn init( &self, params: &Self::Params, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> Self::State

Build the initial state.

Fits the model’s prior from params.model (passing prev = None and empty 0 × 0 / length-0 population and fitness tensors, per the ProbabilityModel invariants). The rng is unused — the prior is deterministic. The best-so-far trackers start empty.

§Panics

Debug-asserts that params.selection_ratio lies strictly in (0, 1). A ratio of 0.0 would select no parents and a ratio of 1.0 would defeat truncation selection entirely.

Source§

fn ask( &self, params: &Self::Params, state: &Self::State, rng: &mut dyn Rng, device: &<B as BackendTypes>::Device, ) -> (Self::Genome, Self::State)

Sample the next candidate population from the current model.

Draws exactly one u64 from rng to seed a per-generation SeedPurpose::EdaSampling stream, samples params.pop_size individuals from the model through that host stream, and applies the optional params.bounds clamp. The state is returned unchanged.

Source§

fn tell( &self, params: &Self::Params, population: Self::Genome, fitness: Tensor<B, 1>, state: Self::State, _rng: &mut dyn Rng, ) -> (Self::State, StrategyMetrics)

Consume the population’s fitness and refit the model.

Pulls fitness to host, sanitizes NaN−inf (worst under the maximise convention) via the crate’s sanitize_fitness helper, updates the best-so-far tracker, truncation-selects the best k rows (descending fitness order, with k = ceil(selection_ratio · pop_size) clamped to [2, pop_size]), and refits the model to them (passing prev = Some(model_state)).

The selected population is also sanitized before the refit as a coarse backstop: non-finite genome values are mapped NaN → 0.0 and ±inf clamped to ±f32::MAX, so a single divergent gene cannot poison a model’s fitted statistics. Each model’s fit keeps its own precise finite-guards (which also protect direct trait callers that bypass this path).

The fitness tensor is forwarded to ProbabilityModel::fit; models that weight or rank their selected individuals can use it. The five built-in models (UnivariateGaussian, UnivariateBernoulli, CompactGenetic, DependencyChain, BayesianNetwork) all perform an unweighted fit and ignore it.

Source§

fn best(&self, state: &Self::State) -> Option<(Self::Genome, f32)>

Return the best-so-far genome (shape (1, D)) and its fitness.

Returns None before the first tell call. The genome is stored internally as a (D,) vector and unsqueezed to (1, D) here to match the Genome = Tensor<B, 2> container.

Source§

type Params = EdaParams<<M as ProbabilityModel<B>>::Params>

Static parameters for a run.
Source§

type State = EdaState<B, <M as ProbabilityModel<B>>::State>

Generation-to-generation state.
Source§

type Genome = Tensor<B, 2>

Genome container produced by ask.

Auto Trait Implementations§

§

impl<B, M> Freeze for EdaStrategy<B, M>
where M: Freeze,

§

impl<B, M> RefUnwindSafe for EdaStrategy<B, M>
where M: RefUnwindSafe,

§

impl<B, M> Send for EdaStrategy<B, M>
where M: Send,

§

impl<B, M> Sync for EdaStrategy<B, M>
where M: Sync,

§

impl<B, M> Unpin for EdaStrategy<B, M>
where M: Unpin,

§

impl<B, M> UnsafeUnpin for EdaStrategy<B, M>
where M: UnsafeUnpin,

§

impl<B, M> UnwindSafe for EdaStrategy<B, M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Adaptor<()> for T

Source§

fn adapt(&self)

Adapt the type to be passed to a metric.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more