Monte Carlo Techniques. Professor Stephen Sekula Guest Lecture PHY 4321/7305 Sep. 3, 2014

Similar documents
Professor Stephen Sekula

1. Practice the use of the C ++ repetition constructs of for, while, and do-while. 2. Use computer-generated random numbers.

Finding Pi: Applications of Loops, Random Numbers, Booleans CS 8: Introduction to Computer Science, Winter 2018 Lecture #6

L20 MPI Example, Numerical Integration. Let s now consider a real problem to write a parallel code for. Let s take the case of numerical integration.

Computational modeling

Chapter Four: Loops II

Stochastic Algorithms

Ph3 Mathematica Homework: Week 8

4. Use a loop to print the first 25 Fibonacci numbers. Do you need to store these values in a data structure such as an array or list?

The Plan: Basic statistics: Random and pseudorandom numbers and their generation: Chapter 16.

Computational modeling

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit IV Monte Carlo

Probability and Statistics for Final Year Engineering Students

Physics 736. Experimental Methods in Nuclear-, Particle-, and Astrophysics. - Statistical Methods -

Diffraction and Interference of Plane Light Waves

Math (Spring 2009): Lecture 5 Planes. Parametric equations of curves and lines

Monte Carlo methods for risk analysis

GAMES Webinar: Rendering Tutorial 2. Monte Carlo Methods. Shuang Zhao

Name: Dr. Fritz Wilhelm Lab 1, Presentation of lab reports Page # 1 of 7 5/17/2012 Physics 120 Section: ####

Day 5: Inscribing and Circumscribing Getting Closer to π: Inscribing and Circumscribing Polygons - Archimedes Method. Goals:

What is the Monte Carlo Method?

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

Mathematics: working hard together, achieving together, making every lesson count

Computational Methods. Randomness and Monte Carlo Methods

You ve already read basics of simulation now I will be taking up method of simulation, that is Random Number Generation

Introduction to Functions

2 + (-2) = 0. Hinojosa 7 th. Math Vocabulary Words. Unit 1. Word Definition Picture. The opposite of a number. Additive Inverse

Photon Maps. The photon map stores the lighting information on points or photons in 3D space ( on /near 2D surfaces)

13 Distribution Ray Tracing

Lagrange Multipliers and Problem Formulation

CS 179: GPU Computing. Lecture 16: Simulations and Randomness

Physics 1CL WAVE OPTICS: INTERFERENCE AND DIFFRACTION Fall 2009

Semester 2 Review Problems will be sectioned by chapters. The chapters will be in the order by which we covered them.

VARIOUS ESTIMATIONS OF π AS DEMONSTRATIONS OF THE MONTE CARLO METHOD

Scientific Computing with MATLAB

Monte Carlo Integration

Functions and Libraries Once upon a time...

Previous Lecture: Today s Lecture: Announcements: Nesting if-statements Logical operators short-circuit. Iteration using for

LIGHT: Two-slit Interference

UNIT 3 CIRCLES AND VOLUME Lesson 5: Explaining and Applying Area and Volume Formulas Instruction

Sampling and Monte-Carlo Integration

Monte Carlo Methods. Named by Stanislaw Ulam and Nicholas Metropolis in 1940s for the famous gambling casino in Monaco.

Decision Support and Intelligent Systems. Monte Carlo Simulation

Length, Area, and Volume - Outcomes

Monte Carlo Integration and Random Numbers

Math Girls rock! Math Club for Young Women Project 2. Geometric Probability and Buffon s Needle Problem

Perimeter and Area of Inscribed and Circumscribed Polygons

4) Simplify 5( 6) Simplify. 8) Solve 1 x 2 4

Geometry / Integrated II TMTA Test units.

Simulation. Monte Carlo

What You ll See in This Chapter. Word Cloud. René Descartes. Introduction. Ian Parberry University of North Texas. Fletcher Dunn

58th ANNUAL HIGH SCHOOL HONORS MATHEMATICS CONTEST

Log1 Contest Round 2 Theta Circles, Parabolas and Polygons. 4 points each

Year 9 Maths Overview

Geometry. Oklahoma Math Day INSTRUCTIONS:

Monte Carlo Simulations

8 TH GRADE MATHEMATICS CHECKLIST Goals 6 10 Illinois Learning Standards A-D Assessment Frameworks Calculators Allowed on ISAT

Monte Carlo Integration

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

Perimeter and Area. Slide 1 / 183. Slide 2 / 183. Slide 3 / 183. Table of Contents. New Jersey Center for Teaching and Learning

Random Numbers Random Walk

Statistical Pi Simulation by Java

Warm-Up 12 Solutions. Peter S. Simon. December 8, 2004

CS 100: Programming Assignment P1

Floating-point numbers. Phys 420/580 Lecture 6

S8.6 Volume. Section 1. Surface area of cuboids: Q1. Work out the surface area of each cuboid shown below:

Math 5320, 3/28/18 Worksheet 26: Ruler and compass constructions. 1. Use your ruler and compass to construct a line perpendicular to the line below:

Efficacy of Numerically Approximating Pi with an N-sided Polygon

