Inverse of a function gives different results than the negative function with fmincon
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a function f(x) which I am trying to maximize. Following the suggestions on: Maximizing an Objective - MATLAB & Simulink (mathworks.com), I can define the function to minimize on fmincon as -f(x). This works as well since my boundaries indicate that x needs to be in the positive regime, and my function is actually one of the two variables x itself, specfically f(x)=-x(1).
However, I previously used to define my variable as the inverse of itself in case I wanted to maximize it, so f(x)=1/(x(1)). Now oddly enough, fmincon gives me different results if I define my function this way... I would love to share my files but I cannot for confidentiality. Assuming that the boundaries are not the problem, is this expected behavior with the fmincon solver? Or am I making a mistake somewhere else?
Thanks.
2 个评论
Mario Malic
2020-12-21
If you want to minimise, then it's f(x), if you want to maximise then it's -f(x).
采纳的回答
Alan Weiss
2020-12-22
The problem could be related to a few things, such as numerical stability and the presence of multiple local minima.
For numerical stability, you didn't tell us the typical ranges of your variables. But for very large or small values, 1/x and -x behave very differently. I expect that your solution might be a large or small number.
For multiple local minima, the fmincon algorithm can take different paths dependinig on many problem inputs, and both results can be true local minima and yet differ.
Without more information, these general optimization characteristics are the best I can offer.
Alan Weiss
MATLAB mathematical toolbox documentation
0 个评论
更多回答(2 个)
Bruno Luong
2020-12-22
If you apply a non-llinear transformation of your decision variables, I would expect the solver behave differently.
The solver is not a miracle blackbox that you can twist in any direction and expect it to be robust.
I relies on the fact that the minimum is on the attraction basin, that the Hessian is more or less change not so quickly, etc....
Transform x -> 1/x will be a major change.
0 个评论
Matt J
2020-12-22
编辑:Matt J
2020-12-22
With f(x)=-x1, the norm of the gradient of f is always 1. However, with f(x)=1/x1, the norm of the gradient will fall off quadratically as x1 gets larger. It therefore becomes possible that the OptimalityTolerance threshold and/or the FunctionTolerance threshold will be reached sooner than it otherwise would and cause the iterations to stop prematurely. You can try reducing these thresholds to see if there is a helpful effect. However, f(x)=-x1 is probably ythe better way to go, for reasons that others have already mentioned.
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!