Re: [Boost-bugs] [Boost C++ Libraries] #9393: quantile for hypergeometric distribution - precision/rounding issue

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #9393: quantile for hypergeometric distribution - precision/rounding issue
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-11-30 22:09:47


#9393: quantile for hypergeometric distribution - precision/rounding issue
--------------------------------------+-------------------------
  Reporter: anonymous | Owner: johnmaddock
      Type: Feature Requests | Status: new
 Milestone: To Be Determined | Component: math
   Version: Boost Development Trunk | Severity: Showstopper
Resolution: | Keywords:
--------------------------------------+-------------------------

Comment (by Paul McClellan <paulm@…>):

 John,

 Here are some examples illustrating the effect of setting the fudge_factor
 to 1 with different quantile policies (thank you Anonymous).


 {{{
 #include "stdafx.h"

 #define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_down

 #include <cstdio>
 #include <boost/math/distributions/hypergeometric.hpp>

 int main()
 {
    unsigned int xmin = 0;
    unsigned int length = 9;

    boost::math::hypergeometric_distribution<> dist( 8u, 8u, 16u );

    for ( unsigned int i = 0; i < length; ++i )
    {
       double x = xmin + i;
       double y =
          boost::math::cdf( dist, x );
          // boost::math::cdf( boost::math::complement( dist, x ) );

       std::printf(
             " x = %g\tCDF(x) = %f\tinverse-CDF(CDF(x)) = %g\n",
             x, y, boost::math::quantile( dist, y ) );
    }

    return 0;
 }
 }}}

 With fudge_factor unchanged, and quantile policy integer_round_down I get:


 {{{
  x = 0 CDF(x) = 0.000078 inverse-CDF(CDF(x)) = 0
  x = 1 CDF(x) = 0.005051 inverse-CDF(CDF(x)) = 0 <--
  x = 2 CDF(x) = 0.065967 inverse-CDF(CDF(x)) = 1 <--
  x = 3 CDF(x) = 0.309635 inverse-CDF(CDF(x)) = 2 <--
  x = 4 CDF(x) = 0.690365 inverse-CDF(CDF(x)) = 3 <--
  x = 5 CDF(x) = 0.934033 inverse-CDF(CDF(x)) = 4 <--
  x = 6 CDF(x) = 0.994949 inverse-CDF(CDF(x)) = 5 <--
  x = 7 CDF(x) = 0.999922 inverse-CDF(CDF(x)) = 7
  x = 8 CDF(x) = 1.000000 inverse-CDF(CDF(x)) = 8
 }}}

 Changing the quantile policy to integer_round_up I get:


 {{{
  x = 0 CDF(x) = 0.000078 inverse-CDF(CDF(x)) = 1 <--
  x = 1 CDF(x) = 0.005051 inverse-CDF(CDF(x)) = 2 <--
  x = 2 CDF(x) = 0.065967 inverse-CDF(CDF(x)) = 3 <--
  x = 3 CDF(x) = 0.309635 inverse-CDF(CDF(x)) = 4 <--
  x = 4 CDF(x) = 0.690365 inverse-CDF(CDF(x)) = 5 <--
  x = 5 CDF(x) = 0.934033 inverse-CDF(CDF(x)) = 6 <--
  x = 6 CDF(x) = 0.994949 inverse-CDF(CDF(x)) = 7 <--
  x = 7 CDF(x) = 0.999922 inverse-CDF(CDF(x)) = 8 <--
  x = 8 CDF(x) = 1.000000 inverse-CDF(CDF(x)) = 8
 }}}

 However, if I force fudge_factor to 1.0 in hypergeometric_quantile.hpp,
 then with quantile policy integer_round_down I get:

 {{{
  x = 0 CDF(x) = 0.000078 inverse-CDF(CDF(x)) = 0
  x = 1 CDF(x) = 0.005051 inverse-CDF(CDF(x)) = 1
  x = 2 CDF(x) = 0.065967 inverse-CDF(CDF(x)) = 2
  x = 3 CDF(x) = 0.309635 inverse-CDF(CDF(x)) = 3
  x = 4 CDF(x) = 0.690365 inverse-CDF(CDF(x)) = 4
  x = 5 CDF(x) = 0.934033 inverse-CDF(CDF(x)) = 5
  x = 6 CDF(x) = 0.994949 inverse-CDF(CDF(x)) = 5 <--
  x = 7 CDF(x) = 0.999922 inverse-CDF(CDF(x)) = 7
  x = 8 CDF(x) = 1.000000 inverse-CDF(CDF(x)) = 8
 }}}

 and with quantile policy integer_round_up I get:


 {{{
  x = 0 CDF(x) = 0.000078 inverse-CDF(CDF(x)) = 0
  x = 1 CDF(x) = 0.005051 inverse-CDF(CDF(x)) = 1
  x = 2 CDF(x) = 0.065967 inverse-CDF(CDF(x)) = 2
  x = 3 CDF(x) = 0.309635 inverse-CDF(CDF(x)) = 4 <--
  x = 4 CDF(x) = 0.690365 inverse-CDF(CDF(x)) = 4
  x = 5 CDF(x) = 0.934033 inverse-CDF(CDF(x)) = 5
  x = 6 CDF(x) = 0.994949 inverse-CDF(CDF(x)) = 6
  x = 7 CDF(x) = 0.999922 inverse-CDF(CDF(x)) = 8 <--
  x = 8 CDF(x) = 1.000000 inverse-CDF(CDF(x)) = 8
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9393#comment:4>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC