octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fmincon wrapping nonlin_min


From: Asma Afzal
Subject: Re: fmincon wrapping nonlin_min
Date: Thu, 2 Jul 2015 03:43:32 +0100

>> - Output Gradient and Hessian at the solution as in Matlab.
>
> What I currently think is we should introduce the options
> 'ret_objf_grad' and 'ret_hessian' to nonlin_min, and compute a
> gradient and Hessian for the final parameters if set. They could be
> returned as .objf_grad and .hessian fields of the 'outp' structure
> (fourth output argument of nonlin_min). And I'd say both or nothing
> should be returned, regardless whether ret_hessian or ret_objf_grad or
> both had been set. As long as I've not implemented this, you could
> just set these options and check if the output fields are present.
>
In my current implementation, I am removing fields "objf_grad",
"hessian" and "lambda" from outp

  if (out_args >= 4)
    outp = min_out{4};
    outp = rmfield (outp, {"lambda", "objf_grad", "hessian"});
    varargout{4} = outp;
  endif

  if (out_args >= 5)
     varargout{5} = min_out{4}.lambda;
  endif

  if (out_args >= 6)
     varargout{6} = min_out{4}.objf_grad;
  endif

  if (out_args >= 7)
     varargout{7} = min_out{4}.hessian;
  endif

This will only work when the lm_feasible algorithm is used. Should I
just set lm_feasible inside fmincon? or have checks on each of these
output arguments whether a field lambda/hessian etc exists in the outp
structure.

> But it would be good if you would provide some examples
> for easy testing of your code.

Do you mean examples as tests for the function or just a collection? I
am testing my functions with various examples in runlsqnonlin.m,
runfmincon.m etc. in the repository but the files are cluttered. I can
refine them if you say.

- I added an additional feature in fmincon [1] to cater for non linear
constraint function set using deal();
Consider the 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

>> 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)
>> Matlab gives
>> x =
>>
>>     0.2578
>>     0.2578
> nonlin_residmin with default options returns:
>
> x =
>
>    0.25699
>    0.26171
>
> with 'sumsq (func (x))' greater than for x = [0.2578; 0.2578].

sumsq (func (x)) = 124.3622

> So Matlab performs better in this example if default options are
> used. It's probably worth changing this, since it's a simple example
> function. You'll probably change some default values of options in
> wrapping. If you find options ('TolFun', 'TypicalX', ...) for which
> nonlin_residmint performs better for this example, please tell me

settings = optimset("TolFun",1e-9)
[x, resnorm] = lsqnonlin(func,x0,[],[], settings)

x =

   0.25797
   0.25794

resnorm =  124.36

Kind Regards,
Asma.

[1] https://github.com/AsmaAfzal/octave_workspace/blob/master/fmincon.m



reply via email to

[Prev in Thread] Current Thread [Next in Thread]