mealpy.math_based package

mealpy.math_based.AOA

class mealpy.math_based.AOA.OriginalAOA(problem, epoch=10000, pop_size=100, alpha=5, miu=0.5, moa_min=0.2, moa_max=0.9, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Arithmetic Optimization Algorithm (AOA)

Links:
  1. https://doi.org/10.1016/j.cma.2020.113609

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • alpha (int): [3, 8], fixed parameter, sensitive exploitation parameter, Default: 5,

  • miu (float): [0.3, 1.0], fixed parameter , control parameter to adjust the search process, Default: 0.5,

  • moa_min (float): [0.1, 0.4], range min of Math Optimizer Accelerated, Default: 0.2,

  • moa_max (float): [0.5, 1.0], range max of Math Optimizer Accelerated, Default: 0.9,

Examples

>>> import numpy as np
>>> from mealpy.math_based.AOA import OriginalAOA
>>>
>>> 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 = 5
>>> miu = 0.5
>>> moa_min = 0.2
>>> moa_max = 0.9
>>> model = OriginalAOA(problem_dict1, epoch, pop_size, alpha, miu, moa_min, moa_max)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Abualigah, L., Diabat, A., Mirjalili, S., Abd Elaziz, M. and Gandomi, A.H., 2021. The arithmetic optimization algorithm. Computer methods in applied mechanics and engineering, 376, p.113609.

evolve(epoch)[source]

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

Parameters

epoch (int) – The current iteration

mealpy.math_based.CGO

class mealpy.math_based.CGO.OriginalCGO(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Chaos Game Optimization (CGO)

Links:
  1. https://doi.org/10.1007/s10462-020-09867-w

Notes

  • 4th seed is mutation process, but it is not clear mutation on multiple variables or 1 variable

  • There is no usage of the variable alpha 4th in the paper

  • The replacement of worst solutions by generated seed are not clear (Lots of grammar errors in this section)

Examples

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

References

[1] Talatahari, S. and Azizi, M., 2021. Chaos Game Optimization: a novel metaheuristic algorithm. Artificial Intelligence Review, 54(2), pp.917-1004.

evolve(epoch)[source]

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

Parameters

epoch (int) – The current iteration

mealpy.math_based.GBO

class mealpy.math_based.GBO.OriginalGBO(problem, epoch=10000, pop_size=100, pr=0.5, beta_minmax=(0.2, 1.2), **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Gradient-Based Optimizer (GBO)

Notes

  • The number of neighbour solutions are equal to user defined

  • The step size to calculate neighbour is randomized

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • pr (float): [0.2, 0.8], Probability Parameter, default = 0.5

  • beta_minmax (list): Fixed parameter (no name in the paper), default = (0.2, 1.2)

Examples

>>> import numpy as np
>>> from mealpy.math_based.GBO import OriginalGBO
>>>
>>> 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.5
>>> beta_minmax = [0.2, 1.2]
>>> model = OriginalGBO(problem_dict1, epoch, pop_size, pr, beta_minmax)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Ahmadianfar, I., Bozorg-Haddad, O. and Chu, X., 2020. Gradient-based optimizer: A new metaheuristic optimization algorithm. Information Sciences, 540, pp.131-159.

evolve(epoch)[source]

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

Parameters

epoch (int) – The current iteration

initialization()[source]

mealpy.math_based.HC

class mealpy.math_based.HC.BaseHC(problem, epoch=10000, pop_size=100, neighbour_size=50, **kwargs)[source]

Bases: mealpy.math_based.HC.OriginalHC

My changed version of: Swarm-based Hill Climbing (S-HC)

Notes

  • Based on swarm-of people are trying to climb on the mountain idea

  • The number of neighbour solutions are equal to population size

  • The step size to calculate neighbour is randomized and based on rank of solution.
    • The guys near on top of mountain will move slower than the guys on bottom of mountain.

    • Imagination: exploration when far from global best, and exploitation when near global best

  • Who on top of mountain first will be the winner. (global optimal)

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • neighbour_size (int): [pop_size/2, pop_size], fixed parameter, sensitive exploitation parameter, Default: 50

Examples

>>> import numpy as np
>>> from mealpy.math_based.HC import BaseHC
>>>
>>> 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
>>> neighbour_size = 50
>>> model = BaseHC(problem_dict1, epoch, pop_size, neighbour_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")
evolve(epoch)[source]
Parameters

epoch (int) – The current iteration

class mealpy.math_based.HC.OriginalHC(problem, epoch=10000, pop_size=100, neighbour_size=50, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

The original version of: Hill Climbing (HC)

Notes

  • The number of neighbour solutions are equal to user defined

  • The step size to calculate neighbour is randomized

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • neighbour_size (int): [pop_size/2, pop_size], fixed parameter, sensitive exploitation parameter, Default: 50

Examples

>>> import numpy as np
>>> from mealpy.math_based.HC import OriginalHC
>>>
>>> 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
>>> neighbour_size = 50
>>> model = OriginalHC(problem_dict1, epoch, pop_size, neighbour_size)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Mitchell, M., Holland, J. and Forrest, S., 1993. When will a genetic algorithm outperform hill climbing. Advances in neural information processing systems, 6.

evolve(epoch)[source]

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

Parameters

epoch (int) – The current iteration

mealpy.math_based.SCA

class mealpy.math_based.SCA.BaseSCA(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Sine Cosine Algorithm (SCA)

Notes

  • The flow and few equations is changed

  • Removed third loop for faster computational time

Examples

>>> import numpy as np
>>> from mealpy.math_based.SCA import BaseSCA
>>>
>>> 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 = BaseSCA(problem_dict1, epoch, pop_size)
>>> 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.math_based.SCA.OriginalSCA(problem, epoch=10000, pop_size=100, **kwargs)[source]

Bases: mealpy.math_based.SCA.BaseSCA

The original version of: Sine Cosine Algorithm (SCA)

Links:
  1. https://doi.org/10.1016/j.knosys.2015.12.022

  2. https://www.mathworks.com/matlabcentral/fileexchange/54948-sca-a-sine-cosine-algorithm

Examples

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

References

[1] Mirjalili, S., 2016. SCA: a sine cosine algorithm for solving optimization problems. Knowledge-based systems, 96, pp.120-133.

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

evolve(epoch)[source]

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

Parameters

epoch (int) – The current iteration