Skip to content

Commit 2033117

Browse files
committed
update documentation
1 parent 086c9f3 commit 2033117

6 files changed

Lines changed: 46 additions & 26 deletions

File tree

src/genotype/multi_range.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub type DefaultAllele = f32;
3939
/// The discrete mutations traverse all allowed values for every scale (see
4040
/// [MutationType::Discrete])
4141
///
42+
/// ** Note: ** When all parameters are discrete, prefer
43+
/// [MultiListGenotype](crate::genotype::MultiListGenotype) as this is more optimized and also
44+
/// balance the mutation probablity per allowed value, not per gene.
45+
///
4246
/// # Heterogeneous Genotype Support
4347
///
4448
/// MultiRangeGenotype supports heterogeneous chromosomes that mix different gene semantics
@@ -55,8 +59,6 @@ pub type DefaultAllele = f32;
5559
/// * Useful for encoding: enums (0.0..=4.0), booleans (0.0..=1.0), or discrete choices
5660
/// * Neighbours and permutations include all integer values in the allele range
5761
///
58-
/// Explicit `.with_mutation_types()` overrides any auto-detected mutation range settings.
59-
///
6062
/// # Example (f32, default, random mutation):
6163
/// ```
6264
/// use genetic_algorithm::genotype::{Genotype, MultiRangeGenotype};

src/genotype/mutation_type.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ use crate::allele::Allele;
7474
/// **Example:** With `Step(5)` on range `0..=100`, a gene value of `50` becomes
7575
/// either `45` or `55` (50% probability each), never values in between.
7676
///
77-
/// **Use case:** Grid-aligned search spaces, discrete optimization where specific
78-
/// increments are meaningful, systematic exploration patterns.
77+
/// **Use case:** Grid-aligned search spaces, discrete optimization where specific increments are
78+
/// meaningful, systematic exploration patterns. Allows [Permutation](crate::strategy::permutate)
79+
/// for (Multi)RangeGenotype
7980
///
8081
/// ## `RangeScaled(Vec<T>)`
8182
/// Multi-phase range mutation with strategy-controlled progression. Each element
@@ -121,8 +122,7 @@ use crate::allele::Allele;
121122
/// - Phase 1: Mutations of exactly ±1
122123
///
123124
/// **Use case:** Grid-like search spaces, systematic parameter sweeps, problems requiring exact
124-
/// step sizes. Allows for [Permutation](crate::strategy::permutate) and
125-
/// [HillClimb](crate::strategy::hill_climb)/steepest-ascent for (Multi)RangeGenotype
125+
/// step sizes. Allows [Permutation](crate::strategy::permutate) for (Multi)RangeGenotype
126126
///
127127
/// Prolonged periods of the same step size can be achieved by setting multiple scales with the
128128
/// same bandwidth value. You could also alternate between exploration and exploitation several
@@ -137,6 +137,7 @@ use crate::allele::Allele;
137137
/// which could map to enum variants or categorical options.
138138
///
139139
/// **Use case:** Heterogeneous chromosomes mixing categorical choices with continuous parameters.
140+
/// Allows [Permutation](crate::strategy::permutate) for (Multi)RangeGenotype
140141
///
141142
/// ** Note: ** When all parameters are discrete, prefer
142143
/// [ListGenotype](crate::genotype::ListGenotype) or
@@ -298,8 +299,8 @@ pub enum MutationType<T: Allele> {
298299
/// Step mutation size (exactly +step or -step, clamped)
299300
Step(T),
300301
/// Range bandwidths for scaled mutations (strategy controls phase advancement)
302+
Discrete,
301303
RangeScaled(Vec<T>),
302304
/// Step sizes for scaled mutations (strategy controls phase advancement)
303305
StepScaled(Vec<T>),
304-
Discrete,
305306
}

src/genotype/range.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub type DefaultAllele = f32;
2222
///
2323
/// # Permutation
2424
///
25-
/// Supports Permutation for scaled mutations only. This approach implements a
25+
/// Supports Permutation for scaled and discrete mutations only. This approach implements a
2626
/// increasingly localized grid search with increasing precision using the
2727
/// [MutationType::StepScaled]
2828
/// to define the search scope and grid steps
@@ -33,6 +33,12 @@ pub type DefaultAllele = f32;
3333
/// the upper bound of the current scale as step size.
3434
/// * Scale down and repeat after grid is fully traversed
3535
///
36+
/// The discrete mutations traverse all allowed values for every scale (see
37+
/// [MutationType::Discrete])
38+
///
39+
/// ** Note: ** When all parameters are discrete, prefer
40+
/// [ListGenotype](crate::genotype::ListGenotype) as this is more optimized.
41+
///
3642
/// # Example (f32, default):
3743
/// ```
3844
/// use genetic_algorithm::genotype::{Genotype, RangeGenotype, MutationType};

