Pi evaluation. Monte Carlo integration

Similar documents
CS667 Lecture 6: Monte Carlo Integration 02/10/05

Continuous Random Variables

Numerical integration

Monte Carlo method in solving numerical integration and differential equation

7 - Continuous random variables

1 Probability Density Functions

Chapter 5 : Continuous Random Variables

CS 109 Lecture 11 April 20th, 2016

38.2. The Uniform Distribution. Introduction. Prerequisites. Learning Outcomes

Expectation and Variance

The Regulated and Riemann Integrals

Problem. Statement. variable Y. Method: Step 1: Step 2: y d dy. Find F ( Step 3: Find f = Y. Solution: Assume

We know that if f is a continuous nonnegative function on the interval [a, b], then b

Integral equations, eigenvalue, function interpolation

Review of Calculus, cont d

INTRODUCTION TO INTEGRATION

Lecture 3 Gaussian Probability Distribution

Math 113 Exam 2 Practice

Main topics for the Second Midterm

Math 113 Exam 1-Review

Improper Integrals, and Differential Equations

Method: Step 1: Step 2: Find f. Step 3: = Y dy. Solution: 0, ( ) 0, y. Assume

Numerical Integration

MATH 144: Business Calculus Final Review

Math 135, Spring 2012: HW 7

Lecture 1. Functional series. Pointwise and uniform convergence.

A REVIEW OF CALCULUS CONCEPTS FOR JDEP 384H. Thomas Shores Department of Mathematics University of Nebraska Spring 2007

Lecture 21: Order statistics

TP 10:Importance Sampling-The Metropolis Algorithm-The Ising Model-The Jackknife Method

5.7 Improper Integrals

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER /2019

Tutorial 4. b a. h(f) = a b a ln 1. b a dx = ln(b a) nats = log(b a) bits. = ln λ + 1 nats. = log e λ bits. = ln 1 2 ln λ + 1. nats. = ln 2e. bits.

1.9 C 2 inner variations

Math 113 Fall Final Exam Review. 2. Applications of Integration Chapter 6 including sections and section 6.8

Math& 152 Section Integration by Parts

Lecture 14: Quadrature

AM1 Mathematical Analysis 1 Oct Feb Exercises Lecture 3. sin(x + h) sin x h cos(x + h) cos x h

1 The Riemann Integral

13: Diffusion in 2 Energy Groups

We divide the interval [a, b] into subintervals of equal length x = b a n

Tests for the Ratio of Two Poisson Rates

Math 116 Calculus II

x = b a n x 2 e x dx. cdx = c(b a), where c is any constant. a b

How can we approximate the area of a region in the plane? What is an interpretation of the area under the graph of a velocity function?

X Z Y Table 1: Possibles values for Y = XZ. 1, p

JDEP 384H: Numerical Methods in Business

Goals: Determine how to calculate the area described by a function. Define the definite integral. Explore the relationship between the definite

Review of basic calculus

Problem Set 3 Solutions

A. Limits - L Hopital s Rule ( ) How to find it: Try and find limits by traditional methods (plugging in). If you get 0 0 or!!, apply C.! 1 6 C.

Chapter 0. What is the Lebesgue integral about?

cos 3 (x) sin(x) dx 3y + 4 dy Math 1206 Calculus Sec. 5.6: Substitution and Area Between Curves

1 Techniques of Integration

Week 10: Line Integrals

Definite integral. Mathematics FRDIS MENDELU

Quantum Physics I (8.04) Spring 2016 Assignment 8

Partial Derivatives. Limits. For a single variable function f (x), the limit lim

Improper Integrals. Type I Improper Integrals How do we evaluate an integral such as

8 Laplace s Method and Local Limit Theorems

The First Fundamental Theorem of Calculus. If f(x) is continuous on [a, b] and F (x) is any antiderivative. f(x) dx = F (b) F (a).

Definite integral. Mathematics FRDIS MENDELU. Simona Fišnarová (Mendel University) Definite integral MENDELU 1 / 30

Consequently, the temperature must be the same at each point in the cross section at x. Let:

Lecture 1: Introduction to integration theory and bounded variation

7.2 The Definite Integral

1 The fundamental theorems of calculus.

Disclaimer: This Final Exam Study Guide is meant to help you start studying. It is not necessarily a complete list of everything you need to know.

Final Exam - Review MATH Spring 2017

AP Calculus Multiple Choice: BC Edition Solutions

Test 3 Review. Jiwen He. I will replace your lowest test score with the percentage grade from the final exam (provided it is higher).

10. AREAS BETWEEN CURVES

Section 5.1 #7, 10, 16, 21, 25; Section 5.2 #8, 9, 15, 20, 27, 30; Section 5.3 #4, 6, 9, 13, 16, 28, 31; Section 5.4 #7, 18, 21, 23, 25, 29, 40

Main topics for the First Midterm

f(x) dx, If one of these two conditions is not met, we call the integral improper. Our usual definition for the value for the definite integral

p(t) dt + i 1 re it ireit dt =

Overview of Calculus I

Physics 116C Solution of inhomogeneous ordinary differential equations using Green s functions

Solution for Assignment 1 : Intro to Probability and Statistics, PAC learning

Big idea in Calculus: approximation

NATIONAL UNIVERSITY OF SINGAPORE Department of Mathematics Semester 1, 2002/2003 MA1505 Math I Suggested Solutions to T. 3

Math Bootcamp 2012 Calculus Refresher

Sections 5.2: The Definite Integral

The final exam will take place on Friday May 11th from 8am 11am in Evans room 60.

Exam 2, Mathematics 4701, Section ETY6 6:05 pm 7:40 pm, March 31, 2016, IH-1105 Instructor: Attila Máté 1

Week 10: Riemann integral and its properties

63. Representation of functions as power series Consider a power series. ( 1) n x 2n for all 1 < x < 1

AB Calculus Review Sheet

Problem Set 9. Figure 1: Diagram. This picture is a rough sketch of the 4 parabolas that give us the area that we need to find. The equations are:

5.5 The Substitution Rule

Riemann is the Mann! (But Lebesgue may besgue to differ.)

P 3 (x) = f(0) + f (0)x + f (0) 2. x 2 + f (0) . In the problem set, you are asked to show, in general, the n th order term is a n = f (n) (0)

Section 17.2 Line Integrals

Riemann Sums and Riemann Integrals

( ) as a fraction. Determine location of the highest

( ) where f ( x ) is a. AB Calculus Exam Review Sheet. A. Precalculus Type problems. Find the zeros of f ( x).

Unit #9 : Definite Integral Properties; Fundamental Theorem of Calculus

f(a+h) f(a) x a h 0. This is the rate at which

CBSE-XII-2015 EXAMINATION. Section A. 1. Find the sum of the order and the degree of the following differential equation : = 0

Math 113 Exam 2 Practice

12 TRANSFORMING BIVARIATE DENSITY FUNCTIONS

approaches as n becomes larger and larger. Since e > 1, the graph of the natural exponential function is as below

Transcription:

Pi evlution y 1 1 x Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (311) Monte Crlo integrtion we wnt to evlute the following integrl: F = f (x) dx remember tht the expecttion vlue of the function f (x) for x distributed ccording to PDF p(x) f = f (x) p(x) dx with: p(x) dx = 1 choosing x to be uniformly distributed in the intervl [, b], one hs: p(x) = 1 b f = 1 b f (x) p(x) dx = b f (x) dx MC integrtion F = f (x) dx = (b ) f = (b ) i=1 f (x i) x i is rndom vrible uniformly distributed in the intervl [, b] error estimtion σ F = (b )σ f σ 2 f = f 2 f 2 σ 2 f = σ2 f σ F = (b ) σ f 1 1 = (b ) ( f (xi ) ) 2 i=1 1 2 f (x i ) i=1 Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (312)

MC integrtion (cont.) Let s compute the integrls of the functions: dx 2 = 0.471239 cos(x) dx = 0.412215 (x + b) dx = 0.622035 Throwing 100 rndom vrible uniformly distributed we obtin the following results: dx 2 = 0.471239 ± 0.000000 cos(x) dx = 0.413671 ± 0.007098 (x + b) dx = 0.622280 ± 0.001037 Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (313) MC integrtion (cont.) double xmin=tmth::pi()*0.2; double xmx=tmth::pi()*0.5; int = 1000; lgorithm TF1 *f1 = new TF1( f1, TMth::Abs(cos(x)),xmin,xmx); TF1 *f2 = new TF1( f2, 0.5,xmin,xmx); TF1 *f3 = new TF1( f3, -0.4/TMth::Pi()*x+0.8,xmin,xmx);... for (int i=0; i<; i++) { double x = xmin + (xmx-xmin)*grndom->uniform(); double func1 = f1->evl(x); double func2 = f2->evl(x); double func3 = f3->evl(x); F1 += func1; F2 += func2; F3 += func3; f1s += func1*func1; f2s += func2*func2; f3s += func3*func3; } double f1m = F1/; //men double f2m = F2/; double f3m = F3/; lgorithm // integrls double I1 = f1m*(xmx-xmin); double I2 = f2m*(xmx-xmin); double I3 = f3m*(xmx-xmin); // vrinces double Vr1 = f1s/ - f1m*f1m; double Vr2 = f2s/ - f2m*f2m; double Vr3 = f3s/ - f3m*f3m; // errors double E1 = (xmx-xmin)/sqrt()*sqrt(vr1); double E2 = (xmx-xmin)/sqrt()*sqrt(vr2); double E3 = (xmx-xmin)/sqrt()*sqrt(vr3); Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (314)

MC integrtion (cont.) Let s check the integrl vlue s function of the number of rndom vribles generted F = cos(x) dx F = dx 2 F = (x + b) dx Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (315) Empty Slide Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (316)

Reduction vrince techniques The cos(x) function vries much more in the intervl of integrtion tht the others Its integrl vlue evlution presents the lrgest vrince. Why? Becuse we re smpling uniformly nd the regions close to zero where the function is more importnt re smpled with the sme importnce s others where the function is smller! In the frmework of the importnce smpling technique n dditionl pdf p(x) cn be used to rend the integrnd smooth! Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (317) Importnce smpling Rend smooth our integrnd by pplying pdf p(x) F = f (x) dx = f (x) p(x) p(x) dx If the pdf is normlized in the integrl intervl [, b] p(x) dx = 1 nd x is vrible distributed ccording to p(x), then f b = p f (x) p(x) p(x) dx Let s mke vrible chnge f (x) p(x) p(x) dx } {{ } p(y)dy p(x)dx = p(y)dy if y is distributed uniformly in [0, 1] then 1 0 p(y)dy = 1 p(y) = 1 The trnsformtion between x nd Y cn be obtined by: x p(x )dx = y 0 dy y = x p(x )dx Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (318)

Importnce smpling (cont.) From the trnsformtion of vribles we hve reltion between x nd y y = x p(x )dx x(y) Generting rndom vrible y uniformly between [0, 1] nd pplying the trnsformtion reltion x(y) we get rndom vribles x distributed ccording to p(x) F = f (x) dx = f (x) p(x) p(x) dx = 1 0 f [ x(y) ] f p [ x(y) ] dy = = 1 p y i=1 f [ x(y i ) ] p [ x(y i ) ] Exercise: mke the following integrl cos(x) dx expected = 0.412215 MC = 0.432225 +/- 0.025083 (100 devites generted) Wht bout using importnce smpling with pdf: p(x) e x? Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (319) Importnce smpling (cont.) The function PDF shpe mtters? Let s study the vrition of the integrl error with the prmeter of the exponentil Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (320)

Importnce smpling (cont.) Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (321) Simultion Simultion is very importnt for understnding rel situtions or for modelling the behviour of system it is lrgely used on prticle nd stroprticle physics for designing the instruments used for prticles detection the vrious rel conditions the system hs cn be introduced esily in simulted process Suppose you hd to design detector system for detecting photons coming from Compton scttering on mteril? I ssume my gmm source emits bem very colimted long n xis (x for instnce) nd in between I hve block of mteril where Compton is going to hppen... Wht we need to know? Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (322)

Buffon s needle problem Buffon s needle problem is question first posed in the 18th century by Georges-Louis Leclerc where simultion cn help us lot! A needle of length l is thrown rndomly onto grid of prllel lines, seprted by distnce d, with d > l Wht is the probbility tht needle intersects line? Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (323) Buffon s needle problem The probbility of crossing the line it s the rtio between the needle "perpendiculr distnce", l sin θ 2 nd the lines seprtion distnce, d P(θ) = l sin θ 2 d All θ re likely, so we need to clculte n verge probbility for θ rnge: 2 [0, π] Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (324)

Generting rndom vribles The common problem is to hve vrible x distributed ccording given distribution function p(x) we re going to mke chnge of vrible such tht the number of events (rndoms) generted is independent of the used vrible d = p(x)dx = p(y)dy Suppose tht y is rndom vrible distributed in [0, 1] nd x strts t x 0 p(y) = 1 y 0 dy = x x p(x )dx y = p(x )dx x 0 x 0 For generting rndom vrible x in intervl [x 0, x 1 ] we just mke sure tht: x1 x 0 p(x)dx = 1 nd we invert the reltion bove (boxed) giving us x(y). Provided rndom y in [0, 1] we generte rndom x in [x 0, x 1 ]. Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (325) uniform [0,1] uniform [,b] Let s trnsform vrible y uniformly distributed in [0, 1] into vrible x uniformly distributed in [, b] ormliztion of p(x): p(x) = 1 b Trnsformtion: y = x 1 b dx = x b x = (b )y x = + (b ) y Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (326)

uniform [0,1] exponentil [0, ] Let s trnsform vrible y uniformly distributed in [0, 1] into vrible x distributed ccording to p(x) e x in [0, ] ormliztion of p(x): k + e x dx = 1 0 k [ e x] 0 = 1 k = 1 p(x) = e x Trnsformtion: y = x 0 e x dx = [ e x ] x = 1 0 e x x = ln(1 y) Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (327) rndoms gen: cceptnce-rejection For pplying the method before sid we need to integrte the pdf nd invert it In cse it is not possible we cn use the more generic but less efficient method of cceptnce-rejection For generting x vrible in the intervl [, b] distributed ccording to pdf p(x) wo do the following: generte uniform rndom x R between [, b] compute p(x R ) nd the rtio p(x R) p mx generte second rndom u R from U(0, 1) if u R p(x R) p mx ccept the vrible x R Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (328)

MC integrtion: cc-rej method introduced by von eumnn for integrting the function we define n envelope with n re A = (x mx x min ) f mx generte two rndom vribles x R in in rnge [x min, x mx ] f R in in rnge [0, f mx ] count the number of events R tht f R f (x R ) the integrl I = (x mx x min ) f mx R the integrl error σ I = (x mx x min ) f mx R ( 1 R ) Using 100 rndoms: cos(x) dx = 0.435 ± 0.037 Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (329) rndom gen: f (x) = 3x 2 The cceptnce-rejection method is inefficient if the function vries quickly The frction of rndoms ccepted (efficiency) is given by: ε = f (x) dx (b ) f mx The efficiency cn be improved using n uxilir function S (x) tht hs shpe close to the one we wnt to smple ε S = f (x) dx q(x) dx where q(x) = C S (x) f (x) for x in [, b] efficiencies: ε = R 0.535 ε S = R 0.91 Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (330)

cc-rej with ux function For generting rndom vrible x distributed ccording to f (x) in the intervl [, b] 1. Find uxilir function S (x) with shpe close to the function f (x) we wnt to smple integrble, invertible from S (x) we define pdf p(x) nd we pply the trnsformtion y U[0, 1] x U(p(x)) invert trnsformtion eqution: x(y) using x(y) nd generting y uniformly between [0, 1] we obtin the rndom vrible x R distributed ccording to p(x) 2. Define function q(x) = C S (x) such tht q(x) f (x) in the intervl [, b] 3. Generte rndom vrible x R ccording to p(x) nd compute f (x R) q(x R ) 4. Generte rndom u R U[0, 1] nd ccept x R if: u R f (x R) q(x R ) Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (331) rndom gen: f (x) = 3x 2 We wnt to generte vrible ccording to function f (x) = 3x 2 1. Define the uxilir function S (x) to improve cceptnce-rejection efficiency 2. define q(x) which in this cse is = S (x) nd generte x R ccording to p(x) 3.,4. generte u R u[0, 1] nd ccept x R if u R f (x R) q(x R ) S (x) = 30x 63 generte rndom in [3,7] intervl ccording to uxilir function get pdf(x): S (x) p(x) with 7 3 p(x)dx = 1 k 7 1 S (x) dx = 1 k = 3 348 p(x) = 1 348 (30x 63) mke trnsformtion: y[0, 1] x ccording to p(x) y = x 3 p(x ) dx = x 1 3 348 (30x 63) dx Derive x(y) from: 15x 2 63x + 54 348y = 0 Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (332)

C++ clsses clss Func1D { public: Func1D(TF1 *fp=ull); // other constructors? ~Func1D(); void Drw(); double Evlute(); (...) protected: TF1 *p; //integrnd function }; clss IntegrtorMC: public Func1D { public: Integrtor(double fx0, double fx1, TF1 *fp=ull) : x0(fx0), x1(fx1), Func1D(fp) {;} ~Integrtor(); // set function void SetIntegrndFunction(TF1*); // simple integrtion void IntegrlMC(double xmin, double xmx, int, double& result, double& error); // importnce smpling void IntegrlMCIS(double xmin, double xmx, int, double& result, double& error, TF1* pdf); // cceptnce-rejection void IntegrlMCIS(double xmin, double xmx, int, double& result, double& error, TF1* pdf); // other methods (...) protected: double x0, x1; // integrnd limits }; Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (341) Computtionl Physics Universe prticle ccelertor Fernndo Bro, Phys Deprtment IST (Lisbon) Computtionl Physics 2018-19 (Phys Dep IST, Lisbon) Fernndo Bro (342)