mealpy.bio_based package

mealpy.bio_based.BBO

class mealpy.bio_based.BBO.BaseBBO(problem, epoch=10000, pop_size=100, p_m=0.01, elites=2, **kwargs)[source]

Bases: mealpy.bio_based.BBO.OriginalBBO

My changed version of: Biogeography-Based Optimization (BBO)

Links:
  1. https://ieeexplore.ieee.org/abstract/document/4475427

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • p_m: [0.01, 0.2], Mutation probability

  • elites: [2, 5], Number of elites will be keep for next generation

Examples

>>> import numpy as np
>>> from mealpy.bio_based.BBO import BaseBBO
>>>
>>> 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_m = 0.01
>>> elites = 2
>>> model = BaseBBO(problem_dict1, epoch, pop_size, p_m, elites)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.bio_based.BBO.OriginalBBO(problem, epoch=10000, pop_size=100, p_m=0.01, elites=2, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Biogeography-Based Optimization (BBO)

Links:
  1. https://ieeexplore.ieee.org/abstract/document/4475427

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • p_m: [0.01, 0.2], Mutation probability

  • elites: [2, 5], Number of elites will be keep for next generation

Examples

>>> import numpy as np
>>> from mealpy.bio_based.BBO import OriginalBBO
>>>
>>> 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_m = 0.01
>>> elites = 2
>>> model = OriginalBBO(problem_dict1, epoch, pop_size, p_m, elites)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Simon, D., 2008. Biogeography-based optimization. IEEE transactions on evolutionary computation, 12(6), pp.702-713.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.bio_based.EOA

class mealpy.bio_based.EOA.BaseEOA(problem, epoch=10000, pop_size=100, p_c=0.9, p_m=0.01, n_best=2, alpha=0.98, beta=1, gamma=0.9, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Earthworm Optimisation Algorithm (EOA)

Links:
  1. http://doi.org/10.1504/IJBIC.2015.10004283

  2. https://www.mathworks.com/matlabcentral/fileexchange/53479-earthworm-optimization-algorithm-ewa

Notes

The original version from matlab code above will not working well, even with small dimensions. I change updating process, change cauchy process using x_mean, use global best solution, and remove third loop for faster

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • p_c: [0.5, 0.95], crossover probability

  • p_m: [0.01, 0.2], initial mutation probability

  • n_best: [2, 5], how many of the best earthworm to keep from one generation to the next

  • alpha: [0.8, 0.99], similarity factor

  • beta: [0.8, 1.0], the initial proportional factor

  • gamma: [0.8, 0.99], a constant that is similar to cooling factor of a cooling schedule in the simulated annealing.

Examples

>>> import numpy as np
>>> from mealpy.bio_based.EOA import BaseEOA
>>>
>>> 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_c = 0.9
>>> p_m = 0.01
>>> n_best = 2
>>> alpha = 0.98
>>> beta = 1.0
>>> gamma = 0.9
>>> model = BaseEOA(problem_dict1, epoch, pop_size, p_c, p_m, n_best, alpha, beta, gamma)
>>> 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., 2018. Earthworm optimisation algorithm: a bio-inspired metaheuristic algorithm for global optimisation problems. International journal of bio-inspired computation, 12(1), pp.1-22.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.bio_based.IWO

class mealpy.bio_based.IWO.OriginalIWO(problem, epoch=10000, pop_size=100, seeds=(2, 10), exponent=2, sigma=(0.5, 0.001), **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Invasive Weed Optimization (IWO)

Links:
  1. https://pdfs.semanticscholar.org/734c/66e3757620d3d4016410057ee92f72a9853d.pdf

Notes

Better to use normal distribution instead of uniform distribution, updating population by sorting both parent population and child population

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • seeds (list): (min_value, max_value) -> ([1, 3], [5, 10]), Number of Seeds

  • exponent (int): [2, 4], Variance Reduction Exponent

  • sigma (list): (initial_value, final_value), ([0.5, 0.9], [0.001, 0.1]), Value of Standard Deviation

Examples

>>> import numpy as np
>>> from mealpy.bio_based.IWO import OriginalIWO
>>>
>>> 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
>>> seeds = [3, 9]
>>> exponent = 3
>>> sigma = [0.6, 0.01]
>>> model = OriginalIWO(problem_dict1, epoch, pop_size, seeds, exponent, sigma)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Mehrabian, A.R. and Lucas, C., 2006. A novel numerical optimization algorithm inspired from weed colonization. Ecological informatics, 1(4), pp.355-366.

evolve(epoch=None)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.bio_based.SBO

class mealpy.bio_based.SBO.BaseSBO(problem, epoch=10000, pop_size=100, alpha=0.94, pm=0.05, psw=0.02, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Satin Bowerbird Optimizer (SBO)

Links:
  1. https://doi.org/10.1016/j.engappai.2017.01.006

Notes

The original version is not good enough, I remove all third loop for faster training, remove equation (1, 2) in the paper, calculate probability by roulette-wheel. My version can also handle negative value

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • alpha (float): [0.5, 0.99], the greatest step size

  • pm (float): [0.01, 0.2], mutation probability

  • psw (float): [0.01, 0.1], proportion of space width (z in the paper)

Examples

>>> import numpy as np
>>> from mealpy.bio_based.SBO import BaseSBO
>>>
>>> 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.9
>>> pm=0.05
>>> psw = 0.02
>>> model = BaseSBO(problem_dict1, epoch, pop_size, alpha, pm, psw)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.bio_based.SBO.OriginalSBO(problem, epoch=10000, pop_size=100, alpha=0.94, pm=0.05, psw=0.02, **kwargs)[source]

Bases: mealpy.bio_based.SBO.BaseSBO

The original version of: Satin Bowerbird Optimizer (SBO)

Links:
  1. https://doi.org/10.1016/j.engappai.2017.01.006

  2. https://www.mathworks.com/matlabcentral/fileexchange/62009-satin-bowerbird-optimizer-sbo-2017

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • alpha (float): [0.5, 0.99], the greatest step size

  • pm (float): [0.01, 0.2], mutation probability

  • psw (float): [0.01, 0.1], proportion of space width (z in the paper)

Examples

>>> import numpy as np
>>> from mealpy.bio_based.SBO import OriginalSBO
>>>
>>> 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.9
>>> pm=0.05
>>> psw = 0.02
>>> model = OriginalSBO(problem_dict1, epoch, pop_size, alpha, pm, psw)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Moosavi, S.H.S. and Bardsiri, V.K., 2017. Satin bowerbird optimizer: A new optimization algorithm to optimize ANFIS for software development effort estimation. Engineering Applications of Artificial Intelligence, 60, pp.1-15.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.bio_based.SMA

class mealpy.bio_based.SMA.BaseSMA(problem, epoch=10000, pop_size=100, pr=0.03, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Slime Mould Algorithm (SMA)

Notes

  • Selected 2 unique and random solution to create new solution (not to create variable) –> remove third loop in original version

  • Check bound and update fitness after each individual move instead of after the whole population move in the original version

  • This version not only faster but also better than the original version

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • pr (float): [0.01, 0.1], probability threshold (z in the paper)

Examples

>>> import numpy as np
>>> from mealpy.bio_based.SMA import BaseSMA
>>>
>>> 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
>>> pr = 0.03
>>> model = BaseSMA(problem_dict1, epoch, pop_size, pr)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
ID_WEI = 2
create_solution() list[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

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.bio_based.SMA.OriginalSMA(problem, epoch=10000, pop_size=100, pr=0.03, **kwargs)[source]

Bases: mealpy.bio_based.SMA.BaseSMA

The original version of: Slime Mould Algorithm (SMA)

Links:
  1. https://doi.org/10.1016/j.future.2020.03.055

  2. https://www.researchgate.net/publication/340431861_Slime_mould_algorithm_A_new_method_for_stochastic_optimization

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • pr (float): [0.01, 0.1], probability threshold (z in the paper)

Examples

>>> import numpy as np
>>> from mealpy.bio_based.SMA import OriginalSMA
>>>
>>> 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
>>> pr = 0.03
>>> model = OriginalSMA(problem_dict1, epoch, pop_size, pr)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Li, S., Chen, H., Wang, M., Heidari, A.A. and Mirjalili, S., 2020. Slime mould algorithm: A new method for stochastic optimization. Future Generation Computer Systems, 111, pp.300-323.

ID_WEI = 2
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.bio_based.TPO

class mealpy.bio_based.TPO.UpdatedTPO(problem, num_branches, num_leaves, epoch, alpha, beta, theta, **kwargs)[source]

Bases: object

The updated Tree Physiology Optimization (TPO) published by A. Hanif Halim and I. Ismail on November 9, 2017.

Notes

The alpha, beta and theta should fine tuned to get faster convergence toward the global optimum. A good approximate range for alpha is [0.3, 3], for beta [20, 70] and for theta [0.7, 0.99].

Examples

>>> def obj_function(solution):
>>>     return np.sum(solution**2)
>>>
>>> problem_dict1 = {
>>>     "fit_func": obj_function,
>>>     "n_dims": 5,
>>>     "lb": [-10, -15, -4, -2, -8],
>>>     "ub": [10, 15, 12, 8, 20],
>>>     "minmax": "min",
>>>     "verbose": False,
>>> }
>>>
>>> alpha = 0.4
>>> beta = 50
>>> theta = 0.95
>>> num_branches = 50
>>> num_leaves = 40
>>> epoch = 50
>>> model1 = UpdatedTPO(problem_dict1, num_branches, num_leaves, epoch, alpha, beta, theta)
>>> solution = model1.solve()
>>> print(solution)

References

[1] Halim, A. Hanif and Ismail, I. “Tree Physiology Optimization in Benchmark Function and Traveling Salesman Problem” Journal of Intelligent Systems, vol. 28, no. 5, 2019, pp. 849-871.

solve()[source]

Minimize the objective function specified in the problem.

Returns

Best solutions of the problem found after specified epochs.

Return type

numpy.array

trim_values()[source]

Trim the values of shoots to make sure they stay within the specified upper and lower bounds.

mealpy.bio_based.VCS

class mealpy.bio_based.VCS.BaseVCS(problem, epoch=10000, pop_size=100, lamda=0.5, xichma=0.3, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Virus Colony Search (VCS)

Links:
  1. https://doi.org/10.1016/j.advengsoft.2015.11.004

Notes

  • Removes all third loop, makes algrithm 10 times faster than original

  • In Immune response process, updates the whole position instead of updating each variable in position

  • Drops batch-size idea to 3 main process of this algorithm, makes it more robust

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • lamda (float): [0.2, 0.5], Number of the best will keep

  • xichma (float): [0.1, 0.5], Weight factor

Examples

>>> import numpy as np
>>> from mealpy.bio_based.VCS import BaseVCS
>>>
>>> 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
>>> lamda = 0.5
>>> xichma = 0.3
>>> model = BaseVCS(problem_dict1, epoch, pop_size, lamda, xichma)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

class mealpy.bio_based.VCS.OriginalVCS(problem, epoch=10000, pop_size=100, lamda=0.5, xichma=0.3, **kwargs)[source]

Bases: mealpy.bio_based.VCS.BaseVCS

The original version of: Virus Colony Search (VCS)

Links:
  1. https://doi.org/10.1016/j.advengsoft.2015.11.004

Notes

This is basic version, not the full version of the paper

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • lamda (float): [0.2, 0.5], Number of the best will keep

  • xichma (float): [0.1, 0.5], Weight factor

Examples

>>> import numpy as np
>>> from mealpy.bio_based.VCS import OriginalVCS
>>>
>>> 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
>>> lamda = 0.5
>>> xichma = 0.3
>>> model = OriginalVCS(problem_dict1, epoch, pop_size, lamda, xichma)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Li, M.D., Zhao, H., Weng, X.W. and Han, T., 2016. A novel nature-inspired algorithm for optimization: Virus colony search. Advances in Engineering Software, 92, pp.65-88.

amend_position(position)[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

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration

mealpy.bio_based.WHO

class mealpy.bio_based.WHO.BaseWHO(problem, epoch=10000, pop_size=100, n_s=3, n_e=3, eta=0.15, local_move=(0.9, 0.3), global_move=(0.2, 0.8), p_hi=0.9, delta=(2.0, 2.0), **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Wildebeest Herd Optimization (WHO)

Links:
  1. https://doi.org/10.3233/JIFS-190495

Notes

Before updated old position, I check whether new position is better or not.

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • n_s (int): [2, 4], number of exploration step

  • n_e (int): [2, 4], number of exploitation step

  • eta (float): [0.05, 0.5], learning rate

  • local_move (list): (alpha 1, beta 1) -> ([0.5, 0.9], [0.1, 0.5]), control local movement

  • global_move (list): (alpha 2, beta 2) -> ([0.1, 0.5], [0.5, 0.9]), control global movement

  • p_hi (float): [0.7, 0.95], the probability of wildebeest move to another position based on herd instinct

  • delta (list): (delta_w, delta_c) -> ([1.0, 2.0], [1.0, 2.0]), (dist to worst, dist to best)

Examples

>>> import numpy as np
>>> from mealpy.bio_based.WHO import BaseWHO
>>>
>>> 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_s = 3
>>> n_e = 3
>>> eta = 0.15
>>> local_move = [0.9, 0.3]
>>> global_move = [0.2, 0.8]
>>> p_hi = 0.9
>>> delta = [2.0, 2.0]
>>> model = BaseWHO(problem_dict1, epoch, pop_size, n_s, n_e, eta, local_move, global_move, p_hi, delta,)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Amali, D. and Dinakaran, M., 2019. Wildebeest herd optimization: a new global optimization algorithm inspired by wildebeest herding behaviour. Journal of Intelligent & Fuzzy Systems, 37(6), pp.8063-8076.

evolve(epoch)[source]

The main operations (equations) of algorithm. Inherit from Optimizer class

Parameters

epoch (int) – The current iteration