How to change Simulate Annealing minimum optimization into maximum?
4 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
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
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.)
See Also
Categories
Find more on Simulated Annealing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!