So my fmincon implementation is coming in shape [1].
[x,fval,exitflag,output,lambda,grad,hessian] =
[x,fval,exitflag,output,lambda,grad,hessian] =
fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
I came across a few issues which turned out to be bugs. Olaf pushed fixes in the central repository. Listing the issues for the record:
- Setting gradc (the gradient of general equality/inequality functions). A bug in nonlin_min.m (and __nonlin_residmin__.m)
Example:
objective_function = @ (p) p(1)^2 + p(2)^2;
pin = [-2; 5];
constraint_function = @ (p) p(1)^2 + 1 - p(2);
gradc = @(p) [2*p(1);-1];
[p, objf, cvg, outp] = nonlin_min (objective_function, pin, optimset
("equc", {constraint_function, gradc}))
pin = [-2; 5];
constraint_function = @ (p) p(1)^2 + 1 - p(2);
gradc = @(p) [2*p(1);-1];
[p, objf, cvg, outp] = nonlin_min (objective_function, pin, optimset
("equc", {constraint_function, gradc}))
error: function handle type invalid as index value
- Giving linear inequality/ equality constraints to lm_feasible. A bug in nonlin_min.m
Example:
f = @(x) -x(1) * x(2) * x(3);
S = [1 -1; 2 -2; 2 -2]
b = [0;72];
x0 = [10;10;10];
[x,fval] = nonlin_min( f, x0, optimset ("inequc",{S,b}) )
S = [1 -1; 2 -2; 2 -2]
b = [0;72];
x0 = [10;10;10];
[x,fval] = nonlin_min( f, x0, optimset ("inequc",{S,b}) )
error: __lm_feasible__: operator -: nonconformant arguments (op1 is
3x1, op2 is 3x0)
3x1, op2 is 3x0)
-Any zero value in initial guess vector for nonin_residmin/nonlin_min gave an error. Required a minor change of sign(0)==0 in __dfdp__.m.
Example:
k = 1:10;
func = @(x) 2 + 2 * k - exp (k * x(1)) - exp (k * x(2));
x0 = [0;0.5];
x = nonlin_residmin(func,x0)
warning: division by zero
warning: called from
__dfdp__ at line 367 column 21
__nonlin_residmin__> at line -1 column -1
__lm_svd__ at line 191 column 9
__nonlin_residmin__ at line 1125 column 21
nonlin_residmin at line 98 column 21
runlsqnonlin at line 9 column 3
error: svd: cannot take SVD of matrix containing Inf or NaN values
func = @(x) 2 + 2 * k - exp (k * x(1)) - exp (k * x(2));
x0 = [0;0.5];
x = nonlin_residmin(func,x0)
warning: division by zero
warning: called from
__dfdp__ at line 367 column 21
__nonlin_residmin__> at line -1 column -1
__lm_svd__ at line 191 column 9
__nonlin_residmin__ at line 1125 column 21
nonlin_residmin at line 98 column 21
runlsqnonlin at line 9 column 3
error: svd: cannot take SVD of matrix containing Inf or NaN values
Functionality for Returning Hessian and Gradient
- New options "ret_objf_grad" and "ret_hessian" to be introduced in nonlin_min (by Olaf). If anyone of these options is set to true, the 'outp' structure output argument of nonlin_min will contain additional fields .objf_grad and .hessian. My code currently checks this.
Rearranging values of lambda in the fields of a structure.
- For lm_feasible, outp will contain an additional field lambda, a structure which contains Lagrange multipliers in fields separated by constraint type.
I added an additional feature in [1] to cater for the non linear constraint function set using deal();
Example:
c = @(x) [x(1) ^ 2 / 9 + x(2) ^ 2 / 4 - 1;
x(1) ^ 2 - x(2) - 1];
ceq = @(x) tanh (x(1)) - x(2);
nonlinfcn = @(x) deal (c(x), ceq(x));
obj = @(x) cosh (x(1)) + sinh (x(2));
z = fmincon (obj, [0;0], [], [], [], [], [], [], nonlinfcn)
z =
-0.6530
-0.5737
c = @(x) [x(1) ^ 2 / 9 + x(2) ^ 2 / 4 - 1;
x(1) ^ 2 - x(2) - 1];
ceq = @(x) tanh (x(1)) - x(2);
nonlinfcn = @(x) deal (c(x), ceq(x));
obj = @(x) cosh (x(1)) + sinh (x(2));
z = fmincon (obj, [0;0], [], [], [], [], [], [], nonlinfcn)
z =
-0.6530
-0.5737
To do:
1- Write test cases/refined examples for for lsqnonlin, lsqcurvefit, nlinfit and fmincon.
2- Start wrapping quadprog to __qp__ instead of qp.m (because of the ordering of the lambda output).
1- Write test cases/refined examples for for lsqnonlin, lsqcurvefit, nlinfit and fmincon.
2- Start wrapping quadprog to __qp__ instead of qp.m (because of the ordering of the lambda output).
No comments:
Post a Comment