使用boost C++从逆伽马分布生成随机样本
generate random sample from inverse gamma distribution with boost C++
我正试图使用以下代码从逆伽马分布中进行采样,以修改我在第行找到的一些代码。我不是C++编码方面的专家,所以我需要你的解释和帮助。
#include <iostream>
#include <fstream>
#include <random>
#include "boost/random.hpp"
#include "boost/generator_iterator.hpp"
#include <boost/math/distributions.hpp>
using namespace std;
int main(){
boost::mt19937 rng;
boost::math::inverse_gamma_distribution<>invg(2.0, 3.0);
cout << " probability variance > 50: " << boost::math::cdf(boost::math::complement(invg, 50.0));
boost::variate_generator<boost::mt19937& , boost::math::inverse_gamma_distribution<> > sampleIG(rng, invg);
for (int i = 0; i < 10; ++i)
{
double d = sampleIG();
std::cout << d << std::endl;
}
}
我得到的错误是:
In file included from /usr/include/boost/random.hpp:55:0,
from vesSimQ.cpp:5:
/usr/include/boost/random/variate_generator.hpp: In instantiation of ‘class boost::random::variate_generator<boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>&, boost::math::inverse_gamma_distribution<double> >’:
vesSimQ.cpp:20:98: required from here
/usr/include/boost/random/variate_generator.hpp:59:48: error: no type named ‘result_type’ in ‘class boost::math::inverse_gamma_distribution<double>’
typedef typename Distribution::result_type result_type;
^
vesSimQ.cpp: In function ‘int main()’:
vesSimQ.cpp:25:26: error: no match for call to ‘(boost::random::variate_generator<boost::random::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>&, boost::math::inverse_gamma_distribution<double> >) ()’
double d = sampleIG();
对于其他发行版,此错误是由于在variate_generator的实例化中使用boost::math而不是boost::random造成的。下面是一个关于如何创建威布尔随机数生成器的示例:
#include <boost/random/mersenne_twister.hpp> // For boost::mt19937
#include <boost/random/variate_generator.hpp>
#include <boost/random/weibull_distribution.hpp>
int main(){
double shape = 3.0;
double scale = 0.5;
boost::mt19937 rng(12);
boost::random::weibull_distribution<> myWeibull(shape, scale);
boost::random::variate_generator<boost::mt19937&, boost::random::weibull_distribution<> > rand_Weibull(rng, myWeibull);
double rn;
for (int i=0; i < 10; ++i)
{
rn = rand_Weibull();
cout << rn << endl;
}
}
我看到,尽管boost::随机范围中有伽马分布,但没有逆伽马分布。
我安装了Boost 1.60.0,它有一个名为\Boost_1_6_0\libs\math\test\的文件夹,其中有一些代码可以帮助你。
相关文章:
- 编译 libfluid 样本控制器时对"event_base_del_virtual"的未定义引用
- 改变或缩放两个正态分布以具有特定的相关系数
- 如何创建没有特定定义的随机分布?uniform_int_distribution是从其他类继承的吗?
- 使用源读取器从网络摄像头源获取 H264 样本
- C++随机数分布传递给函数
- 从转换后的容器元素创建离散分布
- 从 C++ 函数与 Python 函数返回的不一致值用于偏斜正态分布
- 当相机接近模型时,SSAO样本内核会导致性能下降?
- 在编译时选择随机数分布
- 如何从 std::set 绘制 n 个元素的样本
- C++:创建1000次唯一的随机分布,在任何分布中都没有重复的数字
- 如何通过一次运行将多个输入样本馈送到C++张量流模型
- 如何测量一个音频样本中的低音量
- c++在循环中定义一组概率分布
- 分布MPI散点错误的数字
- 无法按 lambda 中的值捕获随机分布和生成器?
- 离散分布不对称
- 如何在C++中将函数值更改为表中的值(伽马分布)?
- 使用boost C++从逆伽马分布生成随机样本
- C++中多变量正态/高斯分布的样本