mealpy.music_based package

mealpy.music_based.HS

class mealpy.music_based.HS.BaseHS(problem, epoch=10000, pop_size=100, c_r=0.95, pa_r=0.05, **kwargs)[source]

Bases: mealpy.optimizer.Optimizer

My changed version of: Harmony Search (HS)

Links:
  1. https://doi.org/10.1177/003754970107600201

Notes

  • Used the global best in the harmony memories

  • Removed third for loop

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • c_r (float): [0.1, 0.5], Harmony Memory Consideration Rate), default = 0.15

  • pa_r (float): [0.3, 0.8], Pitch Adjustment Rate, default=0.5

Examples

>>> import numpy as np
>>> from mealpy.music_based.HS import BaseHS
>>>
>>> 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_r = 0.95
>>> pa_r = 0.05
>>> model = BaseHS(problem_dict1, epoch, pop_size, c_r, pa_r)
>>> 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.music_based.HS.OriginalHS(problem, epoch=10000, pop_size=100, c_r=0.95, pa_r=0.05, **kwargs)[source]

Bases: mealpy.music_based.HS.BaseHS

The original version of: Harmony Search (HS)

Links:
  1. https://doi.org/10.1177/003754970107600201

Hyper-parameters should fine tuned in approximate range to get faster convergen toward the global optimum:
  • c_r (float): [0.1, 0.5], Harmony Memory Consideration Rate), default = 0.15

  • pa_r (float): [0.3, 0.8], Pitch Adjustment Rate, default=0.5

Examples

>>> import numpy as np
>>> from mealpy.music_based.HS import OriginalHS
>>>
>>> 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_r = 0.95
>>> pa_r = 0.05
>>> model = OriginalHS(problem_dict1, epoch, pop_size, c_r, pa_r)
>>> best_position, best_fitness = model.solve()
>>> print(f"Solution: {best_position}, Fitness: {best_fitness}")

References

[1] Geem, Z.W., Kim, J.H. and Loganathan, G.V., 2001. A new heuristic optimization algorithm: harmony search. simulation, 76(2), pp.60-68.

evolve(epoch)[source]

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

Parameters

epoch (int) – The current iteration