Beginner Explanation
Imagine you have a garden full of different types of flowers. Some flowers are taller, some have brighter colors, and some are just healthier. Now, if you want to grow the best flowers, you might pick the best ones and let them produce seeds. Over time, these seeds will grow into new flowers that inherit the good traits of their parents. Evolutionary algorithms work similarly: they start with a group of possible solutions to a problem, choose the best ones, and combine them to create new solutions. Just like nature, the process repeats until they find the best solution, or flower, for the problem at hand.Technical Explanation
An evolutionary algorithm (EA) is a subset of optimization algorithms based on the principles of natural selection. EAs typically involve a population of candidate solutions that evolve over generations. The process includes selection, crossover (recombination), and mutation. Here’s a basic structure in Python using a simple fitness function: “`python import random # Define a simple fitness function def fitness_function(x): return x ** 2 # We want to maximize this (find the maximum x) # Initialize population population = [random.uniform(-10, 10) for _ in range(10)] # Evolution process for generation in range(100): # Selection (pick the best) population.sort(key=fitness_function, reverse=True) survivors = population[:5] # Keep the top 5 # Crossover and mutation offspring = [] for _ in range(5): parent1, parent2 = random.sample(survivors, 2) child = (parent1 + parent2) / 2 + random.uniform(-1, 1) # Crossover offspring.append(child) population = survivors + offspring # Best solution best_solution = max(population, key=fitness_function) print(f’Best solution: {best_solution}’) “`Academic Context
Evolutionary algorithms (EAs) are inspired by Charles Darwin’s theory of natural selection and are part of a broader class of algorithms known as metaheuristics. The foundational concept lies in the idea of survival of the fittest, where the best solutions are selected for reproduction in order to create the next generation. Key mathematical foundations include genetic operators like selection, crossover, and mutation, which are designed to explore the solution space effectively. Notable papers include ‘Genetic Algorithms in Search, Optimization, and Machine Learning’ by David E. Goldberg and ‘An Introduction to Genetic Algorithms’ by Melanie Mitchell, which provide comprehensive insights into the principles and applications of EAs.Code Examples
Example 1:
import random
# Define a simple fitness function
def fitness_function(x):
return x ** 2 # We want to maximize this (find the maximum x)
# Initialize population
population = [random.uniform(-10, 10) for _ in range(10)]
# Evolution process
for generation in range(100):
# Selection (pick the best)
population.sort(key=fitness_function, reverse=True)
survivors = population[:5] # Keep the top 5
# Crossover and mutation
offspring = []
for _ in range(5):
parent1, parent2 = random.sample(survivors, 2)
child = (parent1 + parent2) / 2 + random.uniform(-1, 1) # Crossover
offspring.append(child)
population = survivors + offspring
# Best solution
best_solution = max(population, key=fitness_function)
print(f'Best solution: {best_solution}')
Example 2:
return x ** 2 # We want to maximize this (find the maximum x)
Example 3:
# Selection (pick the best)
population.sort(key=fitness_function, reverse=True)
survivors = population[:5] # Keep the top 5
Example 4:
# Crossover and mutation
offspring = []
for _ in range(5):
parent1, parent2 = random.sample(survivors, 2)
child = (parent1 + parent2) / 2 + random.uniform(-1, 1) # Crossover
offspring.append(child)
population = survivors + offspring
Example 5:
import random
# Define a simple fitness function
def fitness_function(x):
return x ** 2 # We want to maximize this (find the maximum x)
Example 6:
def fitness_function(x):
return x ** 2 # We want to maximize this (find the maximum x)
# Initialize population
population = [random.uniform(-10, 10) for _ in range(10)]
View Source: https://arxiv.org/abs/2511.16485v1