GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

Request: attributes of best solution from all generations

Open Stoops-ML opened this issue 2 years ago • 2 comments

From PyGAD's documentation the best_solutions attribute saves the best solution of every generation:

save_best_solutions=False: When True, then the best solution after each generation is saved into an attribute named best_solutions. If False (default), then no solutions are saved and the best_solutions attribute will be empty. Supported in PyGAD 2.9.0.

I would like an attribute to exist which would be the single best solution from all generations, rather than the existing best_solutions attribute that is a list of the best solutions from every generation. This would be helpful because the single best solution is not always the best solution of the last generation.

Something on the lines of (untested example):

def get_best_solution(self):
    best_gen = np.argmax(self.best_solutions_fitness)
    return self.best_solutions[best_gen]

Stoops-ML avatar May 01 '22 12:05 Stoops-ML

I'm also interested in this.

DCML685 avatar Jun 09 '22 11:06 DCML685

You can also call the best_solution() method which returns the best solution from all generations.

ahmedfgad avatar Feb 25 '23 19:02 ahmedfgad