Harmony Search (HS)¶
A simple method for continuous problems that keeps a small memory of good solutions.
HS ¶
HS(*, pop_size=10, new_count=20, hmcr=0.9, par=0.35, fret_width=0.02, fret_width_damp=0.99, **kwargs)
Harmony Search (Geem, Kim and Loganathan, 2001), continuous version with a bandwidth (Lee and Geem, 2005).
Each iteration creates new_count new harmonies. For every component of a new
harmony, with probability hmcr the value is copied from a random member of the
harmony memory (a new member for each component). A copied value is then, with
probability par, moved by bandwidth * U(-1, 1). Otherwise the component is
random in [0, 1]. The new harmonies join the memory, and the best pop_size are
kept.
Unlike Lee and Geem (2005), the bandwidth is a share of each variable's range that
shrinks by fret_width_damp, and a value that leaves the bounds is clipped.
Parameters
pop_size: harmony memory size (HMS), 10 by default.new_count: number of new harmonies per iteration.new_count=1is the original algorithm, one new harmony per iteration that replaces the worst if it is better. The default 20 did better at the same budget in benchmark tests.hmcr: harmony memory consideration ratepar: pitch adjustment rate (default 0.35, within the 0.1 to 0.5 of Lee and Geem 2005).fret_width: initial bandwidth (in code units, where each variable spans [0, 1])fret_width_damp: the bandwidth is multiplied by this factor after every iteration.fret_width_damp=1keeps the bandwidth fixed.
References
Z. W. Geem, J. H. Kim and G. V. Loganathan, "A new heuristic optimization algorithm: Harmony search", Simulation 76(2), 2001. K. S. Lee and Z. W. Geem, "A new meta-heuristic algorithm for continuous engineering optimization: harmony search theory and practice", Computer Methods in Applied Mechanics and Engineering 194, 2005.
Example¶
import ypea
problem = ypea.Problem(
ypea.Real("x", shape=20, lb=-10, ub=10),
lambda sol: ypea.benchmarks.sphere(sol.x),
vectorized=True,
name="sphere",
)
alg = ypea.HS(max_nfe=20_000)
result = alg.solve(problem, seed=1)
print(result.summary())
HS on sphere
best objective value: 9.91824e-10
feasible: True (violation 0)
evaluations: 20000, iterations: 1000, time: 0.0867 s, stopped by: max_nfe
Differs from Python: MATLAB draws its own random numbers, so the best value differs from Python's.
problem = ypea.Problem( ...
vars=ypea.Real("x", shape=20, lb=-10, ub=10), ...
objective=@(sol) ypea.benchmarks.sphere(sol.x), ...
vectorized=true, ...
name="sphere");
alg = ypea.HS(max_nfe=20000);
result = alg.solve(problem, seed=1);
disp(result.summary())
HS on sphere
best objective value: 1.27508e-09
feasible: true (violation 0)
evaluations: 20000, iterations: 1000, time: 0.212 s, stopped by: max_nfe
Search on Rastrigin¶