Skip to content

Jedrzej-Wydra/genetic-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Genetic algorithm – evolutionary optimization challenge

author: Jędrzej Wydra

Short summary

Implemented a genetic algorithm from scratch in Python to explore evolutionary optimization without relying on machine learning libraries. The project models a population of two-gene individuals evolving toward the minimum of a paraboloid, with convergence visualized across generations.

Technical summary

The algorithm represents each individual as a point in the two-dimensional plane, where each coordinate corresponds to a single gene. Fitness is defined implicitly through survival probability: individuals located higher on the paraboloid have a higher chance of being eliminated, with death probability computed as 0.01 + 0.01 * (x^2 + y^2) / 2, capped at 1.

Selection is implemented probabilistically via survival rather than explicit ranking. Reproduction is constrained to prevent pairing with direct ancestors, and mating is allowed only between individuals whose generation difference does not exceed six. Crossover is performed by independently inheriting the x and y genes from either parent, producing all possible gene combinations. Mutation is applied by adding Gaussian noise to a randomly chosen gene of each offspring. The evolution process is visualized to illustrate population-level convergence toward the global minimum.

History

This project was conceived as a self-imposed challenge to better understand evolutionary algorithms by implementing one manually rather than relying on existing ML libraries. While modern frameworks offer powerful abstractions, building the algorithm from first principles reveals how randomness, selection, and simple biological metaphors combine to produce structured optimization behavior. The goal was not to engineer a production-ready optimizer, but to observe how evolutionary dynamics emerge mathematically — and how quickly a population can converge using surprisingly minimal assumptions.

About

A genetic algorithm implemented from scratch (self-challenge)

Topics

Resources

Stars

Watchers

Forks

Contributors