Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in...

20
Monte Carlo Simulation in complex systems

Transcript of Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in...

Page 1: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

Monte Carlo Simulation in complex systems

Page 2: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

2

Monte Carlo Simulation

• W.S. Gosset in 1908 realised potential of random sampling to generate a random variable

• Von Neumann, Ulam and Metropolis developed algorithms for computer implementation.

• Ulam and Metropolis published the first paper on Monte Carlo in 1949

Page 3: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

3

Uses of Monte Carlo simulations

There are two main uses:1. Computing of definite integrals to yield

an estimate. E.g. PI, or the Value of a stock option contract

2. Mapping out probability distribution e.g. for risk measurement.

Page 4: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

4

Complex Systems Parameter Space

• Complex Systems Characteristics– Large number of components– Many interactions– Large Parameter space– Uncertainty in value of parameters– Uncertainty in outcomes

• Stochastic (unpredictable) behaviour

Page 5: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

5

Examples of Relevant Systems

• Systems with a number of humans interacting through an environment: E.g.– Airspace: containing Aircraft, Pilots, Air Traffic

Controllers, and airlines.– Markets: Contain sellers and buyers.– Risk Measurement / Risk management

Page 6: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

6

Examples of Relevant Systems

• Physical systems:– Thermodynamics– Quantum Mechanical Systems– Quantum Computation– Quantum Chemistry

• Mathematics– Numerical integration, multiple integrals– Does not suffer from curse of dimensionality

Page 7: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

7

Solution of definite problems

• Integration• Requires convergence• In 1864 captain O.C. Fox Computed PI

dropping Needle over floor boards using Buffon’s needle problem: pdf ~ 1/dπ

Page 8: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

8

Parameter Sweep or Scenario Analysis

• Two obvious ways to search the parameter space:– Parameter Sweep

Scan through all possible values of every parameter and simulate/solve system model.

Problem? Very computationally intensive and slow

– Scenario AnalysisSelect key parameters and choose several critical values of

these parameters and solve. Advantages: Much faster and gives a good overview of system

behaviour.Problem? Statistical significance of outcomes is unknown

Page 9: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

9

Monte Carlo Simulation• An extension of the scenario approach where

key parameters are varied and solution recomputed and recorded.– The difference is that the parameter values are

randomly chosen from an appropriate probability distribution which is either based on theory or fitted to experimental data.

– Advantages: Better picture of parameter space with statistically appropriate outcomes. An iterative refinement approach can be used to speed up simulation by fixing parameters to which system is less sensitive.

– Disadvantages: Slower than scenario analysis

Page 10: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

10

Procedure1. Specify problem2. Develop mathematical model3. Identify key parameters4. Select probability distributions

– The potential absence of good data makes this a possible grey area where intuition and experience are as valuable as rigorous analysis. A bit of black magic and taking a risk.

– But remember the bottom line, any sensible distribution is better than a single valued assumption for a parameter we know is highly variable

– Financial markets are a classic example:• Price of oil when planning to drill well for exploration

Page 11: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

11

Procedure

5. Iterate simulation many times while drawing random values of each Monte Carlo variable from distribution:

Pseudo Random number Generation:This is a whole science/art in itself as it is important to note:• The outputs of pseudorandom number generators are of course

not truly random. Pattern repeat after a time.• Von Neumann- “Anyone who considers arithmetical methods of

producing random numbers is, of course, in a state of sin.”Critical for:

– Cryptography– Monte Carlo Methods-….

Page 12: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

12

Pseudorandom Number Generation (PRNG)

There do exist hardware random number generators. Truly random.

• PRNG Techniques:First PRNG – Von Neumann 1946:– Take a number- e.g. 1111 (Seed), square it to get: 1234321.

Take 4 of the middle digits to get: 3432, this is your first random number. Repeat to get: 7786, and continue.

– Problem: Sequence repeats too quickly.– However much better algorithms now exist: “Mersenne twister”

which is fast and has a period of 219937-1 !

Page 13: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

13

Procedure

6. Store relevant values of systems variables for each iteration and at each time step.

• This requires some careful management of data as can easily run out of memory. Good computational tools are a must.

• Suggestion: For prototyping and even final model, Matlab is extremely attractive.

Page 14: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

14

Procedure7. Stopping the simulation, two possible criteria:

• Time: Simulation is running over a specified real world period and the final time is reached for the required number of iterations

• Convergence: Either when expected value of Integral converges or sufficient statistics are gathered to map out the probability distribution of the results. Particularly relevant for risk analysis where the tails of the distribution are most relevant but are sampled infrequently.

8. Compute Statistics:• After simulation has finished, take each system variable of

interest and create and array which contains all simulated values of the particular variable. This data can be used to fit a distribution and then calculate moments (mean, std, and others) or the moments can be calculated directly from the data.

Page 15: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

15

Probabilistic/Stochastic Cellular Automata

• Introduce noise: Stochastic CA’s

Page 16: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

16

Simple Excel Example: Two Aircraft Collision

• Random winds in 2-D• Changes velocity Vector

Monte Carlo AC positions

-100.00

-80.00

-60.00

-40.00

-20.00

0.00

20.00

40.00

60.00

80.00

100.00

0.00 20.00 40.00 60.00 80.00 100.00

x (Metres)

y (M

etre

s)

Aircraft 1Aircraft 2

Monte Carlo AC positions

-100.00

-80.00

-60.00

-40.00

-20.00

0.00

20.00

40.00

60.00

80.00

100.00

0.00 20.00 40.00 60.00 80.00 100.00

x (Metres)y

(Met

res)

Aircraft 1Aircraft 2

Page 17: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

17

Simulation Example

Example simulation

Page 18: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

18

Air Traffic Control Example

• Prolog Simulation - Key random Variables– Selection of activity: Probability distribution: Discrete

Page 19: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

19

Data Analysis ExampleEvents

0

200

400

600

800

1000

1200

0 35 70 105

140

175

210

245

280

315

350

385

420

455

490

525

560

595

630

665

700

735

770

805

840

875

910

945

980

Time (seconds)

Num

ber o

f Eve

nts

conflict_identificationconflict_resolutiondo_nothingmonitor_monitormonitor_resolvedseparation_violation

Page 20: Monte Carlo Simulation in complex systems - ACCS · 2 Monte Carlo Simulation • W.S. Gosset in 1908 realised potential of random sampling to generate a random variable • Von Neumann,

20

Simulation Statistics

Occurance of Flight Level Changes

0

50

100

150

200

250

300

350

400

450

500

1 2 3 4 5 6

Number of FL Changes

Freq

uenc

y

Series2