Open andrey-bat opened 3 years ago
Sometimes there's also an error with model.plot_fitess() on the first run, but could not yet reproduce on some simple dummy case.
Traceback (most recent call last):
File "/home/albat/crop_selector/crops_selector.py", line 625, in
BTW, don't know where 11 comes from, there were just 10 generations in this run.
Hi @andrey-bat,
Thanks for using PyGAD.
Before explaining the solution to this issue, let me quickly explain why it is 11 not 10. The reason is that the fitness of the initial population (before the GA starts its evolution) is saved. This is in addition to the fitness of the 10 generations. So, the total is 1+10=11.
For the issue, let me explain why this happens.
There are 4 variables that store information about the solutions and their fitness after each generation. The 4 variables are:
best_solutions
: Saves the best solution in each generation.best_solutions_fitness
: Saves the fitness value of the best solution for each generation.solutions
: Saves all solutions in each generation.solutions_fitness
: Saves the fitness of all solutions in each generation.When the plot_fitness()
method is called, the best_solutions_fitness
list is used. If there are 10 generations, then this list will hold 11 values after the run()
method completes for the first time.
For each call of the run()
method, new values will be appended at the end of this list. After the second run, the length of the best_solutions_fitness
list will be 11+11=22. Then, it is 33 after the third run.
This issue is solved by resetting the best_solutions_fitness
variable and any variable that is extended after each generation.
def run(self):
....
self.best_solutions = []
self.best_solutions_fitness = []
self.solutions = []
self.solutions_fitness = []
....
The project will be updated soon and a new release of PyGAD will be published.
Thanks for opening this issue.
Hi! Great project, thanks. However I've experianced some bugs.
model = pygad.GA(someparameters - may be even sample model from documentation) model.run() model.plot_fitness(plot_type="scatter") ok model.run() model.plot_fitess() ok model.plot_fitness(plot_type="scatter")
ValueError Traceback (most recent call last)