src/strategy/evolve.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ pub enum EvolveVariant {
5353
/// * max_stale_generations: when the ultimate goal in terms of fitness score is unknown and one depends on some convergion
5454
/// threshold, or one wants a duration limitation next to the target_fitness_score
5555
/// * max_generations: when the ultimate goal in terms of fitness score is unknown and there is a effort constraint
56+
/// * With a scaled [crate::genotype::MutationType]:
57+
/// * Scale down after max_generations or max_stale_generations is reached and reset scale_generations and stale_generations to zero
58+
/// * Only trigger max_generations or max_stale_generations ending condition when already reached the smallest scale
5659
///
5760
/// General Hyper-parameters:
5861
/// * `replacement_rate` (selection): the target fraction of the population which exists of

src/strategy/hill_climb.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,43 @@ pub enum HillClimbVariant {
5454
/// there is a replace_on_equal_fitness consideration or some remaining randomness in the neighbouring population (see RangeGenotype
5555
/// below)
5656
/// * max_generations: when the ultimate goal in terms of fitness score is unknown and there is a effort constraint
57+
/// * With a scaled [crate::genotype::MutationType]:
58+
/// * Scale down after max_generations or max_stale_generations is reached and reset scale_generations and stale_generations to zero
59+
/// * Only trigger max_generations or max_stale_generations ending condition when already reached the smallest scale
5760
///
5861
/// There are optional mutation distance limitations for
5962
/// [RangeGenotype](crate::genotype::RangeGenotype) and
6063
/// [MultiRangeGenotype](crate::genotype::MultiRangeGenotype) neighbouring chromosomes, see [crate::genotype::MutationType].
61-
/// * With MutationType::Scaled
62-
/// * Mutation distance only on edges of current scale (e.g. -1 and +1 for -1..-1 scale)
64+
/// * With MutationType::StepScaled
65+
/// * Mutation distance one step up and down
6366
/// * Pick random edge for [HillClimbVariant::Stochastic]
6467
/// * Take both edges per gene for [HillClimbVariant::SteepestAscent]
65-
/// * Scale down after max_stale_generations is reached and reset stale_generations to zero
66-
/// * Only trigger max_stale_generations ending condition when already reached the smallest scale
6768
/// * max_stale_generations could be set to 1, as there is no remaining randomness
68-
/// * With MutationType::Relative
69-
/// * Mutation distance taken uniformly from mutation range
69+
/// * With MutationType::StepScaled
70+
/// * Mutation distance one step up and down of current scale step
71+
/// * Pick random edge for [HillClimbVariant::Stochastic]
72+
/// * Take both edges per gene for [HillClimbVariant::SteepestAscent]
73+
/// * max_stale_generations could be set to 1, as there is no remaining randomness
74+
/// * With MutationType::Range
75+
/// * Mutation distance taken uniformly from bandwidth
7076
/// * Sample single random value for [HillClimbVariant::Stochastic]
7177
/// * Ensure to sample both a higer and lower value per gene for [HillClimbVariant::SteepestAscent]
72-
/// * Standard max_stale_generations ending condition
78+
/// * max_stale_generations should be set somewhat higher than 1 as there is some remaining randomness
79+
/// * With MutationType::RangeScaled
80+
/// * Mutation distance taken uniformly from current scale bandwidth
81+
/// * Pick random edge for [HillClimbVariant::Stochastic]
82+
/// * Take both edges per gene for [HillClimbVariant::SteepestAscent]
7383
/// * max_stale_generations should be set somewhat higher than 1 as there is some remaining randomness
7484
/// * With MutationType::Random (not advised for hill climbing):
7585
/// * Mutate uniformly over the complete allele range
7686
/// * Sample single random value for [HillClimbVariant::Stochastic]
7787
/// * Ensure to sample both a higer and lower value per gene for [HillClimbVariant::SteepestAscent]
78-
/// * Standard max_stale_generations ending condition
7988
/// * max_stale_generations should be set substantially higher than 1 as there is a lot remaining randomness
8089
/// * With MutationType::Discrete
8190
/// * All values are neighbours, just like ListGenotype
82-
/// * With MutationType::Transition
83-
/// * Behaves like Random and then slowly transitions to Relative
91+
/// * Sample single random value for [HillClimbVariant::Stochastic]
92+
/// * Traverse all values for [HillClimbVariant::SteepestAscent]
93+
/// * max_stale_generations could be set to 1, as there is no remaining randomness
8494
///
8595
/// There are reporting hooks in the loop receiving the [HillClimbState], which can by handled by an
8696
/// [StrategyReporter] (e.g. [HillClimbReporterDuration], [HillClimbReporterSimple]). But you are encouraged to

src/strategy/permutate.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,16 @@ pub enum PermutateVariant {
4444
/// There is a method to permutate
4545
/// [RangeGenotype](crate::genotype::RangeGenotype) and
4646
/// [MultiRangeGenotype](crate::genotype::MultiRangeGenotype) chromosomes, see [crate::genotype::MutationType].
47-
/// * With MutationType::Scaled
48-
/// * First scale (index = 0) traverses the whole allele_range(s) with the upper bound of the
49-
/// first scale as step size.
47+
/// * With MutationType::Step
48+
/// * Traverses the whole allele_range(s) with the step size.
49+
/// * With MutationType::StepScaled
50+
/// * First scale (index = 0) traverses the whole allele_range(s) with the first scale as step size.
5051
/// * Other scales (index > 0) center around the best chromomsome of the previous scale,
51-
/// traversing the previous scale bounds around the best chromosome with the upper bound of the
52-
/// current scale as step size.
52+
/// traversing the previous scale step as bounds around the best chromosome with the
53+
/// current scale as inner step size.
5354
/// * Scale down after grid is fully traversed
5455
/// * With MutationType::Discrete
5556
/// * Always permutate all values, just like ListGenotype
56-
/// * With MutationType::Range: Permutation not supported
57-
/// * With MutationType::Transition: Permutation not supported
58-
/// * With MutationType::Random: Permutation not supported
5957
///
6058
/// There are reporting hooks in the loop receiving the [PermutateState], which can by handled by an
6159
/// [StrategyReporter] (e.g. [PermutateReporterDuration], [PermutateReporterSimple]). But you are encouraged to

0 commit comments

Comments
 (0)