mealpy.music_based package¶
mealpy.music_based.HS module¶
- class mealpy.music_based.HS.DevHS(epoch: int = 10000, pop_size: int = 100, c_r: float = 0.95, pa_r: float = 0.05, **kwargs: object)[source]¶
Bases:
mealpy.optimizer.Optimizer
The developed version: Harmony Search (HS)
Notes
Used the global best in the harmony memories
Removed all third for loops
- Hyper-parameters should fine-tune in approximate range to get faster convergence 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 import FloatVar, HS >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(n_vars=30, lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = HS.DevHS(epoch=1000, pop_size=50, c_r = 0.95, pa_r = 0.05) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")
- class mealpy.music_based.HS.OriginalHS(epoch: int = 10000, pop_size: int = 100, c_r: float = 0.95, pa_r: float = 0.05, **kwargs: object)[source]¶
Bases:
mealpy.music_based.HS.DevHS
The original version of: Harmony Search (HS)
- Links:
- Hyper-parameters should fine-tune in approximate range to get faster convergence 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 import FloatVar, HS >>> >>> def objective_function(solution): >>> return np.sum(solution**2) >>> >>> problem_dict = { >>> "bounds": FloatVar(n_vars=30, lb=(-10.,) * 30, ub=(10.,) * 30, name="delta"), >>> "minmax": "min", >>> "obj_func": objective_function >>> } >>> >>> model = HS.OriginalHS(epoch=1000, pop_size=50, c_r = 0.95, pa_r = 0.05) >>> g_best = model.solve(problem_dict) >>> print(f"Solution: {g_best.solution}, Fitness: {g_best.target.fitness}") >>> print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.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.