bugGNU Octave - Bugs: bug #46658, fzero with single precision args...

 
 

bug #46658: fzero with single precision args fails to terminate

Submitter:  Ceral Paquet <octavebugs>
Submitted:  Thu 10 Dec 2015 04:11:56 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 18 Jan 2016 06:23:19 PM UTC, comment #6: 

I made the change to fzero to correctly choose a stopping tolerance on the stable branch (http://hg.savannah.gnu.org/hgweb/octave/rev/323e92c4589f).  Even though there were no problems reported, I also updated the other scripts in the optimization directory to correctly choose a stopping tolerance (http://hg.savannah.gnu.org/hgweb/octave/rev/52af4092f863).

Closing report.

Rik <rik5>
Group administrator
Fri 11 Dec 2015 09:51:32 AM UTC, comment #5: 

Nice. Works for me with all combos of single and double.

I also looked at

fminsearch.m
fsolve.m
fminbnd.m
fminunc.m

There are a couple of places where class(x0) is used but when I tested them with with similar problems there was no problem with any combination of single/double.

fminunc.m:  macheps = eps (class (x0));
fsolve.m:  macheps = eps (class (x0));

The TolX and TolFun are hardcoded (to 1e-7).

Ceral Paquet <octavebugs>
Thu 10 Dec 2015 10:08:42 PM UTC, comment #4: 

fzero is looking only at the class of x0 to decide what eps to use.  It's pretty simple to extend that to include looking at the results of the function evaluation.  The function fzero is written in fzero.m which means you can go ahead and change it quite easily.

I made a quick attempt which seems to work for me.  See the attached cset.

(file #35694)

Rik <rik5>
Group administrator
Thu 10 Dec 2015 06:01:53 PM UTC, comment #3: 

Problem also goes away if fun returns a double. So, basically x0 and the return value of func need to be the same class.

Ceral Paquet <octavebugs>
Thu 10 Dec 2015 05:43:04 PM UTC, comment #2: 

Seems the problem goes away if the initial estimate is a single too. Perhaps eps is being derived from the initial estimate, whereas it should be eps('single') if any of the inputs is single.

Ceral Paquet <octavebugs>
Thu 10 Dec 2015 04:23:14 PM UTC, comment #1: 

Setting TolX with


optimset ("TolX", 2 * eps (class (x)))


works for me.

Matlab definitely documents that the default TolX value is eps("double"), which is what Octave's fzero is using.

Mike Miller <mtmiller>
Group Member
Thu 10 Dec 2015 04:11:56 PM UTC, original submission:  

The code below does not terminate when data are in single precision although it works fine with doubles. Matlab works in both instances.

Passing opts = optimset('TolX',class(x)) did not fix it. That uses 1.16e-7 rather than 2.2e-16. It seems to need even lower precision, like 1e-6, to finish.



% data
x = -20:20;
y = [
0.030339992
0.033821423
0.041702233
0.054150544
0.069778219
0.085964844
0.099779591
 0.10928077
 0.11479455
 0.11970813
 0.13039705
 0.15512653
 0.20207173
 0.27689669
 0.38052434
 0.50775862
 0.64725506
 0.78300703
 0.89711601
 0.97325319
          1
  0.9732579
 0.89712346
 0.78301448
 0.64725971
 0.50775862
 0.38051969
 0.27688923
 0.20206429
 0.15512197
 0.13039705
 0.11971273
   0.114802
 0.10928822
0.099784195
0.085964851
0.069773585
0.054143101
0.041694809
0.033816814
0.030339992
];

plot(x,y)

% these prevent fzero from terminating
x = single(x);
y = single(y);

% find FWHM
myfunc = @(x,y,pt) interp1(x,y,pt,'spline') - 0.5;

pt0 = 5;
pt = fzero(@(pt)myfunc(x,y,pt),pt0)


Ceral Paquet <octavebugs>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #35694:  fzero.cset added by rik5 (1KiB - application/octet-stream)

 

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 mtmiller (Posted a comment)
  • -email is unavailable- added by octavebugs (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-01-18 rik5 Item GroupPerformance Incorrect Result
        StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2015-12-10 rik5 Attached File- Added fzero.cset, #35694
        StatusConfirmed Patch Submitted
    2015-12-10 mtmiller CategoryNone Octave Function
        Item GroupNone Performance
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code