This project implements and compares two variants of Differential Evolution (DE) algorithms for optimizing a complex, modified 3D Rastrigin function. The comparison focuses on evaluating the performance difference between a classical differential evolution approach and an enhanced variant that integrates deep learning techniques.
- Standard DE: A classical differential evolution algorithm implementing standard mutation, crossover, and selection strategies
- Simplified Deep-DE: An enhanced variant that integrates a surrogate neural network model to guide the mutation process, leveraging an experience buffer to learn from successful mutations
The optimization challenge involves a modified 3D Rastrigin function with several complexity-enhancing modifications:
- Base Function: 3D Rastrigin function with search space bounds [-5.12, 5.12] for each dimension
- Asymmetry: Fixed 3D shift vector [-1.23, 2.41, 0.85] to break symmetry
- Distortion: Additional quadratic and sub-quadratic (power 1.5) penalty terms
- Rotation: Cross-variable interaction terms introducing rotational effects
The mathematical formulation includes:
f(x,y,z) = base_rastrigin + asymmetry_distortion + rotation_terms
The algorithms are compared using four key performance indicators:
- Solution Quality: Best fitness value achieved and corresponding solution coordinates
- Convergence Speed: Number of generations required to reach threshold proximity to optimum
- Improvement Rate: Rate of fitness improvement across successive generations
- Stability: Consistency measured by variance in fitness during final generations
- Random population initialization within problem bounds
- Classical DE mutation:
mutant = a + F Γ (b - c)
- Binomial crossover with rate CR
- Greedy selection based on fitness improvement
- Surrogate Model: Feedforward neural network predicting beneficial mutations
- Experience Buffer: Repository storing successful mutations for model training
- Guided Mutation: Neural network-generated mutations after sufficient training data
- Adaptive Learning: Periodic model updates using collected experiences
- Python 3.7+
- PyTorch
- NumPy
- Matplotlib
- imageio
- Create and activate virtual environment:
python -m venv venv
# On Windows:
venv\Scripts\activate
# On Unix or MacOS:
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Run the comparison:
python main.py
The program will:
- Execute both algorithms with identical parameters
- Generate performance metrics and comparisons
- Create visualizations in the
visualization/
directory - Display comprehensive results in the terminal
Based on experimental runs with population size 100 and 50 generations:
Metric | Standard DE | Deep-DE | Improvement |
---|---|---|---|
Best Fitness | 4.334628 | 4.235910 | 2.28% |
Convergence Speed | 35 generations | 19 generations | 45.71% |
Solution Quality | Good | Superior | β |
Stability | Stable | Stable | β |
The convergence plot demonstrates that Deep-DE not only achieves better final fitness but also converges significantly faster than Standard DE.
The algorithms show distinct population evolution patterns:
Note: Darker points indicate better fitness values (approaching global minimum)
The 3D visualization shows both algorithms' final solutions plotted on the complex Rastrigin landscape, demonstrating their effectiveness in navigating the multimodal search space.
The final population comparison illustrates how both algorithms converge, with Deep-DE showing slightly tighter clustering around the optimum.
Cross-sectional views of the function landscape help visualize the complexity of the optimization problem and solution locations.
βββ main.py # Main execution script and Deep-DE implementation
βββ classic_de.py # Standard Differential Evolution implementation
βββ problem.py # Modified 3D Rastrigin function definition
βββ metrics.py # Performance metrics calculation utilities
βββ visuals.py # Visualization generation functions
βββ requirements.txt # Python dependencies
βββ README.md # This documentation
βββ visualization/ # Generated plots and animations
βββ convergence.png
βββ final_populations.png
βββ 3d_function_comparison.png
βββ 2d_function_slices.png
βββ algorithm_comparison.png
βββ distance_to_optimum.png
βββ standard_de.gif
βββ deep_de.gif
βββ *.png frame files
- Architecture: 3-layer feedforward network (128 β 128 β 64 β 3)
- Input: Concatenated parent triplets (9D β 3D mutation vector)
- Training: Adam optimizer with cosine annealing scheduler
- Loss Function: Mean Squared Error on successful mutations
- Capacity: 1000 experiences (configurable)
- Storage: Parent triplets, resulting mutations, fitness improvements
- Sampling: Random batch selection for neural network training
- Usage: Begins after 32+ successful experiences collected
- Deep-DE demonstrates superior performance with 2.28% better solution quality
- Convergence acceleration of 45.71% - reaching optimum in nearly half the generations
- Maintained stability while achieving faster convergence
- Neural network guidance effectively learns problem-specific mutation strategies
- Reproducibility: Fixed random seeds (torch: 42, numpy: 33) ensure consistent results
- Boundary Handling: Clamping ensures solutions remain within valid bounds
- Crossover Strategy: Binomial crossover with guaranteed minimum one-point exchange
- Visualization: Real-time 3D population tracking with rotating viewpoints
Potential improvements to explore:
- Multi-objective optimization variants
- Adaptive population sizing
- Advanced surrogate architectures (attention mechanisms)
- Hybrid local search integration
- Dynamic parameter adaptation
Note: This implementation serves as a research tool for comparing evolutionary algorithms enhanced with machine learning techniques. Results may vary with different problem instances and parameter settings.