One goal or many
Optimize one objective or return multiple fitness values for multi-objective search with NSGA-II and NSGA-III.
Explore multi-objective optimization ↗Open-source optimization for Python
Build genetic algorithms, search complex solution spaces, and optimize machine-learning models with a library that stays out of your way.
pip install pygadPython 3.8+ · BSD-3-Clause · Lightweight core
An illustrative view of candidates evolving toward better fitness.
Built for real search problems
Start with a fitness function. Shape the search with the operators and constraints your problem needs.
Optimize one objective or return multiple fitness values for multi-objective search with NSGA-II and NSGA-III.
Explore multi-objective optimization ↗Choose parent selection, crossover and mutation methods; add custom operators, constraints and gene spaces.
See the available operators ↗Use Keras and PyTorch integrations to represent model parameters as chromosomes and search for better weights.
Explore Keras integration ↗Batch fitness evaluations, reuse fitness values, or parallelize intensive calculations with threads or processes.
Read about performance ↗Your first experiment
Write a fitness function for your problem, set the search size, and let PyGAD evolve candidate solutions.
Installpip install pygad
Define fitnessScore a candidate solution
Run and inspectExplore the best solution found
# optimize.py
import pygad
def fitness_func(ga_instance, solution, solution_idx):
return 1.0 / (abs(sum(solution) - 42) + 1e-6)
ga = pygad.GA(
num_generations=100,
num_parents_mating=4,
fitness_func=fitness_func,
sol_per_pop=10,
num_genes=6,
)
ga.run()
solution, fitness, _ = ga.best_solution()
print(solution, fitness)
Keep exploring
Read the guides, browse working examples, or join the conversation around PyGAD.
PyGAD meets Vilvik
Bring your PyGAD optimization into Vilvik’s cloud workspace. Run experiments, compare generations, tune the search, and keep the results together.
Explore VilvikA connected workflow for running and refining PyGAD experiments in Vilvik.
Open source moves forward together
PyGAD is available under the BSD-3-Clause license. If it helps your work, you can support its continued development.