Skip to content

Commit de62f66

Browse files
authored
PyGAD 2.10.1 Documentation
1. In the `gene_space` parameter, any `None` value (regardless of its index or axis), is replaced by a randomly generated number based on the 3 parameters `init_range_low`, `init_range_high`, and `gene_type`. So, the `None` value in `[..., None, ...]` or `[..., [..., None, ...], ...]` are replaced with random values. This gives more freedom in building the space of values for the genes. 2. All the numbers passed to the `gene_space` parameter are casted to the type specified in the `gene_type` parameter. 3. The `numpy.uint` data type is supported for the parameters that accept integer values. 4. In the `pygad.kerasga` module, the `model_weights_as_vector()` function uses the `trainable` attribute of the model's layers to only return the trainable weights in the network. So, only the trainable layers with their `trainable` attribute set to `True` (`trainable=True`), which is the default value, have their weights evolved. All non-trainable layers with the `trainable` attribute set to `False` (`trainable=False`) will not be evolved. Thanks to [Prof. Tamer A. Farrag](https://github.com/tfarrag2000) for pointing about that at [GitHub](ahmedfgad/KerasGA#1).
1 parent 6deb2c0 commit de62f66

File tree

4 files changed

+66
-28
lines changed

4 files changed

+66
-28
lines changed

docs/source/Footer.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Release Date: 03 January 2021
461461

462462
2. Support of adaptive mutation where the mutation rate is determined
463463
by the fitness value of each solution. Read the `Adaptive
464-
Mutation <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#adaptive-mutation>`__
464+
Mutation <https://pygad.readthedocs.io/en/latest/README_pygad_torchga_ReadTheDocs.html#adaptive-mutation>`__
465465
section for more details. Also, read this paper: `Libelli, S.
466466
Marsili, and P. Alba. "Adaptive mutation in genetic algorithms."
467467
Soft computing 4.2 (2000):
@@ -509,6 +509,38 @@ Release Date: 03 January 2021
509509
``cal_pop_fitness()`` method is called to calculate the fitness
510510
values of the population.
511511

512+
.. _header-n698:
513+
514+
PyGAD 2.10.1
515+
------------
516+
517+
Release Date: 10 January 2021
518+
519+
1. In the ``gene_space`` parameter, any ``None`` value (regardless of
520+
its index or axis), is replaced by a randomly generated number based
521+
on the 3 parameters ``init_range_low``, ``init_range_high``, and
522+
``gene_type``. So, the ``None`` value in ``[..., None, ...]`` or
523+
``[..., [..., None, ...], ...]`` are replaced with random values.
524+
This gives more freedom in building the space of values for the
525+
genes.
526+
527+
2. All the numbers passed to the ``gene_space`` parameter are casted to
528+
the type specified in the ``gene_type`` parameter.
529+
530+
3. The ``numpy.uint`` data type is supported for the parameters that
531+
accept integer values.
532+
533+
4. In the ``pygad.kerasga`` module, the ``model_weights_as_vector()``
534+
function uses the ``trainable`` attribute of the model's layers to
535+
only return the trainable weights in the network. So, only the
536+
trainable layers with their ``trainable`` attribute set to ``True``
537+
(``trainable=True``), which is the default value, have their weights
538+
evolved. All non-trainable layers with the ``trainable`` attribute
539+
set to ``False`` (``trainable=False``) will not be evolved. Thanks to
540+
`Prof. Tamer A. Farrag <https://github.com/tfarrag2000>`__ for
541+
pointing about that at
542+
`GitHub <https://github.com/ahmedfgad/KerasGA/issues/1>`__.
543+
512544
.. _header-n554:
513545

514546
PyGAD Projects at GitHub