Maths Year 11 Mock Revision list

Which equation could find the distance from point G to the base of the flagpole?

Eighth Grade Math Assessment Framework Standard 6A Representations and Ordering

INTERFERENCE. Interf - 1

P1 REVISION EXERCISE: 1

MATH 209, Lab 5. Richard M. Slevinsky

VARIANCE REDUCTION TECHNIQUES IN MONTE CARLO SIMULATIONS K. Ming Leung

0 Graphical Analysis Use of Excel

Goals: Course Unit: Describing Moving Objects Different Ways of Representing Functions Vector-valued Functions, or Parametric Curves

Algebra II Trigonometric Functions

January 30, 2019 LECTURE 2: FUNCTIONS OF SEVERAL VARIABLES.

Fractals and the Chaos Game

Scientific Computing: An Introductory Survey

Math for Geometric Optics

Part I. There are 5 problems in Part I, each worth 5 points. No partial credit will be given, so be careful. Circle the correct answer.

Lecture 4. Physics 1502: Lecture 35 Today s Agenda. Homework 09: Wednesday December 9

Need more help with decimal subtraction? See T23. Note: The inequality sign is reversed only when multiplying or dividing by a negative number.

RightStart Mathematics

Algebra II. Slide 1 / 162. Slide 2 / 162. Slide 3 / 162. Trigonometric Functions. Trig Functions

11.4 CIRCUMFERENCE AND ARC LENGTH 11.5 AREA OF A CIRCLE & SECTORS

Math 2250 Lab #3: Landing on Target

: Imaging Systems Laboratory II. Laboratory 2: Snell s Law, Dispersion and the Prism March 19 & 21, n 1 n 2

MATHEMATICS FOR ENGINEERING TRIGONOMETRY

More About Factoring Trinomials

Monte Carlo Simula/on and Copula Func/on. by Gerardo Ferrara

YEAR 10- Mathematics Term 1 plan

Physics 736. Experimental Methods in Nuclear-, Particle-, and Astrophysics. Lecture 14

Lab 7 Interference and diffraction

GCSE Mathematics. Higher Tier. Paper 4G (Calculator) Time: 1 hour and 45 minutes. For Edexcel. Name

Answer Key: Three-Dimensional Cross Sections

Random Numbers and Monte Carlo Methods

Math Boot Camp: Coordinate Systems

Transcription:

Monte Carlo Techniques Professor Stephen Sekula Guest Lecture PHY 431/7305 Sep. 3, 014

What are Monte Carlo Techniques? Computational algorithms that rely on repeated random sampling in order to obtain numerical results Basically, you run a simulation over and over again to calculate the underlying probabilities that lead to the outcomes Like playing a casino game over and over again and recording all the game outcomes to determine the underlying rules of the game Monte Carlo is a city famous for its gambling hence the name of this class of techniques

HAVE YOU EVER (KNOWINGLY) USED MONTE CARLO TECHNIQUES? 3

EVER PLAYED BATTLESHIP? MISSES IF SO, YOU HAVE APPLIED MONTE CARLO TECHNIQUES. HITS 4

A Simple Physical Example Let's illustrate this class of techniques with a simple physical example: numerical computation of π π: the ratio of the circumference of a circle to its diameter. It's difficult to whip out a measuring tape or ruler and accurately measure the circumference of an arbitrary circle. The Monte Carlo method avoids this problem entirely 5

Begin by drawing a square, inscribed into which is a circle. The properties of the square are much easier to measure. 6

What do we know? 7

We know the relationship between the radius of a circle and the x and y coordinate of a point on the radius: r = x + y 8

Let us imagine that we have a way of randomly throwing a dot into the square (imagine a game of darts being played, with the square as the board...) Knowns: r = x + y 9

There is a probability that a uniformly, randomly thrown dot will land in the circle, and a probability that it will land out of the circle. What are those probabilities? Knowns: r = x + y 10

Probability of landing in the circle is merely given by the ratio of the areas of the two objects: πr π P (in dot)= = 4 4r Knowns: r = x + y 11

That's nice but we're missing a piece... just what is that probability on the left side? How can we determine it? Knowns: r = x + y P (in dot)= π 4 1

ANSWER: numerically - by throwing dots uniformly in the square and counting the number that land inside the circle, divided by the number that we have thrown in total: N in P (in dot)= N total Knowns: r = x + y P (in dot)= π 4 13

ANSWER: numerically - by throwing dots uniformly in the square and counting the number that land inside the circle, divided by the number that we have thrown in total: Knowns: r = x + y N in π = N total 4 14

π is then simply determined numerically via: N in π=4 N total Knowns: r = x + y N in π = N total 4 15

The Pieces Random numbers Uniformity of coverage needed to throw dots at the board we want to pepper the board using uniform random numbers, to avoid creating artificial pileups that create new underlying probabilities Code/Programming You can do this manually with a square, an inscribed circle, coordinate axes, and a many-sided die. But that limits your time and precision computers are faster for such repetitive tasks 16

