Skip to content

Releases: ahmedfgad/GeneticAlgorithmPython

PyGAD-2.7.2

14 Sep 16:51
ad3d443
Compare
Choose a tag to compare

Bug fix to support building and training regression neural networks with multiple outputs.

PyGAD-2.7.1

14 Sep 16:51
ad3d443
Compare
Choose a tag to compare

A bug fix when the problem_type argument is set to regression.

PyGAD-2.7.0

11 Sep 18:12
0342b13
Compare
Choose a tag to compare

Changes in PyGAD 2.7.0 (11 September 2020):

  1. The learning_rate parameter in the pygad.nn.train() function defaults to 0.01.
  2. Added support of building neural networks for regression using the new parameter named problem_type. It is added as a parameter to both pygad.nn.train() and pygad.nn.predict() functions. The value of this parameter can be either classification or regression to define the problem type. It defaults to classification.
  3. The activation function for a layer can be set to the string "None" to refer that there is no activation function at this layer. As a result, the supported values for the activation function are "sigmoid", "relu", "softmax", and "None".

To build a regression network using the pygad.nn module, just do the following:

  1. Set the problem_type parameter in the pygad.nn.train() and pygad.nn.predict() functions to the string "regression".
  2. Set the activation function for the output layer to the string "None". This sets no limits on the range of the outputs as it will be from -infinity to +infinity. If you are sure that all outputs will be nonnegative values, then use the ReLU function.

Check the documentation of the pygad.nn module for an example that builds a neural network for regression. The regression example is also available at this GitHub project: https://github.com/ahmedfgad/NumPyANN

To build and train a regression network using the pygad.gann module, do the following:

  1. Set the problem_type parameter in the pygad.nn.train() and pygad.nn.predict() functions to the string "regression".
  2. Set the output_activation parameter in the constructor of the pygad.gann.GANN class to "None".

Check the documentation of the pygad.gann module for an example that builds and trains a neural network for regression. The regression example is also available at this GitHub project: https://github.com/ahmedfgad/NeuralGenetic

To build a classification network, either ignore the problem_type parameter or set it to "classification" (default value). In this case, the activation function of the last layer can be set to any type (e.g. softmax).

PyGAD-2.6.0

06 Aug 13:43
13ac039
Compare
Choose a tag to compare

Release Date: 6 August 2020

  1. A bug fix in assigning the value to the initial_population parameter.
  2. A new parameter named gene_type is added to control the gene type. It can be either int or float. It has an effect only when the parameter gene_space is None.
  3. 7 new parameters that accept callback functions: on_start, on_fitness, on_parents, on_crossover, on_mutation, on_generation, and on_stop.

PyGAD-2.5.0

28 Jul 14:29
5be4751
Compare
Choose a tag to compare

Changes in PyGAD 2.5.0 - Release date: 19 July 2020

  1. 2 new optional parameters added to the constructor of the pygad.GA class which are crossover_probability and mutation_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 the crossover_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 the mutation_probability, then this gene is selected for mutation.
  2. A new optional parameter named linewidth is added to the plot_result() method to specify the width of the curve in the plot. It defaults to 3.0.
  3. 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.
  4. 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.
  5. A new optional parameter named gene_space as added to the pygad.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:

  1. List, tuple, or range: It holds the individual gene space.
  2. Number (int/float): A single value to be assigned to the gene. This means this gene will have the same value across all generations.
  3. None: A gene with its space set to None is initialized randomly from the range specified by the 2 parameters init_range_low and init_range_high. For mutation, its value is mutated based on a random value from the range specified by the 2 parameters random_mutation_min_val and random_mutation_max_val. If all elements in the gene_space parameter are None, 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.

PyGAD-2.4.0

06 Jul 14:47
043c7e3
Compare
Choose a tag to compare

Changes in PyGAD 2.4.0:

  1. A new parameter named delay_after_gen is added which accepts a non-negative number specifying the time in seconds to wait after a generation completes and before going to the next generation. It defaults to 0.0 which means no delay after the generation.
  2. The passed function to the callback_generation parameter of the pygad.GA class constructor can terminate the execution of the genetic algorithm if it returns the string stop. This causes the run() method to stop.

One important use case for that feature is to stop the genetic algorithm when a condition is met before passing though all the generations. The user may assigned a value of 100 to the num_generations parameter of the pygad.GA class constructor. Assuming that at generation 50, for example, a condition is met and the user wants to stop the execution before waiting the remaining 50 generations. To do that, just make the function passed to the callback_generation parameter to return the string stop.

Here is an example of a function to be passed to the callback_generation parameter which stops the execution if the fitness value 70 is reached. The value 70 might be the best possible fitness value. After being reached, then there is no need to pass through more generations because no further improvement is possible.

def func_generation(ga_instance):
    if ga_instance.best_solution()[1] >= 70:
        return "stop"

PyGAD-1.0.19

04 May 15:58
9be2205
Compare
Choose a tag to compare

Changes in PyGAD 1.0.19 (4 May 2020):

  • The attributes are moved from the class scope to the instance scope.
  • Raising a ValueError exception on passing incorrect values to the parameters.
  • Two new parameters are added (init_rand_high and init_rand_high) allowing the user to customize the range from which the genes values in the initial population are selected.
  • The code object __code__ of the passed fitness function is checked to ensure it has the right number of parameters.