Computational Science For Engineers - Unit-IV - DataDrivenModels - Simulations, Random Numbers and Random Walk
Computational Science For Engineers - Unit-IV - DataDrivenModels - Simulations, Random Numbers and Random Walk
5 3 0 1 8 2 4 7 6 10
, , , , , , , , ,
11 11 11 11 11 11 11 11 11 11
0.454545, 0.272727, 0.0, 0.0909091, 0.727273, 0.181818, 0.363636, 0.636364, 0.545455,
0.909091
For this computation, the smallest possible pseudo random floating-point number
is 0.0 and the largest is (modulus – 1)/modulus = 10/11. Thus, floating-point
numbers that we generate by dividing by the modulus are in the interval [0.0, 1.0),
or the interval between the two values that includes 0.0 but not 1.0.
Much research has been done to discover choices for multiplier and modulus that
give the largest possible sequence that appears random.
For built-in random number generators, modulus is often the largest integer a
computer can store, such as 231 – 1 = 2,147,483,647 on some machines.
For this modulus, a multiplier of 16,807 and an increment of 0 produce a
sequence of 231 – 2 elements.
In general
min ≤ (max – min) rand + min < max
Frequently, we need a more-restricted range of random integers than from 0 up to modulus. For
example, a simulation might require random integer temperatures between 0 and 99, inclusive.
One method of restricting the range is to multiply a floating-point random number between 0.0 and
1.0 by 100 (the number of integers from 0 through 99, or 99 + 1) and then return the integer part
(the number before the decimal point).
For example, suppose rand is 0.692871.
Multiplying by 100, we obtain 100 · 0.692871 = 69.2871.
Truncating, we obtain an integer (69) between 0 and 99.
Sometimes we want the range of random integers to have a lower bound other than 0, for example,
from 100 to 500, inclusive. Because we include 100 and 500 as options, the number of integers
from 100 to 500 is one more than the difference in these values, (500 – 100 + 1) = 401.
As with the last example, we multiply this value by rand to expand the range. Then, we add the
lower bound, 100, to the product to translate the range to start at 100 as follows:
100 ≤ INT(401 rand + 100) < 501
or
100 ≤ INT(401 rand + 100) ≤ 500
In general
min ≤ INT( (max – min + 1)·rand + min) ≤ max
Simulations – Random Numbers from Various
Distributions
Monte Carlo simulation requires the use
of unbiased random numbers. The
distribution of these numbers is a
description of the portion of times each
possible outcome or each possible range
of outcomes occurs on the average over a
great many trials.
However, the distribution that a simulation
requires depends on the problem.
Now we will discuss the algorithms for
generating random numbers from several
types of distributions.
Suppose a specified range is partitioned into intervals of the same length. With
a uniform distribution, the generator is just as likely to return a value in any
of the intervals.
Equivalently, in a list of many such random numbers, on the average each
interval contains the same number of generated values.
For example, the figure presents a histogram with 10 intervals of length 0.1 of
a table of 10,000 random floating-point numbers, uniformly distributed from
0.0 up to 1.0.
As expected, approximately one-tenth of the 10,000, or 1000, numbers appears
in each subdivision.
Thus, the curve across the tops of the bars is virtually a horizontal line of
height 1000.
As we will see, methods for generating random numbers in other distributions
depend on our ability to produce random numbers with a uniform distribution.
Simulations – Discrete vs. Continuous Distributions
A distribution can be discrete or continuous. To illustrate the difference between the
terms discrete and continuous, a digital clock shows time in a discrete manner, from
one minute to the next, while a clock with two hands indicates time in a continuous,
unbroken way.
Similarly, as you pass the time-and-temperature sign in front of a bank, one moment
it might register 28°C, the next it might jump to 29°C. As a continuous counterpart,
a thermometer outside a house might have a column of liquid (mercury), smoothly
rising and falling to indicate the temperature.
In a simulation of pollution, we might generate a random integer to indicate the
number of dust particles in a cubic meter of air. The distribution of such values is
discrete.
In the same simulation, for the velocities of the particles, we might generate
random floating-point values that have a continuous distribution.
For a discrete distribution, a probability mass function returns the probability of
occurrence of a particular argument value. For example, P(1382) might be the
probability that the random number generator returns 1382, indicating 1382 dust
particles.
However, if a distribution is continuous, the probability of occurrence of any
particular value is zero. Thus, for a continuous distribution, a probability density
function indicates the probability that a given outcome falls inside a specific range
of values.
The integral of the probability function from the lower to the upper bound of the
range, which is the area under that portion of the curve, gives the probability that
the outcome is in that range.
For example, the probability that the random velocity in the x-direction of a dust
particle is between 3.0 and 4.0 mm/s is the integral of the probability density
function from 3.0 to 4.0.
Simulations - Normal Distributions
A normal, or Gaussian, distribution, which statistics frequently
employs, has a probability density function