Dear All,
I am trying to implement a nested optimization routine for a complex problem for which the optimization variables may become more than 10. Before moving forward, I am trying to check this routine in a very simple scenario with just two variables (see code below).
It seems the code actually works but, when comparing with a single-optimization routine solving the same problem, it seems that the requierd time increase significantly (single optimization routine: 0.022 seconds; nested routine: 39 seconds). Am I missing something? What are the situations where a nested optimization may be useful (rather than solving with a single optimization run with more variables)?
Thank you very much
(*Objective function*)
f[x_, y_] := Sin[x + y] + Cos[x - y]
(*Single optimization routine*)
NMinimize[{f[x, y], 0 <= x <= 2 && 0 <= y <= 2}, {x,
y}] // AbsoluteTiming
(*Nested optimization routine*)
(*Inner optimization*)
innerOptimization[x_?NumericQ] :=
NMinimize[{f[x, y], 0 <= y <= 2}, y][[1]]
(*Outer optimization*)
outerOptimization := NMinimize[{innerOptimization[x], 0 <= x <= 2}, x]
(*Perform the optimization*)
result = outerOptimization // AbsoluteTiming
(*Print the optimal values*)
optimalX = x //. result[[2, 2]]
optimalY = y /. Last[NMinimize[{f[optimalX, y], 0 <= y <= 2}, y]]