資源簡介
和聲搜索算法,一種智能優化算法,國外學者編寫的源碼,可以運行,有測試函數和算法的簡要介紹。
代碼片段和文件信息
%?Harmony?Search?Algorithm
%By?Sajjad?Yazdani
%
%?base?on:
%?[1]:
clc;clear?all;close?all
%%?Problem?Prametters
Dim=2;?%?problem?Dimention
Low=[-100?-100];?%?Low?Boundry?of?Problem
High=[100?100];?%?High?Boundry?of?Problem
Min=1;?%?Minimaization?or?maximaiz?of?Fun??if?Min=1?it?will?be?minimaze?the?function?and?if?Min=0?it?will?be?maximized?the?function.
%%?Harmony?Search?Parametters
HMS=100;%Harmony?Memory?Size?(Population?Number)
bw=0.2;
HMCR=0.95;%[1]?Harmony?Memory?Considering?Rate
PAR=0.3;%[1]?Pitch?Adjustment?Rate
MaxItr=10000;%?Maximum?number?of?Iteration
%%?Initialization
HM=zeros(HMSDim);
HF=zeros(HMS1);
for?i=1:HMS
????HM(i:)=Low+(High-Low).*rand(1Dim);
????HF(i1)=MyFun(HM(i:));
end
if?Min==1
????[WorstFitWorstLoc]=max(HF);
else
????[WorstFitWorstLoc]=min(HF);
end
%%?Iteration?Loop
for?Itr=1:MaxItr
????HarmonyIndex=fix(rand(1Dim)*HMS)+1;%?Random?Selection?of?Harmony
????Harmony=diag(HM(HarmonyIndex1:Dim))‘;%?Extraxt?Value?of?harmony?from?Memory(Can?Be?better???)
????CMMask=rand(1Dim) ????NHMask=(1-CMMask);
????PAMask=(rand(1Dim) ????CMMask=CMMask.*(1-PAMask);
????NewHarmony=CMMask.*Harmony+PAMask.*(Harmony+bw*(2*rand(1Dim)-1))+NHMask.*(Low+(High-Low).*rand(1Dim));
????OutOfBoundry=(NewHarmony>High)+(NewHarmony ????NewHarmony(OutOfBoundry==1)=Harmony(OutOfBoundry==1);
????NHF=MyFun(NewHarmony);
????if?(NHF ????????HM(WorstLoc:)=NewHarmony;
????????HF(WorstLoc)=NHF;
????????[WorstFitWorstLoc]=max(HF);
????elseif?(NHF ????????HM(WorstLoc:)=NewHarmony;
????????HF(WorstLoc)=NHF;
????????[WorstFitWorstLoc]=min(HF);
????end
end
%%?Present?Best?Answer
if?Min==1
????[BestFitBestLoc]=min(HF);
else
????[BestFitBestLoc]=max(HF);
end
Best=HM(BestLoc:);
display(Best)
display(BestFit)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????1124324??2009-12-29?02:14??HS\Harmony?Search?Algorithm?.pdf
?????文件???????1877??2014-04-03?17:30??HS\HS.m
?????文件?????????72??2014-04-03?17:26??HS\MyFun.m
?????文件?????????73??2014-04-03?17:27??HS\Sphere.m
?????目錄??????????0??2014-12-05?21:07??HS
-----------?---------??----------?-----??----
??????????????1126346????????????????????5
- 上一篇:形狀匹配(Shape Matching)
- 下一篇:matlab的ISAR成像程序
評論
共有 條評論