Hit-and-Miss (or Rejection) Monte Carlo Method:
description
Transcript of Hit-and-Miss (or Rejection) Monte Carlo Method:
MM
M
M
MA
M largefor lim
4
bar
M
ii
tot
M
ii
OOOMM
MA
OOMM
1
1
1
(hit)
)1 (if otherwise (miss) 0
1 if (hit) 1
2
2
iii
iii
xyO
xyO
Hit-and-Miss (or Rejection) Monte Carlo Method:a “brute-force” method based on completely random
sampling
Then, how do we throw the stones and count them on computer?
:as observablean Define
times.Mfor ),( randomat Choose
O
yx ii
1. Generation of M 2D microstates
2. Measurement (Averaging an observable over M microstates)
x
y
A
O 1
1
(xi,yi)
1,0 ,1)( 2 xxxfy
Obtain an approximate value of A (= /4 M/M) by (1) throwing M stones in the square of the total area 1; (2) counting M stones in a quarter of the circle of the radius 1.
Lab 1. Calculation of the value of /4Simple, Brute-Force, Hit-and-Miss Monte Carlo
Method
Question 1 (Formulation of the problem = Restatement of the last page).
On computer, this problem can be formulated as obtaining the average (or expectation value) of an observable O over M instantaneous Oi values at each microstate (xi, yi) (i = 1 to M).
(1)What values can Oi take?
(2) How does the value of Oi depend on (xi, yi)?
bar
M
ii OOO
MM
M
M
MA
1
1
(throw)
(hit)
Obtain an approximate value of A (= /4 M/M) by (1) throwing M stones in the square of the total area 1; (2) counting M stones in a quarter of the circle of the radius 1.
Lab 1. Calculation of the value of /4Simple, Brute-Force, Hit-and-Miss Monte Carlo
Method
Question 1 (Formulation of the problem = Restatement of the last page).
On computer, this problem can be formulated as obtaining the average (or expectation value) of an observable O over M instantaneous Oi values at each microstate (xi, yi) (i = 1 to M).
(1)What values can Oi take?
Answer: 0 or 1
(2) How does the value of Oi depend on (xi, yi)?
Answer:
bar
M
ii OOO
MM
M
M
MA
1
1
(throw)
(hit)
21 if (hit) 1 iii xyO
)1 (if otherwise (miss) 0 2iii xyO
Lab 1. Calculation of the value of /4 (or )Question 2 (Algorithm & Flow chart).
Draw a flow chart to estimate A (or = 4A) by averaging over M instantaneous Oi values.
barestimated
bartot
M
ii
O
OOM
OO
MA
4
1
1
21 if ,1 iii xyO
otherwise ,0iO
Lab 1. Calculation of the value of /4
?1 2xy
Otot = Otot + O
O = 0.0
O = 1.0
yes
no
x=ran3(&seed)y=ran3(&seed)
i = 1
i = i + 1
?Mi no
Otot = 0.0
Obar = Otot/M; = 4xObar
yes
Question 2 (Algorithm & Flow chart).
Draw a flow chart to estimate A (or = 4A) by averaging over M instantaneous Oi values. 21 if ,1 iii xyO
otherwise ,0iO
Answer.
barestimated
bartot
M
ii
O
OOM
OO
MA
4
1
1
Question 3. Write a program to estimate A by averaging over M instantaneous O values. Try M = 10,000.
Lab 1. Calculation of the value of /4 (or )
trueOO
Flow chart for Question 4: Calculate .
21 if ,1 iii xyO
otherwise ,0iO
?1 2xy
Otot = Otot + O
O = 0.0
no
x=ran3(&seed); y=ran3(&seed)
i = 1
i = i + 1
?Mi no
Otot = 0; input seed
Obar = Otot/M; = 4Obar; true = acos(-1); = fabs(true )
yes
O = 1.0
yes
(accuracy)
error
1)]acos(
4
1
1
esttrue
esttrue
true
barestimated
bartot
M
ii
O
OOM
OO
MA
Question 3. Write a program to estimate A by averaging over M instantaneous O values. Try M = 10,000.
Lab 1. Calculation of the value of /4 (or )
trueOO
Lab 1. Calculation of the value of /4 (or )
Question 6. But, what if we don’t know the true value of what we estimate? Since we can’t estimate the error w.r.t. the true value, how could we estimate the accuracy (error) of the simulation?
Lab 1. Calculation of the value of /4 (or )
(accuracy) or i.e., , deviation standard
)( variance
1limlim and
1
,,,,,, observablean of valuesousinstantane M ofset aFor
2222
11
21
OOOO
OOOO
OOM
OOOM
O
OOOOO
truetrue
true
M
iiMM
M
ii
Mi
Variance, Standard Deviation, Error, and Accuracy
Lab 1. Calculation of the value of /4 (or )
(accuracy) or i.e., , deviation standard
)( variance
1limlim and
1
,,,,,, observablean of valuesousinstantane M ofset aFor
2222
11
21
OOOO
OOOO
OOM
OOOM
O
OOOOO
truetrue
true
M
iiMM
M
ii
Mi
Variance, Standard Deviation, Error, and Accuracy
Flow chart for Question 7: Calculate .
21 if ,1 iii xyO
otherwise ,0iO
?1 2xy
Otot = Otot + O; O2tot = O2
tot + O2
O = 0.0
O = 1.0yes
no
x=ran3(&seed); y=ran3(&seed)
i = 1
i = i + 1
?Mi no
Otot = 0; O2tot =0; input seed
Obar = Otot/M; O2bar = O2
tot/M; = sqrt(O2bar
Obar2)
yes
4)( ,4
(accuracy)
deviation standard
11
)( variance
1
average
estimated
2
11
2
2222
1
O
OO
OO
OM
OM
OOOO
OM
O
true
true
M
ii
M
ii
M
ii
pi = 4 x Obar; _pi = 4 x
Lab 1. Calculation of the value of /4 (or )
Answer: We expected that would be similar to ( ), but it’s not the case (
> ). (~constant with M) is much larger than (which decreases as M
increases)!Thus, itself is not a good indicator of the accuracy of a simulation.Question 8. Then, what else would be an indicator of the accuracy (error) of the
estimation,when we don’t know the true value of what we estimate?
Lab 1. Calculation of the value of /4 (or )
?1 2xy
Otot = Otot + O; O2tot = O2
tot + O2
O = 0.0
O = 1.0yes
no
x=ran3(&seed); y=ran3(&seed)
i = 1
i = i + 1
?Mi no
Otot = 0; O2tot =0
Obar = Otot/M; O2bar = O2
tot/M; = sqrt(O2bar
Obar2)
yes
pi = 4 x Obar; _pi = 4 x
one_estimate
Flow chart for Question 9:
Calculate over n estimates.
Flow chart for Question 9:
Calculate over n estimates.
Obartot = Obartot + Obar
Obarsqtot = Obarsqtot + Obar2
tot = tot +
one_estimate
j = 1
j = j + 1
?nj no
Obartot = 0; Obarsqtot =0; tot = 0; input seed
Obarbar = Obartot/n
Obarsqbar = Obarsqtot/n
bar= sqrt(Obarsqbar Obarbar
2)
bar = tot/n
yes
pi = 4xObarbar; barpi= 4xbar; barpi = 4xbar
4)( ,4)( ,4
1error of average
deviation standard
11
of variance
1
of average
, , , , , , i.e.
of estimatesn ofset aFor
estimated
1
2
1
2
1
222
1
21
O
n
On
On
OOO
On
OO
OOOO
O
n
jj
bar
n
jj
n
jj
n
jj
nj
Lab 1. Calculation of the value of
Lab 1. Calculation of the value of /4 (or )Question 10.But, what if we move onto a very complex problem? Each estimation (simulation) with M trials becomes so time-consuming that we couldn’t afford to running the simulation many times. What should we do in this case?
Answer: Let’s try to find a way to estimate the accuracy from one M-trial simulation.
Lab 1. Calculation of the value of /4 (or )
Lab 1. Calculation of the value of /4 (or )
deviation) standard trials,ofnumber ( MM
where,OOtrue
M largefor M