This section of the PyGAD's library documentation discusses the
pygad.helper module.
The pygad.helper module has 2 submodules:
pygad.helper.unique: A module of methods for creating unique genes.pygad.helper.misc: A module of miscellaneous helper methods.
The pygad.helper.unique module has a class named Unique with the
following helper methods. Such methods help to check and fix duplicate
values in the genes of a solution.
solve_duplicate_genes_randomly(): Solves the duplicates in a solution by randomly selecting new values for the duplicating genes.solve_duplicate_genes_by_space(): Solves the duplicates in a solution by selecting values for the duplicating genes from the gene spaceunique_int_gene_from_range(): Finds a unique integer value for the gene out of a range defined by start and end points.unique_float_gene_from_range(): Finds a unique float value for the gene out of a range defined by start and end points.select_unique_value(): Selects a unique value (if possible) from a list of gene values.unique_genes_by_space(): Loops through all the duplicating genes to find unique values that from their gene spaces to solve the duplicates. For each duplicating gene, a call to theunique_gene_by_space()is made.unique_gene_by_space(): Returns a unique gene value for a single gene based on its value space to solve the duplicates.find_two_duplicates(): Identifies the first occurrence of a duplicate gene in the solution.unpack_gene_space(): Unpacks the gene space for selecting a value to resolve duplicates by converting ranges into lists of values.solve_duplicates_deeply(): Sometimes it is impossible to solve the duplicate genes by simply randomly selecting another value for either genes. This function solve the duplicates between 2 genes by searching for a third gene that can make assist in the solution.
The pygad.helper.misc module has a class called Helper with some
methods to help in different stages of the GA pipeline. It is introduced
in PyGAD
3.5.0.
change_population_dtype_and_round(): For each gene in the population, round the gene value and change the data type.change_gene_dtype_and_round(): Round the change the data type of a single gene.mutation_change_gene_dtype_and_round(): Decides whether mutation is done by replacement or not. Then it rounds and change the data type of the new gene value.validate_gene_constraint_callable_output(): Validates the output of the user-defined callable/function that checks whether the gene constraint defined in thegene_constraintparameter is satisfied or not.get_gene_dtype(): Returns the gene data type from thegene_typeinstance attribute.get_random_mutation_range(): Returns the random mutation range using therandom_mutation_min_valandrandom_mutation_min_valinstance attributes.get_initial_population_range(): Returns the initial population values range using theinit_range_lowandinit_range_highinstance attributes.generate_gene_value_from_space(): Generates/selects a value for a gene using thegene_spaceinstance attribute.generate_gene_value_randomly(): Generates a random value for the gene. Only used ifgene_spaceisNone.generate_gene_value(): Generates a value for the gene. It checks whethergene_spaceisNoneand calls eithergenerate_gene_value_randomly()orgenerate_gene_value_from_space().filter_gene_values_by_constraint(): Receives a list of values for a gene. Then it filters such values using the gene constraint.get_valid_gene_constraint_values(): Selects one valid gene value that satisfy the gene constraint. It simply callsgenerate_gene_value()to generate some gene values then it filters such values usingfilter_gene_values_by_constraint().