mealpy.swarm_based package¶
mealpy.swarm_based.ABC¶
- class mealpy.swarm_based.ABC.BaseABC(problem, epoch=10000, pop_size=100, couple_bees=(16, 4), patch_variables=(5.0, 0.985), sites=(3, 1), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Artificial Bee Colony (ABC)
Notes
This version is based on ABC in the book Clever Algorithms
Improved the function _search_neigh__
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
couple_bees (list): n bees for (good locations, other locations) -> ([10, 20], [3, 8])
patch_variables (list): (patch_var, patch_reduce_factor) -> ([3, 6], [0.85, 0,.99])
patch_variables = patch_variables * patch_factor (0.985)
sites (list): 3 bees (employed bees, onlookers and scouts), 1 good partition -> (3, 1), fixed parameter
Examples
>>> import numpy as np >>> from mealpy.swarm_based.ABC import BaseABC >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> couple_bees = [16, 4] >>> patch_variables = [5, 0.98] >>> sites = [3, 1] >>> model = BaseABC(problem_dict1, epoch, pop_size, couple_bees, patch_variables, sites) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Karaboga, D. and Basturk, B., 2008. On the performance of artificial bee colony (ABC) algorithm. Applied soft computing, 8(1), pp.687-697.
mealpy.swarm_based.ACOR¶
- class mealpy.swarm_based.ACOR.BaseACOR(problem, epoch=10000, pop_size=100, sample_count=50, inten_factor=0.5, zeta=1.0, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Ant Colony Optimization Continuous (ACOR)
Notes
Use Gaussian Distribution instead of random number (np.random.normal() function)
Amend solution when they went out of space
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
sample_count (int): [pop_size/2, pop_size], Number of Newly Generated Samples, default = 50
inten_factor (float): [0.2, 1.0], Intensification Factor (Selection Pressure), (q in the paper), default = 0.5
zeta (int): [1, 2, 3], Deviation-Distance Ratio, default = 1
Examples
>>> import numpy as np >>> from mealpy.swarm_based.ACOR import BaseACOR >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> sample_count = 50 >>> inten_factor = 0.5 >>> zeta = 1.0 >>> model = BaseACOR(problem_dict1, epoch, pop_size, sample_count, inten_factor, zeta) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Socha, K. and Dorigo, M., 2008. Ant colony optimization for continuous domains. European journal of operational research, 185(3), pp.1155-1173.
mealpy.swarm_based.ALO¶
- class mealpy.swarm_based.ALO.BaseALO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.swarm_based.ALO.OriginalALOMy changed version of: Ant Lion Optimizer (ALO)
Notes
Use matrix for better performance.
Change the flow of updating new position makes it better then original one
Examples
>>> import numpy as np >>> from mealpy.swarm_based.ALO import BaseALO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseALO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
- class mealpy.swarm_based.ALO.OriginalALO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Ant Lion Optimizer (ALO)
- Links:
Examples
>>> import numpy as np >>> from mealpy.swarm_based.ALO import OriginalALO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = OriginalALO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Mirjalili, S., 2015. The ant lion optimizer. Advances in engineering software, 83, pp.80-98.
mealpy.swarm_based.AO¶
- class mealpy.swarm_based.AO.OriginalAO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Aquila Optimization (AO)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.AO import OriginalAO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = OriginalAO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Abualigah, L., Yousri, D., Abd Elaziz, M., Ewees, A.A., Al-Qaness, M.A. and Gandomi, A.H., 2021. Aquila optimizer: a novel meta-heuristic optimization algorithm. Computers & Industrial Engineering, 157, p.107250.
mealpy.swarm_based.BA¶
- class mealpy.swarm_based.BA.BaseBA(problem, epoch=10000, pop_size=100, loudness=(1.0, 2.0), pulse_rate=(0.15, 0.85), pulse_frequency=(0, 10), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Bat-inspired Algorithm (BA)
Notes
The value of A and r are changing after each iteration
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
loudness (float): (A_min, A_max) -> ([0.5, 1.5], [1.0, 3.0]): loudness, default = (1.0, 2.0)
pulse_rate (float): (r_min, r_max) -> ([0.1, 0.5], [0.5, 0.95]), pulse rate / emission rate, default = (0.15, 0.85)
pulse_frequency (list): (pf_min, pf_max) -> ([0, 3], [5, 20]), pulse frequency, default = (0, 10)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BA import BaseBA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> loudness = [1.0, 2.0] >>> pulse_rate = [0.15, 0.85] >>> pulse_frequency = [0, 10] >>> model = BaseBA(problem_dict1, epoch, pop_size, loudness, pulse_rate, pulse_frequency) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Yang, X.S., 2010. A new metaheuristic bat-inspired algorithm. In Nature inspired cooperative strategies for optimization (NICSO 2010) (pp. 65-74). Springer, Berlin, Heidelberg.
- ID_LOUD = 3¶
- ID_PFRE = 5¶
- ID_PRAT = 4¶
- ID_VEC = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], velocity, loudness, pulse_rate, pulse_frequency]
- Return type
list
- class mealpy.swarm_based.BA.ModifiedBA(problem, epoch=10000, pop_size=100, pulse_rate=0.95, pulse_frequency=(0, 10), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy modified version of: Bat-inspired Algorithm (MBA)
Notes
Removes A (loudness) parameter
- Changed processes
1st: We proceed exploration phase (using frequency)
2nd: If new position has better fitness we replace the old position
3rd: Otherwise, we proceed exploitation phase (using finding around the best position so far)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
pulse_rate (float): [0.7, 1.0], pulse rate / emission rate, default = 0.95
pulse_frequency (list): (pf_min, pf_max) -> ([0, 3], [5, 20]), pulse frequency, default = (0, 10)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BA import ModifiedBA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> pulse_rate = 0.95 >>> pulse_frequency = [0, 10] >>> model = ModifiedBA(problem_dict1, epoch, pop_size, pulse_rate, pulse_frequency) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
- class mealpy.swarm_based.BA.OriginalBA(problem, epoch=10000, pop_size=100, loudness=0.8, pulse_rate=0.95, pulse_frequency=(0, 10), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Bat-inspired Algorithm (BA)
Notes
The value of A and r parameters are constant
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
loudness (float): (1.0, 2.0), loudness, default = 0.8
pulse_rate (float): (0.15, 0.85), pulse rate / emission rate, default = 0.95
pulse_frequency (list): (pf_min, pf_max) -> ([0, 3], [5, 20]), pulse frequency, default = (0, 10)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BA import OriginalBA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> loudness = 0.8 >>> pulse_rate = 0.95 >>> pulse_frequency = [0, 10] >>> model = OriginalBA(problem_dict1, epoch, pop_size, loudness, pulse_rate, pulse_frequency) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Yang, X.S., 2010. A new metaheuristic bat-inspired algorithm. In Nature inspired cooperative strategies for optimization (NICSO 2010) (pp. 65-74). Springer, Berlin, Heidelberg.
- ID_PFRE = 3¶
- ID_VEC = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], velocity, pulse_frequency]
- Return type
list
mealpy.swarm_based.BES¶
- class mealpy.swarm_based.BES.BaseBES(problem, epoch=10000, pop_size=100, a_factor=10, R_factor=1.5, alpha=2.0, c1=2.0, c2=2.0, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Bald Eagle Search (BES)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
a_factor (int): default: 10, determining the corner between point search in the central point, in [5, 10]
R_factor (float): default: 1.5, determining the number of search cycles, in [0.5, 2]
alpha (float): default: 2, parameter for controlling the changes in position, in [1.5, 2]
c1 (float): default: 2, in [1, 2]
c2 (float): c1 and c2 increase the movement intensity of bald eagles towards the best and centre points
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BES import BaseBES >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> a_factor = 10 >>> R_factor = 1.5 >>> alpha = 2.0 >>> c1 = 2.0 >>> c2 = 2.0 >>> model = BaseBES(problem_dict1, epoch, pop_size, a_factor, R_factor, alpha, c1, c2) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Alsattar, H.A., Zaidan, A.A. and Zaidan, B.B., 2020. Novel meta-heuristic bald eagle search optimisation algorithm. Artificial Intelligence Review, 53(3), pp.2237-2264.
mealpy.swarm_based.BFO¶
- class mealpy.swarm_based.BFO.ABFO(problem, epoch=10000, pop_size=100, Ci=(0.1, 0.001), Ped=0.01, Ns=4, N_minmax=(1, 40), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Adaptive Bacterial Foraging Optimization (ABFO)
Notes
This is the best improvement version of BFO
The population will remain the same length as initialization due to add and remove operators
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
Ci (list): C_s (start), C_e (end) -=> step size # step size in BFO, default=(0.1, 0.001)
Ped (float): Probability eliminate, default=0.01
Ns (int): swim_length, default=4
N_minmax (list): (Dead threshold value, split threshold value), default=(2, 40)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BFO import ABFO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> Ci = [0.1, 0.001] >>> Ped = 0.01 >>> Ns = 4 >>> N_minmax = [2, 40] >>> model = ABFO(problem_dict1, epoch, pop_size, Ci, Ped, Ns, N_minmax) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Nguyen, T., Nguyen, B.M. and Nguyen, G., 2019, April. Building resource auto-scaler with functional-link neural network and adaptive bacterial foraging optimization. In International Conference on Theory and Applications of Models of Computation (pp. 501-517). Springer, Cham.
- ID_LOC_FIT = 4¶
- ID_LOC_POS = 3¶
- ID_NUT = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], nutrient, local_pos_best, local_fit_best]
- Return type
list
- class mealpy.swarm_based.BFO.OriginalBFO(problem, epoch=10000, pop_size=100, Ci=0.01, Ped=0.25, Nc=5, Ns=4, attract_repels=(0.1, 0.2, 0.1, 10), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Bacterial Foraging Optimization (BFO)
Notes
Ned and Nre parameters are replaced by epoch (generation)
The Nc parameter will also decreased to reduce the computation time.
Cost in this version equal to Fitness value in the paper.
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
Ci (float): [0.01, 0.3], step size, default=0.01
Ped (float): [0.1, 0.5], probability of elimination, default=0.25
Ned (int): elim_disp_steps (Removed), Ned=5,
Nre (int): reproduction_steps (Removed), Nre=50,
Nc (int): [3, 10], chem_steps (Reduce), Nc = Original Nc/2, default = 5
Ns (int): [2, 10], swim length, default=4
attract_repels (list): coefficient to calculate attract and repel force, default = (0.1, 0.2, 0.1, 10)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BFO import OriginalBFO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> Ci = 0.01 >>> Ped = 0.25 >>> Nc = 5 >>> Ns = 4 >>> attract_repels = [0.1, 0.2, 0.1, 10] >>> model = OriginalBFO(problem_dict1, epoch, pop_size, Ci, Ped, Nc, Ns, attract_repels) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Passino, K.M., 2002. Biomimicry of bacterial foraging for distributed optimization and control. IEEE control systems magazine, 22(3), pp.52-67.
- ID_COST = 2¶
- ID_INTER = 3¶
- ID_POS = 0¶
- ID_SUM_NUTRIENTS = 4¶
- ID_TAR = 1¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], cost, interaction, sum_nutrients]
- Return type
list
mealpy.swarm_based.BSA¶
- class mealpy.swarm_based.BSA.BaseBSA(problem, epoch=10000, pop_size=100, ff=10, pff=0.8, c_couples=(1.5, 1.5), a_couples=(1.0, 1.0), fl=0.5, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Bird Swarm Algorithm (BSA)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
ff (int): (5, 20), flight frequency - default = 10
pff (float): the probability of foraging for food - default = 0.8
c_couples (list): [c1, c2] -> (2.0, 2.0), Cognitive accelerated coefficient, Social accelerated coefficient same as PSO
a_couples (list): [a1, a2] -> (1.5, 1.5), The indirect and direct effect on the birds’ vigilance behaviours.
fl (float): (0.1, 1.0), The followed coefficient - default = 0.5
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BSA import BaseBSA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> ff = 10 >>> pff = 0.8 >>> c_couples = [1.5, 1.5] >>> a_couples = [1.0, 1.0] >>> fl = 0.5 >>> model = BaseBSA(problem_dict1, epoch, pop_size, ff, pff, c_couples, a_couples, fl) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Meng, X.B., Gao, X.Z., Lu, L., Liu, Y. and Zhang, H., 2016. A new bio-inspired optimisation algorithm: Bird Swarm Algorithm. Journal of Experimental & Theoretical Artificial Intelligence, 28(4), pp.673-687.
- ID_LBF = 3¶
- ID_LBP = 2¶
- ID_POS = 0¶
- ID_TAR = 1¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], local_position, local_fitness]
- Return type
list
mealpy.swarm_based.BeesA¶
- class mealpy.swarm_based.BeesA.BaseBeesA(problem, epoch=10000, pop_size=100, site_ratio=(0.5, 0.4), site_bee_ratio=(0.1, 2), dance_radius=0.1, dance_radius_damp=0.99, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Bees Algorithm (BeesA)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
site_ratio (list): (selected_site_ratio, elite_site_ratio), default = (0.5, 0.4)
site_bee_ratio (list): (selected_site_bee_ratio, elite_site_bee_ratio), default = (0.1, 2)
dance_radius (float): Bees Dance Radius, default = 0.1
dance_radius_damp (float): Bees Dance Radius Damp Rate, default = 0.99
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BeesA import BaseBeesA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> site_ratio = [0.5, 0.4] >>> site_bee_ratio = [0.1, 2] >>> dance_radius = 0.1 >>> dance_radius_damp = 0.99 >>> model = BaseBeesA(problem_dict1, epoch, pop_size, site_ratio, site_bee_ratio, dance_radius, dance_radius_damp) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Pham, D.T., Ghanbarzadeh, A., Koç, E., Otri, S., Rahim, S. and Zaidi, M., 2006. The bees algorithm—a novel tool for complex optimisation problems. In Intelligent production machines and systems (pp. 454-459). Elsevier Science Ltd.
- class mealpy.swarm_based.BeesA.ProbBeesA(problem, epoch=10000, pop_size=100, recruited_bee_ratio=0.1, dance_radius=0.1, dance_radius_damp=0.99, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Bees Algorithm (BeesA)
Notes
This is probabilistic version of Bees Algorithm
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
recruited_bee_ratio (float): percent of bees recruited, default = 0.1
dance_radius (float): Bees Dance Radius, default=0.1
dance_radius_damp (float): Bees Dance Radius Damp Rate, default=0.99
Examples
>>> import numpy as np >>> from mealpy.swarm_based.BeesA import ProbBeesA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> recruited_bee_ratio = 0.1 >>> dance_radius = 0.1 >>> dance_radius_damp = 0.99 >>> model = ProbBeesA(problem_dict1, epoch, pop_size, recruited_bee_ratio, dance_radius, dance_radius_damp) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Pham, D.T. and Castellani, M., 2015. A comparative study of the Bees Algorithm as a tool for function optimisation. Cogent Engineering, 2(1), p.1091540.
mealpy.swarm_based.COA¶
- class mealpy.swarm_based.COA.BaseCOA(problem, epoch=10000, pop_size=100, n_coyotes=5, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Coyote Optimization Algorithm (COA)
- Links:
https://github.com/jkpir/COA/blob/master/COA.py (Old version Mealpy < 1.2.2)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
n_coyotes (int): [3, 15], number of coyotes per group, default=5
Examples
>>> import numpy as np >>> from mealpy.swarm_based.COA import BaseCOA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> n_coyotes = 5 >>> model = BaseCOA(problem_dict1, epoch, pop_size, n_coyotes) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Pierezan, J. and Coelho, L.D.S., 2018, July. Coyote optimization algorithm: a new metaheuristic for global optimization problems. In 2018 IEEE congress on evolutionary computation (CEC) (pp. 1-8). IEEE.
- ID_AGE = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], age]
- Return type
list
mealpy.swarm_based.CSA¶
- class mealpy.swarm_based.CSA.BaseCSA(problem, epoch=10000, pop_size=100, p_a=0.3, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Cuckoo Search Algorithm (CSA)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
p_a (float): [0.1, 0.7], probability a, default=0.3
Examples
>>> import numpy as np >>> from mealpy.swarm_based.CSA import BaseCSA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> p_a = 0.3 >>> model = BaseCSA(problem_dict1, epoch, pop_size, p_a) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Yang, X.S. and Deb, S., 2009, December. Cuckoo search via Lévy flights. In 2009 World congress on nature & biologically inspired computing (NaBIC) (pp. 210-214). Ieee.
mealpy.swarm_based.CSO¶
- class mealpy.swarm_based.CSO.BaseCSO(problem, epoch=10000, pop_size=100, mixture_ratio=0.15, smp=5, spc=False, cdc=0.8, srd=0.15, c1=0.4, w_minmax=(0.4, 0.9), selected_strategy=1, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Cat Swarm Optimization (CSO)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
mixture_ratio (float): joining seeking mode with tracing mode, default=0.15
smp (int): seeking memory pool, default=5 clones (larger is better but time-consuming)
spc (bool): self-position considering, default=False
cdc (float): counts of dimension to change (larger is more diversity but slow convergence), default=0.8
srd (float): seeking range of the selected dimension (smaller is better but slow convergence), default=0.15
c1 (float): same in PSO, default=0.4
w_minmax (list): same in PSO, default=(0.4, 0.9)
selected_strategy (int): 0: best fitness, 1: tournament, 2: roulette wheel, else: random (decrease by quality)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.CSO import BaseCSO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> mixture_ratio = 0.15 >>> smp = 5 >>> spc = False >>> cdc = 0.8 >>> srd = 0.15 >>> c1 = 0.4 >>> w_minmax = [0.4, 0.9] >>> selected_strategy = 1 >>> model = BaseCSO(problem_dict1, epoch, pop_size, mixture_ratio, smp, spc, cdc, srd, c1, w_minmax, selected_strategy) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Chu, S.C., Tsai, P.W. and Pan, J.S., 2006, August. Cat swarm optimization. In Pacific Rim international conference on artificial intelligence (pp. 854-858). Springer, Berlin, Heidelberg.
- ID_FLAG = 3¶
- ID_POS = 0¶
- ID_TAR = 1¶
- ID_VEL = 2¶
- create_solution()[source]¶
x: current position of cat
v: vector v of cat (same amount of dimension as x)
flag: the stage of cat, seeking (looking/finding around) or tracing (chasing/catching) => False: seeking mode , True: tracing mode
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], velocity, flag]
- Return type
list
mealpy.swarm_based.DO¶
- class mealpy.swarm_based.DO.BaseDO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Dragonfly Optimization (DO)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.DO import BaseDO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseDO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Mirjalili, S., 2016. Dragonfly algorithm: a new meta-heuristic optimization technique for solving single-objective, discrete, and multi-objective problems. Neural computing and applications, 27(4), pp.1053-1073.
mealpy.swarm_based.EHO¶
- class mealpy.swarm_based.EHO.BaseEHO(problem, epoch=10000, pop_size=100, alpha=0.5, beta=0.5, n_clans=5, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Elephant Herding Optimization (EHO)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
alpha (float): [0.3, 0.8], a factor that determines the influence of the best in each clan, default=0.5
beta (float): [0.3, 0.8], a factor that determines the influence of the x_center, default=0.5
n_clans (int): [3, 10], the number of clans, default=5
Examples
>>> import numpy as np >>> from mealpy.swarm_based.EHO import BaseEHO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> alpha = 0.5 >>> beta = 0.5 >>> n_clans = 5 >>> model = BaseEHO(problem_dict1, epoch, pop_size, alpha, beta, n_clans) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Wang, G.G., Deb, S. and Coelho, L.D.S., 2015, December. Elephant herding optimization. In 2015 3rd international symposium on computational and business intelligence (ISCBI) (pp. 1-5). IEEE.
mealpy.swarm_based.FA¶
- class mealpy.swarm_based.FA.BaseFA(problem, epoch=10000, pop_size=100, max_sparks=50, p_a=0.04, p_b=0.8, max_ea=40, m_sparks=5, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Fireworks Algorithm (FA)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
max_sparks (int): parameter controlling the total number of sparks generated by the pop_size fireworks, default=50
p_a (float): percent (const parameter), default=0.04
p_b (float): percent (const parameter), default=0.8
max_ea (int): maximum explosion amplitude, default=40
m_sparks (int): number of sparks generated in each explosion generation, default=5
Examples
>>> import numpy as np >>> from mealpy.swarm_based.FA import BaseFA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> max_sparks = 50 >>> p_a = 0.04 >>> p_b = 0.8 >>> max_ea = 40 >>> m_sparks = 5 >>> model = BaseFA(problem_dict1, epoch, pop_size, max_sparks, p_a, p_b, max_ea, m_sparks) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Tan, Y. and Zhu, Y., 2010, June. Fireworks algorithm for optimization. In International conference in swarm intelligence (pp. 355-364). Springer, Berlin, Heidelberg.
mealpy.swarm_based.FFA¶
- class mealpy.swarm_based.FFA.BaseFFA(problem, epoch=10000, pop_size=100, gamma=0.001, beta_base=2, alpha=0.2, alpha_damp=0.99, delta=0.05, exponent=2, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Firefly Algorithm (FFA)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
gamma (float): Light Absorption Coefficient, default = 0.001
beta_base (float): Attraction Coefficient Base Value, default = 2
alpha (float): Mutation Coefficient, default = 0.2
alpha_damp (float): Mutation Coefficient Damp Rate, default = 0.99
delta (float): Mutation Step Size, default = 0.05
exponent (int): Exponent (m in the paper), default = 2
Examples
>>> import numpy as np >>> from mealpy.swarm_based.FFA import BaseFFA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> gamma = 0.001 >>> beta_base = 2 >>> alpha = 0.2 >>> alpha_damp = 0.99 >>> delta = 0.05 >>> exponent = 2 >>> model = BaseFFA(problem_dict1, epoch, pop_size, gamma, beta_base, alpha, alpha_damp, delta, exponent) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Gandomi, A.H., Yang, X.S. and Alavi, A.H., 2011. Mixed variable structural optimization using firefly algorithm. Computers & Structures, 89(23-24), pp.2325-2336. [2] Arora, S. and Singh, S., 2013. The firefly optimization algorithm: convergence analysis and parameter selection. International Journal of Computer Applications, 69(3).
mealpy.swarm_based.FOA¶
- class mealpy.swarm_based.FOA.BaseFOA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.swarm_based.FOA.OriginalFOAMy changed version of: Fruit-fly Optimization Algorithm (FOA)
Notes
The fitness function (small function) is changed by taking the distance each 2 adjacent dimensions
Update the position if only new generated solution is better
Examples
>>> import numpy as np >>> from mealpy.swarm_based.FOA import BaseFOA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseFOA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
- class mealpy.swarm_based.FOA.OriginalFOA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Fruit-fly Optimization Algorithm (FOA)
Notes
This optimization can’t apply to complicated objective function in this library.
So I changed the implementation Original FOA in BaseFOA version
This algorithm is the weakest algorithm in MHAs, that’s why so many researchers produce papers based on this algorithm (Easy to improve, and easy to implement)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.FOA import OriginalFOA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = OriginalFOA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Pan, W.T., 2012. A new fruit fly optimization algorithm: taking the financial distress model as an example. Knowledge-Based Systems, 26, pp.69-74.
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]]]
- Return type
list
- class mealpy.swarm_based.FOA.WhaleFOA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.swarm_based.FOA.OriginalFOAThe original version of: Whale Fruit-fly Optimization Algorithm (WFOA)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.FOA import WhaleFOA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = WhaleFOA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Fan, Y., Wang, P., Heidari, A.A., Wang, M., Zhao, X., Chen, H. and Li, C., 2020. Boosted hunting-based fruit fly optimization and advances in real-world problems. Expert Systems with Applications, 159, p.113502.
mealpy.swarm_based.GOA¶
- class mealpy.swarm_based.GOA.BaseGOA(problem, epoch=10000, pop_size=100, c_minmax=(4e-05, 1), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Grasshopper Optimization Algorithm (GOA)
- Links:
Notes
The matlab version above is not good, therefore
I added np.random.normal() component to Eq, 2.7
I changed the way to calculate distance between two location
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
c_minmax (list): (c_min, c_max) -> ([0.00001, 0.01], [0.5, 2.0]), coefficient c, default = (0.00004, 1)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.GOA import BaseGOA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> c_minmax = [0.00004, 1] >>> model = BaseGOA(problem_dict1, epoch, pop_size, c_minmax) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Saremi, S., Mirjalili, S. and Lewis, A., 2017. Grasshopper optimisation algorithm: theory and application. Advances in Engineering Software, 105, pp.30-47.
mealpy.swarm_based.GWO¶
- class mealpy.swarm_based.GWO.BaseGWO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Grey Wolf Optimizer (GWO)
- Links:
Examples
>>> import numpy as np >>> from mealpy.swarm_based.GWO import BaseGWO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseGWO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Mirjalili, S., Mirjalili, S.M. and Lewis, A., 2014. Grey wolf optimizer. Advances in engineering software, 69, pp.46-61.
- class mealpy.swarm_based.GWO.RW_GWO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Random Walk Grey Wolf Optimizer (RW-GWO)
Notes
This version is always performs worst than BaseGWO. Not sure why paper is accepted at Swarm and evolutionary computation
Examples
>>> import numpy as np >>> from mealpy.swarm_based.GWO import RW_GWO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = RW_GWO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Gupta, S. and Deep, K., 2019. A novel random walk grey wolf optimizer. Swarm and evolutionary computation, 44, pp.101-112.
mealpy.swarm_based.HGS¶
- class mealpy.swarm_based.HGS.OriginalHGS(problem, epoch=10000, pop_size=100, PUP=0.08, LH=10000, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Hunger Games Search (HGS)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
PUP (float): [0.01, 0.2], The probability of updating position (L in the paper), default = 0.08
LH (float): [1000, 20000], Largest hunger / threshold, default = 10000
Examples
>>> import numpy as np >>> from mealpy.swarm_based.HGS import OriginalHGS >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> PUP = 0.08 >>> LH = 10000 >>> model = OriginalHGS(problem_dict1, epoch, pop_size, PUP, LH) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Yang, Y., Chen, H., Heidari, A.A. and Gandomi, A.H., 2021. Hunger games search: Visions, conception, implementation, deep analysis, perspectives, and towards performance shifts. Expert Systems with Applications, 177, p.114864.
- ID_HUN = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], hunger]
- Return type
list
mealpy.swarm_based.HHO¶
- class mealpy.swarm_based.HHO.BaseHHO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Harris Hawks Optimization (HHO)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.HHO import BaseHHO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseHHO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Heidari, A.A., Mirjalili, S., Faris, H., Aljarah, I., Mafarja, M. and Chen, H., 2019. Harris hawks optimization: Algorithm and applications. Future generation computer systems, 97, pp.849-872.
mealpy.swarm_based.JA¶
- class mealpy.swarm_based.JA.BaseJA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy changed version of: Jaya Algorithm (JA)
Notes
All third loops are removed
Change the second random variable r2 to Gaussian instead of Uniform
Examples
>>> import numpy as np >>> from mealpy.swarm_based.JA import BaseJA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseJA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Rao, R., 2016. Jaya: A simple and new optimization algorithm for solving constrained and unconstrained optimization problems. International Journal of Industrial Engineering Computations, 7(1), pp.19-34.
- class mealpy.swarm_based.JA.LevyJA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.swarm_based.JA.BaseJAThe original version of: Levy-flight Jaya Algorithm (LJA)
Notes
All third loops in this version also are removed
The beta value of Levy-flight equal to 1.8 as the best value in the paper.
Examples
>>> import numpy as np >>> from mealpy.swarm_based.JA import LevyJA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = LevyJA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Iacca, G., dos Santos Junior, V.C. and de Melo, V.V., 2021. An improved Jaya optimization algorithm with Lévy flight. Expert Systems with Applications, 165, p.113902.
- class mealpy.swarm_based.JA.OriginalJA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.swarm_based.JA.BaseJAThe original version of: Jaya Algorithm (JA)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.JA import OriginalJA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = OriginalJA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Rao, R., 2016. Jaya: A simple and new optimization algorithm for solving constrained and unconstrained optimization problems. International Journal of Industrial Engineering Computations, 7(1), pp.19-34.
mealpy.swarm_based.MFO¶
- class mealpy.swarm_based.MFO.BaseMFO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy changed version of: Moth-Flame Optimization (MFO)
Notes
The flow of algorithm is changed
The old solution is updated
Examples
>>> import numpy as np >>> from mealpy.swarm_based.MFO import BaseMFO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseMFO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Mirjalili, S., 2015. Moth-flame optimization algorithm: A novel nature-inspired heuristic paradigm. Knowledge-based systems, 89, pp.228-249.
- class mealpy.swarm_based.MFO.OriginalMFO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.swarm_based.MFO.BaseMFOThe original version of: Moth-flame Optimization (MFO)
- Link:
Examples
>>> import numpy as np >>> from mealpy.swarm_based.MFO import OriginalMFO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = OriginalMFO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Mirjalili, S., 2015. Moth-flame optimization algorithm: A novel nature-inspired heuristic paradigm. Knowledge-based systems, 89, pp.228-249.
mealpy.swarm_based.MRFO¶
- class mealpy.swarm_based.MRFO.BaseMRFO(problem, epoch=10000, pop_size=100, somersault_range=2.0, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Manta Ray Foraging Optimization (MRFO)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
somersault_range (float): [1.5, 3], somersault factor that decides the somersault range of manta rays, default=2
Examples
>>> import numpy as np >>> from mealpy.swarm_based.MRFO import BaseMRFO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> sample_count = 50 >>> inten_factor = 0.5 >>> zeta = 1.0 >>> model = BaseMRFO(problem_dict1, epoch, pop_size, sample_count, inten_factor, zeta) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Zhao, W., Zhang, Z. and Wang, L., 2020. Manta ray foraging optimization: An effective bio-inspired optimizer for engineering applications. Engineering Applications of Artificial Intelligence, 87, p.103300.
mealpy.swarm_based.MSA¶
- class mealpy.swarm_based.MSA.BaseMSA(problem, epoch=10000, pop_size=100, n_best=5, partition=0.5, max_step_size=1.0, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy changed version of: Moth Search Algorithm (MSA)
- Links:
Notes
The matlab version of original paper is not good (especially convergence chart)
I add Normal random number (Gaussian distribution) in each updating equation (Better performance)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
n_best (int): [3, 10], how many of the best moths to keep from one generation to the next, default=5
partition (float): [0.3, 0.8], The proportional of first partition, default=0.5
max_step_size (float): [0.5, 2.0], Max step size used in Levy-flight technique, default=1.0
Examples
>>> import numpy as np >>> from mealpy.swarm_based.MSA import BaseMSA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> n_best = 5 >>> partition = 0.5 >>> max_step_size = 1.0 >>> model = BaseMSA(problem_dict1, epoch, pop_size, n_best, partition, max_step_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Wang, G.G., 2018. Moth search algorithm: a bio-inspired metaheuristic algorithm for global optimization problems. Memetic Computing, 10(2), pp.151-164.
mealpy.swarm_based.NMRA¶
- class mealpy.swarm_based.NMRA.BaseNMRA(problem, epoch=10000, pop_size=100, pb=0.75, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Naked Mole-Rat Algorithm (NMRA)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
pb (float): [0.5, 0.95], probability of breeding, default = 0.75
Examples
>>> import numpy as np >>> from mealpy.swarm_based.NMRA import BaseNMRA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> pb = 0.75 >>> model = BaseNMRA(problem_dict1, epoch, pop_size, pb) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Salgotra, R. and Singh, U., 2019. The naked mole-rat algorithm. Neural Computing and Applications, 31(12), pp.8837-8857.
- class mealpy.swarm_based.NMRA.ImprovedNMRA(problem, epoch=10000, pop_size=100, pb=0.75, pm=0.01, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Naked Mole-Rat Algorithm (I-NMRA)
Notes: + Use mutation probability idea + Use crossover operator + Use Levy-flight technique
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
pb (float): [0.5, 0.95], probability of breeding, default = 0.75
pm (float): [0.01, 0.1], probability of mutation, default = 0.01
Examples
>>> import numpy as np >>> from mealpy.swarm_based.NMRA import ImprovedNMRA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> pb = 0.75 >>> pm = 0.01 >>> model = ImprovedNMRA(problem_dict1, epoch, pop_size, pb, pm) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Salgotra, R. and Singh, U., 2019. The naked mole-rat algorithm. Neural Computing and Applications, 31(12), pp.8837-8857.
mealpy.swarm_based.PFA¶
- class mealpy.swarm_based.PFA.BasePFA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Pathfinder Algorithm (PFA)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.PFA import BasePFA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BasePFA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Yapici, H. and Cetinkaya, N., 2019. A new meta-heuristic optimizer: Pathfinder algorithm. Applied soft computing, 78, pp.545-568.
mealpy.swarm_based.PSO¶
- class mealpy.swarm_based.PSO.BasePSO(problem, epoch=10000, pop_size=100, c1=2.05, c2=2.05, w_min=0.4, w_max=0.9, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Particle Swarm Optimization (PSO)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
c1 (float): [1, 3], local coefficient, default = 2.05
c2 (float): [1, 3], global coefficient, default = 2.05
w_min (float): [0.1, 0.5], Weight min of bird, default = 0.4
w_max (float): [0.8, 2.0], Weight max of bird, default = 0.9
Examples
>>> import numpy as np >>> from mealpy.swarm_based.PSO import BasePSO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> c1 = 2.05 >>> c2 = 2.05 >>> w_min = 0.4 >>> w_max = 0.9 >>> model = BasePSO(problem_dict1, epoch, pop_size, c1, c2, w_min, w_max) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Kennedy, J. and Eberhart, R., 1995, November. Particle swarm optimization. In Proceedings of ICNN’95-international conference on neural networks (Vol. 4, pp. 1942-1948). IEEE.
- ID_LOF = 4¶
- ID_LOP = 3¶
- ID_VEC = 2¶
- amend_position(position=None)[source]¶
If solution out of bound at dimension x, then it will re-arrange to random location in the range of domain
- Parameters
position – vector position (location) of the solution.
- Returns
Amended position
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], velocity, local_pos, local_fit]
- Return type
list
- class mealpy.swarm_based.PSO.CL_PSO(problem, epoch=10000, pop_size=100, c_local=1.2, w_min=0.4, w_max=0.9, max_flag=7, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Comprehensive Learning Particle Swarm Optimization (CL-PSO)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
c_local (float): [1.0, 3.0], local coefficient, default = 1.2
w_min (float): [0.1, 0.5], Weight min of bird, default = 0.4
w_max (float): [0.7, 2.0], Weight max of bird, default = 0.9
max_flag (int): [5, 20], Number of times, default = 7
Examples
>>> import numpy as np >>> from mealpy.swarm_based.PSO import CL_PSO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> c_local = 1.2 >>> w_min = 0.4 >>> w_max = 0.9 >>> max_flag = 7 >>> model = CL_PSO(problem_dict1, epoch, pop_size, c_local, w_min, w_max, max_flag) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Liang, J.J., Qin, A.K., Suganthan, P.N. and Baskar, S., 2006. Comprehensive learning particle swarm optimizer for global optimization of multimodal functions. IEEE transactions on evolutionary computation, 10(3), pp.281-295.
- ID_LOF = 4¶
- ID_LOP = 3¶
- ID_VEC = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], velocity, local_pos, local_fit]
- Return type
list
- class mealpy.swarm_based.PSO.C_PSO(problem, epoch=10000, pop_size=100, c1=2.05, c2=2.05, w_min=0.4, w_max=0.9, **kwargs)[source]¶
Bases:
mealpy.swarm_based.PSO.BasePSOThe original version of: Chaos Particle Swarm Optimization (C-PSO)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
c1 (float): [1.0, 3.0] local coefficient, default = 2.05
c2 (float): [1.0, 3.0] global coefficient, default = 2.05
w_min (float): [0.1, 0.4], Weight min of bird, default = 0.4
w_max (float): [0.4, 2.0], Weight max of bird, default = 0.9
Examples
>>> import numpy as np >>> from mealpy.swarm_based.PSO import C_PSO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> c1 = 2.05 >>> c2 = 2.05 >>> w_min = 0.4 >>> w_max = 0.9 >>> model = C_PSO(problem_dict1, epoch, pop_size, c1, c2, w_min, w_max) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Liu, B., Wang, L., Jin, Y.H., Tang, F. and Huang, D.X., 2005. Improved particle swarm optimization combined with chaos. Chaos, Solitons & Fractals, 25(5), pp.1261-1271.
- class mealpy.swarm_based.PSO.HPSO_TVAC(problem, epoch=10000, pop_size=100, ci=0.5, cf=0.0, **kwargs)[source]¶
Bases:
mealpy.swarm_based.PSO.PPSOThe original version of: Ant Colony Optimization Continuous (HPSO-TVAC)
Notes
This code is converted from matlab code (sent from author: Ebrahim Akbari)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
ci (float): [0.3, 1.0], c initial, default = 0.5
cf (float): [0.0, 0.3], c final, default = 0.0
Examples
>>> import numpy as np >>> from mealpy.swarm_based.PSO import HPSO_TVAC >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> ci = 0.5 >>> cf = 0.0 >>> model = HPSO_TVAC(problem_dict1, epoch, pop_size, ci, cf) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Ghasemi, M., Aghaei, J. and Hadipour, M., 2017. New self-organising hierarchical PSO with jumping time-varying acceleration coefficients. Electronics Letters, 53(20), pp.1360-1362.
- class mealpy.swarm_based.PSO.PPSO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Phasor Particle Swarm Optimization (P-PSO)
Notes
This code is converted from matlab code (sent from author: Ebrahim Akbari)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.PSO import PPSO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = PPSO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Ghasemi, M., Akbari, E., Rahimnejad, A., Razavi, S.E., Ghavidel, S. and Li, L., 2019. Phasor particle swarm optimization: a simple and efficient variant of PSO. Soft Computing, 23(19), pp.9701-9718.
- ID_LOF = 4¶
- ID_LOP = 3¶
- ID_VEC = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], velocity, local_pos, local_fit]
- Return type
list
mealpy.swarm_based.SFO¶
- class mealpy.swarm_based.SFO.BaseSFO(problem, epoch=10000, pop_size=100, pp=0.1, AP=4, epxilon=0.0001, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: SailFish Optimizer (SFO)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
pp (float): the rate between SailFish and Sardines (N_sf = N_s * pp) = 0.25, 0.2, 0.1
AP (int): A = 4, 6,… (coefficient for decreasing the value of Attack Power linearly from AP to 0)
epxilon (float): should be 0.0001, 0.001
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SFO import BaseSFO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> pp = 0.1 >>> AP = 4 >>> epxilon = 0.0001 >>> model = BaseSFO(problem_dict1, epoch, pop_size, pp, AP, epxilon) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Shadravan, S., Naji, H.R. and Bardsiri, V.K., 2019. The Sailfish Optimizer: A novel nature-inspired metaheuristic algorithm for solving constrained engineering optimization problems. Engineering Applications of Artificial Intelligence, 80, pp.20-34.
- class mealpy.swarm_based.SFO.ImprovedSFO(problem, epoch=10000, pop_size=100, pp=0.1, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy improved version of: Sailfish Optimizer (I-SFO)
Notes
Reforms Energy equation
Removes parameters AP (A) and epsilon
Applies the idea of Opposition-based Learning technique
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
pp (float): the rate between SailFish and Sardines (N_sf = N_s * pp) = 0.25, 0.2, 0.1
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SFO import ImprovedSFO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> pp = 0.1 >>> model = ImprovedSFO(problem_dict1, epoch, pop_size, pp) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Socha, K. and Dorigo, M., 2008. Ant colony optimization for continuous domains. European journal of operational research, 185(3), pp.1155-1173.
mealpy.swarm_based.SHO¶
- class mealpy.swarm_based.SHO.BaseSHO(problem, epoch=10000, pop_size=100, h_factor=5, rand_v=(0.5, 1), N_tried=10, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy changed version of: Spotted Hyena Optimizer (SHO)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
h_factor (float): default = 5, coefficient linearly decreased from 5 to 0
rand_v (list): (uniform min, uniform max), random vector, default = [0.5, 1]
N_tried (int): default = 10,
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SHO import BaseSHO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> h_factor = 5 >>> rand_v = [0.5, 1] >>> N_tried = 10 >>> model = BaseSHO(problem_dict1, epoch, pop_size, h_factor, rand_v, N_tried) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Dhiman, G. and Kumar, V., 2017. Spotted hyena optimizer: a novel bio-inspired based metaheuristic technique for engineering applications. Advances in Engineering Software, 114, pp.48-70.
mealpy.swarm_based.SLO¶
- class mealpy.swarm_based.SLO.BaseSLO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Sea Lion Optimization Algorithm (SLO)
- Links:
Notes
The original paper is unclear in some equations and parameters
This version is based on my expertise
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SLO import BaseSLO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseSLO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Masadeh, R., Mahafzah, B.A. and Sharieh, A., 2019. Sea lion optimization algorithm. Sea, 10(5), p.388.
- class mealpy.swarm_based.SLO.ISLO(problem, epoch=10000, pop_size=100, c1=1.2, c2=1.2, **kwargs)[source]¶
Bases:
mealpy.swarm_based.SLO.ModifiedSLOMy improved version of: Improved Sea Lion Optimization (ISLO)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
c1 (float): Local coefficient same as PSO, default = 1.2
c2 (float): Global coefficient same as PSO, default = 1.2
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SLO import ISLO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> c1 = 1.2 >>> c2 = 1.5 >>> model = ISLO(problem_dict1, epoch, pop_size, c1, c2) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
- class mealpy.swarm_based.SLO.ModifiedSLO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy modified version of: Sea Lion Optimization (M-SLO)
Notes
Use the idea of shrink encircling combine with levy flight techniques
Beside, the idea of local best in PSO is used
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SLO import ModifiedSLO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = ModifiedSLO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
- ID_LOC_FIT = 3¶
- ID_LOC_POS = 2¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], local_pos, local_fit]
- Return type
list
mealpy.swarm_based.SRSR¶
- class mealpy.swarm_based.SRSR.BaseSRSR(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Swarm Robotics Search And Rescue (SRSR)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SRSR import BaseSRSR >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseSRSR(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Bakhshipour, M., Ghadi, M.J. and Namdari, F., 2017. Swarm robotics search & rescue: A novel artificial intelligence-inspired optimization approach. Applied Soft Computing, 57, pp.708-726.
- ID_FIT_MOVE = 6¶
- ID_FIT_NEW = 5¶
- ID_MU = 2¶
- ID_POS = 0¶
- ID_POS_NEW = 4¶
- ID_SIGMA = 3¶
- ID_TAR = 1¶
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], mu, sigma, x_new, fit_new, fit_move]
- Return type
list
mealpy.swarm_based.SSA¶
- class mealpy.swarm_based.SSA.BaseSSA(problem, epoch=10000, pop_size=100, ST=0.8, PD=0.2, SD=0.1, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy changed version of: Sparrow Search Algorithm (SSA)
Notes
First, I sort the algorithm and find g-best and g-worst
In Eq. 4, Instead of using A+ and L, I used np.random.normal()
Some components (g_best_position, fitness updated) are missing in Algorithm 1 (paper)
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
ST (float): ST in [0.5, 1.0], safety threshold value, default = 0.8
PD (float): number of producers (percentage), default = 0.2
SD (float): number of sparrows who perceive the danger, default = 0.1
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SSA import BaseSSA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> ST = 0.8 >>> PD = 0.2 >>> SD = 0.1 >>> model = BaseSSA(problem_dict1, epoch, pop_size, ST, PD, SD) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Xue, J. and Shen, B., 2020. A novel swarm intelligence optimization approach: sparrow search algorithm. Systems Science & Control Engineering, 8(1), pp.22-34.
- class mealpy.swarm_based.SSA.OriginalSSA(problem, epoch=10000, pop_size=100, ST=0.8, PD=0.2, SD=0.1, **kwargs)[source]¶
Bases:
mealpy.swarm_based.SSA.BaseSSAThe original version of: Sparrow Search Algorithm (SSA)
Notes
The paper contains some unclear equations and symbol
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
ST (float): ST in [0.5, 1.0], safety threshold value, default = 0.8
PD (float): number of producers (percentage), default = 0.2
SD (float): number of sparrows who perceive the danger, default = 0.1
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SSA import OriginalSSA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> ST = 0.8 >>> PD = 0.2 >>> SD = 0.1 >>> model = OriginalSSA(problem_dict1, epoch, pop_size, ST, PD, SD) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Xue, J. and Shen, B., 2020. A novel swarm intelligence optimization approach: sparrow search algorithm. Systems Science & Control Engineering, 8(1), pp.22-34.
mealpy.swarm_based.SSO¶
- class mealpy.swarm_based.SSO.BaseSSO(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Salp Swarm Optimization (SSO)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SSO import BaseSSO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseSSO(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Mirjalili, S., Gandomi, A.H., Mirjalili, S.Z., Saremi, S., Faris, H. and Mirjalili, S.M., 2017. Salp Swarm Algorithm: A bio-inspired optimizer for engineering design problems. Advances in Engineering Software, 114, pp.163-191.
mealpy.swarm_based.SSpiderA¶
- class mealpy.swarm_based.SSpiderA.BaseSSpiderA(problem, epoch=10000, pop_size=100, r_a=1, p_c=0.7, p_m=0.1, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerMy modified version of: Social Spider Algorithm (BaseSSpiderA)
- Links:
https://github.com/James-Yu/SocialSpiderAlgorithm (Modified this version)
Notes
The version on above github is very slow convergence
Changes the idea of intensity, which one has better intensity, others will move toward to it
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
r_a (float): the rate of vibration attenuation when propagating over the spider web, default=1.0
p_c (float): controls the probability of the spiders changing their dimension mask in the random walk step, default=0.7
p_m (float): the probability of each value in a dimension mask to be one, default=0.1
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SSpiderA import BaseSSpiderA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> r_a = 50 >>> p_c = 0.5 >>> p_m = 1.0 >>> model = BaseSSpiderA(problem_dict1, epoch, pop_size, r_a, p_c, p_m) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] James, J.Q. and Li, V.O., 2015. A social spider algorithm for global optimization. Applied soft computing, 30, pp.614-627.
- ID_INT = 2¶
- ID_MASK = 5¶
- ID_POS = 0¶
- ID_PREV_MOVE_VEC = 4¶
- ID_TAR = 1¶
- ID_TARGET_POS = 3¶
- create_solution()[source]¶
x: The position of s on the web.
train: The fitness of the current position of s
target_vibration: The target vibration of s in the previous iteration.
intensity_vibration: intensity of vibration
movement_vector: The movement that s performed in the previous iteration
dimension_mask: The dimension mask 1 that s employed to guide movement in the previous iteration
The dimension mask is a 0-1 binary vector of length problem size
n_changed: The number of iterations since s has last changed its target vibration. (No need)
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], intensity, target_position, previous_movement_vector, dimension_mask]
- Return type
list
mealpy.swarm_based.SSpiderO¶
- class mealpy.swarm_based.SSpiderO.BaseSSpiderO(problem, epoch=10000, pop_size=100, fp=(0.65, 0.9), **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Social Spider Optimization (SSpiderO)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
fp (list): (fp_min, fp_max): Female Percent, default = (0.65, 0.9)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.SSpiderO import BaseSSpiderO >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> fb = [0.65, 0.9] >>> model = BaseSSpiderO(problem_dict1, epoch, pop_size, fb) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Luque-Chang, A., Cuevas, E., Fausto, F., Zaldivar, D. and Pérez, M., 2018. Social spider optimization algorithm: modifications, applications, and perspectives. Mathematical Problems in Engineering, 2018.
- ID_POS = 0¶
- ID_TAR = 1¶
- ID_WEI = 2¶
- amend_position(position=None)[source]¶
If solution out of bound at dimension x, then it will re-arrange to random location in the range of domain
- Parameters
position – vector position (location) of the solution.
- Returns
Amended position
- create_solution()[source]¶
- To get the position, fitness wrapper, target and obj list
A[self.ID_POS] –> Return: position
A[self.ID_TAR] –> Return: [target, [obj1, obj2, …]]
A[self.ID_TAR][self.ID_FIT] –> Return: target
A[self.ID_TAR][self.ID_OBJ] –> Return: [obj1, obj2, …]
- Returns
wrapper of solution with format [position, [target, [obj1, obj2, …]], weight]
- Return type
list
mealpy.swarm_based.WOA¶
- class mealpy.swarm_based.WOA.BaseWOA(problem, epoch=10000, pop_size=100, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Whale Optimization Algorithm (WOA)
Examples
>>> import numpy as np >>> from mealpy.swarm_based.WOA import BaseWOA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> model = BaseWOA(problem_dict1, epoch, pop_size) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Mirjalili, S. and Lewis, A., 2016. The whale optimization algorithm. Advances in engineering software, 95, pp.51-67.
- class mealpy.swarm_based.WOA.HI_WOA(problem, epoch=10000, pop_size=100, feedback_max=10, **kwargs)[source]¶
Bases:
mealpy.optimizer.OptimizerThe original version of: Hybrid Improved Whale Optimization Algorithm (HI-WOA)
- Links:
- Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
feedback_max (int): maximum iterations of each feedback, default = 10
Examples
>>> import numpy as np >>> from mealpy.swarm_based.WOA import HI_WOA >>> >>> def fitness_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict1 = { >>> "fit_func": fitness_function, >>> "lb": [-10, -15, -4, -2, -8], >>> "ub": [10, 15, 12, 8, 20], >>> "minmax": "min", >>> "verbose": True, >>> } >>> >>> epoch = 1000 >>> pop_size = 50 >>> feedback_max = 10 >>> model = HI_WOA(problem_dict1, epoch, pop_size, feedback_max) >>> best_position, best_fitness = model.solve() >>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
References
[1] Tang, C., Sun, W., Wu, W. and Xue, M., 2019, July. A hybrid improved whale optimization algorithm. In 2019 IEEE 15th International Conference on Control and Automation (ICCA) (pp. 362-367). IEEE.