Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update all numpy.max to numpy.nanmax in pygad.py #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pygad.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ def run(self):
_, best_solution_fitness, _ = self.best_solution(pop_fitness=self.last_generation_fitness)
self.best_solutions_fitness.append(best_solution_fitness)

self.best_solution_generation = numpy.where(numpy.array(self.best_solutions_fitness) == numpy.max(numpy.array(self.best_solutions_fitness)))[0][0]
self.best_solution_generation = numpy.where(numpy.array(self.best_solutions_fitness) == numpy.nanmax(numpy.array(self.best_solutions_fitness)))[0][0]
# After the run() method completes, the run_completed flag is changed from False to True.
self.run_completed = True # Set to True only after the run() method completes gracefully.

Expand Down Expand Up @@ -1411,7 +1411,7 @@ def tournament_selection(self, fitness, num_parents):
for parent_num in range(num_parents):
rand_indices = numpy.random.randint(low=0.0, high=len(fitness), size=self.K_tournament)
K_fitnesses = fitness[rand_indices]
selected_parent_idx = numpy.where(K_fitnesses == numpy.max(K_fitnesses))[0][0]
selected_parent_idx = numpy.where(K_fitnesses == numpy.nanmax(K_fitnesses))[0][0]
parents_indices.append(selected_parent_idx)
parents[parent_num, :] = self.population[rand_indices[selected_parent_idx], :].copy()

Expand Down Expand Up @@ -3121,7 +3121,7 @@ def best_solution(self, pop_fitness=None):
if pop_fitness is None:
pop_fitness = self.cal_pop_fitness()
# Then return the index of that solution corresponding to the best fitness.
best_match_idx = numpy.where(pop_fitness == numpy.max(pop_fitness))[0][0]
best_match_idx = numpy.where(pop_fitness == numpy.nanmax(pop_fitness))[0][0]

best_solution = self.population[best_match_idx, :].copy()
best_solution_fitness = pop_fitness[best_match_idx]
Expand Down