比较 fminimax
和 fminunc
minimax 问题旨在最小化一组目标函数的最大值。为什么不直接最小化此最大化函数(它是标量函数)?因为最大值不平滑,而 Optimization Toolbox™ 求解器(如 fminunc
)要求平滑。
例如,将 fun(x)
定义为具有两个变量的三个线性目标函数,并将 fun2
定义为这三个目标的最大值。
a = [1;1]; b = [-1;1]; c = [0;-1]; a0 = 2; b0 = -3; c0 = 4; fun = @(x)[x*a+a0,x*b+b0,x*c+c0]; fun2 = @(x)max(fun(x),[],2);
绘制三个目标函数的最大值。
[X,Y] = meshgrid(linspace(-5,5)); Z = fun2([X(:),Y(:)]); Z = reshape(Z,size(X)); surf(X,Y,Z,'LineStyle','none') view(-118,28)
fminimax
很容易求得 minimax 点。
x0 = [0,0]; [xm,fvalm,maxfval] = fminimax(fun,x0)
Local minimum possible. Constraints satisfied. fminimax stopped because the size of the current search direction is less than twice the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.
xm = 1×2
-2.5000 2.2500
fvalm = 1×3
1.7500 1.7500 1.7500
maxfval = 1.7500
然而,fminunc
停止的点与此 minimax 点相差甚远。
[xu,fvalu] = fminunc(fun2,x0)
Local minimum possible. fminunc stopped because it cannot decrease the objective function along the current search direction.
xu = 1×2
0 1.0000
fvalu = 3.0000
fminimax
可以找到更好(更小)的解。
fprintf("fminimax finds a point with objective %g,\nwhile fminunc finds a point with objective %g.",maxfval,fvalu)
fminimax finds a point with objective 1.75, while fminunc finds a point with objective 3.