https://github.com/robert076/ai-mini-project
The last homework for the AI assignment at UBB. Optimisation using genetic algorithms.
https://github.com/robert076/ai-mini-project
ai genetic-algorithm ubb ubb-computer-science ubb-fmi
Last synced: 8 months ago
JSON representation
The last homework for the AI assignment at UBB. Optimisation using genetic algorithms.
- Host: GitHub
- URL: https://github.com/robert076/ai-mini-project
- Owner: Robert076
- Created: 2025-06-05T04:40:19.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-05T04:52:27.000Z (about 1 year ago)
- Last Synced: 2025-06-05T07:09:49.664Z (about 1 year ago)
- Topics: ai, genetic-algorithm, ubb, ubb-computer-science, ubb-fmi
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# š Benchmark Optimization Functions Using Genetic Algorithms
## š Project Documentation
Hey there! This is my project where I explored how Genetic Algorithms (GAs) perform on some classic optimization problems. I focused on the Griewank and Ackley functions, which are pretty interesting test cases for optimization algorithms. I tried different approaches using both binary and real-valued representations, along with various crossover methods to see what works best.
### š§© What's Inside?
- My implementations of the Griewank and Ackley functions
- Two different GA approaches: binary and real-valued
- A bunch of crossover methods to play with
- Some cool visualization tools I built
- A framework for running experiments
- Tools for analyzing the results
## āļø How I Structured This
Here's how I organized everything:
```
āāā functions/ # Where I put the benchmark functions
ā āāā ackley.py # My Ackley function implementation
ā āāā griewank.py # My Griewank function implementation
āāā ga/ # The genetic algorithm stuff
ā āāā binary_ga.py # Binary version of the GA
ā āāā real_ga.py # Real-valued version
ā āāā crossover.py # Different ways to mix solutions
āāā experiments/ # Where I run and store experiments
āāā analysis/ # Tools I made for analyzing results
āāā plots/ # Where I keep all the visualizations
āāā main.py # The main script to run everything
āāā requirements.txt # What you need to install
```
### What You'll Need
I used:
- Python 3.x
- NumPy (for all the math stuff)
- Matplotlib (for making pretty plots)
- SciPy (for some extra math functions)
## The Fun Stuff: Implementation Details
### The Benchmark Functions
#### Griewank Function
I implemented this one first. It's a pretty tricky function:
- The math looks like this: f(x) = 1 + Ī£(x_i²/4000) - Ī (cos(x_i/āi))
- It's got lots of local minima (that's what makes it interesting!)
- The best solution is at f(0,...,0) = 0
- You can find it in `functions/griewank.py`
#### Ackley Function
This one's my favorite - it's like a flat landscape with a deep hole in the middle:
- Here's the math: f(x) = -a*exp(-b*ā(1/d*Ī£(x_i²))) - exp(1/d*Ī£(cos(c\*x_i))) + a + exp(1)
- It's mostly flat but has this cool central peak/valley
- The best solution is also at f(0,...,0) = 0
- Check it out in `functions/ackley.py`
### My Genetic Algorithm Implementations
#### Binary GA
I started with this one because it's more traditional:
- Uses binary strings to represent solutions
- Flips bits for mutation
- Has different ways to combine solutions
- You can tweak the population size
- Uses tournament selection (I found this works best)
- Adjustable mutation rate
#### Real-valued GA
This one's more modern and often works better:
- Uses actual numbers instead of binary
- Uses Gaussian mutation (more natural for real numbers)
- Has arithmetic crossover
- Same tournament selection
- Also adjustable population and mutation rates
#### The Crossover Methods I Implemented
I tried several ways to combine solutions:
- Single-point (the classic)
- Two-point (more flexible)
- Uniform (more random)
- Arithmetic (for real numbers)
- Blend (another real-number approach)
## š» How to Use This
### Getting Started
1. First, clone this repo
2. Set up a virtual environment (trust me, it's worth it):
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
3. Install what you need:
```bash
pip install -r requirements.txt
```
### Running Things
1. Just run the main script:
```bash
python main.py
```
2. You'll get two options:
- Make some plots (they look pretty cool)
- Run the optimization experiments
### Tweaking Things
Feel free to play around with:
- The parameters in `experiments/run_experiments.py`
- GA settings in the respective files
- How the plots look in `plots/plot_functions.py`
## š What You'll Get
### Outputs
- Cool plots in the `plots/` folder
- Experiment results in `experiments/results/`
- Analysis stuff in `analysis/`
### Analysis Tools I Built
- Ways to measure how well things work
- Tools to check if results are meaningful
- Ways to see how quickly solutions converge
- Methods to check solution quality
### Visualizations
I made several types of plots:
- 2D and 3D views of the functions
- Plots showing how solutions improve over time
- Charts showing where solutions end up
- Comparisons of different methods