Download // THE CONTINUOUS UNIFORM RANDOM VARIABLE ON [0, 1] Let

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

History of statistics wikipedia , lookup

Statistics wikipedia , lookup

Probability wikipedia , lookup

Randomness wikipedia , lookup

Transcript
// THE CONTINUOUS UNIFORM RANDOM VARIABLE ON [0, 1]
Let E be some event in the sample space S . The sample space must include all
possible events. Our sample space for the uniform random variable is all real numbers
from 0 to 1 inclusive; clearly, this is an infinite set of numbers. E can be any event as
†
† say that it cannot occur and
long as it is contained
in S . If E is not contained in S , we
has probability zero. We can ask simple questions about the event E , such as how
† if the set
likely is it? Think for example, how likely is it to see the number 0.5 ? Well,
† as
†any other number, our
† chances of seeing 0.5
is infinite and every number is as likely
† any
is very close to zero. Actually, in the limiting sense, the probability of seeing
†
specific number in an infinite sample space is exactly zero.
†
The probability of event E must be greater than or equal to zero and less than or equal
to one: 0 £ P( E ) £ 1. A probability of 0 means that the event does not happen, and
probability of 1 means that the event is sure to happen.
†
†
For example if the†event E is an event such that we select a number between 0 and
† the probability that event E occurs must be some number
0.5 inclusive, we say that
between 0 and 1 inclusive. We are going to do our study of random numbers
† collect a large number of random numbers and
empirically. That is, we are going to
† what the probability is.
†
then decide
†
†
†
Many mathematicians will ‘roll their eyes’ and here is a partial list why:
1. Using a numerical simulator to answer a mathematically trivial question.
2. Using a discrete variable (computers) to mimic a continuous variable.
3. Making assumptions about randomness.
But if we are to accept the fact that our ‘random’ numbers are equally distributed along
the interval from zero to one inclusive, any occurrence of a particular number should
be as likely as any other number in the interval. So, let’s use our model to see how
often event E occurs ( E is an event such that we select a number between 0 and 0.5
inclusive out of our interval [0, 1] ) in a million trials.
We are going to reuse†the code †
for the function U (*) and will call this function one†
† how often it returns 0 £ U (*) £ 0.5 . There’s a theory in statistics
million times to see
that says we can expect the probability (frequency) of any given event of a particular
†
random variable will approach the true probability (frequency)
by increasing the
† times would give one of the
sample size. For example, a coin flipped only four
following relative frequencies (probabilities) for heads: 0 4 , 1 4 , 2 4 , 3 4 , or 4 4 . However,
† † † †
†
†
PAGE 21
DETERMINISTIC UNCERTAINTIES
if we flip the coin a very large number of times the frequency (probability) of obtaining
a head will approach the actual true value of the underlying random variable. The fair
coin’s random variable ( x = 0 fi heads , and x = 1 fi tails ) looks like this:
Ï0.5 if
x=0
Ô
f ( x) = Ì0.5† if
x =1
Ô0
otherwise
Ó
†
A particular experimental sequence might look like this:
†
number of heads 1 1 2 2 3 4 4
4989
: ,
,
,
,
,
,
, K,
, K.
number of tosses 1 2 3 4 5 6 7
10, 000
Again, let’s trust our source of random numbers on [0, 1] . The question is how often
† the function U (*) return 0 £ U (*) £ 0.5 ?
does the call to
#include <iostream> // needed for cout
#include <cstdlib>
// needed for rand() and RAND_MAX
using namespace std;
†
†
†
const int SAMPLES = 1000000;
const double LOWER_LIMIT = 0.0;
const double UPPER_LIMIT = 0.5;
double uniform(void);
// function U(*) prototype
double uniform(void)
{
return(static_cast<double>(rand()) / RAND_MAX);
} // uniform function
int main ()
{
int i; // counter variable for main loop
int E = 0; // counts success
for (i = 1 ; i <= SAMPLES ; i++)
if ((uniform() <= UPPER_LIMIT) && (uniform() >= LOWER_LIMIT)) E++;
cout << "In " << SAMPLES << " samples, " <<
static_cast<double>(E)/SAMPLES*100
<< "% were contained in "<< "the interval [" << LOWER_LIMIT <<
", " << UPPER_LIMIT << "].\n";
} // main function
Here is the output:
In 1000000 samples, 50.0218% were contained in the interval [0, 0.5].
Thus, empirically it seems that the probability of getting a random number in the
interval [0, 1] to be between 0 and 0.5 is about 50%. This could be used to model our
†
PAGE 22
DETERMINISTIC UNCERTAINTIES
coin problem:
Ïheads if U (*) £ 0.5
Ì
otherwise
Ó tails
†
Let’s return to the actual mathematics of this problem. Recall the mathematical
definition of the uniform random variable. This is continuous function on an interval
[a1 , a2 ] and is uniform (constant) on the interval. The function here is:
Ï 1
Ô
f ( x) =†Ì a2 - a1
ÔÓ 0
if
a1 £ x £ a2
otherwise
If xl Π[a1 , a2 ] < xu Π[a1 , a2 ] then
†
x
†
†
Ûu 1
x -x
P{ xl < X < xu } = Ù
dx = u l .
ıxl a2 - a1
a2 - a1
In our example; a1 = 0 , a2 = 1 , xl = 0 , and xu = 0.5 . Substituting these values in the
0.5
Û 1
above equations gives: P{0 < X < 0.5} = Ù
dx = 0.5 . The numerical result of our
ı0 1
simulation, 0.500218 , is very
value,
† close to
† this theoretical
†
† of 0.5 .
†
Actually, any random number generator
first needs to be validated for these two
† and uniformity). You might†think this is too much detail here
properties (independence
— maybe it is — so I will stop here and assume that we have a good source of random
numbers available. A free research paper written by Louise Foley, Trinity College
Dublin, on this topic is available for download at the following URL:
http://www.random.org/report.
From here on out, we are going to assume that our available source of random numbers
is equally distributed on [0, 1] , and that each request for a random number has
nothing to do with our prior request. A tall order for sure, which would indeed assure
independence and uniformity.
†