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


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

Submitted by:  jose <josombio>
Submitted on:  Wed 25 Sep 2013 04:47:43 PM UTC  
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: JoseOpen/Closed: Closed
Release: 3.6.4Operating System: GNU/Linux

Add a New Comment(Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


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>
Project 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

After applying the changeset

(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 File(s):

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
  • -unavailable- added by rik5 (Updated the item)
  • -unavailable- added by josombio (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 12 Nov 2015 01:00:21 AM UTCrik5StatusPatch Submitted=>Fixed
    Mon 03 Feb 2014 04:18:13 PM UTCjosombioAttached File-=>Added fminunc.diff, #30447
    Thu 17 Oct 2013 11:06:36 PM UTCrik5StatusNone=>Patch Submitted
    Wed 25 Sep 2013 04:47:43 PM UTCjosombioAttached File-=>Added fminunc2.m, #29209
      Attached File-=>Added session.txt, #29210

    Back to the top

    Powered by Savane 3.1-cleanup1