Skip to content

Caculating the total number of fitness function calls #162

Answered by ahmedfgad
TiMo3654 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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 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 makes 50*20 calls. So, the overall total number of calls is 50*20 + 50*20 + 50 = 2050.

In PyGAD, the fitn…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TiMo3654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants