将gsl_ran_hypergeometric_pdf(k,n1,n2,t)转换为boost :: math :: hypergeometric_distribution
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将gsl_ran_hypergeometric_pdf(k,n1,n2,t)转换为boost :: math :: hypergeometric_distribution相关的知识,希望对你有一定的参考价值。
如何翻译使用GNU Scientific Library中的超几何分布函数的C ++程序
http://www.gnu.org/software/gsl/manual/html_node/The-Hypergeometric-Distribution.html
进入一个C ++程序,而不是使用Boost library中的类似函数?
#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;
}
答案
这是Boost功能的翻译:
#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;
}
以上是关于将gsl_ran_hypergeometric_pdf(k,n1,n2,t)转换为boost :: math :: hypergeometric_distribution的主要内容,如果未能解决你的问题,请参考以下文章
Javascript 将正则表达式 \\n 替换为 \n,将 \\t 替换为 \t,将 \\r 替换为 \r 等等