Skip to content

Commit 6659d5d

Browse files
committed
PyGAD 3.0.0 Release
PyGAD 3.0.0 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. ```python ... class GA(utils.parent_selection.ParentSelection, utils.crossover.Crossover, utils.mutation.Mutation, helper.unique.Unique, visualize.plot.Plot): ... ``` 2. 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. 3. A new instance attribute called `logger` to save the logger. 4. 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). ahmedfgad#163 5. 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). ahmedfgad#92 (comment) 6. Validate the value passed to the `initial_population` parameter. 7. Validate the type and length of the `pop_fitness` parameter of the `best_solution()` method. 8. Some edits in the documentation. ahmedfgad#106 9. 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`. 10. The `summary()` method returns the summary as a single-line string. Just log/print the returned string it to see it properly. 11. The `callback_generation` parameter is removed. Use the `on_generation` parameter instead. 12. 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. ahmedfgad#145 ahmedfgad/TorchGA#5 ahmedfgad/KerasGA#6. Thanks to this [StackOverflow answer](https://stackoverflow.com/a/75606666/5426539). 13. Replace `numpy.float` by `float` in the 2 parent selection operators roulette wheel and stochastic universal. ahmedfgad#168
1 parent 30dd023 commit 6659d5d

18 files changed

+1359
-2590
lines changed

README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ The library is under active development and more features are added regularly. I
1414

1515
# Donation
1616

