Why are there repeated values from EXPRND?

I'm generating several hundred values from EXPRND with a given eta parameter, which I'm using to populate an array, which I then use in subsequent processing, finding the minimum value through several iterations of loops, comparing it to the value of other variables, blah blah blah, and replacing that minimum value with other generated values of of EXPRND as necessary. Regardless, I'm using the following command to find the location of the minimum value in my array:
[x,y]=ind2sub(size(array),find(array==min(min(array))));
This works perfectly well, however, the problem is that it will often find instances where there are TWO locations in my large array that have IDENTICAL values, which happen to be the minimum value in the array at that moment in the simulation, which then causes an error when I try to do anything with the (x,y) coordinates I thought I've created, because of dimensional errors, because I'm passing multiple arguments to functions when they're expecting singular arguments, for instance array(x,y)=SOMETHING...
How can it be possible that a random number generator with double precision would produce TWO identical values, which has now occurred on eight consecutive executions of my simulation, even on different machines, no matter if I restart the program or not? I am perplexed...

2 Comments

I'm not able to reproduce this with several trials involving 100 million values:
array = exprnd(1,[10000 10000]);
What values of mu has this problem occurred for?

Sign in to comment.

 Accepted Answer

Well, I don't know what the problem was, but since the exponential distribution is just a simplified version of the two-parameter Weibull distribution with a shape factor of 1, I used WBLRND(8714,1), and didn't get repeat values in 1000 iterations of my analysis. I have no idea why I would have problems with EXPRND but not with WBLRND even though they use the same random number stream. At least I finally got the simulation to work. Thanks everyone for trying to help me out!

More Answers (4)

This is certainly possible for very extreme values of the mean parameter, because the "correct" values saturate to zero or Inf:
>> exprnd(eps(realmin),3)
ans =
0 4.9407e-324 4.9407e-324
0 4.9407e-324 9.8813e-324
4.9407e-324 1.4822e-323 9.8813e-324
>> exprnd(realmax,3)
ans =
Inf 1.8399e+307 1.2851e+308
1.5712e+308 1.021e+307 Inf
Inf 1.2792e+308 1.893e+307
But that's rather extreme. I think you're going to have to provide an example.

1 Comment

I'm using mu=8714. I'm building a symmetric array, but not a rectangular array, so I have to fill the rows of my array in different for loops, then combine the "row variables" into the final array after the different row elements have been filled. My final array has 18 rows, with the two middle rows having 56 elements assigned by the EXPRND function, and at the extreme, the outer rows (1 and 18) having only 8, with the other elements being assigned values of 999999 as placeholders. I just ran my code again to provide you an example, and in this case I got:
>> [x,y]=ind2sub(size(array),find(array==min(min(array))))
x =
3
5
y =
7
7
>> array(3,7)
ans =
6.4872e+003
>> array(5,7)
ans =
6.4872e+003
I don't know if there's something wrong with something in my internal computer clock or whatever Matlab uses to draw from to feed its random number stream that would cause this, but it's starting to really annoy me.

Sign in to comment.

Matt, I am confused. You seem to be saying something roughly equivalent to, "I generated a few hundred values using exprnd(8714,n,1), and the minimum value was around 6487, and there were multiple occurrences of that value." Putting aside the question of non-unique values for a moment, when I generate a few hundred values like that, repeatedly, my minimum values are much smaller:
>> x = exprnd(8714,300,10000);
>> quantile(min(x,[],1),[.01 .05 .25 .5 .75 .95 .99])
ans =
0.28872 1.389 8.2665 20.169 40.089 86 137.22
So somehow we're not on the same page at all. I may be completely misunderstanding what you're saying. I confess that I am unable to understand your description of how you are filling in the array. But it seems like if exprnd is at fault here, you should be able to demonstrate that in a single line of code such as
min(exprnd(8714,n,1))
or
length(unique(exprnd(8714,n,1)))
What do you get from those?
And what do you get from
which rand
which exprnd
Sorry, I should have been more specific. I find these repeats after several iterations of my code (this is a Monte Carlo simulation), which is looking for minimum values in the array, and then replaces that minimum value with another value if several conditions are met which have nothing to do with the generation of a random number. So, yes, I get values in the <1 range. It just so happens that this particular time I ran my code, I happened to "find" a repeat value when I was at the point where the minimum value in my array was 6487.2.

2 Comments

>> which rand
built-in (C:\Apps\matlab\r2011a\toolbox\matlab\randfun\rand)
>> which exprnd
C:\Apps\matlab\r2011a\toolbox\stats\stats\exprnd.m
Perhaps you could record the state information of the random number generator at the appropriate point in the code, and when you detect that condition happening, dump out the state so that the behavior could be replicated more easily?

Sign in to comment.

Matt, without some concrete way to reproduce this, I don't know what to say.
It sounds like what you're saying is that you create an array of random values, and then somehow overwrite the smallest values with something not randomly generated, iteratively, so that eventually you are left with an array whose smallest randomly generated value left is 6487.2 because all the smaller randomly generated values have already been overwritten.
Something like Walter's suggestion might be a way to solve this. Perhaps you could save the random number generator state at the beginning of your simulation ("s = rng"), and then find a repeated value. Then reset to the original state ("rng(s)") and start generating arrays of exp(8714) values until you find that same value occurring twice in the stream. Keep track of the places it occurred.
By the way, if you're changing the 8714 during this simulation to something else, then all bets are off.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!