You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
% non-parallel evaluation and remaining NaN-values
Hi, thanks for this great procedure. I would like to note that the parallel evaluation slows down considerably if the function is evaluated as Nan. I would like to suggest a work-around that could be improved on.
ifflgEvalParallel
qqqqq=find(isnan(fitness.raw));
tries100=1;
% fitness.raw(k) = NaN;
tries =flgEvalParallel; % in parallel case this is the first re-trial% Resample, until fitness is not NaNwhile ~isempty(qqqqq)
Nnanssss=length(qqqqq);
Nminattemps=36;
Nnanreplics=floor(Nminattemps/Nnanssss);
ifNnanreplics>1
qqqqqrepelem=repelem(qqqqq,1,Nnanreplics);
else
qqqqqrepelem=qqqqq;
end
NnanTRIES=length(qqqqqrepelem);
arzTRIES=nan(N,NnanTRIES);
arxTRIES=arzTRIES;
arxvalidTRIES=arzTRIES;
eeeee=0;
for k=qqqqqrepelem
eeeee=eeeee+1;
ifk<=lambda% regular samples (not the re-evaluation-samples)
arzTRIES(:,eeeee) = randn(N,1); % (re)sampleifflgDiagonalOnly
arxTRIES(:,eeeee) =xmean+sigma*diagD.* arzTRIES(:,eeeee); % Eq. (1)else
arxTRIES(:,eeeee) =xmean+sigma* (BD* arzTRIES(:,eeeee)); % Eq. (1)endelse% re-evaluation solution with index > lambdaifflgDiagonalOnly
arxTRIES(:,eeeee) = arx(:,k-lambda) + (noiseEpsilon*sigma) *diagD.* randn(N,1);
else
arxTRIES(:,eeeee) = arx(:,k-lambda) + (noiseEpsilon*sigma) * (BD* randn(N,1));
endend% You may handle constraints here. You may either resample% arz(:,k) and/or multiply it with a factor between -1 and 1% (the latter will decrease the overall step size) and% recalculate arx accordingly. Do not change arx or arz in any% other way.if ~bnd.isactive
arxvalidTRIES(:,eeeee) = arxTRIES(:,eeeee);
else
arxvalidTRIES(:,eeeee) = xintobounds(arxTRIES(:,eeeee), lbounds, ubounds);
endend
fitnessrawTRIES = feval(fitfun, arxvalidTRIES, varargin{:});
tries =tries+ length(qqqqqrepelem);
idTRIES=~isnan(fitnessrawTRIES);
fitnessrawTRIES=fitnessrawTRIES(idTRIES);
qqqqqrepelem=qqqqqrepelem(idTRIES);
arzTRIES=arzTRIES(:,idTRIES);
arxTRIES=arxTRIES(:,idTRIES);
arxvalidTRIES=arxvalidTRIES(:,idTRIES);
for k=qqqqq
idlalala= find(qqqqqrepelem==k,1,'first');
if ~isempty(idlalala)
arz(:,k)=arzTRIES(:,idlalala);
arx(:,k)=arxTRIES(:,idlalala);
arxvalid(:,k)=arxvalidTRIES(:,idlalala);
fitness.raw(k)=fitnessrawTRIES(idlalala);
endend
qqqqq2=find(isnan(fitness.raw));
if ~isempty(qqqqq2)
countevalNaN =countevalNaN+ length(qqqqq2);
counteval =counteval+ length(qqqqq) - length(qqqqq2); % retries due to NaN are not countedendif floor(tries/100) ==tries100
warning([num2str(tries) ...
' NaN objective function values at evaluation ' ...
num2str(counteval)]);
end
tries100=ceil(tries/100);
qqqqq=qqqqq2;
endelsefor k=find(isnan(fitness.raw)),
% fitness.raw(k) = NaN;
tries =flgEvalParallel; % in parallel case this is the first re-trial% Resample, until fitness is not NaNwhile isnan(fitness.raw(k))
ifk<=lambda% regular samples (not the re-evaluation-samples)
arz(:,k) = randn(N,1); % (re)sampleifflgDiagonalOnly
arx(:,k) =xmean+sigma*diagD.* arz(:,k); % Eq. (1)else
arx(:,k) =xmean+sigma* (BD* arz(:,k)); % Eq. (1)endelse% re-evaluation solution with index > lambdaifflgDiagonalOnly
arx(:,k) = arx(:,k-lambda) + (noiseEpsilon*sigma) *diagD.* randn(N,1);
else
arx(:,k) = arx(:,k-lambda) + (noiseEpsilon*sigma) * (BD* randn(N,1));
endend% You may handle constraints here. You may either resample% arz(:,k) and/or multiply it with a factor between -1 and 1% (the latter will decrease the overall step size) and% recalculate arx accordingly. Do not change arx or arz in any% other way.if ~bnd.isactive
arxvalid(:,k) = arx(:,k);
else
arxvalid(:,k) = xintobounds(arx(:,k), lbounds, ubounds);
end% You may handle constraints here. You may copy and alter% (columns of) arxvalid(:,k) only for the evaluation of the% fitness function. arx should not be changed.fitness.raw(k) = feval(fitfun, arxvalid(:,k), varargin{:});
tries =tries+1;
if isnan(fitness.raw(k))
countevalNaN =countevalNaN+1;
endif mod(tries, 100) ==0
warning([num2str(tries) ...
' NaN objective function values at evaluation ' ...
num2str(counteval)]);
endend
counteval =counteval+1; % retries due to NaN are not countedendend
The text was updated successfully, but these errors were encountered:
CMA-ES.github.io/cmaes.m
Line 913 in c1e8786
Hi, thanks for this great procedure. I would like to note that the parallel evaluation slows down considerably if the function is evaluated as Nan. I would like to suggest a work-around that could be improved on.
The text was updated successfully, but these errors were encountered: