parallel harmony search indexing problem
조회 수: 9 (최근 30일)
이전 댓글 표시
i have the following harmony search code:-
if matlabpool('size') == 0 % checking to see if my pool is already open
matlabpool open 2
end
results=zeros(7,1);
Dim=10;
ub=100;
lb=-100;
for s=1:7
timer=0;
timer2=0;
timer3=0;
timer4=0;
counter=0;
if s==1;
HMS=5;
elseif s==2
HMS=10;
elseif s==3
HMS=25;
elseif s==4
HMS=50;
elseif s==5
HMS=100;
elseif s==6
HMS=250;
elseif s==7
HMS=500;
end
% HARMONY basic Harmony Search minimization for continuous variables
% Unpack the parameter vector
for index=1:5
MaxImp = 100000;
HMCR = 0.9;
PAR = 0.3;
% Dimension arrays
N = Dim; % Number of decision variables
HM = zeros(2*HMS,N);
F = zeros(2*HMS,1);
%xnew = zeros(HMS,N);
% Randomly initialize HM, taking care to keep each variable within bounds.
% Evaluate the corresponding objective function values.
HM(1:HMS,:) = lb + (ub-lb).*rand(HMS,N);
F(1:HMS) = sum(HM(1:HMS,:)'.^2);
Convergence = [];
Diversity = [];
[fbest,idxbest] = min(F);
% Loop through MaxImp improvisations
for j = 1 : HMS : MaxImp
% Improvise a new harmony: loop though each variable
b = std(HM(1:HMS,:));
parfor h = 1 : HMS
myTemp = zeros(1,HMS);
for i = 1:N
% Randomly perform one of the three HS operations
if rand < HMCR
% Memory considering: randomly select a note stored in HM
%xnew(h,i) = HM(ceil(rand*HMS),i);
myTemp(HMS+h,i) = myTemp(ceil(rand*HMS),i);
if rand < PAR
% Pitch adjusting: randomly adjust the pitch slightly
% within +/- b(i), and ensure bounds are satisfied
%xnew(h,i) = xnew(h,i) + (2*rand-1)*b(i);
HM(HMS+h,i) = HM(HMS+h,i) + (2*rand-1)*b(i);
HM(HMS+h,i) = min(max(HM(HMS+h,i),lb),ub);
end
else
% Random playing: randomly select any pitch within bounds
%xnew(h,i) = lb + rand*(ub-lb);
HM(HMS+h,i) = lb + rand*(ub-lb);
end
% Finished improvising a new harmony
end
HM(HMS+h,:)=myTemp(1,:);
end
% HM update: check whether the new harmony is better than the worst
% harmony currently in HM
%fnew = f(xnew,function_number) + bias;
tic;
F(HMS+1:2*HMS) = sum(HM(HMS+1:2*HMS,:)'.^2);
timer2=toc;
timer3=timer3+timer2;
[F,Index] = sort(F);
HM = HM(Index,:);
[fbest,idxbest] = min(F);
Convergence = [Convergence,fbest];
counter=counter+1;
end % Maximum number of improvisations reached
timer3=timer3/counter;
timer4=timer3+timer4;
Convergence = [Convergence,fbest];
counter=0;
end
timer=timer4/5;
results(s)=timer;
end
disp(results);
matlabpool close
-the problem is that the HM matrix is indexed in diffrent way causing dependicies between itrations, is there any way to solve this problem, thank you.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Computational Geometry에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!