Opened 7 years ago

Closed 7 years ago

#11556 closed Bugs (fixed)

hypergeometric constructor's n & r are not consistent with online description!

Reported by: mchalabi@… Owned by: John Maddock
Milestone: Boost 1.60.0 Component: math
Version: Boost 1.59.0 Severity: Problem
Keywords: hypergeometric constructor n r Cc: mor.chalabi@…

Description

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

Change History (4)

comment:1 by anonymous, 7 years ago

Summary: hypergeometric constructor's n & r are consistent with online description!hypergeometric constructor's n & r are not consistent with online description!

comment:2 by John Maddock, 7 years ago

Component: Documentationmath
Owner: changed from Matias Capeletto to John Maddock

Ooops!

Will investigate, thanks for reporting that!

comment:3 by John Maddock, 7 years ago

The documentation is correct, the comments in code are wrong, as are the member function getters defective() and sample_count(). If you follow the docs and ignore the code, then everything will work as documented. Will fix the other issues shortly.

comment:4 by John Maddock, 7 years ago

Milestone: To Be DeterminedBoost 1.60.0
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.