Harmony Search
Example:
from bejoor.population_based import HarmonySearch
import math
def rastrigin_function(sol):
n = len(sol)
return 10 * n + sum(x**2 - 10 * math.cos(2 * math.pi * x) for x in sol)
solution_vector = [{"type": "float", "lower_bound": -5.12, "upper_bound": 5.12}] * 7
hs = HarmonySearch(objective_function=rastrigin_function, solution_vector_size=7,
solution_vector=solution_vector, optimization_side="min",
HMCR=0.6, PAR=0.3, population_size=30, epochs=50)
hs.run()
print(f'Best Global Objective Value: {hs.global_best_objective_value}')
print(f'Best Global Solution: {hs.global_best_solution}')
Parameters:
-
objective_function
: Objective function needs to be optimized.
-
solution_vector_size
: Vector size of the candidate solutions.
-
solution_vector
: A vector which determines the types of each variable in solution vectors.
-
optimization_side
: Determines maximize or minimize the objective function.
-
target_objective_value
: Target Objective value.
-
target_objective_lower_bound
: Target Objective lower bound.
-
target_objective_upper_bound
: Target Objective upper bound.
-
population_size
: Number of individuals in the population.
-
epochs
: Number of generations to run the algorithm.
-
HMCR
: Harmony memory consideration rate (probability of choosing values from the harmony memory).
-
PAR
: Pitch adjustment rate (probability of fine-tuning a selected value).
BibTeX citation to the algorithm
@article{geem2001new,
title={A new heuristic optimization algorithm: harmony search},
author={Geem, Zong Woo and Kim, Joong Hoon and Loganathan, Gobichettipalayam Vasudevan},
journal={simulation},
volume={76},
number={2},
pages={60--68},
year={2001},
publisher={Sage Publications Sage CA: Thousand Oaks, CA}
}
More useful resources about the algorithm: