0 views

Uploaded by Abir Sinno

j

- midtermTwo6711F10sols
- Introduction to Monte Carlo Simulation
- Hmm Tutorial 1
- [Krama] DCSch0 Dynamics of Complex Systems; Index # Yaneer Bar-yam
- Prediction of Contaminant Plumes (Shapes, Spatial Moments and Macrodispersion) (1)
- Fatigue Life Estimation Of Hybrid Aluminium Matrix Composites
- Grammar Based Music Composition
- Assessing Land Use and Land Cover of the Marikina Sub Watershed Philippines
- Stationary vectors of stochastic matrices subject to combinatoria.pdf
- Some Remarks on 'Superradiant' Phase Transitions
- Srivastav A
- Antamina Michael 09
- Hybrid 2 Theory Manual
- kadanoff2014a
- 10.1016-j.engfailanal.2014.06.024-Comparative Analysis of Failure Probability for Ethylene Cracking Furnace Tube Using Monte Carlo and API RBI Technology
- d392c1ea91ccc3731662faa05bb648126193
- 07 Fenton Simulation
- mc
- Order Picking
- Pres

You are on page 1of 4

Katzgraber

Introduction – The goal of these exercise sessions is to better understand the concepts taught in

class, such as Monte Carlo integration, simple versus importance sampling, Markov chains, as

well as simulations of the Ising model. You can download all material for the exercises from

" http://katzgraber.org/teaching/SUM/2011-taiwan

The material contains example programs which are the solutions to the problems listed below.

Please first attempt to write your own code. If you have problems, feel free to look at and use

the example code written in C. Pseudo-code for the different routines/exercises can be found at

" http://arxiv.org/pdf/0905.1629.pdf

You are not expected to complete all problems in the first exercise session. I do, however, expect you to

complete at least problems 1 – 4. The last three are more complex and should be completed in

the second exercise session.

Note: Compiling and running code in a Unix environment – All codes are written in C. They

can be edited with any simple Unix editor (vi, pico, nano, emacs, ...) and compiled with the

added Makefile (just type ‘make’ in the shell) or using gcc. If you need help with the Unix

environment, please inform the instructor immediately.

yourself with the use of a random number generator and routines to automatically seed the

generator. Please download ‘problem_1_using_rng’ from the exercise website. The directory

contains C source code for the r1279( ) random number generator, as well as routines

(seedgen.c) to seed the generator. (You will need this for problems 2 – 6 if you program in C).

Write a program that generates 10N (Nmax = 6 is enough) uniform random numbers in the

interval [0,1] and averages these. The seed should be automatically generated. The exact value

for the average should be 0.5. Study how the average changes when N is increased.

If you do not program in C or know/use a better generator, please feel free to use that for this

exercise, as well as the remaining problems.

Note: the program seedgen.c takes the process ID (PID), as well as the wall-clock-time and

produces a semi-random seed via a linear-congruential-like operation. Therefore, every time

you run the code, it should produce a different output.

1

the pond’s area can be computed.

Helmut G. Katzgraber

A slightly more “scientific” example is to comp

integration to the unit circle. The area of the unit

Problem 2: Estimating π using simple-sampling Monter Carlo – The

= 1; the topgoal

rightofquadrant

this problem

can is

betoenclosed by a s

illustrate how π = 3.1415... can be computed by random (see

sampling

Fig. of

3).theAnunit disk. Starting

estimate from

of π can be accomplished

the pseudo-code presented in class, write a program thatalgorithm

calculates [3]

π. that performs a simple sampling of the

In your simulation run the code multiple times for 1 algorithm simple_pi

N = 10i , i = 1, 2, 3, ... random numbers. See how the 2 initialize n_hits 0

estimate for π improves with increasing N and 3 initialize m_trials 10000

compute the deviation from the exact result: error = 4 initialize counter 0

|π - πestimate|. 5

7 x = rand(0,1)

Perform a log-log plot of the error as a function of N

8 y = rand(0,1)

