generate functionThu, 04 May 2023

Haz un ejemplo de la aplicación de la librería PyGAD Python para algoritmos genéticos

from pygad import GA import numpy as np # Define the function that the GA will optimise. def fitness_function(solution): x, y = solution return (x - 2) ** 2 + (y - 2) ** 2 ga = GA(num_generations=50, sol_per_pop=50, num_parents_mating=10, fitness_func=fitness_function, crossover_prob=0.7, mutation_prob=0.1, lower_bound=[-100, -100], upper_bound=[100, 100]) ga.run() print(ga.best_solution()) print(ga.best_solution_fitness())

Want to kickstart your project?Use the new AI Studio to create your code