Skip to content

Commit 3f9e29e

Browse files
authored
PyGAD 2.15.0 Documentation
Changes in PyGAD 2.15.0 1. Control the precision of all genes/individual genes. Thanks to Rainer for asking about this feature: #43 (comment) 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. #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: #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". #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.
1 parent 9b4eee3 commit 3f9e29e

10 files changed

+1395
-675
lines changed

docs/source/Footer.rst

+119-53
Original file line numberDiff line numberDiff line change
@@ -248,61 +248,13 @@ Release date: 19 July 2020
248248
``pygad.GA`` class constructor. It is used to specify the possible
249249
values for each gene in case the user wants to restrict the gene
250250
values. It is useful if the gene space is restricted to a certain
251-
range or to discrete values. Thanks to `Prof. Tamer A.
251+
range or to discrete values. For more information, check the `More
252+
about the ``gene_space``
253+
Parameter <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#more-about-the-gene-space-parameter>`__
254+
section. Thanks to `Prof. Tamer A.
252255
Farrag <https://github.com/tfarrag2000>`__ for requesting this useful
253256
feature.
254257

255-
Assuming that all genes have the same global space which include the
256-
values 0.3, 5.2, -4, and 8, then those values can be assigned to the
257-
``gene_space`` parameter as a list, tuple, or range. Here is a list
258-
assigned to this parameter. By doing that, then the gene values are
259-
restricted to those assigned to the ``gene_space`` parameter.
260-
261-
.. code:: python
262-
263-
gene_space = [0.3, 5.2, -4, 8]
264-
265-
If some genes have different spaces, then ``gene_space`` should accept a
266-
nested list or tuple. In this case, its elements could be:
267-
268-
1. List, tuple, or range: It holds the individual gene space.
269-
270-
2. Number (int/float): A single value to be assigned to the gene. This
271-
means this gene will have the same value across all generations.
272-
273-
3. ``None``: A gene with its space set to ``None`` is initialized
274-
randomly from the range specified by the 2 parameters
275-
``init_range_low`` and ``init_range_high``. For mutation, its value
276-
is mutated based on a random value from the range specified by the 2
277-
parameters ``random_mutation_min_val`` and
278-
``random_mutation_max_val``. If all elements in the ``gene_space``
279-
parameter are ``None``, the parameter will not have any effect.
280-
281-
Assuming that a chromosome has 2 genes and each gene has a different
282-
value space. Then the ``gene_space`` could be assigned a nested
283-
list/tuple where each element determines the space of a gene. According
284-
to the next code, the space of the first gene is [0.4, -5] which has 2
285-
values and the space for the second gene is [0.5, -3.2, 8.8, -9] which
286-
has 4 values.
287-
288-
.. code:: python
289-
290-
gene_space = [[0.4, -5], [0.5, -3.2, 8.2, -9]]
291-
292-
For a 2 gene chromosome, if the first gene space is restricted to the
293-
discrete values from 0 to 4 and the second gene is restricted to the
294-
values from 10 to 19, then it could be specified according to the next
295-
code.
296-
297-
.. code:: python
298-
299-
gene_space = [range(5), range(10, 20)]
300-
301-
If the user did not assign the initial population to the
302-
``initial_population`` parameter, the initial population is created
303-
randomly based on the ``gene_space`` parameter. Moreover, the mutation
304-
is applied based on this parameter.
305-
306258
.. _pygad-260:
307259

308260
PyGAD 2.6.0
@@ -670,7 +622,10 @@ Release Date: 19 May 2021
670622
``list/tuple/numpy.ndarray`` of numeric data types for the genes.
671623
This helps to control the data type of each individual gene.
672624
Previously, the ``gene_type`` can be assigned only to a single data
673-
type that is applied for all genes. Thanks to `Rainer
625+
type that is applied for all genes. For more information, check the
626+
`More about the ``gene_type``
627+
Parameter <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#more-about-the-gene-type-parameter>`__
628+
section. Thanks to `Rainer
674629
Engel <https://www.linkedin.com/in/rainer-matthias-engel-5ba47a9>`__
675630
for asking about this feature in `this
676631
discussion <https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/43>`__:
@@ -731,6 +686,117 @@ Release Date: 6 June 2021
731686
Now, the ``best_solutions`` attribute is updated by each best
732687
solution at its exact generation.
733688

