将gsl_ran_hypergeometric_pdf(k,n1,n2,t)转换为BOOST :: MATH :: HY

translate gsl_ran_hypergeometric_pdf(k, n1, n2, t) to boost::math::hypergeometric_distribution

本文关键字:转换 BOOST MATH HY n1 hypergeometric ran gsl pdf n2      更新时间:2023-10-16

我如何翻译使用超几何的C 程序GNU科学库的分布功能

http://www.gnu.org/software/gsl/manual/html_node/the-hypergeometric-distribution.html

进入C 程序,该程序使用Boost库中使用类似功能?

#include <cstdlib>
#include <iostream>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_cdf.h>
int main(int argc,char *argv[]) {
  unsigned int n1 = 256;
  unsigned int n2 = 1583;
  unsigned int t = 300;
  unsigned int k = 40;
  std::cout << gsl_ran_hypergeometric_pdf(k, n1, n2, t)
            << std::endl
            << gsl_cdf_hypergeometric_P(k, n1, n2, t)
            << std::endl;
  return EXIT_SUCCESS;
}

这是一个转换为增强功能的翻译:

#include <cstdlib>
#include <iostream>
#include <boost/math/distributions/hypergeometric.hpp>
#include <boost/math/policies/policy.hpp>
int main(int argc, char *argv[]) {
  unsigned int n1 = 256;
  unsigned int n2 = 1583;
  unsigned int t = 300;
  unsigned int k = 40;
  boost::math::hypergeometric_distribution<double> hg_dist(n1, t, n1 + n2);
  std::cout << boost::math::pdf<double>(hg_dist, k)
            << std::endl
            << boost::math::cdf<double>(hg_dist, k)
            << std::endl;
  return EXIT_SUCCESS;
}

有关更多信息,请参见http://www.boost.org/doc/libs/1_52_0/libs/math/math/doc/sf_and_dist/html/math/math_tool_tool_tool_tiast/dist_ref/dists/dists_ref/dists/hyhypergemetric_dist.htric_dist.html