GeneticAlgorithmPython

Source code of PyGAD, a Python 3 library for building the genetic algorithm and training machine learning algorithms (Keras & PyTorch).

BSD-3-CLAUSE License

Downloads
93.2K
Stars
1.7K
Committers
23

Bot releases are hidden (Show)

GeneticAlgorithmPython - PyGAD 3.3.1 Latest Release

Published by ahmedfgad 8 months ago

  1. After the last generation and before the run() method completes, update the 2 instance attributes: 1) last_generation_parents 2) last_generation_parents_indices. This is to keep the list of parents up-to-date with the latest population fitness last_generation_fitness. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/275
  2. 4 methods with names starting with run_. Their purpose is to keep the main loop inside the run() method clean. Check the [Other Methods](https://pygad.readthedocs.io/en/latest/pygad.html#other-methods) section for more information.
GeneticAlgorithmPython - PyGAD-3.3.0

Published by ahmedfgad 9 months ago

Release Date 29 January 2024

  1. Solve bugs when multi-objective optimization is used. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/238
  2. When the stop_ciiteria parameter is used with the reach keyword, then multiple numeric values can be passed when solving a multi-objective problem. For example, if a problem has 3 objective functions, then stop_criteria="reach_10_20_30" means the GA stops if the fitness of the 3 objectives are at least 10, 20, and 30, respectively. The number values must match the number of objective functions. If a single value found (e.g. stop_criteria=reach_5) when solving a multi-objective problem, then it is used across all the objectives. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/238
  3. The delay_after_gen parameter is now deprecated and will be removed in a future release. If it is necessary to have a time delay after each generation, then assign a callback function/method to the on_generation parameter to pause the evolution.
  4. Parallel processing now supports calculating the fitness during adaptive mutation. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/201
  5. The population size can be changed during runtime by changing all the parameters that would affect the size of any thing used by the GA. For more information, check the [Change Population Size during Runtime](https://pygad.readthedocs.io/en/latest/pygad_more.html#change-population-size-during-runtime) section. https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/234
  6. When a dictionary exists in the gene_space parameter without a step, then mutation occurs by adding a random value to the gene value. The random vaue is generated based on the 2 parameters random_mutation_min_val and random_mutation_max_val. For more information, check the [How Mutation Works with the gene_space Parameter?](https://pygad.readthedocs.io/en/latest/pygad_more.html#how-mutation-works-with-the-gene-space-parameter) section. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/229
  7. Add object as a supported data type for int (GA.supported_int_types) and float (GA.supported_float_types). https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/174
  8. Use the raise clause instead of the sys.exit(-1) to terminate the execution. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/213
  9. Fix a bug when multi-objective optimization is used with batch fitness calculation (e.g. fitness_batch_size set to a non-zero number).
  10. Fix a bug in the pygad.py script when finding the index of the best solution. It does not work properly with multi-objective optimization where self.best_solutions_fitness have multiple columns.
         self.best_solution_generation = numpy.where(numpy.array(
             self.best_solutions_fitness) == numpy.max(numpy.array(self.best_solutions_fitness)))[0][0]

GeneticAlgorithmPython - PyGAD-3.2.0

Published by ahmedfgad about 1 year ago

  1. A new module pygad.utils.nsga2 is created that has the NSGA2 class that includes the functionalities of NSGA-II. The class has these methods: 1) get_non_dominated_set() 2) non_dominated_sorting() 3) crowding_distance() 4) sort_solutions_nsga2(). Check [this section](https://pygad.readthedocs.io/en/latest/pygad_more.html#multi-objective-optimization) for an example.
  2. Support of multi-objective optimization using Non-Dominated Sorting Genetic Algorithm II (NSGA-II) using the NSGA2 class in the pygad.utils.nsga2 module. Just return a list, tuple, or numpy.ndarray from the fitness function and the library will consider the problem as multi-objective optimization. All the objectives are expected to be maximization. Check [this section](https://pygad.readthedocs.io/en/latest/pygad_more.html#multi-objective-optimization) for an example.
  3. The parent selection methods and adaptive mutation are edited to support multi-objective optimization.
  4. Two new NSGA-II parent selection methods are supported in the pygad.utils.parent_selection module: 1) Tournament selection for NSGA-II 2) NSGA-II selection.
  5. The plot_fitness() method in the pygad.plot module has a new optional parameter named label to accept the label of the plots. This is only used for multi-objective problems. Otherwise, it is ignored. It defaults to None and accepts a list, tuple, or numpy.ndarray. The labels are used in a legend inside the plot.
  6. The default color in the methods of the pygad.plot module is changed to the greenish #64f20c color.
  7. A new instance attribute named pareto_fronts added to the pygad.GA instances that holds the pareto fronts when solving a multi-objective problem.
  8. The gene_type accepts a list, tuple, or numpy.ndarray for integer data types given that the precision is set to None (e.g. gene_type=[float, [int, None]]).
  9. In the cal_pop_fitness() method, the fitness value is re-used if save_best_solutions=True and the solution is found in the best_solutions attribute. These parameters also can help re-using the fitness of a solution instead of calling the fitness function: keep_elitism, keep_parents, and save_solutions.
  10. The value 99999999999 is replaced by float('inf') in the 2 methods wheel_cumulative_probs() and stochastic_universal_selection() inside the pygad.utils.parent_selection.ParentSelection class.
  11. The plot_result() method in the pygad.visualize.plot.Plot class is removed. Instead, please use the plot_fitness() if you did not upgrade yet.
