GA Vectorized do not return the best FF value

1 次查看(过去 30 天)
Hello, I am having a similar problem to this:
https://www.mathworks.com/matlabcentral/answers/367573-ga-didn-t-return-the-x-for-the-best-fitness-value
In my case, I am running GA Vectorized both with ga and gamultiobj. All is fine when Vectorization is off but the solver does not return the best solution with Vectorization on. I am asking myself how to solve this because I need to speed up my optimization.
Here is how my FF is implemented:
function FF=multiobj_mics(pop,n,r,max_d,max_o)
popSize=size(pop,1);
FF=zeros(popSize,2);
k=nchoosek(n,2);
%%Variables
%rad
%meters
%phi=2*pi*rand(1,n); %azimuth
%theta=2*pi*rand(1,n); %elevation
%phi=x(1)....x(n) %-pi pi
%theta=x(n+1)....x(2*n) %0 pi
%%Orientation
vet(1:n-1,1:3,1:n-1,1:popSize)=NaN;
for i=1:1:n-1
x1=r*sin(pop(1:popSize,n+i)).*cos(pop(1:popSize,i));
y1=r*sin(pop(1:popSize,n+i)).*sin(pop(1:popSize,i));
z1=-r*cos(pop(1:popSize,n+i));
p=1;
for j=i+1:1:n
x2=r*sin(pop(1:popSize,n+j)).*cos(pop(1:popSize,j));
y2=r*sin(pop(1:popSize,n+j)).*sin(pop(1:popSize,j));
z2=-r*cos(pop(1:popSize,n+j));
%Normalized mic orientation vector
vet(p,:,i,:)=reshape(([x1 y1 z1]/norm([x1 y1 z1])-[x2 y2 z2]/norm([x2 y2 z2])),[1,3,1,popSize]);
%Cannot use ./
for ii=1:popSize
vet(p,:,i,ii)=vet(p,:,i,ii)/norm(vet(p,:,i,ii));
end
p=p+1;
end
end
%Convert 4D matrix to 3D matrix (vet(3 lines) x pop)
Vet=reshape(vet,[],1);
Vet=reshape(Vet,n-1,3,popSize*(n-1));
C=permute(Vet,[1 3 2]);
C = reshape(C,[],size(Vet,2),1);
[rr,c] = size(C);
Vet = permute(reshape(C',[c,rr/popSize,popSize]),[2,1,3]);
null=any(isnan(Vet),2);
Vet(find(null(:,1,1)==1),:,:) = [];
% Minimum angle btw pairs of mics
for i=1:k
angle=zeros(popSize,k-1);
p=1;
for ii=1:k
if ii~=i
for j=1:popSize
angle(j,p)=atan2(norm(cross(Vet(i,:,j),Vet(ii,:,j))), dot(Vet(i,:,j),Vet(ii,:,j)));
if angle(j,p)>pi/2
angle(j,p)=pi-angle(j,p);
end
end
p=p+1;
end
end
FF(1:popSize,1)=FF(1:popSize,1)+min(angle(:,:),[],2);
end
FF(1:popSize,1)=-max_o*FF(1:popSize,1);
}
if true
% code
end
Is there something not deterministic in this function? Maybe that 'if' to get the supplementary angle? I am using R2016b.
Thanks in advance, Lucas

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by