octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #63240] (optim) fmincon error with Hessian


From: Michael Asam
Subject: [Octave-bug-tracker] [bug #63240] (optim) fmincon error with Hessian
Date: Wed, 19 Oct 2022 10:02:25 -0400 (EDT)

URL:
  <https://savannah.gnu.org/bugs/?63240>

                 Summary: (optim) fmincon error with Hessian 
                 Project: GNU Octave
               Submitter: 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: None
             Assigned to: None
         Originator Name: Michael Asam
        Originator Email: 
             Open/Closed: Open
                 Release: 7.2.0
         Discussion Lock: Any
        Operating System: Microsoft Windows


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Wed 19 Oct 2022 02:02:23 PM UTC By: Michael Asam <stromi>
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.








    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63240>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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