help needed with nonlinear inequality constraints (optimset "inequc") for nonlin_residmin in optim package

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

help needed with nonlinear inequality constraints (optimset "inequc") for nonlin_residmin in optim package

Philippe Dobbelaere
I am using nonlin_residmin (optim 1.5.2) with fixed upper and lower
bounds on the parameters. Now I want to introduce non-linear inequality
constraints.

I was assuming

# working if I do not use inequc below
settings = optimset(settings, 'lbound', lb' , 'ubound', ub');

settings = optimset (settings, "inequc", {@nonlinear_ineq_constraints});

with

function H = nonlinear_ineq_constraints(x)
  h0 = 1 - get_ic0(x)^2 - get_jc0(x)^2 - get_kc0(x)^2; # >= 0
  h1 = 1 - get_ic1(x)^2 - get_jc1(x)^2 - get_kc1(x)^2; # >= 0
  h2 = 1 - get_ic2(x)^2 - get_jc2(x)^2 - get_kc2(x)^2; # >= 0
  H = [h0;h1;h2];
endfunction

would do it, but I keep getting

error: number of columns must match
error: called from
    __nonlin_residmin__> at line -1 column -1
    __nonlin_residmin__> at line -1 column -1
    __nonlin_residmin__> at line -1 column -1
    __lm_svd__ at line 181 column 6
    __nonlin_residmin__ at line 1133 column 21
    nonlin_residmin at line 98 column 21
    solve1.m at line 419 column 29
error: evaluating argument list element number 2
error: called from
    __nonlin_residmin__> at line -1 column -1
    __nonlin_residmin__> at line -1 column -1
    __nonlin_residmin__> at line -1 column -1
    __lm_svd__ at line 181 column 6
    __nonlin_residmin__ at line 1133 column 21
    nonlin_residmin at line 98 column 21
    solve1.m at line 419 column 29
error: evaluating argument list element number 4
error: called from
    __nonlin_residmin__> at line -1 column -1
    __nonlin_residmin__> at line -1 column -1
    __nonlin_residmin__> at line -1 column -1
    __lm_svd__ at line 181 column 6
    __nonlin_residmin__ at line 1133 column 21
    nonlin_residmin at line 98 column 21
    solve1.m at line 419 column 29
error: evaluating argument list element number 3
error: called from
    __nonlin_residmin__> at line -1 column -1
    __lm_svd__ at line 181 column 6
    __nonlin_residmin__ at line 1133 column 21
    nonlin_residmin at line 98 column 21
    solve1.m at line 419 column 29

the error is thrown when executing

        dct = df_cstr (p, ac_idx, ...
                       setfield (dfdp_hook, "f", v_cstr));


Could someone send me a trivial working example or tell me what I am
doing wrong?

--
Philippe Dobbelaere
Bell Labs, Nokia
Contact number +32 3 240 8217


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: help needed with nonlinear inequality constraints (optimset "inequc") for nonlin_residmin in optim package

Olaf Till-2
On Fri, Feb 16, 2018 at 12:49:23PM +0100, Philippe Dobbelaere wrote:

> settings = optimset (settings, "inequc", {@nonlinear_ineq_constraints});
>
> with
>
> function H = nonlinear_ineq_constraints(x)
>   h0 = 1 - get_ic0(x)^2 - get_jc0(x)^2 - get_kc0(x)^2; # >= 0
>   h1 = 1 - get_ic1(x)^2 - get_jc1(x)^2 - get_kc1(x)^2; # >= 0
>   h2 = 1 - get_ic2(x)^2 - get_jc2(x)^2 - get_kc2(x)^2; # >= 0
>   H = [h0;h1;h2];
> endfunction
>
> error: number of columns must match
> error: called from
>     __nonlin_residmin__> at line -1 column -1
>     __nonlin_residmin__> at line -1 column -1
>     __nonlin_residmin__> at line -1 column -1
>     __lm_svd__ at line 181 column 6
>     __nonlin_residmin__ at line 1133 column 21
>     nonlin_residmin at line 98 column 21
The probable cause was a bug, simply a missing line continuation '...'
in line 970 of inst/private/__nonlin_residmin__.m . The fix is
pushed. Can you use it without a new release?

This shows that I really must include tests to prevent such things
from creeping in... I had not even a demo included for nonlinear
constraints...

BTW: In this case the problem was easy to reproduce, but in general
you should provide a minimal code for demonstration. And a newer
Octave version would also help, giving line numbers in anonymous
function definitions, not just:

>     __nonlin_residmin__> at line -1 column -1
>     __nonlin_residmin__> at line -1 column -1
> ...

Olaf

--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: help needed with nonlinear inequality constraints (optimset "inequc") for nonlin_residmin in optim package

Philippe Dobbelaere
On 16/02/2018 23:55, Olaf Till wrote:

> On Fri, Feb 16, 2018 at 12:49:23PM +0100, Philippe Dobbelaere
> wrote:
>> settings = optimset (settings, "inequc",
>> {@nonlinear_ineq_constraints});
>>
>> with
>>
>> function H = nonlinear_ineq_constraints(x) h0 = 1 - get_ic0(x)^2
>> - get_jc0(x)^2 - get_kc0(x)^2; # >= 0 h1 = 1 - get_ic1(x)^2 -
>> get_jc1(x)^2 - get_kc1(x)^2; # >= 0 h2 = 1 - get_ic2(x)^2 -
>> get_jc2(x)^2 - get_kc2(x)^2; # >= 0 H = [h0;h1;h2]; endfunction
>>
>> error: number of columns must match error: called from
>> __nonlin_residmin__> at line -1 column -1 __nonlin_residmin__> at
>> line -1 column -1 __nonlin_residmin__> at line -1 column -1
>> __lm_svd__ at line 181 column 6 __nonlin_residmin__ at line 1133
>> column 21 nonlin_residmin at line 98 column 21
>
> The probable cause was a bug, simply a missing line continuation
> '...' in line 970 of inst/private/__nonlin_residmin__.m . The fix
> is pushed. Can you use it without a new release?
>
>

Thanks, I downloaded your modified version and it seems ok now.


--
Philippe Dobbelaere
Bell Labs, Nokia
Contact number +32 3 240 8217


-----------------------------------------
Join us March 12-15 at CERN near Geneva
Switzerland for OctConf 2018.  More info:
https://wiki.octave.org/OctConf_2018
-----------------------------------------