Entry Point
UTCGP.mage_crossover — Function
mage_crossover(inds::Population, run_config::AbstractRunConf, model_architecture::modelArchitecture,
meta_library::MetaLibrary, shared_inputs::SharedInput, fitness::Vector{Float64}; extras::Dict=Dict()) -> PopulationEntry Point for using the standard mage_crossover.
Creates a new population by performing truncation selection and generating new individuals via crossover (with subsequent mutation). The provided run_config is converted via the trait APIs to extract crossover/mutation and ES parameters.
Lower fitness is considered better.
Arguments
inds: Current population (vector ofUTGenome).run_config: Run configuration that supports the crossover trait and mutation trait.model_architecture: Genome architecture information.meta_library: Library of functions used during mutation.shared_inputs: Shared inputs required during mutation.fitness: Vector of fitness values.extras: Optional extra parameters.
Returns
- A new population (
Vector{UTGenome}).
mage_crossover(inds::Population, crossover_args::CrossOverArgs, evolutionary_strategy_args::GAWithTournamentArgs,
model_architecture::modelArchitecture, meta_library::MetaLibrary,
shared_inputs::SharedInput, fitness::Vector{Float64}; extras::Dict=Dict()) -> PopulationCreates a new population using truncation selection and generating new individuals through crossover (and mutation) using the GA with tournament selection strategy.
Arguments
inds: Current population.crossover_args: Minimal crossover arguments.evolutionary_strategy_args: GA-specific strategy argumentsmodel_architecture: Genome architecture information.meta_library: Library used during mutation.shared_inputs: Shared inputs for mutation.fitness: Vector of fitness values.extras: Optional extra parameters.
Returns
- A new population (
Vector{UTGenome}).
mage_crossover(inds::Population, crossover_args::CrossOverMutRateArgs, evolutionary_strategy_args::OnePlusLambda,
model_architecture::modelArchitecture, meta_library::MetaLibrary,
shared_inputs::SharedInput, fitness::Vector{Float64}; extras::Dict=Dict()) -> PopulationPlaceholder for a crossover method using a mutation rate strategy and OnePlus Lambda
High Level
Crossover Operator
UTCGP.mage_crossover_with_numbered_mutation — Function
mage_crossover_with_numbered_mutation(p1::UTGenome, p2::UTGenome, crossover_args::CrossOverArgs,
model_architecture::modelArchitecture, meta_library::MetaLibrary,
shared_inputs::SharedInput; p1_fitness, p2_fitness) -> UTGenomePerforms individual-level crossover between two parent genomes, with a numbered mutation applied if triggered. Uses a binary mask to swap whole chromosomes.
Behavior
- If the drawn random number for crossover is below
crossover_args.crossover_prob, a crossover is performed. - Otherwise, the fitter parent (or a random parent) is chosen.
- Mutation is applied if the random draw is within
crossover_args.mutation_prob.
Caveats
- Ensures that at least one genetic operator (crossover and/or mutation) is applied.
- Prevents a complete swap of all chromosomes to avoid simply exchanging individuals.
Arguments
p1: First parent genome.p2: Second parent genome.crossover_args: Minimal crossover configuration.model_architecture: Genome architecture information.meta_library: Library for mutation operations.shared_inputs: Shared inputs for mutation.p1_fitness: Fitness of parent1 (optional).p2_fitness: Fitness of parent2 (optional).
Returns
- A new
UTGenomeproduced by crossover and mutation.
Traits
UTCGP.AbstractCrossOverArgs — Type
AbstractCrossOverArgsAbstract type for crossover configuration arguments.
UTCGP.CrossOverArgs — Type
CrossOverArgsBasic crossover configuration parameters.
Fields
mutation_prob::Float64: Probability of applying mutation.mutation_n_active_nodes::Int64: Number of active nodes used in mutation.crossover_prob::Float64: Probability of performing crossover.
UTCGP.CrossOverMutRateArgs — Type
CrossOverMutRateArgsCrossover configuration parameters using an explicit mutation rate.
Fields
mutation_prob::Float64: Probability of applying mutation.mutation_rate::Int64: The Probability for mutation rate (normally on each node).crossover_prob::Float64: Probability of performing crossover.
UTCGP.MissingCrossOverArgs — Type
MissingCrossOverArgsRepresents missing crossover configuration parameters.
UTCGP.runconf_trait_crossover — Function
If there is no method specialized
runconf_trait_crossover(conf::UTCGP.RunConfCrossOverGA) -> CrossOverArgsExtracts the minimal crossover arguments from a run configuration.
UTCGP.numbered_mutation_trait — Function
numbered_mutation_trait(conf::CrossOverArgs) -> NumberedMutationArgsExtracts the arguments for numbered mutation from the provided crossover configuration.
Helper
UTCGP._initialize_population — Function
_initialize_population(inds::Population, evo_args::GAWithTournamentArgs, fitness::Vector{Float64}) -> (Vector{UTGenome}, Int)Initializes a new population vector based on the evolutionary strategy arguments.
Arguments
inds: The current population (after selection).evo_args: Evolutionary strategy arguments.
Returns
- A tuple
(new_pop, n_elite)wherenew_popis an uninitialized vector ofUTGenomewith size equal ton_new + n_elite, andn_eliteis the number of elite individuals to preserve.
Errors
- Throws an error if the expected population size (n_elite) does not match the length of
inds.
UTCGP._apply_truncation_selection! — Function
_apply_truncation_selection!(new_pop::Vector{UTGenome}, inds::Population, fitness::Vector{Float64}, n_elite::Int)Performs truncation selection by copying the best n_elite individuals (with the lowest fitness values) from the current population inds into the beginning of the new population vector new_pop.
Arguments
new_pop: The new population vector to be filled (modified in-place).inds: The current population (vector ofUTGenome).fitness: Vector of fitness values (lower is better).n_elite: Number of elite individuals to preserve.
Returns
- The sorted indices of the whole population.
Side Effects
- Modifies
new_popin-place by copying the elite individuals.
UTCGP._apply_crossover_and_mutation! — Function
_apply_crossover_and_mutation!(new_pop::Vector{UTGenome},
inds::Population,
offset::Int64,
tournament_size::Int64,
n_new::Int64,
crossover_args::CrossOverArgs,
model_architecture::modelArchitecture,
meta_library::MetaLibrary,
shared_inputs::SharedInput,
fitness::Vector{Float64};
crossover_operator::Function = mage_crossover_with_numbered_mutation)Generates new individuals by applying crossover (and mutation) to selected parent pairs and inserts them into the new population vector new_pop, starting at the given offset.
This function performs the following steps:
- For each new individual to be created (total
n_new):- Selects two parents from the current population
indsusing tournament selection with the specifiedtournament_sizeand based on the providedfitness(lower fitness is better). Not possible to select the same ind twice. - Applies the given
crossover_operator(default ismage_crossover_with_numbered_mutation) to the selected parents to produce a new individual. - Inserts the new individual into
new_popat the corresponding position (starting atoffset+1).
- Selects two parents from the current population
- Debug messages are logged at key steps to trace the selection and generation process.
Arguments
new_pop::Vector{UTGenome}: The preallocated population vector where new individuals will be stored.inds::Population: The current population from which parents are selected.offset::Int64: The starting index innew_popwhere new individuals should be placed (typically equal to the number of elite individuals preserved).tournament_size::Int64: The size of the tournament used for parent selection.n_new::Int64: The number of new individuals to generate via crossover.crossover_args::CrossOverArgs: Crossover configuration parameters.model_architecture::modelArchitecture: Information about the genome architecture.meta_library::MetaLibrary: Library of functions used during mutation.shared_inputs::SharedInput: Shared inputs required for mutation operations.fitness::Vector{Float64}: A vector of fitness values for the current population (lower is better).crossover_operator::Function(keyword): The function used to perform crossover and mutation on two parents. Defaults tomage_crossover_with_numbered_mutation.
Side Effects
- Modifies
new_popin-place by inserting new individuals at indicesoffset+1tooffset+n_new.
_apply_crossover_and_mutation!(new_pop::Vector{UTGenome},
inds::Population,
ga_strategy::GAWithTournamentArgs,
crossover_args::CrossOverArgs,
model_architecture::modelArchitecture,
meta_library::MetaLibrary,
shared_inputs::SharedInput,
fitness::Vector{Float64};
crossover_operator::Function = mage_crossover_with_numbered_mutation)Convenience wrapper that extracts parameters from a GA strategy configuration and calls the more general _apply_crossover_and_mutation! function.
This function uses the fields from ga_strategy as follows:
ga_strategy.n_eliteis used as theoffsetinnew_pop.ga_strategy.tournament_sizeis used for tournament selection.ga_strategy.n_newis the number of new individuals to generate.
Side Effects
- Calls the general
_apply_crossover_and_mutation!function with parameters extracted fromga_strategy.
For Crossover :
UTCGP._check_genome_compatibility — Function
_check_genome_compatibility(p1::UTGenome, p2::UTGenome) -> IntEnsures that both parent genomes have the same number of chromosomes and that the genome is not a single-chromosome (CGP) genome. Returns the number of chromosomes.
Errors
- Throws an error if genomes have different lengths or if there is only one chromosome.
UTCGP._draw_until_one_operator — Function
_draw_until_one_operator(crossover_prob::Float64, mutation_prob::Float64) -> (Float64, Float64)Draws random numbers repeatedly until either the crossover or mutation condition is met. Returns a tuple (r_c, r_m) representing the drawn random values.
Side Effects
- Logs the drawn random values.