docs/source/README_pygad_ReadTheDocs.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ The ``pygad.GA`` class constructor supports the following parameters:
132132
be used unchanged in the next generation. ``Adaptive`` mutation is
133133
supported starting from PyGAD 2.10.0. For more information about
134134
adaptive mutation, go the the `Adaptive
135-
Mutation <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#adaptive-mutation>`__
135+
Mutation <https://pygad.readthedocs.io/en/latest/README_pygad_torchga_ReadTheDocs.html#adaptive-mutation>`__
136136
section. For example about using adaptive mutation, check the `Use
137137
Adaptive Mutation in
138-
PyGAD <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#use-adaptive-mutation-in-pygad>`__
138+
PyGAD <https://pygad.readthedocs.io/en/latest/README_pygad_torchga_ReadTheDocs.html#use-adaptive-mutation-in-pygad>`__
139139
section.
140140

141141
- ``mutation_probability=None``: The probability of selecting a gene

docs/source/README_pygad_kerasga_ReadTheDocs.rst

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _header-n0:
1+
.. _header-n194:
22

33
``pygad.kerasga`` Module
44
========================
@@ -25,7 +25,7 @@ The contents of this module are:
2525

2626
More details are given in the next sections.
2727

28-
.. _header-n13:
28+
.. _header-n207:
2929

3030
Steps Summary
3131
=============
@@ -45,7 +45,7 @@ follows:
4545

4646
6. Run the genetic algorithm.
4747

48-
.. _header-n28:
48+
.. _header-n222:
4949

5050
Create Keras Model
5151
==================
@@ -93,7 +93,7 @@ This is the same model created using the Functional API.
9393
9494
Feel free to add the layers of your choice.
9595

96-
.. _header-n44:
96+
.. _header-n238:
9797

9898
``pygad.kerasga.KerasGA`` Class
9999
===============================
@@ -103,7 +103,7 @@ an initial population for the genetic algorithm based on a Keras model.
103103
The constructor, methods, and attributes within the class are discussed
104104
in this section.
105105

106-
.. _header-n46:
106+
.. _header-n240:
107107

108108
``__init__()``
109109
--------------
@@ -116,7 +116,7 @@ parameters:
116116
- ``num_solutions``: Number of solutions in the population. Each
117117
solution has different parameters of the model.
118118

119-
.. _header-n53:
119+
.. _header-n247:
120120

121121
Instance Attributes
122122
-------------------
@@ -134,15 +134,15 @@ Here is a list of all instance attributes:
134134
- ``population_weights``: A nested list holding the weights of all
135135
solutions in the population.
136136

137-
.. _header-n63:
137+
.. _header-n257:
138138

139139
Methods in the ``KerasGA`` Class
140140
--------------------------------
141141

142142
This section discusses the methods available for instances of the
143143
``pygad.kerasga.KerasGA`` class.
144144

145-
.. _header-n65:
145+
.. _header-n259:
146146

147147
``create_population()``
148148
~~~~~~~~~~~~~~~~~~~~~~~
@@ -152,14 +152,14 @@ genetic algorithm as a list of solutions where each solution represents
152152
different model parameters. The list of networks is assigned to the
153153
``population_weights`` attribute of the instance.
154154

155-
.. _header-n67:
155+
.. _header-n261:
156156

157157
Functions in the ``pygad.kerasga`` Module
158158
=========================================
159159

160160
This section discusses the functions in the ``pygad.kerasga`` module.
161161

162-
.. _header-n69:
162+
.. _header-n263:
163163

164164
``pygad.kerasga.model_weights_as_vector()``
165165
--------------------------------------------
@@ -170,13 +170,19 @@ holding all model weights. The reason for representing the model weights
170170
as a vector is that the genetic algorithm expects all parameters of any
171171
solution to be in a 1D vector form.
172172

173+
This function filters the layers based on the ``trainable`` attribute to
174+
see whether the layer weights are trained or not. For each layer, if its
175+
``trainable=False``, then its weights will not be evolved using the
176+
genetic algorithm. Otherwise, it will be represented in the chromosome
177+
and evolved.
178+
173179
The function accepts the following parameters:
174180

175181
- ``model``: The Keras model.
176182

177183
It returns a 1D vector holding the model weights.
178184

179-
.. _header-n76:
185+
.. _header-n270:
180186

181187
``pygad.kerasga.model_weights_as_matrix()``
182188
-------------------------------------------
@@ -190,7 +196,7 @@ parameters:
190196

