How to plot an optimization in logarithmic scale?

7 次查看(过去 30 天)
The following code is expected to plot the output of Rosenbrock's function against number of iterations ( for the sake of the problem, don't be concerned with the quality of the source code).
function value = banana(x0)
a = x0(1);
b = x0(2);
x = x0(3);
y = x0(4);
value = (1 - x + a)^2 + 100 * (y - b * (x - a)^2)^2;
end
a = int8(4 * rand()) / 2;
b = int8(4 * rand()) / 2;
[x1, y1] = random(a, b);
[x2, y2] = random(a, b);
[x3, y3] = random(a, b);
[x4, y4] = random(a, b);
x = [x1; x2; x3; x4];
y = [y1; y2; y3; y4];
save values.mat;
for i = 1
x0 = [a, b, x(i), y(i)];
options = optimset('PlotFcns', { @optimplotfval });
[solution_point, fval,exitflag,output] = fminsearch(@banana,double(x0),options);
old_x=[x(i),y(i)];
new_x_1 = linspace(-2,2,51);
new_x_2 = linspace(-2,2,51);
for j=1:51
if(new_x_1(j)>= old_x(1))
new_x_1(j)=old_x(1);
break;
end
end
for j=1:51
if(new_x_2(j)>= old_x(2))
new_x_2(j)=old_x(2);
break;
end
end
end
My questions are,
(1) Is this plot really showing the output of Rosenbrock's function against number of iterations?
(2) The plot shows a sudden slump in the output of the function. I need to show this plot in logarithmic form, so that a smooth curve is plotted. How can I do that?

采纳的回答

Walter Roberson
Walter Roberson 2017-1-3
For the log plot:
edit optimplotfval
now Save As into your own directory as optimplotlogfval.m . Close the original optimplotfval.m (so you do not accidentally modify it.) Then in the optimplotlogfval.m version, alter the "function" statement to use optimplotlogfval instead of optimplotfval as the name. Then go into the plotscalar function there and for the iteration == 0 case, after the ylabel() call, add
set(gca, 'YScale', 'log');
Make the same change for iteration == 0 in the plotvector function.
Saving all of that, go back to your code and change
options = optimset('PlotFcns', { @optimplotfval });
to
options = optimset('PlotFcns', { @optimplotlogfval });

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by