3
$\begingroup$

I have occasionally used RandomSeed[100] twice in the code and noticed behaviour that I don't understand.

Consider:

Clear[X, tmp, tmp1]
SeedRandom[100];
X = RandomVariate[UniformDistribution[{-1, 1}], 1000];
tmp = RandomVariate[BernoulliDistribution[#]] & /@ LogisticSigmoid[X];

SeedRandom[100]; 
tmp1 = RandomVariate[BernoulliDistribution[#]] & /@ LogisticSigmoid[X];

Then if we plot both responses, they are very different - tmp produces correct (blue) result, but tmp1 (orange) produces strange outcome:

ListPlot[{
  Thread[{X, tmp}], 
  Thread[{X, tmp1}]
  }, PlotMarkers -> {"-", "+"}]

enter image description here

Why is it so?

EDIT As @JimB correctly admits, it appears that tmp1 produces 0's whenever X is negative and 1's whenever X is positive. And it appears to be happening only when the same seed is used, i.e. 100 in the example.

$\endgroup$
  • 1
    $\begingroup$ You're not executing the same statements after setting the seed. You need a X1 = RandomVariate[UniformDistribution[{-1, 1}], 1000]; right before defining tmp1. And the definition of tmp1 also needs X changed to X1. $\endgroup$ – JimB May 13 at 19:46
  • $\begingroup$ @JimB, I know that, but why this other statement generates such picture (I would expect that it would just made another version of distribution but it simply set all 1s for positive and all 0s for negative values without randomness as in the tmp case given similar X. $\endgroup$ – garej May 13 at 19:50
  • 2
    $\begingroup$ I see now. So it appears that tmp1 produces 0's whenever X is negative and 1's whenever X is positive. I think a table showing that would make the issue clearer. And it appears to be happening only when the same seed is used. Maybe this is exactly what you were stating but it wasn't clear to me. $\endgroup$ – JimB May 13 at 20:14
  • 6
    $\begingroup$ It looks like RandomVariate on different distributions use the same underlying random number generator. In other words, when using the same seed, random numbers generated from different distributions will be correlated. I think it's worth reporting to support, since if nothing else, the documentation ought to list this as a possible issue. $\endgroup$ – Carl Woll May 13 at 20:15
  • $\begingroup$ @CarlWoll, thank you. I've sent them a message. I'll come back if get something from support team. $\endgroup$ – garej May 13 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.