17-
For donattion:
18-
* By Card (recommended): https://donate.stripe.com/eVa5kO866elKgM0144
19-
* [Open Collective](https://opencollective.com/pygad): [opencollective.com/pygad](https://opencollective.com/pygad).
20-
* PayPal: Either this link: [paypal.me/ahmedfgad](https://paypal.me/ahmedfgad) or the e-mail address ahmed.f.gad@gmail.com.
17+
* [Credit/Debit Card](https://donate.stripe.com/eVa5kO866elKgM0144): https://donate.stripe.com/eVa5kO866elKgM0144
18+
* [Open Collective](https://opencollective.com/pygad): [opencollective.com/pygad](https://opencollective.com/pygad)
19+
* PayPal: Use either this link: [paypal.me/ahmedfgad](https://paypal.me/ahmedfgad) or the e-mail address ahmed.f.gad@gmail.com
20+
* Interac e-Transfer: Use e-mail address ahmed.f.gad@gmail.com
2121

2222
# Installation
2323

@@ -76,7 +76,7 @@ import numpy
7676
function_inputs = [4,-2,3.5,5,-11,-4.7]
7777
desired_output = 44
7878

79-
def fitness_func(solution, solution_idx):
79+
def fitness_func(ga_instance, solution, solution_idx):
8080
output = numpy.sum(solution*function_inputs)
8181
fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
8282
return fitness
@@ -164,7 +164,7 @@ What are the best values for the 6 weights (w1 to w6)? We are going to use the g
164164
function_inputs = [4,-2,3.5,5,-11,-4.7] # Function inputs.
165165
desired_output = 44 # Function output.
166166

167-
def fitness_func(solution, solution_idx):
167+
def fitness_func(ga_instance, solution, solution_idx):
168168
# Calculating the fitness value of each solution in the current population.
169169
# The fitness function calulates the sum of products between each input and its corresponding weight.
170170
output = numpy.sum(solution*function_inputs)
@@ -280,7 +280,7 @@ To start with coding the genetic algorithm, you can check the tutorial titled [*
280280
- [KDnuggets](https://www.kdnuggets.com/2018/04/building-convolutional-neural-network-numpy-scratch.html)
281281
- [Chinese Translation](http://m.aliyun.com/yunqi/articles/585741)
282282

283-
[This tutorial](https://www.linkedin.com/pulse/building-convolutional-neural-network-using-numpy-from-ahmed-gad) is prepared based on a previous version of the project but it still a good resource to start with coding CNNs.
283+
[This tutorial](https://www.linkedin.com/pulse/building-convolutional-neural-network-using-numpy-from-ahmed-gad)) is prepared based on a previous version of the project but it still a good resource to start with coding CNNs.
284284

285285
[![Building CNN in Python](https://user-images.githubusercontent.com/16560492/82431022-6c3a1200-9a8e-11ea-8f1b-b055196d76e3.png)](https://www.linkedin.com/pulse/building-convolutional-neural-network-using-numpy-from-ahmed-gad)
286286

@@ -331,4 +331,3 @@ If you used PyGAD, please consider adding a citation to the following paper abou
331331
* [KDnuggets](https://kdnuggets.com/author/ahmed-gad)
332332
* [TowardsDataScience](https://towardsdatascience.com/@ahmedfgad)
333333
* [GitHub](https://github.com/ahmedfgad)
334-

__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .pygad import * # Relative import.
22

3-
__version__ = "2.19.2"
3+
__version__ = "3.0.0"

docs/source/Footer.rst

+99-4
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ Release Date: 28 September 2021
852852
equation_inputs = [4,-2,3.5]
853853
desired_output = 44
854854
855-
def fitness_func(solution, solution_idx):
855+
def fitness_func(ga_instance, solution, solution_idx):
856856
output = numpy.sum(solution * equation_inputs)
857857
fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
858858
return fitness
@@ -891,7 +891,7 @@ progress bar.
891891
equation_inputs = [4,-2,3.5]
892892
desired_output = 44
893893
894-
def fitness_func(solution, solution_idx):
894+
def fitness_func(ga_instance, solution, solution_idx):
895895
output = numpy.sum(solution * equation_inputs)
896896
fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
897897
return fitness
@@ -1119,7 +1119,7 @@ Release Date: 22 February 2023
11191119
(https://github.com/cloudpipe/cloudpickle) is used instead of the
11201120
``pickle`` library to pickle the ``pygad.GA`` objects. This solves
11211121
the issue of having to redefine the functions (e.g. fitness
1122-
function). The ``cloudpickle`` library is added as a dependancy in
1122+
function). The ``cloudpickle`` library is added as a dependency in
11231123
the ``requirements.txt`` file.
11241124
https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/159
11251125

@@ -1185,12 +1185,107 @@ Release Date: 22 February 2023
11851185
PyGAD 2.19.2
11861186
------------
11871187

1188-
Release Data 23 February 2023
1188+
Release Date 23 February 2023
11891189

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

1194+
.. _pygad-300:
1195+
1196+
PyGAD 3.0.0
1197+
-----------
1198+
1199+
Release Date ... 2023
1200+
1201+
1. The structure of the library is changed and some methods defined in
1202+
the ``pygad.py`` module are moved to the ``pygad.utils``,
1203+
``pygad.helper``, and ``pygad.visualize`` submodules.
1204+
1205+
2. The ``pygad.utils.parent_selection`` module has a class named
1206+
``ParentSelection`` where all the parent selection operators exist.
1207+
1208+
3. The ``pygad.utils.crossover`` module has a class named ``Crossover``
1209+
where all the crossover operators exist.
1210+
1211+
4. The ``pygad.utils.mutation`` module has a class named ``Mutation``
1212+
where all the mutation operators exist.
1213+
1214+
5. The ``pygad.helper.unique`` module has a class named ``Unique`` some
1215+
helper methods exist to solve duplicate genes and make sure every
1216+
gene is unique.
1217+
1218+
6. | The ``pygad.visualize.plot`` module has a class named ``Plot``
1219+
where all the methods that create plots exist.
1220+
| The ``pygad.GA`` class extends all of these classes.
1221+
1222+
.. code:: python
1223+
1224+
...
1225+
class GA(utils.parent_selection.ParentSelection,
1226+
utils.crossover.Crossover,
1227+
utils.mutation.Mutation,
1228+
helper.unique.Unique,
1229+
visualize.plot.Plot):
1230+
...
1231+
1232+
1. Support of using the ``logging`` module to log the outputs to both
1233+
the console and text file instead of using the ``print()`` function.
1234+
This is by assigning the ``logging.Logger`` to the new ``logger``
1235+
parameter. Check the `Logging
1236+
Outputs <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#logging-outputs>`__
1237+
for more information.
1238+
1239+
2. A new instance attribute called ``logger`` to save the logger.
1240+
1241+
3. The function/method passed to the ``fitness_func`` parameter accepts
1242+
a new parameter that refers to the instance of the ``pygad.GA``
1243+
class. Check this for an example: `Use Functions and Methods to
1244+
Build Fitness Function and
1245+
Callbacks <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#use-functions-and-methods-to-build-fitness-and-callbacks>`__.
1246+
https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/163
1247+
1248+
4. Update the documentation to include an example of using functions
1249+
and methods to calculate the fitness and build callbacks. Check this
1250+
for more details: `Use Functions and Methods to Build Fitness
1251+
Function and
1252+
Callbacks <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#use-functions-and-methods-to-build-fitness-and-callbacks>`__.
1253+
https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/92#issuecomment-1443635003
1254+
1255+
5. Validate the value passed to the ``initial_population`` parameter.
1256+
1257+
6. Validate the type and length of the ``pop_fitness`` parameter of the
1258+
``best_solution()`` method.
1259+
1260+
7. Some edits in the documentation.
1261+
https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/106
1262+
1263+
8. Fix an issue when building the initial population as (some) genes
1264+
have their value taken from the mutation range (defined by the
1265+
parameters ``random_mutation_min_val`` and
1266+
``random_mutation_max_val``) instead of using the parameters
1267+
``init_range_low`` and ``init_range_high``.
1268+
1269+
9. The ``summary()`` method returns the summary as a single-line
1270+
string. Just log/print the returned string it to see it properly.
1271+
1272+
10. The ``callback_generation`` parameter is removed. Use the
1273+
``on_generation`` parameter instead.
1274+
1275+
11. There was an issue when using the ``parallel_processing`` parameter
1276+
with Keras and PyTorch. As Keras/PyTorch are not thread-safe, the
1277+
``predict()`` method gives incorrect and weird results when more
1278+
than 1 thread is used.
1279+
https://github.com/ahmedfgad/GeneticAlgorithmPython/issues/145
1280+
https://github.com/ahmedfgad/TorchGA/issues/5
1281+
https://github.com/ahmedfgad/KerasGA/issues/6. Thanks to this
1282+
`StackOverflow
1283+
answer <https://stackoverflow.com/a/75606666/5426539>`__.
1284+
1285+
12. Replace ``numpy.float`` by ``float`` in the 2 parent selection
1286+
operators roulette wheel and stochastic universal.
1287+
https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/168
1288+
11941289
PyGAD Projects at GitHub
11951290
========================
11961291

0 commit comments

Comments
 (0)