Inverse of a function gives different results than the negative function with fmincon
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alessandro Maria Laspina
el 21 de Dic. de 2020
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 comentarios
Mario Malic
el 21 de Dic. de 2020
If you want to minimise, then it's f(x), if you want to maximise then it's -f(x).
Respuesta aceptada
Alan Weiss
el 22 de Dic. de 2020
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 comentarios
Más respuestas (2)
Bruno Luong
el 22 de Dic. de 2020
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 comentarios
Matt J
el 22 de Dic. de 2020
Editada: Matt J
el 22 de Dic. de 2020
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 comentarios
Ver también
Categorías
Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!