Releases: ahmedfgad/GeneticAlgorithmPython
Releases · ahmedfgad/GeneticAlgorithmPython
PyGAD-2.19.1
- A new
summary()method is supported to return a Keras-like summary of the PyGAD lifecycle. - A new optional parameter called
fitness_batch_sizeis supported to calculate the fitness function in batches. If it is assigned the value1orNone(default), then the normal flow is used where the fitness function is called for each individual solution. If thefitness_batch_sizeparameter is assigned a value satisfying this condition1 < fitness_batch_size <= sol_per_pop, then the solutions are grouped into batches of sizefitness_batch_sizeand 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. #136. - The
cloudpicklelibrary (https://github.com/cloudpipe/cloudpickle) is used instead of thepicklelibrary to pickle thepygad.GAobjects. This solves the issue of having to redefine the functions (e.g. fitness function). Thecloudpicklelibrary is added as a dependancy in therequirements.txtfile. #159 - 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, andon_stop. #92 #138 - Validating the output of the parent selection, crossover, and mutation functions.
- The built-in parent selection operators return the parent's indices as a NumPy array.
- The outputs of the parent selection, crossover, and mutation operators must be NumPy arrays.
- Fix an issue when
allow_duplicate_genes=True. #39 - Fix an issue creating scatter plots of the solutions' fitness.
- Sampling from a
set()is no longer supported in Python 3.11. Instead, sampling happens from alist(). ThanksMarco Brennafor pointing to this issue. - The lifecycle is updated to reflect that the new population's fitness is calculated at the end of the lifecycle not at the beginning. #154 (comment)
- There was an issue when
save_solutions=Truethat causes the fitness function to be called for solutions already explored and have their fitness pre-calculated. #160 - A new instance attribute named
last_generation_elitism_indicesadded 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. - Fewer calls to the
best_solution()method which in turns saves some calls to the fitness function. - Some updates in the documentation to give more details about the
cal_pop_fitness()method. #79 (comment)
PyGAD-2.18.3
Update conf.py
PyGAD-2.18.2
PyGAD-2.18.1
PyGAD 2.18.1
- A big fix when
keep_elitismis used. #132
PyGAD-2.18.0
- Raise an exception if the sum of fitness values is zero while either roulette wheel or stochastic universal parent selection is used. #129
- Initialize the value of the
run_completedproperty toFalse. #122 - The values of these properties are no longer reset with each call to the
run()methodself.best_solutions, self.best_solutions_fitness, self.solutions, self.solutions_fitness: #123. Now, the user can have the flexibility of calling therun()method more than once while extending the data collected after each generation. Another advantage happens when the instance is loaded and therun()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) - 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. 5315bbe
- A bug fixed when
crossover_type=None. - 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). #74 - A new instance attribute named
last_generation_elitismadded to hold the elitism in the last generation. - A new parameter called
random_seedadded to accept a seed for the random function generators. Credit to this issue #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). - Editing the
pygad.TorchGAmodule to make sure the tensor data is moved from GPU to CPU. Thanks to Rasmus Johansson for opening this pull request: ahmedfgad/TorchGA#2
PyGAD-2.17.0
PyGAD 2.17.0
Release Date: 8 July 2022
- An issue is solved when the
gene_spaceparameter is given a fixed value. e.g. gene_space=[range(5), 4]. The second gene's value is static (4) which causes an exception. - Fixed the issue where the
allow_duplicate_genesparameter did not work when mutation is disabled (i.e.mutation_type=None). This is by checking for duplicates after crossover directly. #39 - Solve an issue in the
tournament_selection()method as the indices of the selected parents were incorrect. #89 - Reuse the fitness values of the previously explored solutions rather than recalculating them. This feature only works if
save_solutions=True. - Parallel processing is supported. This is by the introduction of a new parameter named
parallel_processingin the constructor of thepygad.GAclass. Thanks to [@windowshopr](https://github.com/windowshopr) for opening the issue [#78](#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.
PyGAD-2.16.3
Changes in PyGAD 2.16.3
- A new instance attribute called
previous_generation_fitnessadded in thepygad.GAclass. It holds the fitness values of one generation before the fitness values saved in thelast_generation_fitness. - 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 attributeprevious_generation_fitnessto 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. - Validate the fitness value returned from the fitness function. An exception is raised if something is wrong. #67
PyGAD-2.16.1
- Reuse the fitness of previously explored solutions rather than recalculating them. This feature only works if
save_solutions=True. - The user can use the
tqdmlibrary to show a progress bar. #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()- Solved the issue of unequal length between the
solutionsandsolutions_fitnesswhen thesave_solutionsparameter is set toTrue. Now, the fitness of the last population is appended to thesolutions_fitnessarray. #64 - There was an issue of getting the length of these 4 variables (
solutions,solutions_fitness,best_solutions, andbest_solutions_fitness) doubled after each call of therun()method. This is solved by resetting these variables at the beginning of therun()method. #62 - Bug fixes when adaptive mutation is used (
mutation_type="adaptive"). #65
PyGAD-2.16.0
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.
#50
PyGAD-2.15.1
Fix a bug when keep_parents is set to a positive integer. #49