F19 Introduction to Monte Carlo simulations - KTH · 2015-05-14 · Monte Carlo methods: simulation...

Preview:

Citation preview

F19: Introduction to Monte Carlo simulations

Ebrahim Shayesteh

2

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

3

Repetition: fault models

Note: "Non-repairable systems” A summary of functions to describe the stochastic

variable T (when a failure occurs):

tFtF

tRtftz

tRtFtftFtTPtR

tTPtF

1

)(1

Cumulativedistributionfunction:

survivorfunction:

Probabilitydensity function:

Failure rate:

4

Repetition: repairable systems

X (t)

t

1

0T 1 D 1 D 2 D 3T 2 T 3 T 4

Mean Time To Failure (MTTF) Mean Down Time (MDT) Mean Time To Repair (MTTR), sometimes, but not

always the same as MDT Mean Time Between Failure (MTBF = MTTF + MDT)

Repairable systems: ”alternating renewal process”

5

Repetition: repairable systems

The “availability” for a unit is defined as theprobability that the unit is operational at a given time t

1

Note:– if the unit cannot be repaired A (t) = R (t)– if the unit can be repaired, the availability will

depend both on the lifetime distribution and therepair time.

6

Repetition: repairable systems

The share of when the unit has been working thus becomes:

It results when ∞ in:

T

T D

nT

nT

nD

ii

n

ii

n

ii

n

ii

n

ii

n

ii

n

1

1 1

1

1 1

1

1 1

AE T

E T E DMTTF

MTTF MDTav

7

Repetition: repairable systems

The failure frequency (referred to as either ω or f) during the totaltime interval i is provided by:

MDTMTTFf

1

Note the difference between failure rate (λ = 1/MTTF) andfailure frequency (f = 1/MTBF).

For short down time compared to the operation time (i.e.MDT << MTTF), this difference is negligible: λ≈f.

o This assumption is often applicable and used within reliabilityanalyses of power distribution!

8

System of components

A technical system can be described as consisting of a number of

functional blocks that are interconnected to perform a number of

required functions – where components are modeled as blocks.

There are two fundamental system categories:

1. Serial systems (often in power distribution contexts referred to as

radial system/lines/feeders)

2. Parallel systems

• Often, a system can be seen as a composition of several

subsystems of these two fundamental types

9

Methods: approximate equations

Approximate equations for a serial system (MDT << MTTF is assumed):• Failure rate,

Unit, e.g: [failures/year]:

• Unavailability, Unit, e.g: [hours/year]:

• Average repair time, Unit, e.g: [hours]:

n

iis

1

i

n

iis rU

1

s

ss

Ur

10

Methods: approximate equations

Approximate equations for a parallel system (MDT << MTTF is assumed):

• Failure rate, Unit, e.g: [failures/year]:

• Unavailability, Unit, e.g: [hours/year]:

• Average repair time, Unit, e.g: [hours]:

)(1

)(2121

2211

2121 rrrr

rrp

21

21

rrrrrp

2121 rrrU ppp

11

System indices

Additional reliability measures - System indices Previously calculated measures for system reliability λs, Us

and rs specifies expected values, or mean, of a probabilitydistribution.

These measures however not describe the impact of a faultwhich can mean significant differences for different loadpoints:• For example a load point with one customer and a load of

load 10 kW and another with 100 customers and load of500 MW.

In order to take into account more aspects, system indicesare calculated.

12

System indicesCustomer-oriented reliability indices

System average interruption frequency index SAIFI [failures/year, customer]

∑ λ∑

λi is the failure rate of load point i (LPi) and Ni is equal to number of customersin LPi

Customer average interruption frequency index CAIFI [Failure/year, customer]

∑ λ∑ ⊂

13

System indicesCustomer-oriented reliability indices

System average interruption duration index SAIDI [hours/year, customer]:

∑∑

Customer average interruption duration index CAIDI [hours/failure]:

∑∑ λ

Ui is the outage time of load point i (LPi) and Ni is equal to number ofcustomers in Lpi

14

System indices

Average service availability index (ASAI) [probability between 0 and 1] or [%]:

∑ 8760 ∑∑ 8760

where 8760 is number of hours/year

Also Average service unavailability index (ASUI) are used:ASUI = 1-ASAI

15

System indicesEnergy-oriented reliability indices

Energy not supplied index (ENS) [kWh/year]

Average energy not supplied index (AENS) [kWh/year, customer]

∑∑ ∑

Ui is the outage time of load point i (LPi), Ni is equal to number

of customers in Lpi and La(i) is average average load of Lpi :

16

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

17

A class of methods used to solve mathematical problems by studyingrandom samples.

It is, in another word, an experimental approach to solve a problem.

Theoretical basis of Monte Carlo is the Law of Large Numbers:• The average of several independent stochastic variables with the same

expected value m is close to m, when the number of stochasticvariables is large enough.

• The result is that:

∑ → → ∞

∑ → → ∞

Monte Carlo methods: background

18

Monte Carlo methods: background

The second most important (i.e., useful) theoretical result for Monte Carlo isthe Central Limit Theorem.

CLT: The sum of a sufficiently large number of independent identicallydistributed random variables becomes normally distributed as N increases.

This is useful for us because we can draw useful conclusions from theresults from a large number of samples (e.g., 68.7% within one standarddeviation, etc.).

19

Monte Carlo methods: simulation

The word “simulation” in Monte Carlo Simulation is derived from Latinsimulare, which means “to make like”.

Thus, a simulation is an attempt to imitate natural or technical systems.

Different simulation methods:• Physical simulation: Study a copy of the original system which is

usually smaller and less expensive than the real system.

• Computer simulation: Study a mathematical model of the originalsystem.

• Interactive simulation: Study a system (either physical or a computersimulation) and its human operators.

20

Monte Carlo methods: simulation

Inputs:• The inputs are random variables with known probability distributions.

• For convenience, we collect all input variables in a vector, Y.

g(Y)Y X

21

Monte Carlo methods: simulation

Model:• The model is represented by the mathematical function, g(Y).

• The random behavior of the system is captured by the inputs, i.e., themodel is deterministic! Hence, if x1 = g(y1), x2 = g(y2) and y1 = y2 then x1 = x2.

g(Y)Y X

22

Monte Carlo methods: simulation

Outputs:• The outputs are random variables with unknown probability

distributions.

• For convenience, we collect all output variables in a vector, X.

The objective of the simulation is to study the probability distribution of X!.

g(Y)Y X

23

Monte Carlo methods: simulation example

Inputs:• The status of all primary lines, all lateral lines, and the amount of power

consumption and number of customers at each load points.

Model:• The structure of the distribution system given the above inputs.

Outputs:• The reliability measures, e.g., the value of system indices.

g(Y)Y X

24

Monte Carlo methods: motivation

Assume that we want to calculate the expectation value, E[X], of thesystem X = g(Y).

According to the definition of expectation value we get the followingexpression:

What reasons are there to solve this problem using Monte Carlo methodsrather than analytical methods?

25

Monte Carlo methods: motivation

Complexity: The model g(y) may not be an explicit function.• Example: The outputs, x, are given by the solution to an optimization

problem, where the inputs y appear as parameters, i.e.,

Problem size: The model may have too many inputs or outputs.• Example: 10 inputs ⇒ integrate over 10 dimensions!

26

Monte Carlo methods: motivationAnalytic model or simulation method?

The analytic models are usually valid under certain restrictive assumptionssuch as independence of the inputs, limited status number, etc. MC methodcan be used for large problems with multiple status.

Physical visibility of a complex system is higher in the simulation method.

The analytical methods are more accurate than simulations as long as nosimplifying assumption is considered. Otherwise, it cannot be compared.

In the case of future development in the system, simulation methods aremore appropriate since future developments may be more tractable.

For small systems, the analytic methods are faster while enough randomscenarios need to be simulated in MC method which takes longer time.

27

Monte Carlo methods: motivationAnalytic model or simulation method?

Advantages of each method:

Analitical Monte-CarloExact results if there are limited

assumptionsThe analyses are very flexible

The outputs are fast once the model is obtained

The model extention is easy

Computer is not necessarilyneeded

It can easily be understood

28

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

29

Example 1: Buffon’s needle

The position of the needle can be described using two parameters:• a = least distance from the needle center to one of the parallel lines

(0 ≤ a ≤ d/2).• ϑ = least angle between the needle direction and the parallel lines

(0 ≤ ϑ ≤ π/2).

The needle will cross a line if its projection on a line perpendicular to theparallel lines is larger than the distance to the closest line, i.e. if:

Pi and Buffon's Matches - Numberphile.mp4 (from YouTube)

30

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

31

Simple Sampling: introduction

Simple sampling means that completely random observations (samples) of arandom variable, X, are collected.

A sufficient number of samples will provide an estimate of E[X] according tothe law of large numbers:

Simple sampling can also be used to estimate other statistical properties (forexample variance or probability distribution) of X:

g(Y)Y X

Exercise: Show that

32

Simple Sampling: computer simulation

In the computer simulation problem, we generate samples by randomizingthe input values, yi, and calculate the outcome xi = g(yi).

Then, the expected value and variance of all samples are calculated.

g(Y)Y X

33

Simple Sampling: random numbers

How do we generate the inputs Y to a computer simulation?

A pseudo-random number generator provides U(0, 1)- distributed randomnumbers.

Y generally has some other distribution.

There are several methods to transform U(0, 1)- distributed random numbersto an arbitrary distribution.

One example method is to use the inverse transform method.

g(Y)Y X

34

Simple Sampling: random numbers

Inverse transform method:

Theorem: If a random variable U is U(0, 1)-distributed then hasthe distribution function .

g(Y)Y X

35

Simple Sampling: random numbers

Inverse transform method example:

A pseudo-random number generator providing U(0, 1)-distributed randomnumbers has generated the value U = 0.40.

• a) Transform U to a result of throwing a fair six-sided dice.

