bugGNU Octave - Bugs: bug #40101, fminunc outputs - gradient and...

 
 

bug #40101: fminunc outputs - gradient and hessian not always calculated in the solutio

Submitter:  jose <josombio>
Submitted:  Wed 25 Sep 2013 04:47:43 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Jose Open/Closed:  * Closed
Release:  * 3.6.4 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 12 Nov 2015 01:00:21 AM UTC, comment #2: 

Thanks for the patch.  I committed it on the development branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/a7dbc4fc3732).  It will be a part of the 4.2 release of Octave.

Marking bug as fixed and closing.

Rik <rik5>
Group administrator
Mon 03 Feb 2014 04:18:13 PM UTC, comment #1: 

Here is a Mercurial changeset (fminunc.diff) equivalent to the proposed fminunc2.m with an additional modification that fixes a new problem introduced in fminunc2.m itself. This new problem affected the cases in which the gradient function was supplied by the user as a row vector.

An easier way to reproduce the original problem (compared to session.txt) is as follows:
Before applying the changeset

octave:1> l=@(x) exp(sum(x.^2));
octave:2> [x,fval,info,output,grad,hess]=fminunc(l,[1 1]);
octave:3> info
info =  3
octave:4> grad
grad =
   5.3428e-07
   5.2937e-07
octave:5> __fdjac__(l,x,l(x),[1 1],1)
ans =
  -2.4385e-09   2.4568e-09
octave:6> hess
hess =
   1.49999   0.50000
   0.50000   1.50001


After applying the changeset


octave:7>
octave:7>
octave:7> [x,fval,info,output,grad,hess]=fminunc(l,[1 1]);
octave:8> info
info =  3
octave:9> grad
grad =
  -2.4385e-09   2.4568e-09
octave:10> hess
hess =
   1.50920   0.49988
   0.49988   1.49081



(file #30447)

jose <josombio>
Wed 25 Sep 2013 04:47:43 PM UTC, original submission:  

The iteration of fminunc can finish because of several reasons. The particular reason can be checked from the 3rd output (the info).

If I am not mistaken, it seems that when fminunc reaches any of the exit conditions corresponding to info equal to -1, 2 or 3, the gradient is not recalculated after the last modification of x (See lines 283 for the last update of x, and lines 301, 320 and 323 for changes of the variable info that result in exit conditions).

As a consequence, the gradient returned in the output in those cases does not correspond to the gradient calculated in the x returned as output, but to the gradient calculated using the x of the previous iteration.

The file attached (fminunc2.m) is an attempt to fix this. It also recalculates the hessian (using blind copy-paste from the code!!). It has been tested only with a case in which info=3.
Additionally, the fix returns the gradient in the same shape than x.

Find attached (session.txt) one way to reproduce the problem when info=3.

jose <josombio>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #30447:  fminunc.diff added by josombio (1KiB - text/x-patch - Mercurial changeset)
file #29209:  fminunc2.m added by josombio (13KiB - text/x-objcsrc - A fix-attempt)
file #29210:  session.txt added by josombio (1KiB - text/plain - A fix-attempt)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by josombio (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 group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-11-12 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2014-02-03 josombio Attached File- Added fminunc.diff, #30447
    2013-10-17 rik5 StatusNone Patch Submitted
    2013-09-25 josombio Attached File- Added fminunc2.m, #29209
        Attached File- Added session.txt, #29210

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code