[Boost-bugs] [Boost C++ Libraries] #11556: hypergeometric constructor's n & r are consistent with online description!

Subject: [Boost-bugs] [Boost C++ Libraries] #11556: hypergeometric constructor's n & r are consistent with online description!
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-08-19 12:42:39


#11556: hypergeometric constructor's n & r are consistent with online description!
--------------------------------------------+---------------------------
 Reporter: mchalabi@… | Owner: matias
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: Documentation
  Version: Boost 1.59.0 | Severity: Problem
 Keywords: hypergeometric constructor n r |
--------------------------------------------+---------------------------
 Hi, at the following URL it reads:

 r: number of defective items
 n: size of sample

 [http://www.boost.org/doc/libs/1_52_0/libs/math/doc/sf_and_dist/html/math_toolkit/dist/dist_ref/dists/hypergeometric_dist.html]

 However looking into the constructor of hypergeometric distribution
 reveals the contrary:

 r: sample size
 n: number of defective items


 {{{
    class hypergeometric_distribution
    {
    public:
       typedef RealType value_type;
       typedef Policy policy_type;

       hypergeometric_distribution(unsigned r, unsigned n, unsigned N) //
 Constructor.
          : m_n(n), m_N(N), m_r(r)
       {
          static const char* function =
 "boost::math::hypergeometric_distribution<%1%>::hypergeometric_distribution";
          RealType ret;
          check_params(function, &ret);
       }
       // Accessor functions.
       unsigned total()const
       {
          return m_N;
       }

       unsigned defective()const
       {
          return m_n;
       }

       unsigned sample_count()const
       {
          return m_r;
       }

       bool check_params(const char* function, RealType* result)const
       {
          if(m_r > m_N)
          {
             *result = boost::math::policies::raise_domain_error<RealType>(
                function, "Parameter r out of range: must be <= N but got
 %1%", static_cast<RealType>(m_r), Policy());
             return false;
          }
          if(m_n > m_N)
          {
             *result = boost::math::policies::raise_domain_error<RealType>(
                function, "Parameter n out of range: must be <= N but got
 %1%", static_cast<RealType>(m_n), Policy());
             return false;
          }
          return true;
       }
       bool check_x(unsigned x, const char* function, RealType*
 result)const
       {
          if(x < static_cast<unsigned>((std::max)(0, (int)(m_n + m_r) -
 (int)(m_N))))
          {
             *result = boost::math::policies::raise_domain_error<RealType>(
                function, "Random variable out of range: must be > 0 and >
 m + r - N but got %1%", static_cast<RealType>(x), Policy());
             return false;
          }
          if(x > (std::min)(m_r, m_n))
          {
             *result = boost::math::policies::raise_domain_error<RealType>(
                function, "Random variable out of range: must be less than
 both n and r but got %1%", static_cast<RealType>(x), Policy());
             return false;
          }
          return true;
       }

    private:
       // Data members:
       unsigned m_n; // number of "defective" items
       unsigned m_N; // number of "total" items
       unsigned m_r; // number of items picked

    }; // class hypergeometric_distribution
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11556>
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:18 UTC