bugGNU Octave - Bugs: bug #63240, [octave forge] (optim) fmincon...

 
 

bug #63240: [octave forge] (optim) fmincon error with Hessian

Submitter:  Michael Asam <stromi>
Submitted:  Wed 19 Oct 2022 02:02:23 PM UTC
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Michael Asam Open/Closed:  * Open
Release:  * 7.2.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

Wed 19 Oct 2022 04:36:43 PM UTC, comment #1: 

I can confirm the original bug, so I'm marking this as confirmed.

But the proposed fix of "hook.inverse_hessian = false;" gives a different error for me:

[x, fval, exitflag, output] = fmincon(@objf, x0, [], [], [], [], [], [], @constraints, opt)
error: @<anonymous>: function called with too many inputs
error: called from
    fmincon>@<anonymous>
    __jacobian_constants__>@<anonymous> at line 135 column 11
    __lm_feasible__ at line 145 column 8
    fmincon at line 457 column 24

Arun Giridhar <arungiridhar>
Project Member
Wed 19 Oct 2022 02:02:23 PM UTC, original submission:  

In this example the Hessian H is calculated and given to fmincon:

x0 = [-2; 1];

function [f, gf, H] = objf(x)
   r = x(1).^2 + x(2).^2;
   s = exp(-r);

   f = x(1).*s + r/20;
   gf = [(1-2.*x(1).^2).*s+x(1)./10; -2.*x(1).*x(2).*s+x(2)/10];
   H = [2*x(1)*(2*x(1)^2-3)*s+1/10, 2*x(2)*(2*x(1)^2-1)*s;
        2*x(2)*(2*x(1)^2-1)*s,      2*x(1)*(2*x(2)^2-1)*s+1/10];
end

function [c,ceq,gc,gceq] = constraints(x)
   c = x(1).*x(2)/2 + (x(1)+2).^2 + (x(2)-2).^2/2 - 2;
   ceq = [];

   % Note that the gradients have to be row-vectors!!!
   gc = [x(2)/2+2*(x(1)+2), x(1)/2+x(2)-2];
   gceq = [];
end

opt = optimset('GradObj', 'on', 'GradConstr', 'on', 'HessianFcn', 'objective');

[x, fval, exitflag, output] = fmincon(@objf, x0, [], [], [], [], [], [], @constraints, opt)

I get the following error message:

error: structure has no member 'inverse_hessian'
error: called from
    __lm_feasible__ at line 49 column 9
    fmincon at line 457 column 24
    Test_optimization7 at line 29 column 29

If I add "hook.inverse_hessian = false;" after line 434 in fmincon.m

  ## passed function for hessian of objective function
  hook.hessian = f.hessian;
  hook.inverse_hessian = false;

it fixes the problem, but I'm not sure if this is really the correct way to solve it.

Another strange thing is that in contrast to Matlab, the constraint's gradient has to be a row vector. For compatibility it should also accept a column vector. Surprisingly both types are already accepted for the function gradient.

I'm using optim package version 1.6.2.

Michael Asam <stromi>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by stromi (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.

     

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-10-19 arungiridhar StatusNone Confirmed
        Summary(optim) fmincon error with Hessian [octave forge] (optim) fmincon error with Hessian

    Back to the top


    Powered by Savane 3.9