在c ++中生成泊松变量 [英] generating poisson variables in c++
本文介绍了在c ++中生成泊松变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实现了这个函数来生成poisson随机变量
I implemented this function to generate a poisson random variable
typedef long unsigned int luint;
luint poisson(luint lambda) {
double L = exp(-double(lambda));
luint k = 0;
double p = 1;
do {
k++;
p *= mrand.rand();
} while( p > L);
return (k-1);
}
其中mrand是MersenneTwister随机数生成器。我发现,当我增加lambda,预期分布将是错误的,一个平均值饱和在750左右。是由于数字近似还是我犯了什么错误?
where mrand is the MersenneTwister random number generator. I find that, as I increase lambda, the expected distribution is going to be wrong, with a mean that saturates at around 750. Is it due to numerical approximations or did I make any mistakes?
推荐答案
从 poisson(750)为 poisson(375)+ poisson(375)
。
这篇关于在c ++中生成泊松变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文