Skip to content

Commit c4aa825

Browse files
committed
Fitness func not called for idx 0
1 parent 8a6970a commit c4aa825

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/source/pygad.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,6 +4237,48 @@ It accepts an integer and defaults to -1. It set to ``-1`` or a positive
42374237
integer, then it keeps the parents of one generation available in the
42384238
next generation.
42394239

4240+
Why the Fitness Function is not Called for Solution at Index 0?
4241+
===============================================================
4242+
4243+
PyGAD has a parameter called ``keep_elitism`` which defaults to 1. This
4244+
parameter defines the number of best solutions in generation **X** to
4245+
keep in the next generation **X+1**. The best solutions are just copied
4246+
from generation **X** to generation **X+1** without making any change.
4247+
4248+
.. code:: python
4249+
4250+
ga_instance = pygad.GA(...,
4251+
keep_elitism=1,
4252+
...)
4253+
4254+
The best solutions are copied at the beginning of the population. If
4255+
``keep_elitism=1``, this means the best solution in generation X is kept
4256+
in the next generation X+1 at index 0 of the population. If
4257+
``keep_elitism=2``, this means the 2 best solutions in generation X are
4258+
kept in the next generation X+1 at indices 0 and 1 of the population of
4259+
generation 1.
4260+
4261+
Because the fitness of these best solutions are already calculated in
4262+
generation X, then their fitness values will not be recalculated at
4263+
generation X+1 (i.e. the fitness function will not be called for these
4264+
solutions again). Instead, their fitness values are just reused. This is
4265+
why you see that no solution with index 0 is passed to the fitness
4266+
function.
4267+
4268+
To force calling the fitness function for each solution in every
4269+
generation, consider setting ``keep_elitism`` and ``keep_parents`` to 0.
4270+
Moreover, keep the 2 parameters ``save_solutions`` and
4271+
``save_best_solutions`` to their default value ``False``.
4272+
4273+
.. code:: python
4274+
4275+
ga_instance = pygad.GA(...,
4276+
keep_elitism=0,
4277+
keep_parents=0,
4278+
save_solutions=False,
4279+
save_best_solutions=False,
4280+
...)
4281+
42404282
Batch Fitness Calculation
42414283
=========================
42424284

0 commit comments

Comments
 (0)