View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Harmony Search Algorithm

4.3 | 7 ratings Rate this file 39 Downloads (last 30 days) File Size: 1.72 KB File ID: #41158 Version: 1.0

Harmony Search Algorithm


sajjad yazdani (view profile)


Harmony Search Algorithm is a heuristic method for global optimization.

| Watch this File

File Information

Harmony search tries to find a vector which optimizes (minimizes or maximizes) a certain objective function.
The algorithm has the following steps:
Step 1: Generate random vectors () as many as (harmony memory size), then store them in harmony memory (HM).

Step 2: Generate a new vector . For each component ,
with probability (harmony memory considering rate; 0 ≤ ≤ 1), pick the stored value from HM:
with probability , pick a random value within the allowed range.
Step 3: Perform additional work if the value in Step 2 came from HM.
with probability (pitch adjusting rate; 0 ≤ ≤ 1), change by a small amount: or for discrete variable; or for continuous variable.
with probability , do nothing.
Step 4: If is better than the worst vector in HM, replace with .
Step 5: Repeat from Step 2 to Step 4 until termination criterion (e.g. maximum iterations) is satisfied.
The parameters of the algorithm are
 = the size of the harmony memory. It generally varies from 1 to 100. (typical value = 30)
 = the rate of choosing a value from the harmony memory. It generally varies from 0.7 to 0.99. (typical value = 0.9)
 = the rate of choosing a neighboring value. It generally varies from 0.1 to 0.5. (typical value = 0.3)
 = the amount between two neighboring values in discrete candidate set.
 (fret width, formerly bandwidth) = the amount of maximum change in pitch adjustment. This can be (0.01 × allowed range) to (0.001 × allowed range).
It is possible to vary the parameter values as the search progresses, which gives an effect similar to simulated annealing.
Parameter-setting-free researches have been also performed. In the researches, algorithm users do not need tedious parameter setting process.

see more in :

MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
20 Feb 2017 sadjad Yazdani

Note that MyFun is the Objective Function that you want to Optimize.

20 Jan 2017 fang Aphrodite

what is MyFun?

Comment only
05 Jan 2017 Diego Carrion

Do Somebody solve the error in line 28??

Comment only
27 Nov 2016 Fan Zhang

so great!

28 Oct 2016 Xuan Wang

There is an error in line 28:
Undefined function or variable 'MyFun'.

01 Jul 2016 shardul g

getting error for myfun function . how to resolve it ?

Comment only
20 Apr 2016 Nicolás Daniel Andrés Ortega Cárdenas

15 Oct 2014 Suresh

Suresh (view profile)

While running an error is showing in line 28.Please help to rectify it

Comment only
16 Jan 2014 Swapnil

line 28 is showing an error.
MyFun() is not defined.
can you please help

22 Aug 2013 Hock Hung

There is an error in line 28: HF(i,1)=MyFun(HM(i,:))
But i cant find any problem with that.
Can explain that.

01 Jul 2013 Andrés

Thanks, the code has been very useful for my research on the implementation of a multi objective HS technique

Contact us