How to change Simulate Annealing minimum optimization into maximum?

1 次查看(过去 30 天)
I am looking for a maximum Simulate Annealing solver for multidimensional function. The below code works for finding the global minimum. How can I change it into maximum finder? fitness.m file:
function f = fitness(x)
ddd = x(1)+x(2)-(x(2)-2)^2;
eee = abs(ddd);
f = eee * sin(x(1));
end
main.m file:
clc,clear,close all
fitfcn = @fitness;
nvar =2;
Lb = 1*ones(size(1,nvar));
Ub = 3*ones(size(1,nvar));
opt = optimoptions(@simulannealbnd,'Display','iter',...
'reannealinterval',300,...
'plotfcn',@saplotbestf,...
'FunctionTolerance',1e-4);
[xf,fval,exitflag] = simulannealbnd(fitfcn,[1 1],Lb,Ub,opt);

回答(1 个)

John D'Errico
John D'Errico 2016-10-3
If you have a tool that minimizes an objective, is it not true that a maximum can be found instead by minimizing -f(X)?
  2 个评论
Micro Torrent
Micro Torrent 2016-10-4
编辑:Micro Torrent 2016-10-4
Thank you John. I simply multiply the equation to -1 to find the minimum instead of the maximum but the result doesn't converge to a specific value. The Wolframalpha.com shows the same local optimum points in both case. Why I couldn't get the same result in Matlab? I limit my input variable to Lb=-3 and Ub=3 but the input value at the best result goes to 125 or -250, why?
Did I miss something?
John D'Errico
John D'Errico 2016-10-4
编辑:John D'Errico 2016-10-4
Um, the code you show has variables limited to lie between 1 and 3, not -3 and 3. Which is it? My guess is that since this function is unbounded, you have not really used the limits you show in that example. The only evidence that I have is your example is not consistent with your claim. In fact, it is often true that people think they have done something, yet their variables are not as they claim them to be. So I would check the values of the bounds variables Lb and Ub.
For example, over the interval from 1 to 3 in both variables, the function you have shown has a single unique maximum.
I cannot test your code since I do not have that toolbox, nor do I see how you tried to multiply the function by -1. (People do indeed screw up things as simple as that.)

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by