Releases: ahmedfgad/GeneticAlgorithmPython
PyGAD-2.15.0
- Control the precision of all genes/individual genes. Thanks to Rainer for asking about this feature: #43 (comment)
- A new attribute named
last_generation_parents_indicesholds the indices of the selected parents in the last generation. - 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_fitnessandlast_generation_parents_indicesattributes. This speeds-up the adaptive mutation. - When a sublist has a value of
Nonein thegene_spaceparameter (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 ofNonein a sublist of thegene_spaceparameter was identical across all solutions. - The dictionary assigned to the
gene_spaceparameter 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 thegene_spaceParameter section. #48 - A new function called
predict()is added in both thepygad.kerasgaandpygad.torchgamodules to make predictions. This makes it easier than using custom code each time a prediction is to be made. - A new parameter called
stop_criteriaallows the user to specify one or more stop criteria to stop the evolution based on some conditions. Each criterion is passed asstrwhich has a stop word. The current 2 supported words arereachandsaturate.reachstops therun()method if the fitness value is equal to or greater than a given fitness value. An example forreachis"reach_40"which stops the evolution if the fitness is >= 40.saturatemeans stop the evolution if the fitness saturates for a given number of consecutive generations. An example forsaturateis"saturate_7"which means stop therun()method if the fitness does not change for 7 consecutive generations. Thanks to Rainer for asking about this feature: #44 - A new bool parameter, defaults to
False, namedsave_solutionsis added to the constructor of thepygad.GAclass. IfTrue, then all solutions in each generation are appended into an attribute calledsolutionswhich is NumPy array. - The
plot_result()method is renamed toplot_fitness(). The users should migrate to the new name as the old name will be removed in the future. - Four new optional parameters are added to the
plot_fitness()function in thepygad.GAclass which arefont_size=14,save_dir=None,color="#3870FF", andplot_type="plot". Usefont_sizeto change the font of the plot title and labels.save_diraccepts the directory to which the figure is saved. It defaults toNonewhich means do not save the figure.colorchanges the color of the plot.plot_typechanges the plot type which can be either"plot"(default),"scatter", or"bar". #47 - The default value of the
titleparameter in theplot_fitness()method is"PyGAD - Generation vs. Fitness"rather than"PyGAD - Iteration vs. Fitness". - 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 theplot_fitness()method. This method only works whensave_solutions=Truein thepygad.GAclass's constructor. - 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 theplot_fitness()method in addition to thegraph_type,fill_color, andsolutionsparameters. Thegraph_typeparameter can be either"plot"(default),"boxplot", or"histogram".fill_coloraccepts the fill color which works whengraph_typeis either"boxplot"or"histogram".solutionscan be either"all"or"best"to decide whether all solutions or only best solutions are used. - The
gene_typeparameter now supports controlling the precision offloatdata types. For a gene, rather than assigning just the data type likefloat, assign alist/tuple/numpy.ndarraywith 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 like0.1234to be0.12. For more information, check the More about thegene_typeParameter section.
PyGAD-2.14.3
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.
PyGAD-2.14.2
Some bug fixes when the gene_type parameter is nested. Thanks to Rainer Engel for opening a discussion to report this bug: #43 (reply in thread)
Rainer Engel helped a lot in suggesting new features and suggesting enhancements in 2.14.0 to 2.14.2 releases.
PyGAD-2.14.1
- Issue #40 is solved. Now, the
Nonevalue works with thecrossover_typeandmutation_typeparameters: #40 - The
gene_typeparameter supports accepting alist/tuple/numpy.ndarrayof numeric data types for the genes. This helps to control the data type of each individual gene. Previously, thegene_typecan be assigned only to a single data type that is applied for all genes. - A new
boolattribute namedgene_type_singleis added to thepygad.GAclass. It isTruewhen there is a single data type assigned to thegene_typeparameter. When thegene_typeparameter is assigned alist/tuple/numpy.ndarray, thengene_type_singleis set toFalse. - The
mutation_by_replacementflag now has no effect ifgene_spaceexists except for the genes withNonevalues. For example, forgene_space=[None, [5, 6]]themutation_by_replacementflag affects only the first gene which hasNonefor its value space. - When an element has a value of
Nonein thegene_spaceparameter (e.g.gene_space=[None, [5, 6]]), then its value will be randomly generated for each solution rather than being generate once for all solutions. Previously, the gene withNonevalue ingene_spaceis the same across all solutions - Some changes in the documentation according to issue #32: #32
PyGAD-2.13.0
PyGAD 2.13.0
Release Date: 12 March 2021
- A new
boolparameter calledallow_duplicate_genesis supported. IfTrue, which is the default, then a solution/chromosome may have duplicate gene values. IfFalse, then each gene will have a unique value in its solution. Check the Prevent Duplicates in Gene Values section for more details. - The
last_generation_fitnessis updated at the end of each generation not at the beginning. This keeps the fitness values of the most up-to-date population assigned to thelast_generation_fitnessparameter.
PyGAD-2.12.0
Release Date: 20 February 2021
- 4 new instance attributes are added to hold temporary results after each generation:
last_generation_fitnessholds the fitness values of the solutions in the last generation,last_generation_parentsholds the parents selected from the last generation,last_generation_offspring_crossoverholds the offspring generated after applying the crossover in the last generation, andlast_generation_offspring_mutationholds the offspring generated after applying the mutation in the last generation. You can access these attributes inside theon_generation()method for example. - A bug fixed when the
initial_populationparameter is used. The bug occurred due to a mismatch between the data type of the array assigned toinitial_populationand the gene type in thegene_typeattribute. Assuming that the array assigned to theinitial_populationparameter is((1, 1), (3, 3), (5, 5), (7, 7))which has typeint. Whengene_typeis set tofloat, then the genes will not be float but casted tointbecause the defined array hasinttype. The bug is fixed by forcing the array assigned toinitial_populationto have the data type in thegene_typeattribute. Check the issue at GitHub: #27
Thanks to Marios Giouvanakis, a PhD candidate in Electrical & Computer Engineer, Aristotle University of Thessaloniki (Αριστοτέλειο Πανεπιστήμιο Θεσσαλονίκης), Greece, for emailing me about these issues.
PyGAD-2.11.0
PyGAD 2.11.0
Release Date: 16 February 2021
- In the
gene_spaceargument, the user can use a dictionary to specify the lower and upper limits of the gene. This dictionary must have only 2 items with keyslowandhighto specify the low and high limits of the gene, respectively. This way, PyGAD takes care of not exceeding the value limits of the gene. For a problem with only 2 genes, then usinggene_space=[{'low': 1, 'high': 5}, {'low': 0.2, 'high': 0.81}]means the accepted values in the first gene start from 1 (inclusive) to 5 (exclusive) while the second one has values between 0.2 (inclusive) and 0.85 (exclusive). For more information, please check the Limit the Gene Value Range section of the documentation. - The
plot_result()method returns the figure so that the user can save it. - Bug fixes in copying elements from the gene space.
- For a gene with a set of discrete values (more than 1 value) in the
gene_spaceparameter like[0, 1], it was possible that the gene value may not change after mutation. That is if the current value is 0, then the randomly selected value could also be 0. Now, it is verified that the new value is changed. So, if the current value is 0, then the new value after mutation will not be 0 but 1.
PyGAD-2.10.2
A bug fix when save_best_solutions=True. Refer to this issue for more information: #25
PyGAD-2.10.1
Changes in PyGAD 2.10.1
- In the
gene_spaceparameter, anyNonevalue (regardless of its index or axis), is replaced by a randomly generated number based on the 3 parametersinit_range_low,init_range_high, andgene_type. So, theNonevalue in[..., None, ...]or[..., [..., None, ...], ...]are replaced with random values. This gives more freedom in building the space of values for the genes. - All the numbers passed to the
gene_spaceparameter are casted to the type specified in thegene_typeparameter. - The
numpy.uintdata type is supported for the parameters that accept integer values. - In the
pygad.kerasgamodule, themodel_weights_as_vector()function uses thetrainableattribute of the model's layers to only return the trainable weights in the network. So, only the trainable layers with theirtrainableattribute set toTrue(trainable=True), which is the default value, have their weights evolved. All non-trainable layers with thetrainableattribute set toFalse(trainable=False) will not be evolved. Thanks to Prof. Tamer A. Farrag for pointing about that at GitHub.
PyGAD-2.10.0
- Support of a new module
pygad.torchgato train PyTorch models using PyGAD. Check its documentation. - Support of adaptive mutation where the mutation rate is determined by the fitness value of each solution. Read the Adaptive Mutation section for more details. Also, read this paper: Libelli, S. Marsili, and P. Alba. "Adaptive mutation in genetic algorithms." Soft computing 4.2 (2000): 76-80.
- Before the
run()method completes or exits, the fitness value of the best solution in the current population is appended to thebest_solution_fitnesslist attribute. Note that the fitness value of the best solution in the initial population is already saved at the beginning of the list. So, the fitness value of the best solution is saved before the genetic algorithm starts and after it ends. - When the parameter
parent_selection_typeis set tosss(steady-state selection), then a warning message is printed if the value of thekeep_parentsparameter is set to 0. - More validations to the user input parameters.
- The default value of the
mutation_percent_genesis set to the string"default"rather than the integer 10. This change helps to know whether the user explicitly passed a value to themutation_percent_genesparameter or it is left to its default one. The"default"value is later translated into the integer 10. - The
mutation_percent_genesparameter is no longer accepting the value 0. It must be>0and<=100. - The built-in
warningsmodule is used to show warning messages rather than just using theprint()function. - A new
boolparameter calledsuppress_warningsis added to the constructor of thepygad.GAclass. It allows the user to control whether the warning messages are printed or not. It defaults toFalsewhich means the messages are printed. - A helper method called
adaptive_mutation_population_fitness()is created to calculate the average fitness value used in adaptive mutation to filter the solutions. - The
best_solution()method accepts a new optional parameter calledpop_fitness. It accepts a list of the fitness values of the solutions in the population. IfNone, then thecal_pop_fitness()method is called to calculate the fitness values of the population.