• b) Transform U to a result from a U(10, 20)-distribution.

36

Simple Sampling: random numbers

Inverse transform method example:

A pseudo-random number generator providing U(0, 1)-distributed randomnumbers has generated the value U = 0.40.

• a) Transform U to a result of throwing a fair six-sided dice.Answer:

37

Simple Sampling: random numbers

Inverse transform method example:

A pseudo-random number generator providing U(0, 1)-distributed randomnumbers has generated the value U = 0.40.

• b) Transform U to a result from a U(10, 20)-distribution.Answer: The inverse distribution function is given by

38

Simple Sampling: computer simulation

Therefore, the computer simulation problem can be updated as follows:

g(Y)Y X

39

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

40

Example 2: Travel time from A to B

Questions:

• a) Estimate the expected travel time from A to B!

• b) Estimate Var[X] assuming that 1000 scenarios of the system inexample 6 have been generated, and the following results are obtained:

41

Example 2: Travel time from A to B

Questions:

• a) Estimate the expected travel time from A to B!Answer:

42

Example 2: Travel time from A to B

Questions:

• a) Estimate Var[X] assuming that 1000 scenarios of the system inexample 6 have been generated, and the following results are obtained:

Answer:

43

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

44

Accuracy: Variance reduction techniques

A Monte Carlo simulation does not converge towards the true expectationvalue in the same sense as the geometric series is converging to 1.

