Monte Carlo Methods.

Slides:



Advertisements
Similar presentations
RSLAB-NTU Lab for Remote Sensing Hydrology and Spatial Modeling 1 An Introduction to R Pseudo Random Number Generation (PRNG) Prof. Ke-Sheng Cheng Dept.
Advertisements

Generating Random Numbers
Monte Carlo Methods and Statistical Physics
Random variables 1. Note  there is no chapter in the textbook that corresponds to this topic 2.
Random Number Generation. Random Number Generators Without random numbers, we cannot do Stochastic Simulation Most computer languages have a subroutine,
Random Numbers. Two Types of Random Numbers 1.True random numbers: True random numbers are generated in non- deterministic ways. They are not predictable.
Random number generation Algorithms and Transforms to Univariate Distributions.
CDA6530: Performance Models of Computers and Networks Chapter 5: Generating Random Number and Random Variables TexPoint fonts used in EMF. Read the TexPoint.
Random Number Generators. Why do we need random variables? random components in simulation → need for a method which generates numbers that are random.
Monte-Carlo Techniques Roger Crawfis. June 9, 2015OSU/CIS 5412 Monte-Carlo Integration Overview 1.Generating Psuedo-Random Numbers 2.Multidimensional.
Sampling Attila Gyulassy Image Synthesis. Overview Problem Statement Random Number Generators Quasi-Random Number Generation Uniform sampling of Disks,
Simulation Modeling and Analysis
Using random numbers Simulation: accounts for uncertainty: biology (large number of individuals), physics (large number of particles, quantum mechanics),
CS 351/ IT 351 Modelling and Simulation Technologies Random Variates Dr. Jim Holten.
1 Random Number Generation H Plan: –Introduce basics of RN generation –Define concepts and terminology –Introduce RNG methods u Linear Congruential Generator.
Genetic Algorithms Can Be Used To Obtain Good Linear Congruential Generators Presented by Ben Sproat.
Pseudorandom Number Generators
Statistics.
 2007 Pearson Education, Inc. All rights reserved C Functions.
Distinguishing Features of Simulation Time (CLK)  DYNAMIC focused on this aspect during the modeling section of the course Pseudorandom variables (RND)
K. Desch – Statistical methods of data analysis SS10
 2007 Pearson Education, Inc. All rights reserved C Functions.
CSCE Monte Carlo Methods When you can’t do the math, simulate the process with random numbers Numerical integration to get areas/volumes Particle.
Properties of Random Numbers
The Monte Carlo Method: an Introduction Detlev Reiter Research Centre Jülich (FZJ) D Jülich
APPENDIX D RANDOM NUMBER GENERATION
Random Number Generation Fall 2013
Problem 1 Given a high-resolution computer image of a map of an irregularly shaped lake with several islands, determine the water surface area. Assume.
ETM 607 – Random Number and Random Variates
1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo
Simulation of Random Walk How do we investigate this numerically? Choose the step length to be a=1 Use a computer to generate random numbers r i uniformly.
1 Statistical Mechanics and Multi- Scale Simulation Methods ChBE Prof. C. Heath Turner Lecture 11 Some materials adapted from Prof. Keith E. Gubbins:
Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights.
D MANCHE Finding the area under curves:  There are many mathematical applications which require finding the area under a curve.  The area “under”
Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte.
Monte Carlo Simulation and Personal Finance Jacob Foley.
1 Theoretical Physics Experimental Physics Equipment, Observation Gambling: Cards, Dice Fast PCs Random- number generators Monte- Carlo methods Experimental.
General Principle of Monte Carlo Fall 2013 By Yaohang Li, Ph.D.
1 Lesson 3: Choosing from distributions Theory: LLN and Central Limit Theorem Theory: LLN and Central Limit Theorem Choosing from distributions Choosing.
Random-Number Generation Andy Wang CIS Computer Systems Performance Analysis.
© 2003, Carla Ellis Simulation Techniques Overview Simulation environments emulation exec- driven sim trace- driven sim stochastic sim Workload parameters.
Chapter 7 Random-Number Generation
Module 1: Statistical Issues in Micro simulation Paul Sousa.
Basic Concepts in Number Theory Background for Random Number Generation 1.For any pair of integers n and m, m  0, there exists a unique pair of integers.
Random Numbers and Simulation  Generating truly random numbers is not possible Programs have been developed to generate pseudo-random numbers Programs.
1 Lesson 8: Basic Monte Carlo integration We begin the 2 nd phase of our course: Study of general mathematics of MC We begin the 2 nd phase of our course:
Random Number Generators 1. Random number generation is a method of producing a sequence of numbers that lack any discernible pattern. Random Number Generators.
Experimental Method and Data Process: “Monte Carlo Method” Presentation # 1 Nafisa Tasneem CHEP,KNU
Monte Carlo Methods Versatile methods for analyzing the behavior of some activity, plan or process that involves uncertainty.
Monte Carlo Methods So far we have discussed Monte Carlo methods based on a uniform distribution of random numbers on the interval [0,1] p(x) = 1 0  x.
Simulation is the process of studying the behavior of a real system by using a model that replicates the behavior of the system under different scenarios.
APPENDIX D R ANDOM N UMBER G ENERATION Organization of chapter in ISSO* – General description and linear congruential generators Criteria for “good” random.
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
Techniques in Signal Processing CSC 508 Generating Random Numbers with a Computer.
Random numbers in C++ Nobody knows what’s next....
CHAPTER 5 Simulation Modeling. Introduction In many situations a modeler is unable to construct an analytic (symbolic) model adequately explaining the.
MAT 4830 Mathematical Modeling 04 Monte Carlo Integrations
EMIS 7300 SYSTEMS ANALYSIS METHODS FALL 2005 Dr. John Lipp Copyright © 2005 Dr. John Lipp.
G. Cowan Lectures on Statistical Data Analysis Lecture 5 page 1 Statistical Data Analysis: Lecture 5 1Probability, Bayes’ theorem 2Random variables and.
0 Simulation Modeling and Analysis: Input Analysis 7 Random Numbers Ref: Law & Kelton, Chapter 7.
Module 9.2 Simulations. Computer simulation Having computer program imitate reality, in order to study situations and make decisions Applications?
Problem 1: Service System Capacity CustomersServed Customers Queue Server Problem: Can a server taking an average of x time units meet the demand? Solution.
Lesson 8: Basic Monte Carlo integration
Monte Carlo Methods Some example applications in C++
Why they aren't really random
MONTE CARLO SIMULATION
Random numbers Taken from notes by Dr. Neil Moore
Random-Number Generation
Lecture 2 – Monte Carlo method in finance
Computing and Statistical Data Analysis Stat 3: The Monte Carlo Method
Presentation transcript:

Monte Carlo Methods

“Monte Carlo”? Any problem-solving technique that uses random numbers is called a Monte Carlo method, used in: Games Simulations Many scientific applications Named after the famous country that enshrines games of chance for the wealthy Can be used to adequately approximate the solution of difficult problems

Random Numbers The key to Monte Carlo methods is a good random number generator The ones that come in standard libraries aren’t all that good There are statistical tests to evaluate random number generators For uniformity Are they sufficiently “spread out” (coverage) For randomness Do they avoid gratuitous runs of repetitions or other patterns? It is difficult to achieve both simultaneously

Properties of RNGs Deterministic Reproducible Periodic They aren’t really “random” After all, we use formulas! We call the numbers produced, “pseudo-random” Reproducible You should be able to get the same sequence of pseudo-random numbers on request This is important for comparing experiments Periodic You get the next number in the sequence by applying a formula to the last one Eventually, the sequence repeats

Uniform Generators Generate a nicely spread-out sequence of numbers on some interval (usually (0, m)) e.g., std::rand( ) evenly covers (0, RAND_MAX) As opposed to Normal, Poisson or other distributions If you use more than RAND_MAX calls to rand, you’ll start repeating the sequence RAND_MAX = 32767 is unacceptable It may even start repeating sooner We want a large period for Monte Carlo methods

Linear Congruential Generators Of the form: The constants a, c, and m must be chosen carefully The period is <= m, but we want to maximize it There is an entire body of literature based on number theory for this Some generators combine LCGs with other kinds

A Quick and Dirty RNG Very fast And pretty doggone good! Period is not as large as others, though(?) See qadrng.h

UNI A uniform RNG from the 80s In file uni.h, uni.cpp Uses a lagged Fibonacci approach Uses different samples from a LCG with a=1, c = -7654321, m = 224 xn+1 = xn-17 – xn-5 Must call ustart( ) to seed

The Mersenne Twister Has a very large period 219937-1 (!!!) Written by Makoto Matsumoto http://www.math.sci.hiroshima-u.ac.jp/~m-mat/eindex.html Uses Mersenne primes and other tricks as a modification to a linear congruential method We won’t look any more into the theory We’ll just use it!

Using the Mersenne Twister In file mersenne.c Pass a long to init_genrand( ) to seed Can use std::time( ) to get a random seed Call genrand_int32( ) for numbers in the interval [0, 232) Call genrand_real3( ) for numbers in the interval (0, 1) You can use math to transform to other intervals Don’t forget to include a prototype for the functions you call

Interval mapping formulas Most RNGs give reals in the range (0,1) or integers in the range (0, m) You can map to and from these ranges with simple algebraic transformations Well, they’re simple to me 

Open Interval Mapping formulas

Interval Mapping Formulas

Open vs. Closed intervals Closed intervals are often used for integers Not for reals, since the endpoints might not be representable The formulas on the previous slide don’t work! i.e., when converting from open (real) to closed (integer) intervals Example: (0, 1) => integers on [10, 20] Since 1 is never reached, 20 won’t be with the formulas on the previous slide Instead: Use int(11*x) + 10

Mapping from Open (real) to Closed (integer) Intervals Start with w in (0,1) Transform it if necessary: To map w to [k,n]: Multiply w by n-k+1, Truncate, Add k:

Monte Carlo Methods Example: Computing Pi Monte Carlo methods use random numbers to solve numeric problems For example, generate uniform random x-y points in the unit square Generate x and y independently in the range [0,1] The number of points should be >= 10,000 Determine if x2 + y2 < 1 or not The ratio of points inside the circle = π/4 See pi.cpp pi = 3.141592;

Results of pi.cpp

Monte Carlo Integration Uses RNGs to approximate areas under curves, surfaces Two approaches Average function value Throwing darts (what we did with pi)

Monte Carlo Integration Average Function Value Approach Approximate the average function value on the interval (a,b) Just take the average of a large random sample of f(xi) (watch for overflow!) Multiply this by (b-a) The result ≈ area: See average.cpp

Monte Carlo Integration Dart-Throwing Approach Obtain many random points, (xi,yi) in region of interest The area of the region is known, i.e., a rectangle with width (b-a) containing the curve Count the number of yi that are less than f(xi) The percentage of “hits” (count / n) is the proportion of your region that represents an approximation of the sought-for area below the curve f(x) See darts.cpp

When to use Monte Carlo Not for simple integrals like these They’re handy for multiple integrals Or for calculating volumes defined by constraints See the homework!