GeneticAlgorithmPython - PyGAD-3.1.0

Published by ahmedfgad over 1 year ago

Release Date 20 June 2023

  1. Fix a bug when the initial population has duplciate genes if a nested gene space is used.
  2. The gene_space parameter can no longer be assigned a tuple.
  3. Fix a bug when the gene_space parameter has a member of type tuple.
  4. A new instance attribute called gene_space_unpacked which has the unpacked gene_space. It is used to solve duplicates. For infinite ranges in the gene_space, they are unpacked to a limited number of values (e.g. 100).
  5. Bug fixes when creating the initial population using gene_space attribute.
  6. When a dict is used with the gene_space attribute, the new gene value was calculated by summing 2 values: 1) the value sampled from the dict 2) a random value returned from the random mutation range defined by the 2 parameters random_mutation_min_val and random_mutation_max_val. This might cause the gene value to exceed the range limit defined in the gene_space. To respect the gene_space range, this release only returns the value from the dict without summing it to a random value.
  7. Formatting the strings using f-string instead of the format() method. https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/189
  8. In the __init__() of the pygad.GA class, the logged error messages are handled using a try-except block instead of repeating the logger.error() command. https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/189
  9. A new class named CustomLogger is created in the pygad.cnn module to create a default logger using the logging module assigned to the logger attribute. This class is extended in all other classes in the module. The constructors of these classes have a new parameter named logger which defaults to None. If no logger is passed, then the default logger in the CustomLogger class is used.
  10. Except for the pygad.nn module, the print() function in all other modules are replaced by the logging module to log messages.
  11. The callback functions/methods on_fitness(), on_parents(), on_crossover(), and on_mutation() can return values. These returned values override the corresponding properties. The output of on_fitness() overrides the population fitness. The on_parents() function/method must return 2 values representing the parents and their indices. The output of on_crossover() overrides the crossover offspring. The output of on_mutation() overrides the mutation offspring.
  12. Fix a bug when adaptive mutation is used while fitness_batch_size>1. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/195
  13. When allow_duplicate_genes=False and a user-defined gene_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.
  14. Use probabilities to select parents using the rank parent selection method. https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/205
  15. The 2 parameters random_mutation_min_val and random_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. https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/198
  16. The 2 parameters init_range_low and init_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.
  17. The data parameter in the predict() function of the pygad.kerasga module can be assigned a data generator. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/115 https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/207
  18. The predict() function of the pygad.kerasga module accepts 3 optional parameters: 1) batch_size=None, verbose=0, and steps=None. Check documentation of the [Keras Model.predict()](https://keras.io/api/models/model_training_apis) method for more information. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/207
  19. The documentation is updated to explain how mutation works when gene_space is used with int or float data types. Check [this section](https://pygad.readthedocs.io/en/latest/pygad.html#limit-the-gene-value-range-using-the-gene-space-parameter). https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/198
GeneticAlgorithmPython - PyGAD-3.0.1

Published by ahmedfgad over 1 year ago

Fix an issue with passing user-defined function/method for parent selection. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/179

GeneticAlgorithmPython - PyGAD-3.0.0

Published by ahmedfgad over 1 year ago

This release has a major change where the fitness function accepts a mandatory parameter referring to the instance of the pygad.GA class.

This is the release notes:

  1. The structure of the library is changed and some methods defined in the pygad.py module are moved to the pygad.utils, pygad.helper, and pygad.visualize submodules.
  2. The pygad.utils.parent_selection module has a class named ParentSelection where all the parent selection operators exist. The pygad.GA class extends this class.
  3. The pygad.utils.crossover module has a class named Crossover where all the crossover operators exist. The pygad.GA class extends this class.
  4. The pygad.utils.mutation module has a class named Mutation where all the mutation operators exist. The pygad.GA class extends this class.
  5. The pygad.helper.unique module has a class named Unique some helper methods exist to solve duplicate genes and make sure every gene is unique. The pygad.GA class extends this class.
  6. The pygad.visualize.plot module has a class named Plot where all the methods that create plots exist. The pygad.GA class extends this class.
...
class GA(utils.parent_selection.ParentSelection, 
         utils.crossover.Crossover, 
         utils.mutation.Mutation, 
         helper.unique.Unique,
         visualize.plot.Plot):
...
  1. Support of using the logging module to log the outputs to both the console and text file instead of using the print() function. This is by assigning the logging.Logger to the new logger parameter. Check the [Logging Outputs](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#logging-outputs) for more information.
  2. A new instance attribute called logger to save the logger.
  3. The function/method passed to the fitness_func parameter accepts a new parameter that refers to the instance of the pygad.GA class. Check this for an example: [Use Functions and Methods to Build Fitness Function and Callbacks](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#use-functions-and-methods-to-build-fitness-and-callbacks). https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/163
  4. Update the documentation to include an example of using functions and methods to calculate the fitness and build callbacks. Check this for more details: [Use Functions and Methods to Build Fitness Function and Callbacks](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#use-functions-and-methods-to-build-fitness-and-callbacks). https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/92#issuecomment-1443635003
  5. Validate the value passed to the initial_population parameter.
  6. Validate the type and length of the pop_fitness parameter of the best_solution() method.
  7. Some edits in the documentation. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/106
  8. Fix an issue when building the initial population as (some) genes have their value taken from the mutation range (defined by the parameters random_mutation_min_val and random_mutation_max_val) instead of using the parameters init_range_low and init_range_high.
  9. The summary() method returns the summary as a single-line string. Just log/print the returned string it to see it properly.
  10. The callback_generation parameter is removed. Use the on_generation parameter instead.
  11. There was an issue when using the parallel_processing parameter with Keras and PyTorch. As Keras/PyTorch are not thread-safe, the predict() method gives incorrect and weird results when more than 1 thread is used. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/145 https://github.com/ahmedfgad/TorchGA/issues/5 https://github.com/ahmedfgad/KerasGA/issues/6. Thanks to this [StackOverflow answer](https://stackoverflow.com/a/75606666/5426539).
  12. Replace numpy.float by float in the 2 parent selection operators roulette wheel and stochastic universal. https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/168
GeneticAlgorithmPython - PyGAD-2.19.2

Published by ahmedfgad over 1 year ago

  1. Fix an issue when paralell processing was used where the elitism solutions' fitness values are not re-used. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/160#issuecomment-1441718184
GeneticAlgorithmPython - PyGAD-2.19.1

Published by ahmedfgad over 1 year ago

  1. A new summary() method is supported to return a Keras-like summary of the PyGAD lifecycle.
  2. A new optional parameter called fitness_batch_size is supported to calculate the fitness function in batches. If it is assigned the value 1 or None (default), then the normal flow is used where the fitness function is called for each individual solution. If the fitness_batch_size parameter is assigned a value satisfying this condition 1 < fitness_batch_size <= sol_per_pop, then the solutions are grouped into batches of size fitness_batch_size and the fitness function is called once for each batch. In this case, the fitness function must return a list/tuple/numpy.ndarray with a length equal to the number of solutions passed. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/136.
  3. The cloudpickle library (https://github.com/cloudpipe/cloudpickle) is used instead of the pickle library to pickle the pygad.GA objects. This solves the issue of having to redefine the functions (e.g. fitness function). The cloudpickle library is added as a dependancy in the requirements.txt file. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/159
  4. Support of assigning methods to these parameters: fitness_func, crossover_type, mutation_type, parent_selection_type, on_start, on_fitness, on_parents, on_crossover, on_mutation, on_generation, and on_stop. https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/92 https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/138
  5. Validating the output of the parent selection, crossover, and mutation functions.
  6. The built-in parent selection operators return the parent's indices as a NumPy array.
  7. The outputs of the parent selection, crossover, and mutation operators must be NumPy arrays.
  8. Fix an issue when allow_duplicate_genes=True. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/39
  9. Fix an issue creating scatter plots of the solutions' fitness.
  10. Sampling from a set() is no longer supported in Python 3.11. Instead, sampling happens from a list(). Thanks Marco Brenna for pointing to this issue.
  11. The lifecycle is updated to reflect that the new population's fitness is calculated at the end of the lifecycle not at the beginning. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/154#issuecomment-1438739483
  12. There was an issue when save_solutions=True that causes the fitness function to be called for solutions already explored and have their fitness pre-calculated. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/160
  13. A new instance attribute named last_generation_elitism_indices added to hold the indices of the selected elitism. This attribute helps to re-use the fitness of the elitism instead of calling the fitness function.
  14. Fewer calls to the best_solution() method which in turns saves some calls to the fitness function.
  15. Some updates in the documentation to give more details about the cal_pop_fitness() method. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/79#issuecomment-1439605442
GeneticAlgorithmPython - PyGAD-2.18.3

Published by ahmedfgad over 1 year ago

GeneticAlgorithmPython - PyGAD-2.18.2

Published by ahmedfgad over 1 year ago

PyGAD 2.18.2 release notes

  1. Remove numpy.int and numpy.float from the list of supported data types. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/151 https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/152
  2. Call the on_crossover() callback function even if crossover_type is None. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/138
  3. Call the on_mutation() callback function even if mutation_type is None. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/138
GeneticAlgorithmPython - PyGAD-2.18.1

Published by ahmedfgad about 2 years ago

PyGAD 2.18.1

  1. A big fix when keep_elitism is used. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/132
GeneticAlgorithmPython - PyGAD-2.18.0

Published by ahmedfgad about 2 years ago

  1. Raise an exception if the sum of fitness values is zero while either roulette wheel or stochastic universal parent selection is used. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/129
  2. Initialize the value of the run_completed property to False. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/122
  3. The values of these properties are no longer reset with each call to the run() method self.best_solutions, self.best_solutions_fitness, self.solutions, self.solutions_fitness: https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/123. Now, the user can have the flexibility of calling the run() method more than once while extending the data collected after each generation. Another advantage happens when the instance is loaded and the run() method is called, as the old fitness value are shown on the graph alongside with the new fitness values. Read more in this section: [Continue without Loosing Progress](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#continue-without-loosing-progress)
  4. Thanks [Prof. Fernando Jiménez Barrionuevo](http://webs.um.es/fernan) (Dept. of Information and Communications Engineering, University of Murcia, Murcia, Spain) for editing this [comment](https://github.com/ahmedfgad/GeneticAlgorithmPython/blob/5315bbec02777df96ce1ec665c94dece81c440f4/pygad.py#L73) in the code. https://github.com/ahmedfgad/GeneticAlgorithmPython/commit/5315bbec02777df96ce1ec665c94dece81c440f4
  5. A bug fixed when crossover_type=None.
  6. Support of elitism selection through a new parameter named keep_elitism. It defaults to 1 which means for each generation keep only the best solution in the next generation. If assigned 0, then it has no effect. Read more in this section: [Elitism Selection](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#elitism-selection). https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/74
  7. A new instance attribute named last_generation_elitism added to hold the elitism in the last generation.
  8. A new parameter called random_seed added to accept a seed for the random function generators. Credit to this issue https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/70 and [Prof. Fernando Jiménez Barrionuevo](http://webs.um.es/fernan). Read more in this section: [Random Seed](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#random-seed).
  9. Editing the pygad.TorchGA module to make sure the tensor data is moved from GPU to CPU. Thanks to Rasmus Johansson for opening this pull request: https://github.com/ahmedfgad/TorchGA/pull/2
GeneticAlgorithmPython - PyGAD-2.17.0

Published by ahmedfgad over 2 years ago

PyGAD 2.17.0

Release Date: 8 July 2022

  1. An issue is solved when the gene_space parameter is given a fixed value. e.g. gene_space=[range(5), 4]. The second gene's value is static (4) which causes an exception.
  2. Fixed the issue where the allow_duplicate_genes parameter did not work when mutation is disabled (i.e. mutation_type=None). This is by checking for duplicates after crossover directly. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/39
  3. Solve an issue in the tournament_selection() method as the indices of the selected parents were incorrect. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/89
  4. Reuse the fitness values of the previously explored solutions rather than recalculating them. This feature only works if save_solutions=True.
  5. Parallel processing is supported. This is by the introduction of a new parameter named parallel_processing in the constructor of the pygad.GA class. Thanks to [@windowshopr](https://github.com/windowshopr) for opening the issue [#78](https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/78) at GitHub. Check the [Parallel Processing in PyGAD](https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#parallel-processing-in-pygad) section for more information and examples.
GeneticAlgorithmPython - PyGAD-2.16.3

Published by ahmedfgad over 2 years ago

Changes in PyGAD 2.16.3

  1. A new instance attribute called previous_generation_fitness added in the pygad.GA class. It holds the fitness values of one generation before the fitness values saved in the last_generation_fitness.
  2. Issue in the cal_pop_fitness() method in getting the correct indices of the previous parents. This is solved by using the previous generation's fitness saved in the new attribute previous_generation_fitness to return the parents' fitness values. Thanks to Tobias Tischhauser (M.Sc. - [Mitarbeiter Institut EMS, Departement Technik, OST – Ostschweizer Fachhochschule, Switzerland](https://www.ost.ch/de/forschung-und-dienstleistungen/technik/systemtechnik/ems/team)) for detecting this bug.
  3. Validate the fitness value returned from the fitness function. An exception is raised if something is wrong. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/67
GeneticAlgorithmPython - PyGAD-2.16.1

Published by ahmedfgad about 3 years ago

  1. Reuse the fitness of previously explored solutions rather than recalculating them. This feature only works if save_solutions=True.
  2. The user can use the tqdm library to show a progress bar. https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/50
import pygad
import numpy
import tqdm

equation_inputs = [4,-2,3.5]
desired_output = 44

def fitness_func(solution, solution_idx):
    output = numpy.sum(solution * equation_inputs)
    fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
    return fitness

num_generations = 10000
with tqdm.tqdm(total=num_generations) as pbar:
    ga_instance = pygad.GA(num_generations=num_generations,
                           sol_per_pop=5,
                           num_parents_mating=2,
                           num_genes=len(equation_inputs),
                           fitness_func=fitness_func,
                           on_generation=lambda _: pbar.update(1))
    
    ga_instance.run()

ga_instance.plot_result()
  1. Solved the issue of unequal length between the solutions and solutions_fitness when the save_solutions parameter is set to True. Now, the fitness of the last population is appended to the solutions_fitness array. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/64
  2. There was an issue of getting the length of these 4 variables (solutions, solutions_fitness, best_solutions, and best_solutions_fitness) doubled after each call of the run() method. This is solved by resetting these variables at the beginning of the run() method. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/62
  3. Bug fixes when adaptive mutation is used (mutation_type="adaptive"). https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/65
GeneticAlgorithmPython - PyGAD-2.16.0

Published by ahmedfgad over 3 years ago

A user-defined function can be passed to the mutation_type, crossover_type, and parent_selection_type parameters in the pygad.GA class to create a custom mutation, crossover, and parent selection operators. Check the User-Defined Crossover, Mutation, and Parent Selection Operators section in the documentation: https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#user-defined-crossover-mutation-and-parent-selection-operators
The example_custom_operators.py script gives an example of building and using custom functions for the 3 operators.
https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/50

GeneticAlgorithmPython - PyGAD-2.15.1

Published by ahmedfgad over 3 years ago

Fix a bug when keep_parents is set to a positive integer. https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/49

GeneticAlgorithmPython - PyGAD-2.15.0

Published by ahmedfgad over 3 years ago

  1. Control the precision of all genes/individual genes. Thanks to Rainer for asking about this feature: https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/43#discussioncomment-763452
  2. A new attribute named last_generation_parents_indices holds the indices of the selected parents in the last generation.
  3. In adaptive mutation, no need to recalculate the fitness values of the parents selected in the last generation as these values can be returned based on the last_generation_fitness and last_generation_parents_indices attributes. This speeds-up the adaptive mutation.
  4. When a sublist has a value of None in the gene_space parameter (e.g. gene_space=[[1, 2, 3], [5, 6, None]]), then its value will be randomly generated for each solution rather than being generated once for all solutions. Previously, a value of None in a sublist of the gene_space parameter was identical across all solutions.
  5. The dictionary assigned to the gene_space parameter itself or one of its elements has a new key called "step" to specify the step of moving from the start to the end of the range specified by the 2 existing keys "low" and "high". An example is {"low": 0, "high": 30, "step": 2} to have only even values for the gene(s) starting from 0 to 30. For more information, check the More about the gene_space Parameter section. https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/48
  6. A new function called predict() is added in both the pygad.kerasga and pygad.torchga modules to make predictions. This makes it easier than using custom code each time a prediction is to be made.
  7. A new parameter called stop_criteria allows the user to specify one or more stop criteria to stop the evolution based on some conditions. Each criterion is passed as str which has a stop word. The current 2 supported words are reach and saturate. reach stops the run() method if the fitness value is equal to or greater than a given fitness value. An example for reach is "reach_40" which stops the evolution if the fitness is >= 40. saturate means stop the evolution if the fitness saturates for a given number of consecutive generations. An example for saturate is "saturate_7" which means stop the run() method if the fitness does not change for 7 consecutive generations. Thanks to Rainer for asking about this feature: https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/44
  8. A new bool parameter, defaults to False, named save_solutions is added to the constructor of the pygad.GA class. If True, then all solutions in each generation are appended into an attribute called solutions which is NumPy array.
  9. The plot_result() method is renamed to plot_fitness(). The users should migrate to the new name as the old name will be removed in the future.
  10. Four new optional parameters are added to the plot_fitness() function in the pygad.GA class which are font_size=14, save_dir=None, color="#3870FF", and plot_type="plot". Use font_size to change the font of the plot title and labels. save_dir accepts the directory to which the figure is saved. It defaults to None which means do not save the figure. color changes the color of the plot. plot_type changes the plot type which can be either "plot" (default), "scatter", or "bar". https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/47
  11. The default value of the title parameter in the plot_fitness() method is "PyGAD - Generation vs. Fitness" rather than "PyGAD - Iteration vs. Fitness".
  12. A new method named plot_new_solution_rate() creates, shows, and returns a figure showing the rate of new/unique solutions explored in each generation. It accepts the same parameters as in the plot_fitness() method. This method only works when save_solutions=True in the pygad.GA class's constructor.
  13. A new method named plot_genes() creates, shows, and returns a figure to show how each gene changes per each generation. It accepts similar parameters like the plot_fitness() method in addition to the graph_type, fill_color, and solutions parameters. The graph_type parameter can be either "plot" (default), "boxplot", or "histogram". fill_color accepts the fill color which works when graph_type is either "boxplot" or "histogram". solutions can be either "all" or "best" to decide whether all solutions or only best solutions are used.
  14. The gene_type parameter now supports controlling the precision of float data types. For a gene, rather than assigning just the data type like float, assign a list/tuple/numpy.ndarray with 2 elements where the first one is the type and the second one is the precision. For example, [float, 2] forces a gene with a value like 0.1234 to be 0.12. For more information, check the More about the gene_type Parameter section.
GeneticAlgorithmPython - PyGAD-2.14.3

Published by ahmedfgad over 3 years ago

Some bug fixes when setting the save_best_solutions parameter to True. Previously, the best solution for generation i was added into the best_solutions attribute at generation i+1. Now, the best_solutions attribute is updated by each solution at its exact generation.

GeneticAlgorithmPython - PyGAD-2.14.2

Published by ahmedfgad over 3 years ago

Some bug fixes when the gene_type parameter is nested. Thanks to Rainer Engel for opening a discussion to report this bug: https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/43#discussioncomment-763342

Rainer Engel helped a lot in suggesting new features and suggesting enhancements in 2.14.0 to 2.14.2 releases.

Package Rankings
Top 2.15% on Pypi.org
Badges
Extracted from project README
Downloads PyPI version PyGAD PyTest / Python 3.11 PyGAD PyTest / Python 3.10 PyGAD PyTest / Python 3.9 PyGAD PyTest / Python 3.8 PyGAD PyTest / Python 3.7 License Translation REUSE Genetic Algorithm Implementation in Python Introduction to Genetic Algorithm Building Neural Networks Python Training Neural Networks using Genetic Algorithm Python Building CNN in Python Derivation of CNN from FCNN
Related Projects