-
Based on my understanding so far, one can calculate the number of total fitness function calls by multiplying the number of solutions per population with the number of generations plus the function calls for an initial population. So with a sol_per_pop = 50 and num_generations = 20, I would expect 50 + 21 *49 = 1079 fitness function calls in total. But by printing a message every time the fitness function is called, I noticed that the total count amounts to 2059 function calls. In another case, the object returned 8 completed generations and the cost function was called 932 times not my expected 491 times. My implementation is like this:
Any help, on how to calculate the total number of function calls is greatly appreciated or why I might see different call numbers than exspected. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @TiMo3654, The reason for doubling the number of calls to the fitness function is calling the def check_for_termination(ga_instance):
if ga_instance.best_solution()[1] == np.float64(-0.0):
return "stop" When this method is called without passing the As you have 50 solutions, then one call to the In PyGAD, the fitness of the current population is already calculated and saved in the def check_for_termination(ga_instance):
if ga_instance.best_solution(pop_fitness=ga_instance.last_generation_fitness)[1] == np.float64(-0.0):
return "stop" Hope this helps. Please let me know if you have any other questions. |
Beta Was this translation helpful? Give feedback.
Hi @TiMo3654,
The reason for doubling the number of calls to the fitness function is calling the
best_solution()
method in the generation callback function.When this method is called without passing the
pop_fitness
parameter, then it works as by calculating the fitness of the current population by calling the fitness function.As you have 50 solutions, then one call to the
best_solution()
method makes 50 calls to the fitness function. For 20 generations, then it makes50*20
calls. So, the overall total number of calls is50*20 + 50*20 + 50 = 2050
.In PyGAD, the fitn…