# How to implement something like NMaximize[ NMinimize [ f(x,y) , {x} ], {y} ]?

Title says it all, really.

I want to find some set of values for which a function of those values can't be made larger than a certain number, when some other values (on which that function is also dependent) are unknown.

Guard against premature evaluation of the inside minimization by putting it inside a function which won't evaluate until a numeric argument is supplied:

f[x_, y_] = 1 + x^2 - y^2;
fminx[y_?NumericQ] := NMinValue[f[x, y], {x}];
FindMaximum[fminx[y], {y, 1.}] // AbsoluteTiming
(*
{0.515133, {1., {y -> -7.45058*10^-9}}}
*)

NMaximize[fminx[y], {y}] // AbsoluteTiming
(*
{47.629574, {1., {y -> -5.83182*10^-9}}}
*)


NMaximize takes a lot longer. You might want to tune constraints and methods to suit your objective function.

• @quantum_loser You're welcome. Depending on the function, one might use both local optimization functions FindMinimum and FindMaximum, which would be fastest. (But local optimization only works reliably if there is only one extremum.) – Michael E2 Aug 29 '14 at 13:24
• Related to this MSE thread on bilevel optimization. – Daniel Lichtblau Aug 29 '14 at 15:21