Lect 15
Lect 15
They are:
Random number generator
Sampling rule
Error estimation
1
2024/12/26
To be fast.
2
2024/12/26
3
2024/12/26
4
2024/12/26
iseed=iy+70(im+12{id+31[ih+23(in+59is)]})
as the initial seed, which is roughly in the region of [1,231-1].
The results should never be the same as long as the jobs
are started at least a second apart but within 100 years.
5
2024/12/26
6
2024/12/26
7
2024/12/26
( )/
∝ ,
where is the Boltzmann constant and is the zero point energy.
One way to generate the exponential distribution is to relate to a
uniform distribution random number.
8
2024/12/26
( ) = = ( ) =
which gives
( ) − (0) = 1 −
We can set (0) = 0 and invert the above equation to have
= −ln(1 − )
which relates the exponential distribution of to the uniform
distribution of [0,1].
9
2024/12/26
function eranf()
common /cseed/ iseed
eranf =-alog(1.0-ranf())
return
end
10
2024/12/26
Subroutine grnf(x,y)
common /cseed/ iseed
pi=4.0*atan(1.0)
r1=-alog(1-ranf())
r2=2.0*pi*ranf()
r1=sqrt(2.0*r1)
x=r1*cos(r2)
y=r1*sin(r2)
return
end
11
2024/12/26
= ( )
is rewritten:
( )
= ( )
( )
12
2024/12/26
13
2024/12/26
Sampling
Monte Carlo works by using random numbers to sample the
“solution space” of the problem to be solved. In our
examples of the calculation of p, simulation of radioactive
decay and Monte Carlo integration we employed a “simple”
sampling technique in which all points were accepted with
equal probability.
Sampling (contd)
In view of this, rather than sampling the entire region
randomly, it would be computationally advantageous
to sample those regions which make the largest
contribution to the solution while avoiding low
contributing regions. This type of sampling is referred
to as “importance sampling.”
14
2024/12/26
Sampling (contd)
and using importance sampling
1 ( )
=
( )
In the later case, each point is chosen in accordance with
the anticipated importance of the value to the function
and the contribution it makes weighted by the inverse of
the probability ( ) of choice. Unlike the simple sampling
scheme, the estimate is no longer a simple average of all
points sampled but it is a weighted average.
It should be noted that this type of sampling introduces a
bias which must be eliminated. Importance sampling will
be discussed in greater detail later
Importance Sampling
Put more quadrature points in regions where
integral receives its greatest contributions
The 1-dimensional example
( )=3 2
= 3
( )=2
Most contribution from region near
= 1
Choose quadrature points not uniformly, but
according to distribution ( )
linear form is one possibility
15
2024/12/26
The Importance-Sampled
Integral
Consider a rectangle-rule quadrature with
unevenly spaced abscissas
1 1
≈ Δ ;Δ =
( )
Spacing between points
reciprocal of local number of points per unit
length Δ Δ Δ … Δ
Greater more points smaller spacing choose points
1 ( ) according to
≈
( )
( )
Importance-sampled rectangle rule
The Importance-Sampled
Integral
Choose quadrature points not uniformly, but
according to distribution ( )
Transform from uniform random number into
( ) distributed random number
( ) = = ( ) =2
= = 2 =
⇒ =
16
2024/12/26
The Importance-Sampled
Integral
The Importance-Sampled
Integral
Consider the integral =∫ 3
− ( )
≈ =
( )
( )
( ) =1= 2 = |
1
⇒ =
−
2
( )=
−
17
2024/12/26
The Importance-Sampled
Integral
Transform from uniform random number into
( ) distributed random number
2
( ) = = ( ) =
−
2 −
= = =
− −
⇒ = ( − ) +
The Importance-Sampled
Integral
Using different pdf, the result??
=
18
2024/12/26
Probability Distribution
Functions
As illustrated above, Monte Carlo methods work by
sampling according to a probability distribution function
(PDF).
In the previous examples, using simple sampling, we
have in effect been sampling from a “uniform distribution
function” in which every selection is made with equal
probability.
In statistics, the most important PDF is probably the
Gaussian or Normal Distribution:
( )
( )=
2
where is the mean of the distribution and σ2 is the
variance.
Probability Distribution
Functions (contd)
This function has the well-known “bell-shape” and gives
a good representation of such things as the distribution
of the intelligence quotient (IQ) in the community
centered on a “normal” value of IQ = 100.
19