bugGNU Octave - Bugs: bug #34405, Validation for betainc() inputs

 
 

bug #34405: Validation for betainc() inputs

Submitter:  Rik <rik5>
Submitted:  Tue 27 Sep 2011 03:30:07 AM UTC
   
 
Category:  Libraries Severity:  3 - Normal
Priority:  3 - Low Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 27 Mar 2018 12:20:18 AM UTC, comment #4: 

Fixes from GSOC2018 special function project were incorporated during OctConf 2018.  Closing report.

Rik <rik5>
Group administrator
Sat 19 Nov 2016 03:31:52 PM UTC, comment #3: 

This issue is still present in Octave 4.2.0.

Hartmut <hardy>
Tue 27 Sep 2011 04:55:06 PM UTC, comment #2: 

I'm moving the priority down a few notches.  I would like to see this fixed since it impacts betacdf.m, binocdf.m, fcdf.m, nbincdf.m, and tcdf.m.  On the other hand, those functions mostly already validate their inputs before calling betainc().  The validation isn't perfect but I'm willing to let the corner case of a,b=Inf slide for now.

Since the revisions to the statistics distribution functions were done on the default branch I would say we are safe to go slow there and implement any proper fix you like (templates, etc.).  For the existing stable branch let's apply the lo-specfun.cc patch.

Rik <rik5>
Group administrator
Tue 27 Sep 2011 04:51:19 AM UTC, comment #1: 

A simple fix would be to just add the checks in the betainc functions in lo-specfun.cc that accept scalar values.  See the attached patch.

But then we are checking all inputs all the time, even when one or two are scalars and the others are large arrays.  But before attempting to fix this in the code that performs the loops, I think it would be better to first convert those functions to use templates to avoid some duplication.

I can work on this if you would like, but I don't want to change the stable branch to use templates, and I don't want to have to add the checks to all the current functions in lo-specfun.cc.  So what do you think we should do?  Add the simple but slow check to the stable branch, then make a better fix using templates for the default branch?

(file #24030)

John W. Eaton <jwe>
Group administrator
Tue 27 Sep 2011 03:30:07 AM UTC, original submission:  

betainc which calculates the incomplete Beta function needs better input validation.

Example 1 : NaN inputs


betainc (NaN, 1, 2)
 ans =


The correct answer should be NaN.

Example 2 : negative or Inf parameters


betainc (0.5, 1, Inf)

 ***MESSAGE FROM ROUTINE D9LGMC IN LIBRARY SLATEC.
 ***POTENTIALLY RECOVERABLE ERROR, PROG ABORTED, TRACEBACK REQUESTED
 *  X SO BIG D9LGMC UNDERFLOWS
 *  ERROR NUMBER = 2
 *
 ***END OF MESSAGE

 ***JOB ABORT DUE TO UNRECOVERED ERROR.
0          ERROR MESSAGE SUMMARY
 LIBRARY    SUBROUTINE MESSAGE START             NERR     LEVEL     COUNT
 SLATEC     DBETAI     X IS NOT IN THE RANG         1         2         2
 SLATEC     D9LGMC     X SO BIG D9LGMC UNDE         2         1         4
 SLATEC     DBETAI     P AND/OR Q IS LE ZER         2         2         2

error: betainc: exception encountered in Fortran subroutine xdbetai_


It would be much nicer on the user to simply return NaN for values which are invalid.

Example 3 : x outside range [0, 1]


betainc (2, 1, 2)
 ***MESSAGE FROM ROUTINE DBETAI IN LIBRARY SLATEC.
 ***FATAL ERROR, PROG ABORTED, TRACEBACK REQUESTED
 *  X IS NOT IN THE RANGE (0,1)
 *  ERROR NUMBER = 1
 *
 ***END OF MESSAGE

 ***JOB ABORT DUE TO FATAL ERROR.
0          ERROR MESSAGE SUMMARY
 LIBRARY    SUBROUTINE MESSAGE START             NERR     LEVEL     COUNT
 SLATEC     DBETAI     X IS NOT IN THE RANG         1         2         3
 SLATEC     D9LGMC     X SO BIG D9LGMC UNDE         2         1         4
 SLATEC     DBETAI     P AND/OR Q IS LE ZER         2         2         2

error: betainc: exception encountered in Fortran subroutine xdbetai_


One possible strategy would be to validate the inputs and only pass computable values to Fortran.  An m-file implementation might be the following


retval = NaN (size (x));
ok = (!isnan (x) & !isnan (a) & !isnan (b) &
      (a > 0) & (a < Inf) & (b > 0) & (b < Inf) & (x >= 0) & (x <= 1));
retval(ok) = betainc (x(ok), a(ok), b(ok));


This isn't quite right because betainc is implemented in C++ in the file betainc.cc but the concept could be translated.

Rik <rik5>
Group administrator

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #24030:  diffs.txt added by jwe (887B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by rik5 (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-27 rik5 StatusPostponed Fixed
        Open/ClosedOpen Closed
    2016-11-18 mtmiller StatusNone Postponed
    2011-09-27 rik5 Priority5 - Normal 3 - Low
    2011-09-27 jwe Attached File- Added diffs.txt, #24030

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code