MATLAB: Gaplotbestf shows “Best fitness plot: not available”

gamultiobjgaplotbestfGlobal Optimization Toolboxnot availableplot

I am trying to make a plot of the best function value versus generation with gamultiobj. I have set the options as follows:
options = gaoptimset('PlotFcns', @gaplotbestf);
and provide these to gamultiobj:
fitnessFunction = @schaffer2;
lowerBound = 0;
upperBound = 5;
[x1, f1, exitflag1, output1, population1, score1] = gamultiobj(fitnessFunction,...
1, [], [], [], [], lowerBound, upperBound, options);
Where fitnessFunction is the schaffer2 function from the gamultiobj documentation:
function y = schaffer2(x) % y has two columns
% Initialize y for two objectives and for all x
y = zeros(length(x),2); % ready for vectorization
% Evaluate first objective.
% This objective is piecewise continuous.
for i = 1:length(x)
if x(i) <= 1
y(i,1) = -x(i);
elseif x(i) <=3
y(i,1) = x(i) -2;
elseif x(i) <=4
y(i,1) = 4 - x(i);
else
y(i,1) = x(i) - 4;
end
end
% Evaluate second objective
y(:,2) = (x -5).^2;
The output of the algorithm is not empty. However, the plot is blank with the title "Best fitness plot: not available". I have tried other plots such as @gaplotselection and @gaplotpareto which do work. What does this mean? Am I doing something wrong?

Best Answer

I believe that gamultiobj does not support @gaplotbestf for the simple reason that @gaplotbestf is for a single objective function, and gamultiobj is for multiple objective functions. So it is not clear what that plot function should do in the presence of multiple objectives.
If you want to write your own plot function, feel free to do so. I have found @gaplotpareto to be quite useful for visualizing gamultiobj iterations.
Alan Weiss
MATLAB mathematical toolbox documentation
Related Question