and show that the data can be fit to a straight line of 9 if(x**2 + y**2 < 1)

slope -1/2. 10 n_hits++

11 fi

12 counter++

13 done

14

15 return pi = 4*n_hits/m_trials

Problem 3: Simple-sampling Monte Carlo estimate of the integral f(x) = xn – The goal of the !

exercise is to apply the concepts learned in problem 2 and apply these to a real function where

f (x) = xn → I=

the integral is exactly known, namely I[f(x)] = 1/(n + 1) in the interval [0,1]. For now, set n = 3,

you can change the value of the exponent n later. Start from the pseudo-code presented in class.

with n > −1. Using simple-sampling Monte Carlo,

As in problem 2, run the code multiple times for N =1 algorithm simple_integrate

10i , i = 1, 2, 3, ... random numbers. See how the2 initialize integral 0

estimate for I[f(x)] in the interval [0,1] improves3 initialize m_trials 10000

with increasing N and compute the deviation from4 initialize counter 0

the exact result: error = |I - Iestimate|. Again, the error5

should scale ~ N-1/2. 6 while(counter < m_trials) do

7 x = rand(0,1)

8 integral += x**n

9 counter++

10 done

11

12 return integral/m_trials

Problem 4: Importance-sampling Monte Carlo estimate of the of

estimate the integral,

integral f(x) = xn i.e.,

– The goal of M

this exercise is to show that with the same numerical effort as in problem 3 importance sampling 1 "

I= f (xi )

delivers smaller errors. We want to compute the integral of the function f(x) = xn in the interval M

i

[0,1], but instead of using uniform random numbers, we want to use power-law distributed

random numbers according to the distribution p(x) = (kwhere

+ 1)xk we

withhave

k < n.set m trials = M . To calculate the

compute the variance of the function. For this we n

pling of the square of the function, i.e., add a line t

+= x**(2*n). It then follows [43] for the statistica

2

#

Varf

δI = , Varf

M −1

with

Helmut G. Katzgraber

Power-law distributed random number can be computed from uniform random numbers by

transforming a uniform random number x in the following way:

given by a Monte Carlo sampling where f(x) is replaced by the

following function

distributed according to p(y). Start with n = 3 (I = 0.25) and k =

2.5 and compare to the results obtained in problem 3. As in

problem 3, run the code multiple times for N = 10i , i = 1, 2, 3, ...

random numbers. See how the estimate for I[f(x)] improves with increasing N and compute the

deviation from the exact result: error = |I - Iestimate|. Compare to the results of problem 3.

"

Problem 5: Esimating π using Markov-chain Monte Carlo – The goal of this problem is to

illustrate how π can be computed by randomMonte Carlo

sampling of Methods (Katzgraber)

the unit disk, however, using a

Markov chain. For the sake of simplicity, we will neglect autocorrelation effects that in this case

would only influence the error. Therefore, measurements should be done at every step of the

introduced in detail using models from statistical physics

simulation. Starting from the pseudo-code presented in class, modify your program to calculate

π using a Markov chain.

describes Markov-chain Monte Carlo for estimating π:

times for N = 10i , i = 1, 2, 3, ... random2 initialize n_hits 0

numbers. See how the estimate for π3 initialize m_trials 10000

4 initialize x 0

improves with increasing N and compute the

5 initialize y 0

deviation from the exact result: error = |π -

6 initialize counter 0

πestimate|.

7

Note that for the Markov chain you will have9 dx = rand(-p,p)

to select a step size in the interval [-p,p]. To10 dy = rand(-p,p)

do so, take a uniform random number x and11 if(|x + dx| < 1 and |y + dy| < 1)

compute a shifted uniform random number12 x = x + dx

in the interval [a,b] via y = a + (b - a)x. The13 y = y + dy

value of p strongly influences the algorithm.14 fi

If p is too small, then it will converge slowly.15 if(x**2 + y**2 < 1)

If p is too large, many moves will be rejected.16 n_hits++

Ideally, 50% of the moves should be17 fi

accepted. To verify this, measure the18 counter++

