Clear Filters
Clear Filters

How to change Simulate Annealing minimum optimization into maximum?

1 view (last 30 days)
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);

Answers (1)

John D'Errico
John D'Errico on 3 Oct 2016
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 Comments
Micro Torrent
Micro Torrent on 4 Oct 2016
Edited: Micro Torrent on 4 Oct 2016
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 on 4 Oct 2016
Edited: John D'Errico on 4 Oct 2016
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.)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!