As we collect more samples, the probability of getting an inaccurateestimate is decreasing, but there is no guarantee that we get a betterestimate if we generate another sample.

It is more or less inevitable that the result of a Monte Carlo simulation isinaccurate—the question is how inaccurate it is!

45

Remember that MX is a random variable and E[MX] = E[X].

Hence, Var[MX] is an indicator of the accuracy of the simulation method.

Accuracy: Variance reduction techniques

46

Theorem: In simple sampling, the variance of the estimated expectationvalue is:

For infinite populations we get:

Accuracy: Variance reduction techniques

47

We have in many cases some knowledge about the system to besimulated.

This knowledge can be used to improve the accuracy of the simulation.

Methods based on some knowledge of the system are called variancereduction techniques, since improving the accuracy is equivalent toreducing Var[MX].

Accuracy: Variance reduction techniques

48

Some examples of such techniques are as follows:

• Complementary random numbers

• Dagger Sampling

• Control Variates

• Correlated Sampling

• Importance Sampling

• Strata Sampling

Accuracy: Variance reduction techniques

49

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

50

All observations in simple sampling are independent of each other.

Sometimes it is possible to increase the probability of a good selection ofsamples if the samples are not independent.

VRT 1: Complementary random numbers

51

Consider two estimates MX1 and MX2 of the same expectation value μX,i.e.,

Study the mean of these estimates, i.e.,

Expectation value:

i.e., the combined estimate MX is also an estimate of μX.

VRT 1: Complementary random numbers

52

Variance:

If MX1 and MX2 both are independent estimates obtained with simplesampling and the number of samples is the same in both simulations, thenwe get Var[MX1] = Var[MX2] and Cov[MX1, MX2] = 0. Hence,

VRT 1: Complementary random numbers

53

Variance:

The variance obtained is equivalent to one run of simple sampling using 2nsamples; according to theorem mentioned, we should get half the variancewhen the number of samples is doubled.

However, if the MX1 and MX2 are not independent but negatively correlatedthen the covariance term will make Var[MX] smaller than the correspondingvariance for simple sampling using the same number of samples.

VRT 1: Complementary random numbers

54

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

55

Example 3: DC OPF problem

Question: How many random number do we need?Answer: 11 random numbers (3+4+4=11)

56

Example 3: DC OPF problemAnswer:

Question: Which technique is the best?

57

Agenda Introduction and repetition

Monte Carlo methods: Background, Introduction, Motivation

Example 1: Buffon’s needle

Simple Sampling

Example 2: Travel time from A to B

Accuracy: Variance reduction techniques

VRT 1: Complementary random numbers

Example 3: DC OPF problem

58

Agenda

Thank you!

Recommended