Monte Carlo and cold gases Lode Pollet - Max Planck Societybec10/Pollet_QuoVadis_1.pdf · 2010. 8....

36
Monte Carlo and cold gases Lode Pollet [email protected] 1 Monday, August 2, 2010

Transcript of Monte Carlo and cold gases Lode Pollet - Max Planck Societybec10/Pollet_QuoVadis_1.pdf · 2010. 8....

  • Monte Carlo and cold gases

    Lode [email protected]

    1Monday, August 2, 2010

    mailto:[email protected]:[email protected]

  • Outline

    •The Monte Carlo trick•Markov chains•Metropolis algorithm•Ising model•critical slowing down

    Classical Monte Carlo

    Quantum Monte Carlo

    Applications

    •diffusion Monte Carlo•worm algorithm•sign problem

    2Monday, August 2, 2010

  • What I will not do

    •high performing computing•parallelization•programming language (C++)•other numerical methods

    Required knowledge

    •statistical mechanics•quantum mechanics•some knowledge about many-body physics

    3Monday, August 2, 2010

  • Integration

    f(x)

    I =

    � b

    af(x)dx = h

    N�

    i=1

    f(a+ ih) +O(1/N)

    h =b− aN

    a b

    discrete sum:

    higher order integrators

    I = h

    �1

    2f(a) +

    N−1�

    i=1

    f(a+ ih) +1

    2f(b)

    I =h

    3

    �f(a) +

    N−1�

    i=1

    (3− (−1)i)f(a+ ih) + f(b)�

    trapezoidal

    Simpson(N even)

    +O(1/N4)

    +O(1/N2)

    4Monday, August 2, 2010

  • Integration

    Simpson rule with M points per dimension

    The error in one dimension is

    In d dimensions we need N = Md pointsthe error is

    O(M−4)

    O(M−4) = O(N−4/d)

    Integration becomes inefficient in higher dimensions

    In statistical mechanics the integrals are 6N-dimensional(3N positions, 3N momenta)

    5Monday, August 2, 2010

  • I =

    ∫D

    g(x)dx

    identical and independent random samples uniformly drawn from D

    Îm =1

    m

    (

    g(x(1)) + · · · + g(x(m)))

    P

    [

    limm→∞

    |Îm − I| = 0]

    = 1

    law of the large numbers

    The Monte Carlo trick

    D

    g(x)

    6Monday, August 2, 2010

  • The Monte Carlo trick

    limm→∞

    Cdf√

    m(

    Îm − I)

    = CdfN(0, σ2)

    central limit theorem

    convergence is

    O(m−1/2)

    regardless of the dimensionality of D

    7Monday, August 2, 2010

  • random numbers

    Pseudo random numbers•not random at all, but generated by an algorithm•probably good enough•reproducible

    Linear congruential generatorsxn+1 = f(xn)

    xn+1 = (ax+ c) mod mGGLa = 16807, c = 0,m = 231 − 1problem is periodicitywith 500 million random numbers per second : 4sshould not be used any more

    8Monday, August 2, 2010

  • Lagged Fibonacci generatorxn = xn−p ⊗ xn−q mod m

    0 < p < q , ⊗ = +,−,×,XORInitialization using linear congruential generatorvery long period (large block of seeds)very fast complex mathematics

    see: http://beta.boost.org/doc/libs/1_42_0/libs/random/random-generators.html

    9Monday, August 2, 2010

    http://beta.boost.org/doc/libs/1_42_0/libs/random/random-generators.htmlhttp://beta.boost.org/doc/libs/1_42_0/libs/random/random-generators.html

  • Independent sampling

    Known geometryconverges to π/4

    10Monday, August 2, 2010

  • demonstration

    1e-05

    0.0001

    0.001

    0.01

    0.1

    1

    10

    1 10 100 1000 10000 100000 1e+06 1e+07 1e+08

    ! - <

    MC

    >

    Nsteps

    1./sqrt(x)

    Segmentation fault

    11Monday, August 2, 2010

  • Importance sampling

    draw random numbers that are exponentially distributed, then

    I =

    ∫∞

    0

    g(x)e−xdx

    Îm =1

    m

    (

    g(x(1)) + · · · + g(x(m)))

    how?

    u ∈ [0, 1[

    p = −lnu p ∈ [0,∞[

    inverse transformation is needed

    standard random number generator

    12Monday, August 2, 2010

  • Importance sampling

    �f� = 1V

    �f(x)dx =

    1

    V

    �f(x)

    p(x)p(x)dx ≈ 1

    N

    N�

    i=1

    f(xi)

    p(xi)

    ∆ =

    �Varf/p

    N

    •imagine function f is sharply peaked•then the variance can be reduced by finding p(x) such that p(x) is close to f(x) and that it is easy to generate random numbers according to p(x)

    13Monday, August 2, 2010

  • change of variables

    Box-Mueller (gaussian)

    exponential

    general

    p = − ln(u)

    p1 = R cos(θ) =�

    −2 ln(u1) cos(2πu2)

    p2 = R sin(θ) =�

    −2 ln(u1) sin(2πu2)

    y = F (y) =

    � y

    0f(u)du f(x) = x

    x = F−1(y)y = F (x) =

    � x

    0x�dx� =

    x2

    2

    x = 2√y

    14Monday, August 2, 2010

  • 〈Q〉 =1

    ZTr

    [

    Qe−βH]

    =Tr[Qe−βH ]

    Tr[e−βH ]

    W (x) = e−βE(x)unnormalized weights

    Statistical mechanics :

    how do we get random variables that are distributed according to W(x) ?

    15Monday, August 2, 2010

  • ?

    Small stepsrandom walk

    through configuration space

    at each time : measure

    Rejection : stay at same configuration, update clock and measure

    transition function

    Markov chains and rejections

    16Monday, August 2, 2010

  • • A Markov chain is a sequence of random variables X1, X2, X3, ... with the property that the future state depends only on the past via the present state.

    P [Xn+1 = x|Xn = xn, . . . , X1 = x1, X0 = x0] = P [Xn+1 = x|Xn = xn]

    transition functionT (x, y)

    y

    T (x, y) = 1conservation of probability

    Markov chains

    irreducible : it must be possible to reach any configuration x from any other configuration y in a finite number of steps.

    17Monday, August 2, 2010

  • Markov chain

    • irreducible• aperiodic

    convergence to the stationary distribution W

    transition kernel has one eigenvalue 1, while all other eigenvalues satisfy

    |λj | < 1, j = 2, . . . N

    The second largest eigenvalue determines the correlations in the

    Markov process

    }

    18Monday, August 2, 2010

  • Detailed balance

    A transition rule T(x,y) leaves the target distribution W(x) invariant if

    x

    W (x)T (x, y) ∼ W (y)

    This will certainly be the case if detailed balance is fulfilled,

    W (x)T (x, y) = W (y)T (y, x)

    19Monday, August 2, 2010

  • Metropolis algorithm

    we cannot construct a transition kernel T that fulfills

    detailed balance.

    proposal function P(x,y)

    acceptance factor

    q = min

    [

    1,W (y)P (y, x)

    W (x)P (x, y)

    ]

    go to the proposed configuration y with prob q, otherwise stay in x

    20Monday, August 2, 2010

  • thermalization

    energy landscapeInitial configuration

    Discard the first 20% of the Markov steps !

    Markov Chain should be sufficiently long

    |λ2|

    λ2τint

    21Monday, August 2, 2010

  • recapitulation

    W (X) = e−βE(X)

    W (Y ) = e−βE(Y )

    N particles interacting via Lennard-Jones interactions

    P (X → Y ) = 1N

    1δ2

    P (Y → X) = 1N

    1δ2

    qX→Y = min�1, e−β(E(Y )−E(X))

    δ

    22Monday, August 2, 2010

  • autocorrelations

    Markov chains trivially correlate measurements

    autocorrelations decay exponentially

    integrated autocorrelation time

    number of independent measurements is reduced, but central limit theorem still holds

    23Monday, August 2, 2010

  • Binning analysis

    • Markov chain correlates measurements• if chain is long enough, then the configuration is

    independent of the initial one

    21 m

    identically and independentτint(l) =

    lσ2(l)

    2σ2

    How to get correct error bars?

    http://arxiv.org/abs/cond-mat/9707221 appendix

    24Monday, August 2, 2010

    http://arxiv.org/abs/cond-mat/9707221http://arxiv.org/abs/cond-mat/9707221

  • Jackknife analysis

    R(0)

    R(j), j = 1, k

    Bias = (k-1)(Rav - R(0))

    δR =√

    k − 1

    1

    k

    k∑

    j

    (R(j))2 − (Rav)2

    1/2

    R = R(0) - Bias

    25Monday, August 2, 2010

  • 2d Ising model

    H = −J∑

    σiσj

    W (x)T (x, y) = W (y)T (y, x)

    q = min

    [

    1,W (y)P (y, x)

    W (x)P (x, y)

    ]

    Select random spin

    P (x, y) = P (y, x) =1

    L2

    W (y)

    W (x)= exp

    −2βJσi∑

    σj

    q = min

    [

    1, e−2βJσi

    σj

    ]

    26Monday, August 2, 2010

  • Critical slowing down

    Tc =ln(1 +

    2)

    2

    Magnetization 1e-06

    1e-05

    0.0001

    0.001

    0.01

    0.1

    0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    1/T

    error(M)

    divergence of correlation

    length, critical fluctuations

    ∆m = ±2

    27Monday, August 2, 2010

  • improved estimator

    domain size ~ susceptibility

    �m2� = 1L2

    i,j

    �σiσj� =1

    L�S(cluster)�

    There exist more formal ways and also other ways to solve

    the problem of critical slowing down

    28Monday, August 2, 2010

  • cluster algorithm

    select like spins with probability p

    p = 1 − exp[−2β]

    then update always accepted

    (exercise : show that this is true)

    (why is this not the same as flipping many spins at the same time?)

    29Monday, August 2, 2010

  • e−β(c1−c2)(1− p)c2qX→Y = e−β(c2−c1)(1− p)c1

    min�1,

    e−β(c2−c1)(1− p)c1e−β(c1−c2)(1− p)c2

    30Monday, August 2, 2010

  • 1e-06

    1e-05

    0.0001

    0.001

    0.01

    0.1

    0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    1/T

    local

    Wolff

    Error on magnetization

    0

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    1/T

    cluster size in Wolff

    phase transitions and critical phenomena

    31Monday, August 2, 2010

  • phase transitions and critical phenomena

    P.S. you need to know about finite size scaling

    critical exponents have to be calculated numerically

    32Monday, August 2, 2010

  • Wang-Landau sampling

    Cluster algorithms do not help near first order transitions

    33Monday, August 2, 2010

  • Wang-Landau sampling

    Z =�

    E

    ρ(E)e−E/kT

    Density of states is however unknown. probability minimum disappears however if we choose

    p(E) ∼ 1/ρ(E)

    - start with ρ(E) = 1 and f =1- repeat

    - stop when

    - reset histogram H(E) = 0

    - when histogram is flat, reduce f →�

    f

    - perform simulations by picking random site and Metropolis updates p(E) ∼ 1/ρ(E)H(E) → H(E) + 1

    ρ(E) → ρ(E) · f

    f ≈ 1 + 10−8

    34Monday, August 2, 2010

  • References

    • J. S. Liu, Monte Carlo strategies in scientific computing, Springer Verlag

    • W. Krauth, “Statistical Mechanics : algorithms and computations”, Oxford University Press

    • ETH Zurich professor scripts : http://www.ifb.ethz.ch/education/IntroductionComPhys ( and references therein)

    35Monday, August 2, 2010

    http://www.ifb.ethz.ch/education/IntroductionComPhyshttp://www.ifb.ethz.ch/education/IntroductionComPhyshttp://www.ifb.ethz.ch/education/IntroductionComPhyshttp://www.ifb.ethz.ch/education/IntroductionComPhys

  • Homework

    calculate (mean value, no error analysis) :

    by : 1. direct integration (analytical/Monte Carlo by exponentially distributed random numbers)2. Markov chain Monte Carlo : choose a step size d (wisely), and update the current position according to the

    Metropolis algorithm by choosing a random step of. Don’t forget that in every step you can move to larger or smaller x values. Show that you satisfy detailed balance.

    3. modification (advanced). Suppose the following. Suppose you start with moving to the right. If you accept the move, then always choose moving to the right in the next step. If you reject the move, then start moving to the left. So, you keep moving in one direction until you have a rejection (bounce), and then you change the direction and keep moving in this direction until there is another bounce after which you change the direction again. Does this Monte Carlo Markov chain produce the right answer ?

    I =� 6

    0exp(−x/2)dx

    36Monday, August 2, 2010