-
-
Notifications
You must be signed in to change notification settings - Fork 463
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
Save the instance of a GA during fitness evaluation #242
Comments
Saving the GA instance during the fitness evaluation will not save the fitness of the of the subset of solutions that have their fitness already calculated. But you can add a new attribute to the GA instance before saving it. This attribute saves the fitness of the subset of solution with their fitness calculated. This is an example that saves the solutions with their fitness calculated into the import pygad
import numpy
function_inputs = [4,-2,3.5,5,-11,-4.7]
desired_output = 44
solutions_fitness = []
def fitness_func(ga_instance, solution, solution_idx):
global solutions_fitness
output = numpy.sum(solution*function_inputs)
fitness = 1.0 / (numpy.abs(output - desired_output) + 0.000001)
solutions_fitness.append(fitness)
ga_instance.save('test')
return fitness
def on_generation(ga_instance):
global solutions_fitness
print(f"Generation = {ga_instance.generations_completed}")
solutions_fitness = []
ga_instance = pygad.GA(num_generations=50,
num_parents_mating=5,
sol_per_pop=10,
num_genes=len(function_inputs),
fitness_func=fitness_func,
on_generation=on_generation,
suppress_warnings=True)
ga_instance.run() |
How can I save the instance of a GA during the fitness evaluation of the population? In other words, if it has evaluated the fitness of 15 individuals over a population of 30, I would like to save the progress and, in the future, consider only the remaining 15.
I need that cause the evaluation of fitness, in my case, is done by a resource-intensive simulation where the fitness evaluation of the whole population takes a day. So if something happens and the run is terminated before the evaluation of every individual then I lose calculations that might worth up to one day.
The text was updated successfully, but these errors were encountered: