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 Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Michael Asam Open/Closed:  * Closed
Release:  * 7.2.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Post a Comment

Add a New Comment Rich Markup
   

Discussion

Sat 09 Aug 2025 11:59:07 AM UTC, comment #2: 

Yes, I think it this is a correct fix, thanks. The other error is probably fixed in the latest version.

Fixed this way in the repository:

https://sourcefor ... 8bcd40f3f8fdfd18/

Olaf Till <i7tiol>
Group Member
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>
Group 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>

 

Attached Files

This item currently has no attached files.

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

Attach Files:
   
   
Comment:
   

 

Dependencies

This item does not depend on any other items.

No items depend on this one.

 

Mail Notification Carbon-Copy List

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

    Votes

    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 group members can vote.

     

    History

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-08-09 i7tiol StatusConfirmed Fixed
        Open/ClosedOpen Closed
    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.16-ed84.
    Corresponding source code