Skip to main content

elitist

Function elitist 

Source
pub fn elitist<B: Backend>(
    current_pop: Tensor<B, 2>,
    current_fitness: &[f32],
    offspring_pop: Tensor<B, 2>,
    offspring_fitness: &[f32],
    k: usize,
    device: &<B as BackendTypes>::Device,
) -> (Tensor<B, 2>, Vec<f32>)
Expand description

Elitist replacement: keeps the k best parents and the best remaining offspring.

Selects the k highest-fitness members of the current generation (elites) and the pop_size − k highest-fitness offspring, then concatenates them to form the next generation of size pop_size. Both selections use truncation_indices_host and are therefore deterministic.

The returned fitness vector has the elites’ fitnesses first, followed by the kept offspring fitnesses, in the same order as the corresponding rows of the returned tensor.

§Panics

Panics if k > current_fitness.len(), or if pop_size − k > offspring_fitness.len() (not enough offspring to backfill).