Problem 44435. Testing for randomness: uniform distribution of real numbers (distribution checking)
You will be presented with a variety of sequences of real numbers. Your job is to answer the question: "Is this a uniformly distributed sequence of random numbers?"
Only the distribution needs to be examined in this problem. (You do not need to check for autocorrelation.)
Input: x, a row vector of real numbers. Output: y, a Boolean scalar.
Some sequences have been generated by MATLAB's (pseudo)random number generator, such as:
x = 0.062 0.945 0.006 0.301 0.638 0.920 0.043 0.533 0.539 0.292 0.218 0.465 0.826 0.172 0.686 0.040 0.489 0.3950 0.761 0.038
On average these will have a uniform distribution. Thus, by splitting up the sequence into 'bins' we find for the example above there are twelve numbers falling into the 0.0-to-0.5 bin, and a further eight numbers falling into the 0.5-to-1.0 bin. For this length of sequence (a total of twenty numbers), that would be a sufficiently even division to retain the hypothesis that the underlying distribution from which the numbers were sampled was indeed a random, uniform distribution function (UDF). However, please note that it may be necessary to divide the data into more than just two bins.
Other sequences will have been constructed so as to weight unevenly. For example:
x = 7.004 1.002 1.984 3.868 2.048 1.014 1.066 1.337 1.074 60.266 1.008 1.783 2.196 1.065 1.0613 1.049 1.236 1.235 1.394 1.107
has fifteen numbers in the 1.0-to-2.0 bin, but then there are some weird 'outliers' in the remaining five numbers, which reach up to more than 60. It does not seem likely that this would have been generated from a UDF.
Note: the sequences in the examples above were for illustrative purposes; most sequences in the Test Suite are considerably longer.
See also:
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers2
Suggested Problems
-
Count from 0 to N^M in base N.
235 Solvers
-
108 Solvers
-
Project Euler: Problem 7, Nth prime
1409 Solvers
-
Matrix with different incremental runs
491 Solvers
-
Six Steps to PCA - Step 2: Covariance
13 Solvers
More from this Author32
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!