pyMetaheuristic: A Comprehensive Python Library for Optimization
Project description
pyMetaheuristic
Introduction
pyMetaheuristic is a robust Python Library crafted to provide a wide range of metaheuristic algorithms, ideal for tackling complex optimization tasks. It encompasses a diverse mix of algorithms, from traditional to modern methods. For a detailed list of these metaheuristics and their demonstrations, refer to Section 3. The library is also equipped with a selection of test functions, useful for benchmarking and evaluating algorithm performance. Details on these functions can be found in Section 4. Getting started with pyMetaheuristic is straightforward. Install the package using pip and begin exploring the available algorithms and test functions, as outlined in Sections 1 and 2. Whether you're addressing intricate optimization problems or experimenting with different algorithms, pyMetaheuristic is your essential toolkit.
Each metaheuristic includes two parameters: 'start_init' and 'target_value'. By default, 'start_init' is set to None, but it can be assigned an initial guess in the form of a NumPy array. The default value of 'target_value' is also None. However, you can specify a continuous value for it. If during the iterations, the objective function reaches a value that is equal to or less than this specified 'target_value', the iterations will halt.
Usage
- Install
pip install pyMetaheuristic
- Import
# Import PSO
from pyMetaheuristic.algorithm import particle_swarm_optimization
# Import a Test Function. Available Test Functions: https://bit.ly/3KyluPp
from pyMetaheuristic.test_function import easom
# OR Define your Custom Function. The function input should be a list of values,
# each value representing a dimension (x1, x2, ...xn) of the problem.
import numpy as np
def easom(variables_values = [0, 0]):
x1, x2 = variables_values
func_value = -np.cos(x1)*np.cos(x2)*np.exp(-(x1 - np.pi)**2 - (x2 - np.pi)**2)
return func_value
# Run PSO
parameters = {
'swarm_size': 250,
'min_values': (-5, -5),
'max_values': (5, 5),
'iterations': 500,
'decay': 0,
'w': 0.9,
'c1': 2,
'c2': 2,
'verbose': True,
'start_init': None,
'target_value': None
}
pso = particle_swarm_optimization(target_function = easom, **parameters)
# Print Solution
variables = pso[:-1]
minimum = pso[ -1]
print('Variables: ', np.around(variables, 4) , ' Minimum Value Found: ', round(minimum, 4) )
# Plot Solution
from pyMetaheuristic.utils import graphs
plot_parameters = {
'min_values': (-5, -5),
'max_values': (5, 5),
'step': (0.1, 0.1),
'solution': [variables],
'proj_view': '3D',
'view': 'browser'
}
graphs.plot_single_function(target_function = easom, **plot_parameters)
- Colab Demo
Try it in Colab:
- Adaptive Random Search ( Colab Demo ) ( Original Paper )
- Ant Lion Optimizer ( Colab Demo ) ( Original Paper )
- Arithmetic Optimization Algorithm ( Colab Demo ) ( Original Paper )
- Artificial Bee Colony Optimization ( Colab Demo ) ( Original Paper )
- Artificial Fish Swarm Algorithm ( Colab Demo ) ( Original Paper )
- Bat Algorithm ( Colab Demo ) ( Original Paper )
- Biogeography Based Optimization ( Colab Demo ) ( Original Paper )
- Cat Swarm Optimization ( Colab Demo ) ( Original Paper )
- Chicken Swarm Optimization ( Colab Demo ) ( Original Paper )
- Clonal Selection Algorithm ( Colab Demo ) ( Original Paper )
- Coati Optimization Algorithm ( Colab Demo ) ( Original Paper )
- Cockroach Swarm Optimization ( Colab Demo ) ( Original Paper )
- Cross-Entropy Method ( Colab Demo ) ( Original Paper )
- Crow Search Algorithm ( Colab Demo ) ( Original Paper )
- Cuckoo Search ( Colab Demo ) ( Original Paper )
- Cultural Algorithm ( Colab Demo ) ( Original Paper )
- Differential Evolution ( Colab Demo ) ( Original Paper )
- Dispersive Flies Optimization ( Colab Demo ) ( Original Paper )
- Dragonfly Algorithm ( Colab Demo ) ( Original Paper )
- Dynamic Virtual Bats Algorithm ( Colab Demo ) ( Original Paper )
- Elephant Herding Optimization Algorithm ( Colab Demo ) ( Original Paper )
- Firefly Algorithm ( Colab Demo ) ( Original Paper )
- Flow Direction Algorithm ( Colab Demo ) ( Original Paper )
- Flower Pollination Algorithm ( Colab Demo ) ( Original Paper )
- Genetic Algorithm ( Colab Demo ) ( Original Paper )
- Geometric Mean Optimizer ( Colab Demo ) ( Original Paper )
- Grey Wolf Optimizer ( Colab Demo ) ( Original Paper )
- Grey Wolf Optimizer - Adaptive Chaotic GWO ( Colab Demo ) ( Original Paper )
- Grey Wolf Optimizer - Improved GWO ( Colab Demo ) ( Original Paper )
- Grasshopper Optimization Algorithm ( Colab Demo ) ( Original Paper )
- Gravitational Search Algorithm ( Colab Demo ) ( Original Paper )
- Harmony Search Algorithm ( Colab Demo ) ( Original Paper )
- Harris Hawks Optimization ( Colab Demo ) ( Original Paper )
- Hunting Search Algorithm ( Colab Demo ) ( Original Paper )
- Jaya ( Colab Demo ) ( Original Paper )
- Jellyfish Search Optimizer ( Colab Demo ) ( Original Paper )
- Krill Herd Algorithm ( Colab Demo ) ( Original Paper )
- Memetic Algorithm ( Colab Demo ) ( Original Paper )
- Monarch Butterfly Optimization ( Colab Demo ) ( Original Paper )
- Moth Flame Optimization ( Colab Demo ) ( Original Paper )
- Multiverse Optimizer ( Colab Demo ) ( Original Paper )
- Pathfinder Algorithm ( Colab Demo ) ( Original Paper )
- Particle Swarm Optimization ( Colab Demo ) ( Original Paper )
- Population-Based Incremental Learning ( Colab Demo ) ( Original Paper )
- Random Search ( Colab Demo ) ( Original Paper )
- Salp Swarm Algorithm ( Colab Demo ) ( Original Paper )
- Simulated Annealing ( Colab Demo ) ( Original Paper )
- Sine Cosine Algorithm ( Colab Demo ) ( Original Paper )
- Student Psychology Based Optimization ( Colab Demo ) ( Original Paper )
- Symbiotic Organisms Search ( Colab Demo ) ( Original Paper )
- Teaching Learning Based Optimization ( Colab Demo ) ( Original Paper )
- Whale Optimization Algorithm ( Colab Demo ) ( Original Paper )
- Whale Optimization Algorithm - Improved WOA ( Colab Demo ) ( Original Paper )
- Test Functions
- Ackley ( Paper ) ( Plot )
- Axis Parallel Hyper-Ellipsoid ( Paper ) ( Plot )
- Beale ( Paper ) ( Plot )
- Bohachevsky F1 ( Paper ) ( Plot )
- Bohachevsky F2 ( Paper ) ( Plot )
- Bohachevsky F3 ( Paper ) ( Plot )
- Booth ( Paper ) ( Plot )
- Branin RCOS ( Paper ) ( Plot )
- Bukin F6 ( Paper ) ( Plot )
- Cross in Tray ( Paper ) ( Plot )
- De Jong F1 ( Paper ) ( Plot )
- Drop Wave ( Paper ) ( Plot )
- Easom ( Paper ) ( Plot )
- Eggholder ( Paper ) ( Plot )
- Goldstein-Price ( Paper ) ( Plot )
- Griewangk F8 ( Paper ) ( Plot )
- Himmelblau ( Paper ) ( Plot )
- Holder Table ( Paper ) ( Plot )
- Matyas ( Paper ) ( Plot )
- McCormick ( Paper ) ( Plot )
- Levi F13 ( Paper ) ( Plot )
- Rastrigin ( Paper ) ( Plot )
- Rosenbrocks Valley (De Jong F2) ( Paper ) ( Plot )
- Schaffer F2 ( Paper ) ( Plot )
- Schaffer F4 ( Paper ) ( Plot )
- Schaffer F6 ( Paper ) ( Plot )
- Schwefel ( Paper ) ( Plot )
- Six Hump Camel Back ( Paper ) ( Plot )
- Styblinski-Tang ( Paper ) ( Plot )
- Three Hump Camel Back ( Paper ) ( Plot )
- Zakharov ( Paper ) ( Plot )
Multiobjective Optimization or Many Objectives Optimization
For Multiobjective Optimization or Many Objectives Optimization try pyMultiobjective
TSP (Travelling Salesman Problem)
For Travelling Salesman Problems, try pyCombinatorial
Acknowledgement
This section is dedicated to everyone who helped improve or correct the code. Thank you very much!
- Raiser (01.MARCH.2022) - https://github.com/mpraiser - University of Chinese Academy of Sciences (China)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyMetaheuristic-1.9.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d558cd33274261cf8283d7d7884bce7f419a897f94c97e059ced3f4340f0ea04 |
|
MD5 | eee05d5d947fe4269037ffdec6bad8ad |
|
BLAKE2b-256 | 63c5b433899977085ce3e36bdbec8d77e1c3bfd4b1cea9ecf87a30513bbe2cdf |