689+
.. _pygad-2150:
690+
691+
PyGAD 2.15.0
692+
------------
693+
694+
Release Date: 17 June 2021
695+
696+
1. Control the precision of all genes/individual genes. Thanks to
697+
`Rainer <https://github.com/rengel8>`__ for asking about this
698+
feature:
699+
https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/43#discussioncomment-763452
700+
701+
2. A new attribute named ``last_generation_parents_indices`` holds the
702+
indices of the selected parents in the last generation.
703+
704+
3. In adaptive mutation, no need to recalculate the fitness values of
705+
the parents selected in the last generation as these values can be
706+
returned based on the ``last_generation_fitness`` and
707+
``last_generation_parents_indices`` attributes. This speeds-up the
708+
adaptive mutation.
709+
710+
4. When a sublist has a value of ``None`` in the ``gene_space``
711+
parameter (e.g. ``gene_space=[[1, 2, 3], [5, 6, None]]``), then its
712+
value will be randomly generated for each solution rather than being
713+
generated once for all solutions. Previously, a value of ``None`` in
714+
a sublist of the ``gene_space`` parameter was identical across all
715+
solutions.
716+
717+
5. The dictionary assigned to the ``gene_space`` parameter itself or
718+
one of its elements has a new key called ``"step"`` to specify the
719+
step of moving from the start to the end of the range specified by
720+
the 2 existing keys ``"low"`` and ``"high"``. An example is
721+
``{"low": 0, "high": 30, "step": 2}`` to have only even values for
722+
the gene(s) starting from 0 to 30. For more information, check the
723+
`More about the ``gene_space``
724+
Parameter <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#more-about-the-gene-space-parameter>`__
725+
section.
726+
https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/48
727+
728+
6. A new function called ``predict()`` is added in both the
729+
``pygad.kerasga`` and ``pygad.torchga`` modules to make predictions.
730+
This makes it easier than using custom code each time a prediction
731+
is to be made.
732+
733+
7. A new parameter called ``stop_criteria`` allows the user to specify
734+
one or more stop criteria to stop the evolution based on some
735+
conditions. Each criterion is passed as ``str`` which has a stop
736+
word. The current 2 supported words are ``reach`` and ``saturate``.
737+
``reach`` stops the ``run()`` method if the fitness value is equal
738+
to or greater than a given fitness value. An example for ``reach``
739+
is ``"reach_40"`` which stops the evolution if the fitness is >= 40.
740+
``saturate`` means stop the evolution if the fitness saturates for a
741+
given number of consecutive generations. An example for ``saturate``
742+
is ``"saturate_7"`` which means stop the ``run()`` method if the
743+
fitness does not change for 7 consecutive generations. Thanks to
744+
`Rainer <https://github.com/rengel8>`__ for asking about this
745+
feature:
746+
https://github.com/ahmedfgad/GeneticAlgorithmPython/discussions/44
747+
748+
8. A new bool parameter, defaults to ``False``, named
749+
``save_solutions`` is added to the constructor of the ``pygad.GA``
750+
class. If ``True``, then all solutions in each generation are
751+
appended into an attribute called ``solutions`` which is NumPy
752+
array.
753+
754+
9. The ``plot_result()`` method is renamed to ``plot_fitness()``. The
755+
users should migrate to the new name as the old name will be removed
756+
in the future.
757+
758+
10. Four new optional parameters are added to the ``plot_fitness()``
759+
function in the ``pygad.GA`` class which are ``font_size=14``,
760+
``save_dir=None``, ``color="#3870FF"``, and ``plot_type="plot"``.
761+
Use ``font_size`` to change the font of the plot title and labels.
762+
``save_dir`` accepts the directory to which the figure is saved. It
763+
defaults to ``None`` which means do not save the figure. ``color``
764+
changes the color of the plot. ``plot_type`` changes the plot type
765+
which can be either ``"plot"`` (default), ``"scatter"``, or
766+
``"bar"``.
767+
https://github.com/ahmedfgad/GeneticAlgorithmPython/pull/47
768+
769+
11. The default value of the ``title`` parameter in the
770+
``plot_fitness()`` method is ``"PyGAD - Generation vs. Fitness"``
771+
rather than ``"PyGAD - Iteration vs. Fitness"``.
772+
773+
12. A new method named ``plot_new_solution_rate()`` creates, shows, and
774+
returns a figure showing the rate of new/unique solutions explored
775+
in each generation. It accepts the same parameters as in the
776+
``plot_fitness()`` method. This method only works when
777+
``save_solutions=True`` in the ``pygad.GA`` class's constructor.
778+
779+
13. A new method named ``plot_genes()`` creates, shows, and returns a
780+
figure to show how each gene changes per each generation. It accepts
781+
similar parameters like the ``plot_fitness()`` method in addition to
782+
the ``graph_type``, ``fill_color``, and ``solutions`` parameters.
783+
The ``graph_type`` parameter can be either ``"plot"`` (default),
784+
``"boxplot"``, or ``"histogram"``. ``fill_color`` accepts the fill
785+
color which works when ``graph_type`` is either ``"boxplot"`` or
786+
``"histogram"``. ``solutions`` can be either ``"all"`` or ``"best"``
787+
to decide whether all solutions or only best solutions are used.
788+
789+
14. The ``gene_type`` parameter now supports controlling the precision
790+
of ``float`` data types. For a gene, rather than assigning just the
791+
data type like ``float``, assign a
792+
``list``/``tuple``/``numpy.ndarray`` with 2 elements where the first
793+
one is the type and the second one is the precision. For example,
794+
``[float, 2]`` forces a gene with a value like ``0.1234`` to be
795+
``0.12``. For more information, check the `More about the
796+
``gene_type``
797+
Parameter <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#more-about-the-gene-type-parameter>`__
798+
section.
799+
734800
PyGAD Projects at GitHub
735801
========================
736802

0 commit comments

Comments
 (0)