Computational Examples I will demonstrate the underlying computation framework principles using OCTAVE, a free and open-source computation framework similar to MATLAB (which costs a lot of money) Why? I have a web interface running on my own server that lets us ALL follow along and write code today! At the end of this, you will have a program you can take with you and adapt into ANY language. If you've never seriously written code before, today is your lucky day 17

Basics of Coding Numbers all programming languages can minimally handle numbers: integers, decimals Variables placeholders for numbers, whose values can be set at any time by the programmer Functions any time you have to repeatedly perform an action, write a function. A function is just like in math it represents a complicated set of actions on variables Code an assembly of variables and functions whose goal is determined by the programmer. Task-oriented mathematics Coding is the poetry of mathematics it takes the basic rules of mathematics and does something awesome with them. 18

You type it, it does it. 19

0

Uniform Random Numbers Computers can generate (pseudo)random numbers using various algorithms this is a whole lecture in and of itself if you're interested in pseudo-random numbers, etc. go do some independent reading We will utilize the rand function in OCTAVE to obtain our uniform random numbers 1

rand generates a uniform random decimal number between 0 and 1 (inclusive)

Designing our game board 3

Designing our game board L= R=1 We don't need the whole game board we can just use onequarter of it. This keeps the program simple! Alternative: you can rescale the output of rand to generate random numbers between -1 and 1 (1/ 4) π r π = =P (in dot) 4 (1/4) 4 r 4

5

Repetition You don't want to manually type 100 (or more) computations of your dot throwing You need a loop! A loop is a small structure that automatically repeats your computation an arbitrary number of times In OCTAVE: Ntotal=100 Ntotal=100 for i=1:ntotal for i=1:ntotal x=rand x=rand y=rand y=rand endfor endfor 6

Loops are powerful they are a major workhorse of any repetitive task coded up in a programming language. 7

Final Piece So we have generated a dot by generating its x and y coordinates throwing uniform random numbers... How do we determine if it's in or out of the circle? ANSWER: if r = (x+y) < R, it's in the circle; otherwise, it is out of the circle! 8

A working program. You can increase Ntotal to get increased precision! 9

A Comment on Precision Given finite statistics, each set of trials carries an uncertainty (π ± σπ). A point, (x,y), can either be in or out of the circle of radius, R. Thus the uncertainty on Nin can be treated as a binomial error: σ N = N total p(1 p) where p=n in / N total in Propagating this to π: N in σ π =4 σ N / N total =4 (1 ) N total N total in N in 30

Precision (continued) Relative error: σπ 1 1 π = N N in total For 100 trials, σπ/π = 5.0% (e.g. 3.0 ± 0.16) For 1000 trials, σπ/π = 1.7% (e.g. 3.1 ± 0.05) For 10,000 trials: σπ/π = 0.5% (e.g. 3.131 ± 0.017) Note that uncertainty scales only as 1/ Ntotal 31

Why is this powerful? You've just learned how to compute an integral NUMERICALLY. You can apply this technique to any function whose integral (area) you wish to determine For instance, consider the next slide. 3

Given an arbitrary function, f(x), you can determine its integral numerically using the Accept/Reject Method First, find the maximum value of the function (e.g. either analytically, if you like, or by calculating the value of f(x) over steps in x to find the max. value, which I denote F(x)) Second, enclose the function in a box, h(x), whose height is F(x) and whose length encloses as much of f(x) as is possible. Third, compute the area of the box (easy!) Fourth, throw points in the box using uniform random numbers. Throw a value for x, denotes x'. Throw a value for y, denoted y'. If y' < f(x'), it's a hit! If not, it's a miss! 33

N hits I ( f ( x)) = N total A(h( x)) This, in the real world, is how physicists, engineers, statisticians, mathematicians, etc. compute integrals of arbitrary functions. Learn it. Love it. It will save you. 34

Generating Simulations The Monte Carlo technique, given a function that represents the probability of an outcome, can be used to generate simulated data Simulated data is useful in designing an experiment, or even running an experiment over and over to see all possible outcomes 35

36

Young's Double-Slit Experiment Simulation Consider slits of width, b, separated by a distance, d. Given the function that describes the probability of finding a photon at a given angle: [ ] [ π d sin (θ) π b sin (θ) I (θ) cos sinc λ λ ] sin( x)/ x ( x 0) sinc(x)= 1 ( x=0) 37

Next Steps Need the max. value of I(θ) occurs at θ = 0 Use that to compute the height of the box; the width of the box is π (ranging from -π to +π) Throw random points in the box until you get 1000 accepts Now you have a simulated data sample of 1000 photons scattered in the two-slit experiment. 38

λ = 550 nm d = 0.1 mm b=0 1000 simulated photons scattered through a double-slit experiment. This was done in C++ using the free ROOT High-Energy Physics data analysis framework, so I could easily generate a histogram a binned data sample. 39

Resources Octave: (open-source, free) http://www.gnu.org/software/octave/ Python: (open-source, free) http://www.python.org/ Mathematica: (non-free) http://www.wolfram.com/mathematica/ Maxima (open-source, free Mathematica ) http://maxima.sourceforge.net Monte Carlo Techniques: http://en.wikipedia.org/wiki/monte_carlo_method 40