probability for a move to occur, i.e., prob =19 done

(accepted_moves/total_attempts). Values of20

p between 0.2 and 1.0 seem to be optimal. 21 return pi = 4*n_hits/m_trials

and generates the position of the new dot from the positi

3

the new position is outside the square, it is rejected (line

the step size p used to generate random numbers in the ran

When p is too small, convergence is slow, whereas if p is

Helmut G. Katzgraber

Problem 6: Simulating the one-dimensional Ising model – In this problem we now apply the

concepts learned to the simulation of a physical system, the one-dimensional Ising model on a

closed ring. This problem is slightly more work intensive.

The goal of the problem is to compute the energy per spin e = E/N as a function of temperature

T in [0.2, 5.0] for the model and compare to the exact analytical expression computed by Ernst

Ising in his thesis: � −J/T �

1 e −eJ/T

e=

N e−J/T + eJ/T

Run your code for ~3000 equilibration Monte Carlo sweeps (N attempted spin updates) and

then for 3000 measurement Monte Carlo sweeps and record the internal energy. Compare your

results for N = 3, 10, 30, 100, 300 spins to the exact expression. You should see convergence to

the exact values [also provided as a text file] for increasing system size.

S8

SN

The Hamiltonian of the 1D Ising model is given by S7

�

H = −J Si Si+1 , S1

i

S6

where the spins lie on a one-dimensional chain with

periodic boundaries. For simplicity, we set J = 1. It is S2

recommended to tackle the problem bottom-up, i.e., S5

write individual routines first. S3

S4

update.c: For the Monte Carlo update routine you need to compute the difference in energy

between the old and new configuration when flipping a randomly selected spin Si: dE = 2Si(Si-1 +

Si+1). To flip a spin

" flip spin;

" update energy;

" }

The function ir1279range(1,N) will select a random spin in the interval [1,N]. Keep in mind that

we use periodic boundaries, i.e., the ‘left’ neighbor if spin S1 is the spin SN. If this is unclear,

please look at the provided code.

Problem 7: Java applet of the two-dimensional Ising model – Play with the Java applet at

" http://tinyurl.com/3fm6kcl

Set the system size to N = 100x100 spins and tune the temperature. Observe what happens when

you cross the transition temperature Tc ~ 2.269 below which the model orders ferromagnetically.

- midtermTwo6711F10solsUploaded bySongya Pan
- Introduction to Monte Carlo SimulationUploaded bydiego_is_online
- Hmm Tutorial 1Uploaded byLala Nguyen
- [Krama] DCSch0 Dynamics of Complex Systems; Index # Yaneer Bar-yamUploaded byآركان الدين ياسين
- Prediction of Contaminant Plumes (Shapes, Spatial Moments and Macrodispersion) (1)Uploaded bycgajendran_56098156
- Fatigue Life Estimation Of Hybrid Aluminium Matrix CompositesUploaded byDhanashekar Manickam
- Grammar Based Music CompositionUploaded bydcollettseattle
- Assessing Land Use and Land Cover of the Marikina Sub Watershed PhilippinesUploaded byTemesgen M. Manderso
- Stationary vectors of stochastic matrices subject to combinatoria.pdfUploaded byDanang Stwn
- Some Remarks on 'Superradiant' Phase TransitionsUploaded byYash
- Srivastav AUploaded bywill2222
- Antamina Michael 09Uploaded byveda20
- Hybrid 2 Theory ManualUploaded byEric Morgan
- kadanoff2014aUploaded byPradhyapak Surjit Singh
- 10.1016-j.engfailanal.2014.06.024-Comparative Analysis of Failure Probability for Ethylene Cracking Furnace Tube Using Monte Carlo and API RBI TechnologyUploaded byamirlove206
- d392c1ea91ccc3731662faa05bb648126193Uploaded byRod_do
- 07 Fenton SimulationUploaded byAndres Pino
- mcUploaded byYassine Ramli
- Order PickingUploaded byBala Ganesh
- PresUploaded byAbdelkbir Ws
- PageRank Algorithm JournalUploaded byxyz
- ch10a_particleUploaded bymarykia
- Stochastic Modeling of Uncertainties in Computational Structural Dynamics - SoizeUploaded byBernardofn
- homework 2.pdfUploaded by鄧新弘
- PageRank Algorithm JournalUploaded byNeptali Jose Piña
- 39_1Uploaded bySam Saqib
- 10.1.1.534.901Uploaded byGokul Prabu
- MB0048 spring 2013 set 1 mba sem 2Uploaded byShivendra Singh
- IPC2012-90502Uploaded byMarcelo Varejão Casarin
- 1Uploaded bykannanchammy

- CFA Pass RatesUploaded byPortia
- d.docxUploaded byAbir Sinno
- 82-293-1-PBUploaded byAbir Sinno
- hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhUploaded byAbir Sinno
- 9e Financial Calculator ReferenceUploaded bykhopdi_number1
- An Effective CFA Level I Study Session OrderUploaded byAbir Sinno
- Understanding Your CFA Exam ResultUploaded byAbir Sinno
- Proposal Submission Form FILL 26.10.2016Uploaded byAbir Sinno
- 80043 - Introdax-navuction to Microsoft Dynamics NAV 2009Uploaded byAbir Sinno
- Is This the Right Journal-Flowchart.docxUploaded byAbir Sinno
- HenetUploaded byAbir Sinno
- ERPUploaded byAbir Sinno
- ERPUploaded byAbir Sinno
- How to Compare Two Excel Sheets and Combine Unique Data 4938 Nve8nvUploaded byAbir Sinno
- Henet.docxUploaded byAbir Sinno
- 21Uploaded byAbir Sinno

- Massive MIMO Meets Small CellUploaded byIlias Mansouri
- Quality of Experience Estimation for VoLTE ServicesUploaded byarushi sharma
- GraceUploaded byNarakula Srinivasa Rao
- Docslide.us Mar 102Uploaded byLinda Hayes
- Triangle ProblemUploaded bygauss202
- ngUploaded byShariq Ali
- QuenchingUploaded byjohn yabez
- 200905094-Ppt on Classification of Air CompressorsUploaded byPrasanna Kumar
- Mil Std 331dUploaded byNicolasSuch
- GMAW (Solid Wire) vs. FCAW (Flux-cored Wire)Uploaded bymomoitachi
- Enercon Uv Flexo Ink Adhesion for Flexible PackagingUploaded byAndrei Paun
- d5f0d544375547209ffa27cac0d76fa4.pdfUploaded bysai
- 2013 MetrobankUploaded byChrisseMarthaGillesania
- Excavadora Multifuncional Sobre Llantas de La Marca Mecalac Modelo 714MWeUploaded byMelquiades Ruiz
- Module 1-Chapter 4Uploaded byRomalyn Galingan
- Jacketed Piping_ Interview Questions and Answers _ What is PipingUploaded byVivekanandan Mahendran
- Views for Product Manual leap powerUploaded byNasredine Alain
- Controlling Linux Memory Fragmentation and Higher Order Allocation Failure- Analysis, Observations and ResultsUploaded byprabhatravi09
- Spirit Elite ManualUploaded byMoafar
- Single and Three_2Uploaded byRafiq_Hasan
- me471s03_q2_ansUploaded byHasen Bebba
- Conversor EnUploaded byDanilo Souza
- Pumping Plant Performance EvaluationUploaded bypeach5
- HVAC Operation and Problems - Jeep Cherokee ForumUploaded byChandra Petra
- PC-DMIS_CMMUploaded byVasile Negulescu
- Part of Chapter 2_Biophysics an IntroductionUploaded byJamila Rohmah
- Aromatic CompoundsUploaded byAmanMittal25
- Polygon Build Functionality in MineSight® 3-DUploaded by11804
- Honeywell - Energy Analytics Projects in US : Saket AgrawalUploaded bySaket Agrawal
- Tf Seal SelectionUploaded byPete Pompes