Effacer les filtres
Effacer les filtres

How to plot an optimization in logarithmic scale?

7 vues (au cours des 30 derniers jours)
Ba Ba Black Sheep!
Ba Ba Black Sheep! le 3 Jan 2017
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?

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Jan 2017
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 });

Plus de réponses (0)

Catégories

En savoir plus sur Log Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by