문제

The general Accept rejection algorithm is as usual .

1 generate U 1 ,U 2 ,U 3 from Unif[0,1]

2 X ← −log(U 1 )

3 if U 2 > exp(−0.5(X − 1) 2 ).... go back until condition met.

My question is do I need to use separate seed for each uniform distribution or using the same seed?

도움이 되었습니까?

해결책

You need to use the same seed – as in, you must seed the generator only once. What’s more, you should use only one generator: there is no reason to use more than one, and it’s easy to introduce subtle errors with more than one.

Technically, for a good enough PRNG it doesn’t matter (as long as the seeds are distinct) but it won’t hurt either. For an inferior PRNG, using separate seeds may skew your results significantly if the seeds are correlated in any way (and they practically often are unless you seed from a true random device).

Be sure to use the new <random> standard header in C++! std::rand should be considered deprecated.

다른 팁

I gather that the question is if the pseudo random number generators (PRNGs) used to generate the helper variables in acceptance rejection algorithms should be seeded differently.

You cannot have good statistical properties without a good PRNG, therefore before thinking about seeding, choose a good generator. Given a good generator, you don't need to use different seeds in your use case of creating two independent distributions. In fact, you could accidently (even if very unlikely with a good generator) choose an especially bad combination of seeds, leading to statistical anomalies.

Fortunately, as of C++11 you are usually supplied with good PRNGs in the header <random>. My default choice is the Mersenne Twister. I take it you want to generate normal distributions by manually coded acceptance rejection as practice or due to some other requirement. If not, C++11 already provides you with a ready to use normal distribution.

You have to use different seeds, since if you use the same seed, then your random variables will have a covariance of 1.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top