PyGAD-2.5.0
Changes in PyGAD 2.5.0 - Release date: 19 July 2020
- 2 new optional parameters added to the constructor of the
pygad.GA
class which arecrossover_probability
andmutation_probability
.
While applying the crossover operation, each parent has a random value generated between 0.0 and 1.0. If this random value is less than or equal to the value assigned to thecrossover_probability
parameter, then the parent is selected for the crossover operation.
For the mutation operation, a random value between 0.0 and 1.0 is generated for each gene in the solution. If this value is less than or equal to the value assigned to themutation_probability
, then this gene is selected for mutation. - A new optional parameter named
linewidth
is added to theplot_result()
method to specify the width of the curve in the plot. It defaults to 3.0. - Previously, the indices of the genes selected for mutation was randomly generated once for all solutions within the generation. Currently, the genes' indices are randomly generated for each solution in the population. If the population has 4 solutions, the indices are randomly generated 4 times inside the single generation, 1 time for each solution.
- Previously, the position of the point(s) for the single-point and two-points crossover was(were) randomly selected once for all solutions within the generation. Currently, the position(s) is(are) randomly selected for each solution in the population. If the population has 4 solutions, the position(s) is(are) randomly generated 4 times inside the single generation, 1 time for each solution.
- A new optional parameter named
gene_space
as added to thepygad.GA
class constructor. It is used to specify the possible values for each gene in case the user wants to restrict the gene values. It is useful if the gene space is restricted to a certain range or to discrete values.
Assuming that all genes have the same global space which include the values 0.3, 5.2, -4, and 8, then those values can be assigned to the gene_space
parameter as a list, tuple, or range. Here is a list assigned to this parameter. By doing that, then the gene values are restricted to those assigned to the gene_space
parameter.
gene_space = [0.3, 5.2, -4, 8]
If some genes have different spaces, then gene_space
should accept a nested list or tuple. In this case, its elements could be:
- List, tuple, or range: It holds the individual gene space.
- Number (int/float): A single value to be assigned to the gene. This means this gene will have the same value across all generations.
None
: A gene with its space set toNone
is initialized randomly from the range specified by the 2 parametersinit_range_low
andinit_range_high
. For mutation, its value is mutated based on a random value from the range specified by the 2 parametersrandom_mutation_min_val
andrandom_mutation_max_val
. If all elements in thegene_space
parameter areNone
, the parameter will not have any effect.
Assuming that a chromosome has 2 genes and each gene has a different value space. Then the gene_space
could be assigned a nested list/tuple where each element determines the space of a gene. According to the next code, the space of the first gene is [0.4, -5] which has 2 values and the space for the second gene is [0.5, -3.2, 8.8, -9] which has 4 values.
gene_space = [[0.4, -5], [0.5, -3.2, 8.2, -9]]
For a 2 gene chromosome, if the first gene space is restricted to the discrete values from 0 to 4 and the second gene is restricted to the values from 10 to 19, then it could be specified according to the next code.
gene_space = [range(5), range(10, 20)]
If the user did not assign the initial population to the initial_population
parameter, the initial population is created randomly based on the gene_space
parameter. Moreover, the mutation is applied based on this parameter.