独立与提升随机

时间:2014-10-20 17:40:39

标签: c++ boost random

我正在尝试使用mersenne twister来生成各种分布的样本。我有一个生成器,它用于生成所有这些。这里发生了一些奇怪的事(至少对我而言)。一方面计算各种样本的相关系数几乎为零,这看起来不错。但是当我更改一个分布的参数(在其他地方没有使用)时,它会以某种方式改变我在其他分布中获得的结果。具体做法是:

#include <boost/random.hpp>

using namespace boost; // boost random library for random generators

mt19937 generator(7687); // mersenne twister random number generator, seed = 7687

double normal_sample(double mu, double sigma)
// returns a sample from normal distribution with mean mu and variance sigma 
{
    normal_distribution<> norm_dist;
    variate_generator<mt19937&, normal_distribution<> > norm_rnd(generator, norm_dist);

    return(mu + sigma * norm_rnd());
}    

double poisson_sample(double intensity)
// returns a number of points in a realization of a Poisson point process
{
    poisson_distribution<> poiss_dist(intensity);
    variate_generator<mt19937&, poisson_distribution<> > poiss_rnd(generator, poiss_dist);

    return(poiss_rnd());
}

这是代码......生成器部分,然后我从这两个分布中绘制,更改名为intensity的参数。这不仅改变了泊松样本,也改变了普通样本......实际上,现在我想起来,它有点意义,因为我的泊松样本确定了使用相同生成器随机生成的多个点...然后,根据它们中有多少,我得到其他东西,因为正常样本是使用序列中的不同数字生成的。这是对的吗?

如果是这样,怎么会改变呢?我应该使用多台发电机吗?

1 个答案:

答案 0 :(得分:1)

这可能意味着根据参数,从mersenne twister中提取更少或更多的随机样本。

这在逻辑上意味着所有其他结果都会发生变化,从而使所有其他结果不同。

  

[...] 它有点意义,因为我的Poisson样本确定了使用同一个生成器随机生成的多个点...那么那么取决于它们中有多少个,我得到别的东西,因为正常的样本是使用序列中的不同数字生成的。这是对的吗?

对我来说,你已经弄明白了,是的。

如果您想要可重复的PRNG,请使用单独的PRNG状态,即不同的mersenne egnines。

相关问题