Upload
simon-crawford
View
217
Download
1
Tags:
Embed Size (px)
Citation preview
Cornelia Parker Colder Dark Matter
Introduction to
Carlos Mana Benasque-2014Astrofísica y Física de PartículasCIEMAT
numerical method
What is the Monte Carlo method ?
What kind of problems can we tackle ?
Magic Box?, …, more information?...
incapability?
What do we get ?
Why Monte Carlo ?
…or simulate on a computer
Outcome problemDesign theexperiment
Theory of Probability and Statistics
stochastic processsolutionproblem
Monte Carlo
How does it work ?
Do it
Particle physics, Bayesian inference,…
Example: Estimation of (… a la Laplace)
Probability that a draw falls inside the circumference 4)(
)(
S
C
C
S
X {Point falls inside the circumference}
trialsNevent
4
),|(~ NxBiX
)2/1,2/1|(~ nNnBe
N
n4~
… for large N:
N
6.1)~(
100 83 3.32 0.15031000 770 3.08 0.0532
10000 7789 3.1156 0.0166100000 78408 3.1363 0.0052
1000000 785241 3.141 0.0016
Throws (N) Accepted (n) N
n4~
21
~)~4(~
N
The dependence of the uncertainty with is a general feature of the Monte Carlo estimations regardless the number of dimensions of the problem
N1
Important and General Feature of Monte Carlo estimations:
Need sequences of
random numbers
Basis of Monte Carlo simulations
Get a sequence
of random numbers
nzzz ,..., 21
Get a sampling of size n from a stochastic
process
generate sequences of (pseudo-)random numbers
on a computer…
…or simulate on a computer
Do it
1,0|~ xUnX D
Do not do the experiment but….
Design theexperiment
(∞ Refs.)
“Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin”
J. von Neumann
n
j
kjk x
nm
1
1
5002.01 m
0833.02 sam 0025.01 sam
0003.0
2029.12 sam
5000.0
1210833.02
0.01
562.12
1,0xUn
kj
kn
jjk xx
knc
1
1
00076.0),( 1 ii xx
00096.0),( 2 ii xx
00010.0),( 3 ii xx
Sampling moments:
Sample size: 106 events
TricksNormal DistributionM(RT)2 (Markov Chains)Gibbs Sampling,….
Great! But life is not uniform…
Usually a combination of them
Inverse Transform
Acceptance-Rejection (“Hit-Miss”)
“Importance Sampling”,…
How?
We can generate pseudo-random sequences
kzzz ,..., 21 )1,0(~ zUnZwith
In Physics, Statistics,… we wantto generate sequences from
)|(~},...,,{ 21 θxX pxxx n
+
Method 1: Inverse Transform
We want to generate a sample of )(~ xpX
yxdFyFXPyXFPyYPyFyF
Y
)|(
1
1
)|()|()|()(
1,0:)( XXFY How is distributed?
)1,0(xUn ~)|( XFY
Y
)1,0(~ yUnyi
)(1 YFX )(1 ii yFx n)
)(~,..., 21 xpxxx n
i) Sample )1,0(~ yUnY
ii) Transform
Algorithm
yyFY )(
)|()|()|()|],(( xFxdFdxxpxXPxx
Examples: Sampling of
xexp )( xexF 1)(
)1,0(~) uUnui i
i
ii
uuFxii
ln)() 1
)(~ xExX
Sampling of )()( ),0[
121
212 xexxp x
1θ
)1,0(~) uUnui i
2
1
1
1 ln1
)|()
iii uuFxii θ
),(~ 21 xWeX
)1(xEx
…some fun…
)(1)( ),0[
21 xexF x
1θ
)7.1,2.0(xWe
4) If and
Problem:
)1,0(~ xUnX
1) Generate a sample : nxxx ,..., 21610n
)(2
3)(~ ]1,1[
2 xxxpX I21
11)1,0(~
xxCaX
2) Get for each case the sampling distribution of
m
kkm X
mY
1
1
}50,20,10,5,2{m
3) Discuss the sampling distribution of in connection with the Law of Large Numbers and the Central Limit Theorem
mY
]1,0[1
n
kkn UW)1,0(~ xUnX How is distributed?nn WZ log
5) If ),0(~ kxGaX k How is distributed?mn
nn XX
XZ
6) If ),|(~ ii xGaX i
iXY
(assumed to be independent random quantities)
How is distributed?
)1,0(~ xUnX )(2
3)(~ ]1,1[
2 xxxpX I
21
11)1,0(~
xxCaX
m
kkm X
mY
1
1
}50,20,10,5,2,1{m
For discrete random quantities 00 )0( pXPF
101 )1( ppXPF
n
kkn pnXPF
1
)(
...,2,1,0k
0p 1p2p
0F 1F 2F0 1
kpkXpX )(~
)1,0(~ uUnui
kxi n)
)(~,..., 21 xpxxx n
i) Sample )1,0(~ xUnU
ii) Find
Algorithm
kik FuFk 1
)0( 1 F
… …
Example: Sampling of )|(~ XPoX
)1(!
)(
kXPkk
ekXP
k
)1,0(~) uUnui i
1)) kk pk
paii
kkk pFFb 1)
kik FuF 1
0kfrom until
k
50,000 events
)2(kPo
ep0
Sampling of nNn
n
NNXBiX
1),|(~
),|1(1
1),|(
NnXP
n
nNNnXP
)1,0(~) uUnui i
11
1))
nn p
n
nNpaii
nnn pFFb 1)
Np 10
nin FuF 1
0nfrom until
50,000 events
)5.0,10(nBi
n
)2(kPo
50,000 events
)5.0,10(nBiSampling of nNn
n
NNXBiX
1),|(~
),|1(1
1),|(
NnXP
n
nNNnXP
)1,0(~) uUnui i
11
1))
nn p
n
nNpaii
nnn pFFb 1)
Np 10
nin FuF 1
0nfrom until
n
)|(~ XPoX
)1(!
)(
kXPkk
ekXP
k
)1,0(~) uUnui i
1)) kk pk
paii
kkk pFFb 1)
kik FuF 1
0kfrom until
k
ep0
Sampling of 50,000 events
Examples:
Even though Discrete Distributions can be sampled this way,usually one can find more efficient algorithms…
)1,0|(~ uUnui
]1,0[1
n
kkn UW
1)log()(
1)|(~
nnnn w
nnwpW
a
nxn dxxe
naW
log
1
)(
1)(P
ea
)1()1(
)(1
0
nXm
eeWn
m
m
n PoP
i) generate
ii) multiply them
iii) deliver
nn uuw 1ewnand go to i) while
)|(~1 xPonx
)|(~ XPoX
)1,0|(~ uUnU i
Example:
1
01 )1()1(
)(
)(
n
m
mn
k
kn
me
kn
n
n
e
PROBLEMS:
1) Show that if then ),1|(~ byGaaXY ),|(~ baxGaX
2) Show that if ),1|(~1
nyGaZYn
ii
( generate exponentials)
1) Show that if then ),|(~ 2121
1 bbyBeXX
XY
),|(~
),|(~
222
111
baxGaX
baxGaX
Gamma Distribution:
Beta Distribution:
Nnb
)1|()1,1|(~ zExzGaZ i
Generalization to n dimensions… trivial but …
)()(),...,(),...,(),...,,( 1112212111121 xFxxFxxxFxxxFxxxF nnnnnnn
)()(),...,(),...,(),...,,( 1112212111121 xpxxpxxxpxxxpxxxp nnnnnnn
… but if not ...
and
there are ways to decompose the pdf and some are easier to sample than others!n
n
iiin xFxxxF
121 )(),...,,(
n
iiin xpxxxp
121 )(),...,,(
if are independentkX
Example: 1,0;,0;exp2),(~),(
yxy
xyxpYX
ydxyxpypy 2),()(0
x
u
x duu
exdyyxpxp 2
1
0
2),()(
)()(),( ypxpyxp yx not independent Conditional Densities:
Marginal Densities:
y
yx
ypyxp
yxpy
exp
)(),(
)(
y
xyxFx exp1)(
easy
difficult 2)( yyFy
)()|(),( ypyxpyxp y )()|(),( xpxypyxp x
Properties:
Direct and efficient in the sense that
Useful for many distributions of interest
)1,0(~ uUnui )(~ xpxione one
(Exponential, Cauchy, Weibull, Logistic,…)
)( xF…but in general, difficult to invert numeric approximations are slow,…
Method 2: Acceptance-Rejection “Hit-Miss”J. Von Neuman, 1951
k
dzdzdzdzzzg 21
2121 )|,(
),( 21 ZZZ2) Consider a two-dimensional random quantity
uniformly distributed in the domain k,0, ; that is:
)|(max xp
)|( xp
a b
k
0
))|(,( xpyx k,0,
,, ba kxp ,0)|(max,0
1) Enclose the pairs in a domain
such that: and
],[ baX X Sample )(~ xpX )|(max)|(0 xpxp x
3) Which is the conditional distribution
? ))|(( 21 xpZxZP
(not necessarily hypercube)
)|(max xp
)|( xp
a b
k
0
accepted
rejected
)(xF
11],[1
11],[1
)|(
0
2211
)|(
0
2211
)()|(
)()|(
)|,(
)|,(
1
1
dzzzp
dzzzp
dzzzgdz
dzzzgdz
ba
x
ba
zp
zpx
))|((
))|(,(
22
21
xpZP
xpZxZP))|(( 21 xpZxZP
)(~ xpXn)
i) Sample
ii) Get
Algorithm
1Z ),(~ 11 zUnz i
2Z ),0(~ 22 kzUnz iand
if )( 12 ii zpz accept ii zx 1
and go back to i) if )( 12 ii zpz reject ii zx 1
)(~,..., 21 xpxxx n
Example:
1,0;1),|( 11 xxxbaxp ba
),(~ baxBeX
density:
(pedagogical; low efficiency)
Covering adjusted for maximum efficiency:
2
11
max )2(
)1()1(),|2
1(),(max
ba
ba
ba
bababa
axpbaxp
),( yx
),(max,01,0,0, baxpk
generated in the domain
(normalisation: ),(,1
0
baBedxbaxp …not needed )
i) Sample )1,0(~ xUnxi
ii) Accept-Reject n)
)),(,0(~ baxpmaxyUnyi
if ),( baxpy ii
),( baxpy ii if accept ix
reject ix and go to i)
7.5;3.2 ba
3864.0gen
accff n
ne
),(max)( baxp
016791.0)()(
gen
acc
n
ndxxp
X
Algorithm
1000000accn2588191genn
)000013.0(
01678944.0)7.5,3.2( Be
)7.5,3.2|(xBe
),(max,01,0 baxp
… weighted events ???
We can do the rejection as follows:
i) Assign a weight to each generated pair
)1,0(~ uUnui
ii) Acceptance-rejection
ii wu accept if
10 iw
reject if ii wu
Obviously, events with a larger weight are more likely to be accepted
After step ii), all weights are: 01
if rejected
if accepted
kxp ,0)|(max,0
),( ii yx
ix
ix
k
xpw i
i
)(
Sometimes, it is interesting not to apply step ii) and keep the weights
n
ii
n
iiip
wwwxgw
xgdxxpxgx
11
;1
)()(
iw
)|(max xpk (if we know )|(max xp
)
And suddenly…
)(max xpk
Many times we do not know and start with an initial guess )(max xp 1k
After having generated events in the domain tN
we find a value
1,0, k
1)|(| kxp m mx
incorrect estimation of
)|( xp
a b
1k
0
mx
Don't throw away all generated events…
The pairs ),( yx have been generated in
with constant density so with 21 )()( k
NN
k
N ett
1
1
2
kk
NN te
we have to generate:
additional pairs ),( yx
… in the domain 21,, kk with the pseudo-distribution
12 )|( kxpk m
1,0, k
)(11 xkxpxg kxp 1
22 ,0, k … and proceed with
Properties:
Easy to implement and generalize to n dimensions
Efficiency
)( xparea under
1fe
1fe is equivalent to the Inverse Transform
The better adjusted the covering is, the higher the efficiency
area covering domain # generated events # accepted events
gen
accf N
Nedxxp
X
)()()(
k,0, depends on the covering domain
)|(max xp
)|( xp
a b
k
0
accepted
rejected
Straight forward generalization to n dimensions
i) Generate n+1 distributed random quantities
ii) Accept or reject k)
)|,...,,( ))2)1 niiii xxxpy
if accept
reject if not and go back to i)back to i)
Algorithm:
...)()(~);,...,,( 2)2
1)1))2)1 xUnxUnyxxx i
niii
),0()(... ) kyUnxUn nn
),...,,( ))2)1 niii xxx
)( xUn
Cover the torus by a
parallelepiped: Points inside a torus of radius ),( oi rr 0,0,0centred at
iioioioioi rrrrrrrrrr ,)(),()(),(
Algorithm: i) Generate ))(),((~ oioii rrrrxUnx
ii) Reject if n)
)0,0,0,,(),,(),...,,,(),,,( 222111 ionnn rrTzyxzyxzyx
222 )( oiii rryx
otherwise accept
And go back
to i)
(pedagogical; low efficiency) 3D Example:
))(),((~ oioii rrrryUny ),(~ iii rryUnz
222 )( oiii rryx or or 222
1220
2 ))(( iiii ryxrz
),,( iii zyx
ir 0,0,0
or
000,5acceptedN786,10generatedN
4636.0generated
accepted
N
N128ipedparallelepV
61,034,59 ipedoparallelepftoroid VeV
218,59toroidV
3;1 oi rr
knowing that: we can
estimate:
20
20
2
8
2
ii
if
rrr
rr
ipedparallelepvolume
toroidvolumee
),( yx ),( zx ),( zy
(3,1
,0)
(3,2
,±
1)
Problem 3D:
,,,, rmln
,,, mlln YrR
mlnrP ,,,,
sin, 22
,2
, rYrR mlln
Sampling of Hidrogen atom wave functions
Evaluate the energy using Virial Theorem
(3,2
,0)
VT 21
nnVE 2
1
r
erV
1
4)(
0
2
02
)2/(/2)()( 2/
nn
n
n
nf
nnHVSV
e
n-dimensional sphere of radius centred at
Example in n-dimensions:
Problems with low efficiency
1r )0,...,0,0(
ii) Acceptance-rejection:
i) Sample
if accept as inner point of the sphere
or over the surface
if reject the n-tuple and go back to
i)
1,11,1~,, ))1))1 nnii xUnxUnxx
2)2)22)12 niii xxxy
y
x
y
x nii))1
,,
))1 ,, nii xx 12 y
12 y
(problem for convergence of estimations,…)
%31)4( ne f
%16)5( ne f
Why do we have low efficiency?
Most of the samplings are done in regions of the sample space that have low probability
Example:
Generate values of xuniformly in 1,0x
]1,0[;~)(~ xexpX x
Sampling of
… do a more clever sampling…
usually used in combination with “Importance Sampling”
ee
xFx
11
)(xe
exp
1
)(
Example of inefficiencies: Usual problem in Particle Physics…
231111 2)|,,,()|,,()|,,( qnjjnjjnn dmpppqdqppdpppd
)|,(||)2(
12
4
pppdiMF
d nnfi
ii) Acceptance-rejection on
i) Sample phase-space variables
2|| fiiM
)|,( 1 pppd nn
]|[| 2fiiMEiii) Estimate cross-section
“Naïve” and simple generation of n-body phase-space
sample of events with dynamics of the process
21121211 1
)|,()|,,()|,,( qnnnn dmppqdqppdpppd
21222232121 2)|,()|,,()|,,( qnnnn dmqpqdqppdqppd 1p
p
12 1)( mMmmm pqn
4p
np
2p
2q
1q
23 12)( mmmmm qqn
n
kiik mS
)( 223 12SmuSm qq
)1,0(~1 Unu
)1,0(~2 Unu
11
6212
||
)2(4
1)|,( d
m
ppppd
p
and then weight each event…
2
0
2/1 ),,(1
n
k q
qknqT
k
kk
m
mmmW
+ Lorentz boosts to overall centre of mass system
])(][)([),,( 2222 zyxzyxzyx
1q
3p
np
2p
3p
kqqnk mmmmmkk
1)( 1
)(11 kqkkq SmuSm
kk
)( 112 01SmuSm qq
nqpq mmMmn
10;In rest-frame: p
)1,0(~Unuk
2,,1 nk for the intermediate states
…but , cuts,…!2|| fiiM
usually inefficient (“very”)
Method 3: Importance Sampling
SampleXxxpX ;0)|(~
)( 2xh probability density
Xxxhxgxp ;0)|()|()|( 21
Xxxhxg ;0)(;0)( 21 i)
ii)
)|()|()|()|()|( 2121 xdHxgdxxhxgdxxp
1) Express
0)|( 2 xh)|(
)|()|(
21
xh
xpxg In particular, take a convenient (easiness) and define
2) Consider a sampling of
and apply the acceptance-rejection algorithm to
)|(~ 2xhX
How are the accepted values distributed?
0)( 1 xg
xdxp
xdxp
xdxgxh
xdxgxhxx
)(
)(
)()(
)()(
12
12
)|(
2
)|(
2
1
1
1
1
)|(1
)|(1
)|(
)|(,
xg
x xg
dyxdxh
dyxdxh
xgYP
xgYxXP
YX
)()()( YX
i) Sample )(~ 2xhxi
ii) Apply Acceptance-Rejection to
Algorithm
)( 1xg
)()()( 21 xhxgxp sample drawn from nxxx ,..., 21
…∞ manners to choose )( 2xh
)|(| 1xgYxXP
)|( xF
Take as “close” as possible to
Easiest choice: )()(
1)|( 2 xxh 1
… but this is just the acceptance – rejection procedure
Easy to invert so we can apply the Inverse Transform Method
We would like to choose such that, instead of sampling uniformly the whole domain , we sample with higher probability from those regions where is “more important”
X
will be ”as flat as possible” (“flatter” than ) and we shall have a higher efficiency when applying the acceptance-rejection algorithm
)|(
)|()|(
21
xh
xpxg
)|( xp
)|( 2xh
)|( xp
)|( 2xh
)|( xp
Example:
)(1),|( ]1,0[11 xxxbaxp ba 1
),(~ baxBeX
density:
7.5;3.2 ba
1111
11
11
1),|(
nmnm
ba
xxxx
xxbaxp
3.0;2][ 11 maam
]1][1[ 1121 nm xxxx
1) We did “standard” acceptance-rejection
2) “Importance Sampling” 7.0;5][ 22 nbbn
),|(]1[~),|( 21 nmxdBexxbaxdP
21
21
)()}({max
21
21
xgx
21 1)( xxxg
1,0x
]1][1[),|( 1121 nm xxxxbaxp
2.1) Generate ),(~ nmxBeX)1,0(~ xUnU k
),1(~)log(1
mxGaUYm
kkm
),(~ nmxBe
YY
YZ
nm
m
2.2) Acceptance-Rejection on
)(xg concave on
)5,2(xBe
)1,0(xUn )5,2(xBe
)7.5,3.2(xBe
)1,0(xUn
1,0 21
)( xXP )|( xp
)7.5,3.2(xBe
acceptance-rejection Importance Sampling
3864.0eff
max)7.5,3.2( feffBe
016791.0000013.0
9279.0eff
0167912.00000045.0
1077712genn
1000000accn
2588191genn
1000000accn
01678944.0)7.5,3.2( Be
)5,2()7.5,3.2( max BefeffBe
)|()|(1
xpaxpm
iii
Each density
1;0 i
ii aa
m
ii
m
iii adxxpadxxp
11
1)|()|(
has a relative weight
)|( xpi ia
Sample )|(~ xpX i
with
probability ii ap … thus, more often from those with larger
weight
Idea:
Normalisation:
Method 4: Decomposition
0)|( xpi
xx
mi ,1
Decompose the pdf as a sum of simpler densities
(… trick)
i) Generate to select with probability )1,0(~ uUnui
)(~ xpX i
n)
ii) Sample
Algorithm
)|( xpi ia
Note:
Sometimes the pdf can not be easily integrated
)|( xpi
… normalisation unknown generate from
Evaluate the normalisation integrals during the generation process (numeric
integration) and assign eventually a weight to each event
m
iiii
m
i i
iii xpIa
I
xfIaxp
11
)|(
xpxf ii
iI
iii Iaw
Example: 1)(1 xg
]1,1[;18
3)(~ 2 xxxpX
21)(1 xpnormalisatio
n
)(4
1)(
4
3)( 21 xpxpxp
i)
Generate )1,0(~ uUnui
43iu 1
43 iu
ii) Sample
from: 2
2 )( xxp
15% of the times 75% of the times
Algorithm:2
2 )( xxg 23)(
2
2xxp
21)( xxp
constxp )(1
constxp )(1
22 )( xxp
Generalisation:
Extend )(1
xgm
ii
dyyg )(to a continuous
family and consider
as a marginal density: )|( xp
yy
dyypyxpdyyxpxp )|(),()|,()|(
Algorithm:i) Sample )|(~ ypyi
ii) Sample n)
),(~ ii yxpx
Structure in bayesian analysis
)()|()|( xpxp
Experimental resolution
)|(),|(),|,( xpxyRyxp t
Y
dxxpxyRyp tobs )|(),|(),|(
Standardisation
X
Z
but...
22
2
1)1,0(~
zezNZ
ZX
ii) Central Limit Theorem:
i) Inverse Transform: is not an elementary function
entire function series expansion convergent but inversion slow,…
iii) Acceptance - Rejection: not efficient although…
iv) Importance Sampling: easy to find good approximations
12
1
6i
iUZ)1,0(~ uUnU i
Sometimes, going to higher dimensions helps: in two dimensions…
)(zF
The Normal Distribution 2
2
2)(
2
1),(~
x
exNX
1)(;0][;]6,6[ ZVZEZ )1,0(~ zNZapprox
i) Consider two independent random quantities
)1,0(~, 21 xNXX 22212
1
21 21
),(xx
exxp
),(),( 21 RXX
sin2 RX
ii) Polar Transformation:
)()(2
1),( 2
2
prprerpr
iii) Marginal Distributions:
…trivial inversion
2
2
0
2
1),()(r
r edrprF
2
),()(0
drrpF
Inverse Transform in two dimensions
),( R
cos1 RX
)2,0[),0[
independent
(G.E.P.Box, M.E. Muller; 1958)
n
)
i) Generate
ii) Invert and to get
Algorithm
)1,0(~, 21 uUnuu
22 u 1ln2 ur
)(rFr)(F
)1,0(~, 21 xNxx
111 2cos)ln(2 uux 112 2sen)ln(2 uux
iii) Obtain as
(independent)
Sampling from Conditional Densities
),,,,,(~),( 21212121 xxNXXStandardisatio
n
i
iii
XW
)(),|()|,( 11221 wpwwpwwp
)1,0|())1(,|( 1212
12 wNwwN
)1,0|(~1
22
122 zN
WWZ
)1,0|(~)( 111 zNWZ
)1( 2
212
11
2
1
2
1
zz
z
x
x
)1,0(~, 21 zNzzi) Generate
ii)
Example: 2-dimensional Normal random quantity
n-dimensional Normal Density … different ways
nnV
TCCV
Factorisation Theorem:(Cholesky)
symmetric and positive definedif
C unique, lower triangular and with positive diagonal elements
such that
niV
VC i
i 1;11
11
nijC
CCVC
jj
j
kjkikij
ij
1;
1
1
niCVCi
kikiii
1;21
1
1
21
take ),(~ VμxX N
such that
if
C),(~ I0yY N
CYμX and
since it is triangular inferior matrix
ijCij ;0
111 CCVT )()( 111 μxCμxCμxVμx TT
Algorithm:
0) Determine matrix C Vfrom
i) Generate n independent random quantities
each as
nzzz ,...,, 21
)1,0(~ zNzi
ii) Get
n
jjijii zx
1
C),(~ Vμxx N
)(1 μxCz
zCμx n)
2221
2121
V 111
1111
V
VC
211
2121
C
VC
012 C
22 1
21
2212222 CVC
222
1
1
0
C
zCμx )1,0(~, 21 zNzz
Example: 2-dimensional Normal random quantity
Example: Interaction of photons with matter
(Compton scattering)
Rayleigh (Thomson)
Pairs e+e-
Photoelectric
Photonucle
ar Absorptio
n
Compton
Interaction of Interaction of photons with photons with
mattermatter
Photon beam
Carbon
Iron
Photographic film
Radiography
pairsComptont t
ComptonComptonp
t
pairspairsp
)1,0(~ uUnu
pairsCompton ppF 2
ComptonpF 1
pairsComptoni ppF
1) What kind of process?
1nF
1Fu
21 FuF
Compton
pairs
= cross-section = “probability of interaction” with atom expressed in cm2
In a thin slab of surface S and thickness
SA
NS A
Volume cm3
Density g cm-3
Total surface S
A
N
S
SPp Aeff
I )(
S
Probability to interact with an atom in a thin slab
We have atoms
AN
A
)()()( IINoIOne PxPxP
has slabs of thickness
x 1 xm
dxepeppxP xmpp
mIOne
1/)1()(
,0;)|( 1 xexp
x
][xE
“mean free path”
2) Where do we have the first/next interaction?
= cross-section = “probability of interaction” with atom expressed in cm2
“Interaction surface” covered by atoms cm2
A
NSS A
eff
Get the “mean free path”
pairsComptont
x
int exF1)|(
)1,0(~ uUnu cmux ln
… Inverse Transform
Generate distance until the next interaction
cmN
A
At
)1()2(
1int )|(
x
exp
220 )21(
31)21ln(
21
)21ln(1
21)1(21
4)(
aa
aa
aaa
aa
aE Thomson
freeatomic ee
)()( 0 EZEt
cmNEZ
A
A)]([ 0
freeeatomatom
In this example, we shall simulate only the Compton process so I took the “Mean Free Path” for Compton Interaction only
1
1
dxdxd
)1()2(
em
Ea
3) Compton Interaction easy:
)cos1(11
aE
Ein
out
’
e
inE
outE
e
in
m
Ea ,0
0 1 inout EEmaxE
a21
1
a
EEminE
inout
21
Perturbative expansion in Relativistic Quantum Mechanics
)(8
3xf
dxd Thomson
22410665.0665.0 cmbarnThomson
)1(1)1(
1)1(1
1)(
222
2 xaxa
xxa
xf
1,1cos x 2,0(integrated)
2 variables (8-2-4) ,
)()(1)()2(
1)(21
12
xfxfxfx
xg
nn xaxf
)1(1
1)(
)()()()()( 321 xgxfxfxfxf
easy to invert… Inverse Transform
“fairly flat”… Acceptance-rejection
0)( xfn
0)( xg
)1(1)1(
1)1(1
1)(
222
2 xaxa
xxa
xf
3.1) Generate polar angle for the outgoing photon ()
straight-forward acceptance-rejection very inefficient...
complicated to apply inverse transform…
Use: Decomposition + inverse transform + acceptance-rejection
1,1cos x
)()()()()( 331 xgxfxfxfxf
)(1
)( xfw
xp ii
i
1
1
)( dxxfw ii
1
1
1)( dxxpi2233 )1(
2
ba
bw
)1(2222
ba
w
ba
w ln1
1
ab 21
)()()()( 332211 xgxpwxpwxpw
)()()()( 332211 xgxpxpxpwT 321 wwwwT
T
ii w
w
1321
)()()( xfxgxhwT
Probability Densities
… we have everything...
)()()()()( 331 xgxfxfxfxf nn xa
xf)1(1
1)(
1) Sample
b
xaxF
ln)1(1ln
1)(1
axbb
xF21
)(21
)(2
2
1
)()1(
)1(41
)( 2
2
3 xbb
aaxF
)1,0(~ uUnu
aba
xu
g
1
auba
bxg 21)1( 2
21)1(41
1
uaa
bbxg
Inverse transform
x
ii dsspxF1
)()(
acceptance-rejection ),0(~ MguUnu
)(xgmaxgM
)( gxgu
211)1(
bbb
xg
)( gxgu
accept
reject
gx
gx
)1,0(~ uUnu
1u
211 u
u 21
)(~ 1 xpxg
)(~ 3 xpxg
)(~ 2 xpxg
Decomposition
)()()()(~ 332211 xgxpxpxpwX Tg
’
e
0,0, inE
gggout xE ),(acos,
gwith respect to the direction of incidence of the photon !! …
rotation
)1(1 g
inout
xa
EE
2-body kinematics
a
EE inoute
11
ae 1
2cottan
)2,0(~ Ung
)(~ xfxg
… for the electron:
cosx
in
out
E
E
N
e e
100,000 generated photons
MeV1inE
)26.2,12,6(: 3 cmgrAZ C
)87.7,85.55,26(: 3 cmgrAZ Fe
trajectory of one
photon
END OF FIRST PARTEND OF FIRST PART
To come: Markov Chain Monte Carlo (Metropolis, Hastings, Gibbs,…)Examples: Path Integrals in Quantum Mechanics
Bayesian Inference
),|(~ pnkBiX
)(1 kXPk
knk ppk
npnkXP
)1(),|(
nk ,,2,1,0
121 ,,, n π
1;01
1
n
iii
11
45.0
10
binsn
p
n
nk ,,1,0
Method 5: Markov Chain Monte Carlo
10,,1,0 k
Probability vector
),|( pnkXP
knkXP ;111
11)(
121 ,,, nddd
Nd
Nd
Nd n
n121)0(
1)0(
2)0(
1)0( ,,,,,, π
)111,,1( nkUnD
Ndn
ii
1
1
First step done: We have already the N=100,000 events
kkXP )(
Second step: redistribute all N generated events moving each event from its present bin to a different one (or the same) to get eventually a sampling from
number of bins = 11
Sampling probability vector
HOW?
Step 0) Generate N=100,000
But we want this:
),|( pnjXP In one step: an event in bin i goes to bin j with probability
… But this is equivalent to sample from ),|( pnkBi
Sequentially: At every step of the evolution, we move all events from the bin where they are to a new bin (may be the same) with a migration probability
populations step
probability vector
)1(1
)1(2
)1(1
)1( ,,,
in
iii π
)( 1)(2
)(1
)( ,,, in
iii π
)1(1
)1(2
)1(1 ,,,
i
nii ddd
)(i
)1( i
)0( 1)0(2
)0(1 ,,, nddd )0( )0( 1)0(
2)0(
1)0( ,,, n π
)( 1)(
2)(
1 ,,, in
ii ddd
)|()()( ijajiPij P
)1( 1)1(2
)1(1 ,,, nddd )1( )1( 1)1(
2)1(
1)1( ,,, n π
to go from to desired
kkkk PπPπPππ )0(2)2()1()(
Pππ )0()1( 2)0()1()2( PπPππ
)0(π
nnnn
n
n
ppp
ppp
ppp
21
22221
11211
P
Transition Matrix among states
Goal: Find a Transition Matrix that allows
N ,,, 21 π)0(π
nnR P
Transition Matrix is a Probability Matrix
n
j
n
jij jiPp
11
1)( the probability to go from state i to whatever some other state is 1
Markov Chain with transition matrix P
)1( iπ )(iπ )( ijπdepends upon and not on
Transitions among states of the system
)|()()( ijajiPij P
irreducible : all the states of the system communicate among themselves
recurrent : being at one state, we shall return to it with
and ergodic: that is, the states of the system are
Remainder: If the Markov Chain is…
1p
positive: we shall go to it in a finite number of steps
aperiodic: the system is not trapped cycles
i) There is a unique stationary distribution with (unique fix vector)
πPπ
ii) Starting at any arbitrary state , the sequence
tends asymptotically to the fix vector iii)
)0(π
,,,, )0()1()()0()1()0( nnn PπPππPπππ
N
N
N
nlim
21
21
21
P
πPπ π
A sufficient condition (not necessary) for to be a fix vector of is that P
ways to choose the Probability Transition Matrix π
the Detailed Balance relation is satisfiedjijiji )()( PP
πPPPPπ
N
iiNi
N
iii
N
iii
112
11 ,,,
N
ikkik
N
iiki
11
PP
Nk ,,2,1
Why? πPπ It assures that
jijiji )()( PP If
After specifying according to the
Accept the migration with probability
populations step )( 1)(
2)(
1)( ,,, i
niii
π)(i )( 1)(2
)(1 ,,, i
nii ddd
For each event at bin choose a candidate bin 11,...,1ito go (j) among the 11 possible ones as
ii) ji Accept the migration with probability ijaii ija1
For
all
the
11
bins
probability vector(state of the system)
)11,1|(kUndisc
)1(1
)1(2
)1(1
)1( ,,,
in
iii π )1(1
)1(2
)1(1 ,,,
i
nii ddd )1( i
Procedure to follow
i)
ijij ajiP )()(PDetailed Balance
condition
ππ )(i
ilim
)|()|( jiaija ji i
j
i
jji ija
,1min)|( 1,1min)|(
j
ijia
1,1min)|(
i
jji ija
j
i
j
ijia
,1min)|(
jijiji )()( PP
How do we take so that
jijjijijiiji aa )()( PP
),,,(lim 1010)( pppi
i ππ)|( ijaaij
Detailed Balance condition
For instance, at step t …
7i
2j
)11,1(~ jUnJ D
For an event in bin
)1,0(~ uUnu 026.0u
026.0026.0)6(
)1(,1min)27(
7
272
XP
XPaa
Move event to bin 2
Choose a bin j to go as
026.0u Leave event in bin 7
6j .147.1)6(
)5(,1min)67(
7
676
XP
XPaa
Move event to bin 6
45.0
10
p
n
67
27
After 20 steps…
)45.0,10|(~ pnkBiX
5.4][ NXE
475.2)1(][ NXV
k k
kkKL p
ppppD ~log]~|[
Convergence?
Watch for trends, correlations, “good mixing”,…
Still Freedom to choose the Transition Matrix
Basis for Markov Chain Monte Carlo simulation
Detailed Balance Condition P
Trivial election: jij )(P ijji
Select a new state migrating events from one bin to another with probability kkXP )(
ijij aijq )()(P
Simple probability to choose a new possible bin j for an event that is
at bin i
probability to accept the proposed new bin j for an event at bin i taken in such a way that the Detailed Balance Condition is satisfied
jijiji )()( PP
Metropolis-Hastings algorithm
)(
)(,1
ijq
jiqmina
i
jij
1)(
)(,1
jiq
ijqmina
ji
iji
)(
)(
)(
)(,1
ijq
jiq
ijq
jiqmina
i
j
i
jij
)(
)()()(
ijq
jiqijqaijq
i
jiiji
jijj ajiqjiq )()( jij )(P
iji )(P
)()( jqijq
but better as close as possible to desired distribution for high acceptance probability
1)( iji ajiq
Can take: )()( jiqijq (not symmetric), even
If symmetric: )()( jiqijq
Metropolis algorithm
i
jij mina
,1)()( jiqijq
(symmetric)
For absolute continuous distributions
Probability density function )|( θx
)()|()( xxxxxx aqp
)|()|(
)|()|(,1min)(
xxθx
xxθxxx
q
qa
Xxx ,
)|(~ θxX
)1()( 3 sss
)2,4(~ xBeX
)()()( ssassqssp
sssq 2)( )1,0()( sUnssq
)1()1(
,1)( 3
3
ssss
minssa
)1()1(
,1)( 2
2
ssss
minssa… and after 20 steps..
Example:
step=1
Metropolis-Hastings
Metropolis
)1,0(~ xUnX
step=0
step=1
2) Generate a proposed new value from the distribution
),|(),|( )1()1( xxxx tt qq(symmetric)
),|(),|( )1()1( xxxx tt qq
)|(
)|(,1min),(
)1()1(
θx
θxxx
tta
),|(
),|(
)|(
)|(,1min),(
)1(
)1(
)1()1(
t
t
tt
q
qa
xx
xx
θx
θxxx
3) Accept the new value with probability
x
x
4) If accepted, set xx )(t )1()( tt xx Otherwise, set
1) At step , choose an admissible arbitrary state
)0(x 0)|(; )0()0( θxx x
1tt
0t
In practice, we do not proceed as in the previous examples, (meant for illustration)
Once equilibrium reached…
1) Need some initial steps to reach “equilibrium” (stable running conditions)
2) For samplings, take draws every few steps to reduce correlations (if important)
Metropolis Metropolis-Hastings
different steps different samplings from “same” distribution
(not symmetric)
“Easy” and powerful Virtually any density regardless the number of dimensions and analytic complexity
Sampling “correct” asymptotically
Need previous sweeps (“burn-out”, “thermalization”) to reach asymptotic limit
Changes of configurations depend on
Normalization is not relevant
Properties:
Correlations among different states
… nevertheless, in many circumstances is the only practical
solution...
)()(
)()(
ssqs
ssqsr
If an issue, additional sweeps
Method 5: Markov Chain Monte Carlo with Gibbs Sampling
1) Some (“many”) times, we do not have the explicit expression of the pdf but know the conditional densities
2) Usually, conditionals densities have simpler expressions
3) Bayesian Structure: )()|(),|()|,( ppxpxp
And Last…
…Sampling from Conditional densities
(and in particular hierarchical models)
)|(~ xStX
2
12
1)|(
xNxp;
bbau abduue
)(0
1
EXAMPLE: Sampling from Conditionals
Sampling of
1) Introduce a new random quantity (extra dimension) with),|(~ bauGaU
aub eub
Nuxp
1
)()|,(
baduuxpxp
0
)|,()|(
ub eudxuxpup
2/3)|,()|(
1),(0
duuxpdx2
11
2
b
xa
0) Consider that
),0|()|(
)|,(),|( 12 uxN
up
uxpuxp
Marginals: Conditionals:
),|()|(
)|,(),|( bauGa
xp
uxpxup
)2/,2/3,2/)1(,2/1()2/(
)2/)1((
2
1)|( 2xxFxF
)|(~ xSt
),|(~ bauGa
1) Start at t=0 with
5
0][ XE
667.1][ 2 XE
)5|(~ xStX
Rx 0
2) At step t Sample ),|(~| bauGaXU
),0|(~| 12 uxNUX
21
11 txa
Sampling:
2
1
b
~21 W duuxsuwxswpnn
)2/1(22
22
)2/1(21
2121
21)()(~),|( xx
Trivial marginals for the Behrens-Fisher problem (lect. 2)
)1|(~ iii ntStt 2/1)1( iiiii nstx
)|()|(),|,( 22112121 xxxx ppp However:
n)
Algorithm
1) 2,1i
2) 21 w
)1|(~1
ii
i
iiii ntSt
s
xnT
2,1i
so, instead of sampling from ),|( 21 xxwp
Yet another EXAMPLE…
2) Sample the n-dimensional random quantity from the conditional distributions
121
312
321
,,,|
,,,|
,,,|
nn
n
n
xxxxp
xxxxp
xxxxp
nn xxxpXXX ,,,~,,, 2121 X
Basic Idea:
X
marginal densities
We want a sampling of
},,,,...,{ 111 niii xxxxs
ini dxxxxpsp ),,,()( 21
)(
),,,()|( 21
i
nii sp
xxxpsxp
conditional densities
Consider:
nxxxxq ,,,, 321
2) The conditional densities
3) An arbitrary initial state Xnxxx ))0(,),0(),0(( 21
1) The probability density function
(usually less than n are needed)
)()|()( xxxxxx aqp
First, sampling from conditional densities:
121
312
321
,,,|
,,,|
,,,|
nn
n
n
xxxxq
xxxxq
xxxxq
4) Sampling of the random quantities at
1tstep
nkX k ,,1;
Z ))1(,),1(),1(( 21 txtxtx n
tstep )(txk kX
)1(,),1(),(,),(),(| 1121 txtxtxtxtxxq nkkk
Generate a possible new value of from the conditional density
t 1t
Propose a change of the system from
)1(,),1(),1(),(,),(),( 1121 txtxtxtxtxtxs nkkk
)1(,),1(),(),(,),(),( 1121 txtxtxtxtxtxs nkkk the state
the state
to
tstep
At the end of step
Desired density nxxxp ,,, 21
Acceptance factor
)1(,),1(),1(),(,),(),(
)1(,),1(),(),(,),(),(
1121
1121
txtxtxtxtxtxp
txtxtxtxtxtxp
nkkk
nkkk
Metropolis-Hastings:
),1min()( ssa
nxxx ,,, 21 nxxxp ,,, 21
the sequences
regardless the starting sampling
so we shall accept the change with probability
)1(,),1(),(,),(),(|)(
)1(,),1(),(,),(),(|)1(
1121
1121
txtxtxtxtxtxq
txtxtxtxtxtxq
nkkk
nkkk
will converge towards the stationary p.d.f
Xn txtxtx ))(,),(),(( 21 t
Xnxxx ))0(,),0(),0(( 21
In particular,… Gibbs algorithm…
)1(,),1(),(,),(),(|
)1(,),1(),(,),(),(|
1121
1121
txtxtxtxtxxp
txtxtxtxtxxq
nkkk
nkkk
)1(,),1(),(,),(),(
)1(,),1(),1(),(,),(),(
)1(,),1(),(,),(),(|)1(
)1(,),1(),(,),(),(|)1(
1121
1121
1121
1121
txtxtxtxtxp
txtxtxtxtxtxp
txtxtxtxtxtxp
txtxtxtxtxtxq
nkk
nkkk
nkkk
nkkk
)1(,),1(),(,),(),(
)1(,),1(),(),(,),(),(
)1(,),1(),(,),(),(|)(
)1(,),1(),(,),(),(|)(
1121
1121
1121
1121
txtxtxtxtxp
txtxtxtxtxtxp
txtxtxtxtxtxp
txtxtxtxtxtxq
nkk
nkkk
nkkk
nkkk
11)( ssa
Take as conditional densities to generate a proposed value the desired conditional densities
So we accept the “proposed” change with probability
Gibbs Algorithm:
acceptance factor:
))2
)1
)1)12
)11 ,,,,,,,, m
nmm
n xxxxxx
After enough steps to erase the effect of the initial values in the samplings and to achieve a good approximation to the asymptotic limit, we shall have sequences
),,,(~ 21 nxxxp
152.0,101.0,262.0,273.0,211.0)0( x
1)0( k
kx
112
11
1
0 21
)(
)()|(
n
nn
kk
xxxp
αx
5,4,3,2,1α
)|(~},...,{ 1 αxX DiXX n
n
kkx
1
1
0k
]1,0[kx
k
k 0
5n
11 )1(),|( nkkkkkk xSxsxp α
},,,...,,{ 11121 nkkk xxxxxs
n
kjj
jk xS1
),|(~1 nk
k
kk zBe
S
xz
Example: Conjugated prior for Multinomial:
),1(~ kk GaZ
n
kk
jj
Z
ZX
1
)|(~},...,{~ 1 αxX DiXX n
112
11
21)()|( nnxxxDp ααx
n
kkx
1
1
0k
]1,0[kx
1
1
11
1
1 )1()()|(n
kk
n
ii
ni xxDp ααx
1
1
1n
kkn xx
n
kk
D
1
0
)(
)()(
α
)|(~},...,{ 1 αxX DiXX n
Example: Dirichlet and Generalised Dirichlet
Conjugated priors for Multinomial:
Degenerated Distribution:
0
][ i
iXE )1(
],[0
20
0
jiijiji XXV
n
kk
10
),(~ kkk BeZ
),|(~},...,{~ 1 βαxX GDiXX n
1
1
1n
kkx
0k
10 ix
i
i
i
kk
n
ii
ii
ii xxp
1
1
1
1 1)()(
)()|( αx
1
1
1n
kkn xx
0k i2,...,2,1;11 niiii
1;11 nin
1
1
1k
jjkk XZX
1,...,1 nk
1
1
1n
jjn XX
iii
ii SXE
][
][1
][][ iiii
ijiii XETXEXV
1
1
1)(i
kkkkiS
1
1
1)1)(1(i
kkkkiT
),|(~},...,{~ 1 βαxX GDiXX n
11 ~ ZX)1(~| 1212 XZXX
)1(~,| 213213 XXZXXX
Quantum Mechanics
paths
txSi
iiff txDtxtxK e )(),,()(
Path Integral formulation of Q.M. (R.P. Feynman)
f
i
t
t
dttxxLtxS ;,
Probability Amplitude
Local Lagrangians (additive actions)
dxtxtxKtxtxKtxtxK iiffiiff ,,,,,, Chapman-
Kolmogorov
n
infn
ttEi
iiff xxtxtxK e ifn )()(),,()(
Feynman-Kac Expansion Theorem
ifiiiffffff ttdxtxtxtxKtx ;,,,,Propagator
),( ii tx
),( ff tx
)(tx
)(
)()()(
)(
txD
txDtxAA
ee
txSi
txSi
Expected Value of an operator xA
)()(21
;, 2 txVtxmtxxL
ittei 2
it Wick Rotation
f
i
dttxVtxmitxS
)]([)(2
1 2
One Dimensional Paticle
n
infn
E
iiff xxxxK e ifn )()(),,()( Feynman-Kac
expansion theorem
0 if xx0i
nnn
E
f e fnK )0()0()0,0,0(
)0()0( 11
1 e fE
),,,(exp),,( 1011
11
NN
x
N
x
Niiff xxxSdxdxAtxtxKN
N
jj
jjNN xV
xxmxxxS
1
2
110 )(
21
,,,
Discretised time
1
1
)]([N
jjN dxAtxD
intt 0
finn tt
1t2t
1nt2nt
1it
it
1x2x
ix
1ix2nx
1nx
nttn 0
),,,(exp
),,,(exp),,,(
10
1
1
1010
1
1
NN
N
jj
NNN
N
jj
xxxSdx
xxxSxxxAdx
A
),,,(exp
),,,(exp),,,(
10
1
1
1010
1
1
NN
N
jj
NNN
N
jj
xxxSdx
xxxSxxxAdx
A
),,,(exp),,,( 1010 NNN xxxSxxxp
),,,,( )(1
1
)(10 N
kN
N
k
k xxxxAAtray
(importance sampling)
Goal: generat
e trayN as
and estimate
Very complicated
…
Markov Chain Monte Carlo
2)(21
)( txktxV
N
jj
jjNN xk
xxmxxxS
1
2
2
110 2
,,,
Harmonic Potential
0)(0 intxx
0)( finN txx
1,,1; NjRx j
10,10jx
25.02000N
1000termN3000trayN 1000utilN
0 finin xx0int
finn tt
1t2t
1nt2nt
1it
it
1x2x
ix
1ix2nx
1nx
Parameters
)( continuot)( NN fin
To isolate fundamental state
Termalisation and correlations
1) Generate initial trajectory
3) Repeat 2)
),,,,( )0(1
)0(10 NN xxxx
2) Sweep over 11 ,, Nxx
N-1
vece
s )10,10(~ xUnx j
),,,,,(exp)( 10 NjNjj xxxxSxxP
),,,,,(exp)( 10 NjNjj xxxxSxxP
)(
)(,1)(
jj
jjjj xxP
xxPminxxa
),(),(exp,1 1111 jjjNjjjN xxxSxxxSmin
1000termN times
3000trayN4) Repeat 2) times and take one trajectory out of
3
trajectories 1000utilN 0,,,,0 110 NN xxxx
Generación de trayectorias
Virial Theorem )(
21
xVxT
2
21
xkVT
2)(21
)( txktxV
2xkVTE
222
14
)(
a
xatxV
443 2
242
axx
aE
1
2
222
a
x
a
xaT
Harmonic Potential
X4 Potential
486.00
2
0 xE
5.00
exactE
1k
Harmonic Potential
5a
1)(
4)(
22
atxa
txV
25.09000N
668.044
3 2
0
2
0
420
axx
aE
697.00
exactE
X4 Potential