191197
It returns the restored model weights after reshaping the vector.
192198

193-
.. _header-n84:
199+
.. _header-n278:
194200

195201
Examples
196202
========
@@ -199,7 +205,7 @@ This section gives the complete code of some examples that build and
199205
train a Keras model using PyGAD. Each subsection builds a different
200206
network.
201207

202-
.. _header-n86:
208+
.. _header-n280:
203209

204210
Example 1: Regression Example
205211
-----------------------------
@@ -296,7 +302,7 @@ subsections discuss each part in the code.
296302
abs_error = mae(data_outputs, predictions).numpy()
297303
print("Absolute Error : ", abs_error)
298304
299-
.. _header-n89:
305+
.. _header-n283:
300306

301307
Create a Keras Model
302308
~~~~~~~~~~~~~~~~~~~~
@@ -328,7 +334,7 @@ The model can also be build using the Keras Sequential Model API.
328334
model.add(dense_layer1)
329335
model.add(output_layer)
330336
331-
.. _header-n94:
337+
.. _header-n288:
332338

333339
Create an Instance of the ``pygad.kerasga.KerasGA`` Class
334340
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -344,7 +350,7 @@ Change this number according to your needs.
344350
keras_ga = pygad.kerasga.KerasGA(model=model,
345351
num_solutions=10)
346352
347-
.. _header-n97:
353+
.. _header-n291:
348354

349355
Prepare the Training Data
350356
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -369,7 +375,7 @@ output.
369375
[1.3],
370376
[2.5]])
371377
372-
.. _header-n100:
378+
.. _header-n294:
373379

374380
Build the Fitness Function
375381
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -400,7 +406,7 @@ function to calculate the fitness value.
400406
401407
return solution_fitness
402408
403-
.. _header-n104:
409+
.. _header-n298:
404410

405411
Create an Instance of the ``pygad.GA`` Class
406412
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -435,7 +441,7 @@ accepts <https://pygad.readthedocs.io/en/latest/README_pygad_ReadTheDocs.html#in
435441
keep_parents=keep_parents,
436442
on_generation=callback_generation)
437443
438-
.. _header-n108:
444+
.. _header-n302:
439445

440446
Run the Genetic Algorithm
441447
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -508,7 +514,7 @@ The next code measures the trained model error.
508514
509515
Absolute Error : 0.013740465
510516
511-
.. _header-n124:
517+
.. _header-n318:
512518

513519
Example 2: XOR Binary Classification
514520
------------------------------------
@@ -679,7 +685,7 @@ Here is some information about the trained model. Its fitness value is
679685
680686
Accuracy : 1.0
681687
682-
.. _header-n144:
688+
.. _header-n338:
683689

684690
Example 3: Image Multi-Class Classification (Dense Layers)
685691
----------------------------------------------------------
@@ -789,7 +795,7 @@ cross entropy.
789795
cce = tensorflow.keras.losses.CategoricalCrossentropy()
790796
solution_fitness = 1.0 / (cce(data_outputs, predictions).numpy() + 0.00000001)
791797
792-
.. _header-n149:
798+
.. _header-n343:
793799

794800
Prepare the Training Data
795801
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -839,7 +845,7 @@ Here are some statistics about the trained model.
839845
Categorical Crossentropy : 0.23823906
840846
Accuracy : 0.9852192
841847
842-
.. _header-n164:
848+
.. _header-n358:
843849

844850
Example 4: Image Multi-Class Classification (Conv Layers)
845851
---------------------------------------------------------
@@ -974,7 +980,7 @@ each input sample is 100x100x3.
974980
975981
model = tensorflow.keras.Model(inputs=input_layer, outputs=output_layer)
976982
977-
.. _header-n170:
983+
.. _header-n364:
978984

979985
Prepare the Training Data
980986
~~~~~~~~~~~~~~~~~~~~~~~~~

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
author = 'Ahmed Fawzy Gad'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '2.10.0'
25+
release = '2.10.1'
2626

2727
master_doc = 'index'
2828

0 commit comments

Comments
 (0)