An Introduction to Random Number Generators and Monte Carlo Methods Josh Gilkerson Wei Li David Owen Josh Gilkerson Wei Li David Owen.

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 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.
Generated Waypoint Efficiency: The efficiency considered here is defined as follows: As can be seen from the graph, for the obstruction radius values (200,
1 CE 530 Molecular Simulation Lecture 8 Markov Processes David A. Kofke Department of Chemical Engineering SUNY Buffalo
Random Number Generators. Why do we need random variables? random components in simulation → need for a method which generates numbers that are random.
Introduction to Cryptography and Security Mechanisms: Unit 5 Theoretical v Practical Security Dr Keith Martin McCrea
Maximum likelihood (ML) and likelihood ratio (LR) test
Maximum likelihood Conditional distribution and likelihood Maximum likelihood estimations Information in the data and likelihood Observed and Fisher’s.
Maximum likelihood (ML) and likelihood ratio (LR) test
Genetic Algorithms Can Be Used To Obtain Good Linear Congruential Generators Presented by Ben Sproat.
Chapter 4 Probability Distributions
Pseudorandom Number Generators
Statistics.
Code and Decoder Design of LDPC Codes for Gbps Systems Jeremy Thorpe Presented to: Microsoft Research
CSCE Monte Carlo Methods When you can’t do the math, simulate the process with random numbers Numerical integration to get areas/volumes Particle.
Maximum likelihood (ML)
Lecture II-2: Probability Review
Stevenson and Ozgur First Edition Introduction to Management Science with Spreadsheets McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies,
Random Number Generation Fall 2013
©2003/04 Alessandro Bogliolo Background Information theory Probability theory Algorithms.
Introduction to Monte Carlo Methods D.J.C. Mackay.
Component Reliability Analysis
1 CE 530 Molecular Simulation Lecture 7 David A. Kofke Department of Chemical Engineering SUNY Buffalo
Advanced methods of molecular dynamics Monte Carlo methods
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.
880.P20 Winter 2006 Richard Kass 1 Confidence Intervals and Upper Limits Confidence intervals (CI) are related to confidence limits (CL). To calculate.
Random Numbers CSE 331 Section 2 James Daly. Randomness Most algorithms we’ve talked about have been deterministic The same inputs always give the same.
Slide 1 Copyright © 2004 Pearson Education, Inc..
Monte Carlo Simulation and Personal Finance Jacob Foley.
1 CE 530 Molecular Simulation Lecture 17 Beyond Atoms: Simulating Molecules David A. Kofke Department of Chemical Engineering SUNY Buffalo
Section 8.1 Estimating  When  is Known In this section, we develop techniques for estimating the population mean μ using sample data. We assume that.
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 Number Generators 1. Random number generation is a method of producing a sequence of numbers that lack any discernible pattern. Random Number Generators.
Monte Carlo Methods.
Monte Carlo Methods in Statistical Mechanics Aziz Abdellahi CEDER group Materials Basics Lecture : 08/18/
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.
Simulated Annealing.
For a new configuration of the same volume V and number of molecules N, displace a randomly selected atom to a point chosen with uniform probability inside.
8. Selected Applications. Applications of Monte Carlo Method Structural and thermodynamic properties of matter [gas, liquid, solid, polymers, (bio)-macro-
Lesson 4: Computer method overview
Simulation is the process of studying the behavior of a real system by using a model that replicates the system under different scenarios. A simulation.
Molecular Modelling - Lecture 2 Techniques for Conformational Sampling Uses CHARMM force field Written in C++
Computer simulation Sep. 9, QUIZ 2 Determine whether the following experiments have discrete or continuous out comes A fair die is tossed and the.
Monte Carlo method: Basic ideas. deterministic vs. stochastic In deterministic models, the output of the model is fully determined by the parameter values.
Interacting Molecules in a Dense Fluid
An Introduction to Monte Carlo Methods in Statistical Physics Kristen A. Fichthorn The Pennsylvania State University University Park, PA
Lab for Remote Sensing Hydrology and Spatial Modeling Dept of Bioenvironmental Systems Engineering National Taiwan University 1/45 GEOSTATISTICS INTRODUCTION.
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.
1.  How does the computer generate observations from various distributions specified after input analysis?  There are two main components to the generation.
Systematic errors of MC simulations Equilibrium error averages taken before the system has reached equilibrium  Monitor the variables you are interested.
Monte Carlo methods 10/20/11.
An Introduction to Random Number Generators and Monte Carlo Methods
Parallel Programming in C with MPI and OpenMP
Chapter 3 Component Reliability Analysis of Structures.
Professor S K Dubey,VSM Amity School of Business
Lecture 2 – Monte Carlo method in finance
Computing and Statistical Data Analysis Stat 3: The Monte Carlo Method
Computer Simulation Techniques Generating Pseudo-Random Numbers
Random Number Generation
Presentation transcript:

An Introduction to Random Number Generators and Monte Carlo Methods Josh Gilkerson Wei Li David Owen Josh Gilkerson Wei Li David Owen

Random Number Generators

Uses for Random Numbers  Monte Carlo Simulations  Generation of Cryptographic Keys  Evolutionary Algorithms  Many Combinatorial Optimization Algorithms  Monte Carlo Simulations  Generation of Cryptographic Keys  Evolutionary Algorithms  Many Combinatorial Optimization Algorithms

Two Types of Random Numbers  Pseudorandom numbers are numbers that appear random, but are obtained in a deterministic, repeatable, and predictable manner.  True random numbers are generated in non- deterministic ways. They are not predictable. They are not repeatable.  Pseudorandom numbers are numbers that appear random, but are obtained in a deterministic, repeatable, and predictable manner.  True random numbers are generated in non- deterministic ways. They are not predictable. They are not repeatable.

True Random Generators  Use one of several sources of randomness –decay times of radioactive material –electrical noise from a resistor or semiconductor –radio channel or audible noise –keyboard timings  some are better than others  usually slower than PRNGs  Use one of several sources of randomness –decay times of radioactive material –electrical noise from a resistor or semiconductor –radio channel or audible noise –keyboard timings  some are better than others  usually slower than PRNGs

RNG And Random Machines  It is not viable to generate a true random number using computers since they are deterministic. However, we can generate a good enough random numbers that have properties close to true random numbers. –The first machine used to produce a table of 100,000 random digits was done by M. G. Kendall and B. Babington-Smith in –RAND Corporation in 1955 released a table of a million random digits. –ERNIE is a random number generator machine used to pick the winning numbers in the British Premium Bonds lottery.  It is not viable to generate a true random number using computers since they are deterministic. However, we can generate a good enough random numbers that have properties close to true random numbers. –The first machine used to produce a table of 100,000 random digits was done by M. G. Kendall and B. Babington-Smith in –RAND Corporation in 1955 released a table of a million random digits. –ERNIE is a random number generator machine used to pick the winning numbers in the British Premium Bonds lottery.

Desirable Properties of PRNGs  Uniform  Lengthy period  Serially uncorrelated  Fast  Uniform  Lengthy period  Serially uncorrelated  Fast

Problems With PRNG  It is very difficult to pin point the problem with random number generators when they arise. Usually, the programmers would need to replace the whole random number generator with a better ones.  With small test cases, problems rarely arises. However, when it gets to large scale random number generations (possibly in millions or even billions of numbers) the problem could be apparent. This makes debugging difficult.  In large-scale computing problems, one might need to use a parallel algorithm. The effect is that, sometimes it is not possible to duplicate the simulation exactly.  It is very difficult to pin point the problem with random number generators when they arise. Usually, the programmers would need to replace the whole random number generator with a better ones.  With small test cases, problems rarely arises. However, when it gets to large scale random number generations (possibly in millions or even billions of numbers) the problem could be apparent. This makes debugging difficult.  In large-scale computing problems, one might need to use a parallel algorithm. The effect is that, sometimes it is not possible to duplicate the simulation exactly.

Linear Congruential Generator(LCG)  Most common  Maximum period of 2 n for n-bit numbers  X n+1 =( aX n + c ) mod m  a,c,m are constants  X 0 is the seed  Most common  Maximum period of 2 n for n-bit numbers  X n+1 =( aX n + c ) mod m  a,c,m are constants  X 0 is the seed

Advantages of LCG  Most common  Very easily implemented  Fast and small (remember only last number)  Easily parallelized –N processes 1... N. –numbers for process n are X n+iN –no more expensive than serial version.  Most common  Very easily implemented  Fast and small (remember only last number)  Easily parallelized –N processes 1... N. –numbers for process n are X n+iN –no more expensive than serial version.

Disadvantages of LCGs  Other generators have longer maximum periods.  Bad choices of M result in very bad sequences (primes work best, powers of 2 are fast, but not nearly as good).  Initial seed affects period.  Low order bits are not random.  Other generators have longer maximum periods.  Bad choices of M result in very bad sequences (primes work best, powers of 2 are fast, but not nearly as good).  Initial seed affects period.  Low order bits are not random.

Lagged Fibonacci Generators  Similar to Fibonacci Sequence  Increasingly popular  X n = (X n-l + X n-k ) mod m (l>k>0)  l seeds are needed  m usually a power of 2  Maximum period of (2 l -1)x2 M-1 when m=2 M  Similar to Fibonacci Sequence  Increasingly popular  X n = (X n-l + X n-k ) mod m (l>k>0)  l seeds are needed  m usually a power of 2  Maximum period of (2 l -1)x2 M-1 when m=2 M

Add-with-carry & Subtract-with- borrow  Similar to LFG  AWC: X n =(X n-l +X n-k +carry) mod m  SWB: X n =(X n-l -X n-k -carry) mod m  Similar to LFG  AWC: X n =(X n-l +X n-k +carry) mod m  SWB: X n =(X n-l -X n-k -carry) mod m

Multiply-with-carry Generators  Similar to LCG  X n =(aX n-1 +carry) mod m  Similar to LCG  X n =(aX n-1 +carry) mod m

Inverse Congruential Generators  X n =(a * ~X n-1 + b) mod m  m should be prime  ~y is the multiplicative inverse of y in the field over {0,1,...,m-1}.  X n =(a * ~X n-1 + b) mod m  m should be prime  ~y is the multiplicative inverse of y in the field over {0,1,...,m-1}.

PRNG Review  This is just a short review. There are many other PRNGs.  Linear Congruential Generator  Lagged Fibonacci Generator  Add-with-carry Generator  Subtract-with-carry Generator  Multiply-with-carry Generator  Inverse Congruential Generator  This is just a short review. There are many other PRNGs.  Linear Congruential Generator  Lagged Fibonacci Generator  Add-with-carry Generator  Subtract-with-carry Generator  Multiply-with-carry Generator  Inverse Congruential Generator

Testing Randomness  Test for uniform distribution (of singletons, pairs, triples, etc) of the sequence and all subsequences.  DIEHARD -  NIST -  Test for uniform distribution (of singletons, pairs, triples, etc) of the sequence and all subsequences.  DIEHARD -  NIST -

Monte Carlo Methods

Introduction of Monte Carlo  Monte Carlo methods have been used for centuries.  However during World War II, this method was used to simulate the probabilistic issues with neutron diffusion (first real use).  Named after the capital of Monaco (one of the world’s center for gambling), due to the similarity to games of chance.  Monte Carlo methods have been used for centuries.  However during World War II, this method was used to simulate the probabilistic issues with neutron diffusion (first real use).  Named after the capital of Monaco (one of the world’s center for gambling), due to the similarity to games of chance.

What is Monte Carlo  Non Monte Carlo methods typically involve ODE/PDE equations that describe the system.  Monte Carlo methods are stochastic techniques.  It is based on the use of random numbers and probability statistics to simulate problems.  Something can be called a Monte Carlo method if it uses random numbers to examine the problem it is solving.  First, we would need to determine the probability density function (PDF). Then perform random sampling from the PDF. We keep record of each simulation performed and tally them.  Non Monte Carlo methods typically involve ODE/PDE equations that describe the system.  Monte Carlo methods are stochastic techniques.  It is based on the use of random numbers and probability statistics to simulate problems.  Something can be called a Monte Carlo method if it uses random numbers to examine the problem it is solving.  First, we would need to determine the probability density function (PDF). Then perform random sampling from the PDF. We keep record of each simulation performed and tally them.

Probability Density Function  A probability density function (or probability distribution function) is a function f defined on an interval (a, b) and having the following properties:

Why use Monte Carlo  It allows us to examine complex system. And is usually easy to formulate (independent of the problem).  For example, solving equations which describe two atoms interactions. This would be doable without using Monte Carlo method. But solving the interactions for thousands of atoms using the same equations is impossible.  However, the solutions are imprecise and it can be very slow if higher precision is desired.  It allows us to examine complex system. And is usually easy to formulate (independent of the problem).  For example, solving equations which describe two atoms interactions. This would be doable without using Monte Carlo method. But solving the interactions for thousands of atoms using the same equations is impossible.  However, the solutions are imprecise and it can be very slow if higher precision is desired.

Components of Monte Carlo simulation  Probability distribution functions (pdf's) - the physical (or mathematical) system must be described by a set of pdf's.  Random number generator - a source of random numbers uniformly distributed on the unit interval must be available.  Sampling rule - a prescription for sampling from the specified pdf's, assuming the availability of random numbers on the unit interval, must be given.  Scoring (or tallying) - the outcomes must be accumulated into overall tallies or scores for the quantities of interest.  Probability distribution functions (pdf's) - the physical (or mathematical) system must be described by a set of pdf's.  Random number generator - a source of random numbers uniformly distributed on the unit interval must be available.  Sampling rule - a prescription for sampling from the specified pdf's, assuming the availability of random numbers on the unit interval, must be given.  Scoring (or tallying) - the outcomes must be accumulated into overall tallies or scores for the quantities of interest.

Components of Monte Carlo simulation (cont.)  Error estimation - an estimate of the statistical error (variance) as a function of the number of trials and other quantities must be determined.  Variance reduction techniques - methods for reducing the variance in the estimated solution to reduce the computational time for Monte Carlo simulation  Parallelization and vectorization - algorithms to allow Monte Carlo methods to be implemented efficiently on advanced computer architectures.  Error estimation - an estimate of the statistical error (variance) as a function of the number of trials and other quantities must be determined.  Variance reduction techniques - methods for reducing the variance in the estimated solution to reduce the computational time for Monte Carlo simulation  Parallelization and vectorization - algorithms to allow Monte Carlo methods to be implemented efficiently on advanced computer architectures.

Monte Carlo Example Computing Pi

Monte Carlo Example (cont.)  So, we can compute PI by generating two numbers for x and y component of a simulated throw. Then we can figure out by using Pythagorean theorem if this throw is inside or outside the circle. We count this hits, and after doing this thousands of times (or more), we can get an estimate value of PI.  Accuracy of the estimate depends on the number of “throws”. An example code would be (assuming we set the radius = 1): double x = rand();// get random # in [0, 1] for x double y = rand();// get random # in [0, 1] for y double dist = sqrt(x*x + y*y); if (distFromOrigin(x,y) <= 1) hits++;  So, we can compute PI by generating two numbers for x and y component of a simulated throw. Then we can figure out by using Pythagorean theorem if this throw is inside or outside the circle. We count this hits, and after doing this thousands of times (or more), we can get an estimate value of PI.  Accuracy of the estimate depends on the number of “throws”. An example code would be (assuming we set the radius = 1): double x = rand();// get random # in [0, 1] for x double y = rand();// get random # in [0, 1] for y double dist = sqrt(x*x + y*y); if (distFromOrigin(x,y) <= 1) hits++;

What MC Needs  MC methods might needs different RNG. –For example, when simulating outgoing direction for a launched particle and interactions of the particle with the medium, the following would be the desirable properties:  The attribute of each particle should be independent from each other.  The attribute of all the particles should span across the entire attribute space. I.e., as we approach infinite numbers of particles, the particles launched into a space should cover the space completely. Next slide will states the properties of the RNG needed.  MC methods might needs different RNG. –For example, when simulating outgoing direction for a launched particle and interactions of the particle with the medium, the following would be the desirable properties:  The attribute of each particle should be independent from each other.  The attribute of all the particles should span across the entire attribute space. I.e., as we approach infinite numbers of particles, the particles launched into a space should cover the space completely. Next slide will states the properties of the RNG needed.

What MC Needs (cont.)  Any subsequence of random numbers should not be correlated with any other subsequence of random numbers. For example, when simulating the launched particles, we should not generate geometrical patterns.  Random number repetition should occur only after a very large generation of random numbers.  The random numbers generated should be uniform. This point and the first one are loosely related. To achieve more uniformity, some correlations between random numbers must be established.  The RNG should be efficient. It should be vectorizable with low overhead. The processors in parallel systems, should not be required to talk between each other.  Any subsequence of random numbers should not be correlated with any other subsequence of random numbers. For example, when simulating the launched particles, we should not generate geometrical patterns.  Random number repetition should occur only after a very large generation of random numbers.  The random numbers generated should be uniform. This point and the first one are loosely related. To achieve more uniformity, some correlations between random numbers must be established.  The RNG should be efficient. It should be vectorizable with low overhead. The processors in parallel systems, should not be required to talk between each other.

Appropriate PRNGs  The following are packages of available RNGs (  Uniform RNG in C++ & assembly language  Mersenne twister.  Mother-of-all.  RANROT.  In C, we can use drand48() to generate a double type of random number which is produced using 48-bit integers.  The following are packages of available RNGs (  Uniform RNG in C++ & assembly language  Mersenne twister.  Mother-of-all.  RANROT.  In C, we can use drand48() to generate a double type of random number which is produced using 48-bit integers.

An Application of the Monte Carlo Method The Effect of Space Discretization on the Canonical Monte Carlo Simulation

Agenda  Introduction to the Monte Carlo (MC) molecular simulation  Canonical Ensemble  Importance Sampling  Simulation Process  Simulation of the equation of state of the Lennard-Jones Fluid – Continuum Model  Discretized Model  Comparison of the simulation results  Introduction to the Monte Carlo (MC) molecular simulation  Canonical Ensemble  Importance Sampling  Simulation Process  Simulation of the equation of state of the Lennard-Jones Fluid – Continuum Model  Discretized Model  Comparison of the simulation results

Introduction  Why molecular simulation? –Help explaining experimental observations –simulate critical or extreme conditions –Guide real experiments  Purpose of this study –Long-term goal - simulation of self-assembly of surfactant solutions – fine lattice –The continuum model is not viable under the current computing power –The discretized model is at least 10 times faster compared with the continuum model –The effect of space discretization on the simulation results  Why molecular simulation? –Help explaining experimental observations –simulate critical or extreme conditions –Guide real experiments  Purpose of this study –Long-term goal - simulation of self-assembly of surfactant solutions – fine lattice –The continuum model is not viable under the current computing power –The discretized model is at least 10 times faster compared with the continuum model –The effect of space discretization on the simulation results

Canonical Ensemble  fixed number of molecules N, fixed volume V (volume), fixed temperature T  The canonical ensemble partition function from statistical mechanics  Evaluation of observable properties A  Random sampling - brute force Monte Carlo  When estimate, most of the computing is wasted  fixed number of molecules N, fixed volume V (volume), fixed temperature T  The canonical ensemble partition function from statistical mechanics  Evaluation of observable properties A  Random sampling - brute force Monte Carlo  When estimate, most of the computing is wasted

Importance Sampling Change the integration variable Standard deviation Impossible to find the weight function w in multidimensional integrals

The Metropolis Method Probability of finding the system in a configuration around r Evaluation of observable properties A Randomly generate sampling points according to the probability distribution N(r)

The Detailed Balance Generate sampling points according to the probability distribution – detailed balance If α is a symmetric matrix

Simulation Process  Initialize the system –Put the system in a random state  Make a trial move –Randomly make a trial move  Calculate the energy change –Reevaluate the interactions of the moved particles with its neighbors and calculate the energy change  Accept the trial move with the Metropolis scheme  Keep trying the moves until system approach equilibrium –Either monitor the total energy change, or monitor the structure formed in the simulation box  Sampling –Sample a certain property over a certain number of configurations  Initialize the system –Put the system in a random state  Make a trial move –Randomly make a trial move  Calculate the energy change –Reevaluate the interactions of the moved particles with its neighbors and calculate the energy change  Accept the trial move with the Metropolis scheme  Keep trying the moves until system approach equilibrium –Either monitor the total energy change, or monitor the structure formed in the simulation box  Sampling –Sample a certain property over a certain number of configurations

Continuum Model  Fixed N, V, T  Lennard-Jones potential  Intermolecular force  Virial of the system  Pressure of the system  Fixed N, V, T  Lennard-Jones potential  Intermolecular force  Virial of the system  Pressure of the system

Simulation Process Read simulation parameters Start Initialize positions of all particles New simulation? Read old configuration Monte Carlo loop Stop yesno Monte Carlo loop Subroutine Start Stop Trial move Satisfy Metropolis rule? Accept the trial move Update energy and virial Sample the pressure End of simulation? yes no yes no Main program

Parameters Modeling Potential minimum between 2 particles Average distance between 2 particles Maximum displacement of a particle Number of particles Temperature Density of the system

Simulation Results – Continuum Model

Discretized Model  Space is discretized. Particles can only move on a 3D mesh (fine lattice).  Distance between particles is a set of fixed values.  Evaluation of complex functions against distance can be precalculated.  Depends on the form the functions, the simulation can be accelerated times  Space is discretized. Particles can only move on a 3D mesh (fine lattice).  Distance between particles is a set of fixed values.  Evaluation of complex functions against distance can be precalculated.  Depends on the form the functions, the simulation can be accelerated times move

Simulation Results – Discretized Model

Conclusion  The equation of state of L-J fluid from the canonical MC simulation agrees with what reported on literature  The Discretized Model can produce results comparable to the Continuum Model  The Discretized Model can make simulations where the normal Continuum Model cannot access  The equation of state of L-J fluid from the canonical MC simulation agrees with what reported on literature  The Discretized Model can produce results comparable to the Continuum Model  The Discretized Model can make simulations where the normal Continuum Model cannot access

RNG Resources  True Random Numbers – – – –  Pseudo-random Number Generators – – – –  Others –ftp://ftp.isi.edu/in-notes/rfc1750.txtftp://ftp.isi.edu/in-notes/rfc1750.txt  True Random Numbers – – – –  Pseudo-random Number Generators – – – –  Others –ftp://ftp.isi.edu/in-notes/rfc1750.txtftp://ftp.isi.edu/in-notes/rfc1750.txt

Monte Carlo Method Resources            