Skip to content

Commit 438ec84

Browse files
committed
update Changelog and docs
1 parent 7e6a61e commit 438ec84

File tree

6 files changed

+55
-18
lines changed

6 files changed

+55
-18
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.20.2] - 2025-05-12
8+
### Added
9+
* Add `max_generations` ending condition on `Evolve` and `HillClimb` strategies
10+
(also blocked by optional `valid_fitness_score,` as `max_stale_generations` is)
11+
* Add `ExtensionMassDeduplication` which requires `with_genes_hashing(true)` on
12+
the `Genotype` (otherwise ignored)
13+
* Add `Population` `unique_chromosome_indices()` and
14+
`best_unique_chromosome_indices()` support functions
15+
16+
### Changed
17+
* Nuance `ExtensionMassGenesis` trying to use unique Adam en Eve Chromosomes
18+
when genes_hashes are availble, otherwise just take 2 best chromosomes
19+
(possibly duplicates)
20+
* Decided not to use unique best chromosomes for the elitism_rate in
21+
`ExtensionMassDegeneration` and `ExtensionMassExtinction`. Just use the best
22+
chromosomes (possibly duplicates), as uniqueness hard-limits the amount of selected
23+
elites in the typical low cardinality situation, which seems unwanted behaviour
24+
725
## [0.20.1] - 2025-05-08
826
### Added
927
* Add `elitism_rate` to `ExtensionMassExtinction` and

src/crossover.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
//! [selection](crate::select) phase determines the order the parent pairing (overall with fitter
33
//! first).
44
//!
5-
//! For the selection-rate, typically set between 0.2 and 0.5 (20%-50% of the population is
6-
//! selected for reproduction). A higher selection rate (closer to 50%) can accelerate convergence
7-
//! but risks premature convergence (getting stuck in local optima). A lower selection rate (closer
8-
//! to 20%) maintains diversity but may slow down the algorithm. Other sources suggest a higher
9-
//! selection-rate, somewhere in the 0.75-1.0 range. Apparantly there is no broad consensus.
5+
//! The selection_rate is the fraction of parents which are selected for
6+
//! reproduction. This selection adds offspring to the population, the other
7+
//! parents do not. The population now grows by the added offspring, as the
8+
//! parents are not replaced yet. Value should typically be between 0.4 and
9+
//! 0.8. High values risk of premature convergence. Low values reduce diversity
10+
//! if overused.
1011
//!
11-
//! For the crossover-rate, typically set between 0.7 and 0.9 (70%-90% of the population undergoes
12-
//! crossover). Higher crossover rates promote exploration and recombination of genetic material.
12+
//! The crossover_rate (or recombination-rate) is the fraction of selected parents to crossover,
13+
//! the remaining parents just clone as offspring. Value should typically be between 0.5 and 0.8.
14+
//! High values converge faster, but risk losing good solutions. Low values have poor exploration
15+
//! and risk of premature convergence
1316
//!
14-
//! The crossover adds children, thus potentially increasing the population_size above the
15-
//! target_population_size
17+
//! Normally the crossover adds children to the popluation, thus increasing the population_size
18+
//! above the target_population_size. Selection will reduce this again in the next generation
1619
mod clone;
1720
mod multi_gene;
1821
mod multi_point;

src/crossover/rejuvenate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::strategy::{StrategyAction, StrategyReporter, StrategyState};
66
use rand::Rng;
77
use std::time::Instant;
88

9-
/// Drop non-selected parents, then clone top parents to repopulate, then rejuvenate selected
10-
/// parents to children in place. No copying of chromosomes for creating the offspring itself, only
11-
/// for repopulating the dropped non-selected parents (smaller fraction)
9+
/// Drop non-selected parents, then clone top parents to repopulate up to target_population_size,
10+
/// then rejuvenate selected parents to children in place. No copying of chromosomes for creating
11+
/// the offspring itself, only for repopulating the dropped non-selected parents (smaller fraction)
1212
/// Allowed for unique genotypes.
1313
#[derive(Clone, Debug)]
1414
pub struct Rejuvenate {

src/extension.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub trait Extension: Clone + Send + Sync + std::fmt::Debug {
4040
config: &EvolveConfig,
4141
elitism_size: usize,
4242
) -> Vec<G::Chromosome> {
43-
let mut elite_chromosomes: Vec<G::Chromosome> = Vec::new();
43+
let mut elite_chromosomes: Vec<G::Chromosome> = Vec::with_capacity(elitism_size);
4444
for index in state
4545
.population
4646
.best_chromosome_indices(elitism_size, config.fitness_ordering)
@@ -60,17 +60,17 @@ pub trait Extension: Clone + Send + Sync + std::fmt::Debug {
6060
config: &EvolveConfig,
6161
elitism_size: usize,
6262
) -> Vec<G::Chromosome> {
63-
let mut unique_elite_chromosomes: Vec<G::Chromosome> = Vec::new();
63+
let mut elite_chromosomes: Vec<G::Chromosome> = Vec::with_capacity(elitism_size);
6464
for index in state
6565
.population
6666
.best_unique_chromosome_indices(elitism_size, config.fitness_ordering)
6767
.into_iter()
6868
.rev()
6969
{
7070
let chromosome = state.population.chromosomes.swap_remove(index);
71-
unique_elite_chromosomes.push(chromosome);
71+
elite_chromosomes.push(chromosome);
7272
}
73-
unique_elite_chromosomes
73+
elite_chromosomes
7474
}
7575

7676
fn extract_unique_chromosomes<G: EvolveGenotype>(

src/extension/mass_genesis.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use rand::Rng;
77
use std::time::Instant;
88

99
/// A version of [MassExtinction](crate::extension::ExtensionMassExtinction), where only an Adam
10-
/// and Eve of current best chromosomes survive. Tries to select distinct Adem and Eve when
10+
/// and Eve of current best chromosomes survive. Tries to select distinct Adam and Eve when
1111
/// genes_hash is stored on chromosome, otherwise it will just take 2 of the best (possibly
12-
/// dupicates).
12+
/// duplicates).
1313
///
1414
/// Population will recover in the following generations
1515
#[derive(Debug, Clone)]

src/select.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
//! The selection phase, where chromosomes are lined up for pairing in the
22
//! [crossover](crate::crossover) phase, dropping the chromosomes outside of the
33
//! target_population_size.
4+
//!
5+
//! The replacement_rate is the target fraction of the population which exists of
6+
//! children. Generational Replacement and Steady-State Replacement can both be
7+
//! modelled with this parameter by setting it respectively to 1.0 and 0.2-0.8.
8+
//! High values converge faster, but risk losing good solutions. Low values
9+
//! convergence slower. If there is a shortage of population after the ideal
10+
//! fraction, firstly remaining non-selected children and secondly remaining
11+
//! non-selected parents will be used to fill the shortage to avoid population
12+
//! collapse.
13+
//!
14+
//! The elitism_rate is a non-generational elite gate, which ensures passing of the
15+
//! best chromosomes before selection and replacement takes place. Value should
16+
//! typically be very low, between 0.01 and 0.05. Relevant for
17+
//! `SelectTournament` where the best chromosome is not guaranteed to be
18+
//! selected for a tournament if the `population_size` is larger than the
19+
//! `target_population_size`
420
mod elite;
521
mod tournament;
622
mod wrapper;

0 commit comments

Comments
 (0)