PyGAD-3.1.0
Release Date 20 June 2023
- Fix a bug when the initial population has duplciate genes if a nested gene space is used.
- The
gene_space
parameter can no longer be assigned a tuple. - Fix a bug when the
gene_space
parameter has a member of typetuple
. - A new instance attribute called
gene_space_unpacked
which has the unpackedgene_space
. It is used to solve duplicates. For infinite ranges in thegene_space
, they are unpacked to a limited number of values (e.g. 100). - Bug fixes when creating the initial population using
gene_space
attribute. - When a
dict
is used with thegene_space
attribute, the new gene value was calculated by summing 2 values: 1) the value sampled from thedict
2) a random value returned from the random mutation range defined by the 2 parametersrandom_mutation_min_val
andrandom_mutation_max_val
. This might cause the gene value to exceed the range limit defined in thegene_space
. To respect thegene_space
range, this release only returns the value from thedict
without summing it to a random value. - Formatting the strings using f-string instead of the
format()
method. #189 - In the
__init__()
of thepygad.GA
class, the logged error messages are handled using atry-except
block instead of repeating thelogger.error()
command. #189 - A new class named
CustomLogger
is created in thepygad.cnn
module to create a default logger using thelogging
module assigned to thelogger
attribute. This class is extended in all other classes in the module. The constructors of these classes have a new parameter namedlogger
which defaults toNone
. If no logger is passed, then the default logger in theCustomLogger
class is used. - Except for the
pygad.nn
module, theprint()
function in all other modules are replaced by thelogging
module to log messages. - The callback functions/methods
on_fitness()
,on_parents()
,on_crossover()
, andon_mutation()
can return values. These returned values override the corresponding properties. The output ofon_fitness()
overrides the population fitness. Theon_parents()
function/method must return 2 values representing the parents and their indices. The output ofon_crossover()
overrides the crossover offspring. The output ofon_mutation()
overrides the mutation offspring. - Fix a bug when adaptive mutation is used while
fitness_batch_size
>1. #195 - When
allow_duplicate_genes=False
and a user-definedgene_space
is used, it sometimes happen that there is no room to solve the duplicates between the 2 genes by simply replacing the value of one gene by another gene. This release tries to solve such duplicates by looking for a third gene that will help in solving the duplicates. These examples explain how it works. Check [this section](https://pygad.readthedocs.io/en/latest/pygad.html#prevent-duplicates-in-gene-values) for more information. - Use probabilities to select parents using the rank parent selection method. #205
- The 2 parameters
random_mutation_min_val
andrandom_mutation_max_val
can accept iterables (list/tuple/numpy.ndarray) with length equal to the number of genes. This enables customizing the mutation range for each individual gene. #198 - The 2 parameters
init_range_low
andinit_range_high
can accept iterables (list/tuple/numpy.ndarray) with length equal to the number of genes. This enables customizing the initial range for each individual gene when creating the initial population. - The
data
parameter in thepredict()
function of thepygad.kerasga
module can be assigned a data generator. #115 #207 - The
predict()
function of thepygad.kerasga
module accepts 3 optional parameters: 1)batch_size=None
,verbose=0
, andsteps=None
. Check documentation of the [Keras Model.predict()](https://keras.io/api/models/model_training_apis) method for more information. #207 - The documentation is updated to explain how mutation works when
gene_space
is used withint
orfloat
data types. Check [this section](https://pygad.readthedocs.io/en/latest/pygad.html#limit-the-gene-value-range-using-the-gene-space-parameter). #198