48
CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

Embed Size (px)

Citation preview

Page 1: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

CS433: Modeling and Simulation

Dr. Anis Koubâa

Al-Imam Mohammad bin Saud UniversityAl-Imam Mohammad bin Saud University

05 March 2010

Lecture 03: Probability Review

Page 2: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

2

Goals of today

Review the fundamental concepts of probability

Understand the difference between discrete and continuous random variable

Page 3: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

3

Topics

Fundamental Laws of Probability Discrete Random Variable

Probability Mass Function (PMF) Continuous Random Variable

Probability Density Function (PDF) Cumulative Distribution Function (CDF) Mean and Variance

Page 4: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

Probability Review

Page 5: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

5

Fundamentals

We measure the probability for Random Events How likely an event would occur

The set of all possible events is called Sample Space

In each experiment, an event may occur with a certain probability (Probability Measure)

Example: Tossing a dice with 6 faces The sample space is {1, 2, 3, 4, 5, 6} Getting the Event « 2 » in on experiment has a

probability 1/6

Page 6: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

6

The probability of every set of possible events is between 0 and 1, inclusive.

The probability of the whole set of outcomes is 1. Sum of all probability is equal to one Example for a dice: P(1)+P(2)+P(3)+

P(4)+P(5)+P(6)=1 If A and B are two events with no common outcomes,

then the probability of their union is the sum of their probabilities. Event E1={1}, Event E2 ={6} P(E1 U E2)=P(E1)+P(E2)

Probability

Page 7: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

7

Complementary Event of A is not(A)

P(A)=1-P(not A)

The probability that event A will not happen is

1-P(A).

Example

Event E1={1}

Probability to get a value different from {1} is 1-P(E1).

Complementary Event

Page 8: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

8

Event Union (U = OR) Event Intersection (∩= AND)

Joint Probability (A ∩ B)

The probability of two events in conjunction. It is the probability of both

events together.

Independent Events

Two events A and B are independent if

p A B p A p B p A B

p A B p A p B

Joint Probability

Page 9: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

9

p A B p A p B

Example on Independence

321

Case 1: Drawing with replacement of the ballThe second draw is independent of the first draw

1 1 11 2 1 2

3 3 9p E E p E p E

E1: Drawing Ball 1E2: Drawing Ball 2E3: Drawing Ball 3

Case 2: Drawing without replacement of the ballThe second draw is dependent on the first draw

1 1 11 2 1 2

3 2 6p E E p E p E

P(E1): 1/3P(E2):1/3P(E3): 1/3

Quiz: Show that in Case 2, we have 11 2

2p E E

Page 10: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

10

Conditional Probability Conditional Probability p(A|B) is the probability of

some event A, given the occurrence of some other event B.

If A and B are independent, then and If A and B are independent, the conditional probability of A, given

B is simply the individual probability of A alone; same for B given A.

p(A) is the prior probability; p(A|B) is called a posterior probability. Once you know B is true, the universe you care about shrinks to B.

|p A B

p A Bp B

|

p B Ap B A

P A

|p A B p A |p B A p B

Page 11: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

11

Example on Independence

321

Case 1: Drawing with replacement of the ballThe second draw is independent of the first draw

11| 2

3p E E

E1: Drawing Ball 1E2: Drawing Ball 2E3: Drawing Ball 3

Case 2: Drawing without replacement of the ballThe second draw is dependent on the first draw

11| 2

2p E E

P(E1): 1/3P(E2):1/3P(E3): 1/3

|p A B

p A Bp B

1 11 2 13 31| 2

12 33

p E Ep E E

p E

1 11 2 13 21| 2

12 23

p E Ep E E

p E

Page 12: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

12

Baye’s Rule

We know that

Using Conditional Probability definition, we have

The Bayes rule is:

|

|p B A p A

p A Bp B

p A B p B A

| |p A B P B p B A P A

Page 13: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

13

|p A E p A N

Law of Total Probability In probability theory, the law of total

probability means the prior probability of A, P(A), is equal to

the expected value of the posterior probability of A.

That is, for any random variable N,

where p(A|N) is the conditional probability of A given N.

Page 14: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

14

Law of Total Probability Law of alternatives: The term law of total

probability is sometimes taken to mean the law of alternatives, which is a special case of the law of total probability applying to discrete random variables.

if { Bn : n = 1, 2, 3, ... } is a finite partition of a

probability space and each set Bn is measurable,

then for any event A we have

or, alternatively, (using Rule of Conditional Probability)

nn

p A p A B

| nn

p A p A B p B

Page 15: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

15

Example: Law of Total Probability

1 2 3{3}

0 {3} {2,3,6} 0 {3}

p A p p A B p A B p A B

p p

{1,2,3,4,5,6,7}S

2 {2,3,6}B 3 {4,7}B 1 {1,5}B

Sample Space

Partitions

Event {3}A

Law of Total Probability

Page 16: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

Five Minutes Break

You are free to discuss with your classmates about the previous slides, or to refresh a bit, or to ask questions.

Administrative issues Groups Formation (mandatory to do it this week)

Page 17: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

17

A random variable

► Random variable is a measurable function from a sample space of events to the measurable space S of values of possible values of the variable

:

i i

X S

E x

Event Value

Each value/event has a probability of occurrence

Page 18: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

18

A random variable

► Random Variable is also know as stochastic variable.► A random variable is not a variable. It is a

function. It maps from the sample space to the real numbers.

► random variable is defined as a quantity whose values are random and to which a probability distribution is assigned.

Page 19: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

19

A random variable: Examples.

► The number of packets that arrives to the

destination

► The waiting time of a customer in a queue

► The number of cars that enters the parking

each hour

► The number of students that succeed in the

exam

Page 20: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

20

Random Variable Types► Discrete Random Variable:

► possible values are discrete (countable sample space, Integer values)

► Continuous Random Variable: ► possible values are continuous (uncountable

space, Real values)

: {1,2,3,4,...}

i i

X

E x

: 1.4,32.3

i i

X

E x

Page 21: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

21

Discrete Random Variable The probability distribution for discrete

random variable is called Probability Mass Function (PMF).

Properties of PMF

Cumulative Distribution Function (CDF)

Mean value

0 1 ip x 1 ii

p x

i ip x P X x

and

( )i

ix xp X x p x

1

n

X i ii

E X x p x

Page 22: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

22

Discrete Random Variable Mean (Expected) value

Variance

1

n

X i ii

E X x p x

2 22 2XV X E X E X E X E X

2

2

1 1

n n

i i i ii i

V X x p x x p x

General Equation

For Discrete RV

2

1

n

i x ii

V X x p x

Page 23: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

23

Discrete Random Variable: Example Random Variable: Grades of the students

21 1 0.2

10p P X

Student ID

1 2 3 4 5 6 7 8 9 10

Grade 3 2 3 1 2 3 1 3 2 2

42 2 0.4

10p P X

43 3 0.4

10p P X

Probability Mass Function

0 1 1p

0 2 1p

0 3 1p

PDF

Grade

Page 24: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

24

Discrete Random Variable: Example Random Variable: Grades of the students

Student ID

1 2 3 4 5 6 7 8 9 10

Grade 3 2 3 1 2 3 1 3 2 2

Probability Mass Function Property 1 2 3 1i

i

p x p p p

Cumulative Distribution Function

( )i

ix xp X x p x

2

2 ( ) 1 2 0.2 0.4 0.6i

ixp X p x p p

CDF

Grade

2

3 ( ) 1 2 3 1i

ixp X p x p p p

Page 25: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

25

Discrete Random Variable: Example Random Variable: Grades of the students

Student ID

1 2 3 4 5 6 7 8 9 10

Grade 3 2 3 1 2 3 1 3 2 2

The Mean Value

1 0 2 2 0 4 3 0 4 2 2i ii

x p x . . . .

2 210

i

Grade

.

Page 26: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

26

Continuous Random Variable The probability distribution for continuous

random variable is called Probability Density Function (PDF).

The probability of a given value is always 0 The sample space is infinite

For continuous random variable, we compute Properties of PDF

f x

X

R

X

Rxxf

dxxf

Rxxf

X

in not is if ,0)( 3.

1)( 2.

in allfor , 0)( 1.

0ip x x

p a x b

Page 27: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

27

Continuous Random Variable Cumulative Distribution Function (CDF)

Mean/Expected value

Variance

( )i

ix xp X x p x

0x

p X x f t dt

b

ap a X b f x dx

X E X x f x dx

2xV X x f x dx

2 2xV X x f x dx

and

Page 28: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

28

Discrete versus Continuous Random Variables

Discrete Random Variable Continuous Random Variable

Finite Sample Space

e.g. {0, 1, 2, 3}

Infinite Sample Space

e.g. [0,1], [2.1, 5.3]

1

1. ( ) 0, for all

2. ( ) 1

i

ii

p x i

p x

i ip x P X x

Cumulative Distribution Function (CDF)

f xProbability Density Function

(PDF)

X

R

X

Rxxf

dxxf

Rxxf

X

in not is if ,0)( 3.

1)( 2.

in allfor , 0)( 1.

p X x

( )i

ix xp X x p x

0

xp X x f t dt

b

ap a X b f x dx

Probability Mass Function (PMF)

Page 29: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

29

Continuous Random Variables: Example

Example: modeling the waiting time in a queue

People waiting for service in bank queue

Time is a continuous random variable Random Time is typically modeled as exponential

distribution is the mean value 1

exp , 0( )

0, otherwise

xx

f x

Exponential DistributionExp (µ)

Page 30: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

30

Continuous Random Variables: Example

We assume that with average waiting time of one customer is 2 minutes

otherwise ,0

0 x,2

1)(

2/xexf

PDF: f (time)

time

Page 31: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

31

Continuous Random Variables: Example

Probability that the customer waits exactly 3 minutes is:

Probability that the customer waits between 2 and 3 minutes is:

The Probability that the customer waits less than 2 minutes

3 /2

2

1(2 3) 0.145

2xP x e dx

3 /2

3

1( 3) (3 3) 0

2xP x P x e dx

1(0 2) (2) (0) (2) 1 0.632P X F F F e

145.0)1()1()2()3()32( 1)2/3( eeFFXP CDF

CDF

Page 32: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

32

Continuous Random Variables: Example

The mean of life of the previous device is:

To compute variance of X, we first compute E(X2):

Hence, the variance and standard deviation of the device’s life are:

/2 /2

0 00

1( ) 2

2

/2x xE X xe dx e dxxxe

82/22

1)(

0

2/

00

2/22

dxexdxexXE xx ex

2)(

428)( 2

XV

XV

Expected Value and Variance

Page 33: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

Two Minutes Break

You are free to discuss with your classmates about the previous slides, or to refresh a bit, or to ask questions.

Administrative issues Groups Formation (mandatory to do it this week)

Page 34: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

34

Variance

The standard deviation is defined as the square root of the variance, i.e.:

2X X V X s

Page 35: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

35

Coefficient of Variation

The Coefficient of Variance of the random variable X is defined as:

X

X

V XCV X

E X

Page 36: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

End of lectureThere are some additional slides afterwards that

may help to explain some concepts

Page 37: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

37

Discrete Probability Distribution

The probability distribution of a discrete

random variable is a list of probabilities

associated with each of its possible values.

It is also sometimes called the probability

function or the probability mass function

(PMF) for discrete random variable.

Page 38: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

38

Probability Mass Function (PMF) Formally

the probability distribution or probability mass function (PMF) of a discrete random variable X is a function that gives the probability p(xi) that the random variable equals xi, for each value xi:

It satisfies the following conditions: 0 1 ip x

1 ii

p x

i ip x P X x

Page 39: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

39

Continuous Random Variable

A continuous random variable is one which takes an infinite number of possible values.

Continuous random variables are usually measurements. Examples include height, weight, the amount of sugar

in an orange, the time required to run a mile.

Page 40: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

40

Probability Density Function (PDF) For the case of continuous variables, we do

not want to ask what the probability of "1/6" is, because the answer is always 0...

Rather, we ask what is the probability that the value is in the interval (a,b).

So for continuous variables, we care about the derivative of the distribution function at a point (that's the derivative of an integral). This is called a probability density function (PDF).

The probability that a random variable has a value in a set A is the integral of the p.d.f. over that set A.

Page 41: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

41

Probability Density Function (PDF) The Probability Density Function (PDF) of a

continuous random variable is a function that can be integrated to obtain the probability that the random variable takes a value in a given interval.

More formally, the probability density function, f(x), of a continuous random variable X is the derivative of the cumulative distribution function F(x):

Since F(x)=P(X≤x), it follows that:

d

f x F xdx

b

a

F b F a P a X b f x dx

Page 42: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

42

Cumulative Distribution Function (CDF)

The Cumulative Distribution Function (CDF) is a function giving the probability that the random variable X is less than or equal to x, for every value x.

Formally the cumulative distribution function F(x) is defined

to be:

,

x

F x P X x

Page 43: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

43

Cumulative Distribution Function (CDF)

For a discrete random variable, the cumulative distribution function is found by summing up the probabilities as in the example below.

For a continuous random variable, the cumulative distribution function is the integral of its probability density function f(x).

,

( ) ( )

i i

i ix x x x

x

F x P X x P X x p x

b

a

F a F b P a X b f x dx

Page 44: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

44

Cumulative Distribution Function (CDF)

► Example ► Discrete case: Suppose a random variable X has

the following probability mass function p(xi):

► The cumulative distribution function F(x) is then:

xi 0 1 2 3 4 5

p(xi) 1/32 5/32 10/32 10/32 5/32 1/32

xi 0 1 2 3 4 5

F(xi) 1/32 6/32 16/32 26/32 31/32 32/32

Page 45: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

45

Mean or Expected Value

1

n

X i ii

E X x p x

X E X x f x dx

Page 46: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

46

Example: Mean and variance

When a die is thrown, each of the possible faces 1, 2, 3, 4, 5, 6 (the xi's) has a probability of 1/6 (the p(xi)'s) of showing. The expected value of the face showing is therefore:

µ = E(X) = (1 x 1/6) + (2 x 1/6) + (3 x 1/6) + (4 x 1/6) + (5 x 1/6) + (6 x 1/6) = 3.5

Notice that, in this case, E(X) is 3.5, which is not a possible value of X.

Page 47: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

47

Variance

The variance is a measure of the 'spread' of a distribution about its average value.

Variance is symbolized by V(X) or Var(X) or σ2.

The mean is a way to describe the location of a distribution,

the variance is a way to capture its scale or degree of being spread out. The unit of variance is the square of the unit of the original variable.

Page 48: CS433: Modeling and Simulation Dr. Anis Koubâa Al-Imam Mohammad bin Saud University 05 March 2010 Lecture 03: Probability Review

48

Variance The Variance of the random variable X is

defined as:

where E(X) is the expected value of the random variable X.

The standard deviation is defined as the square root of the variance, i.e.:

2 22 2XV X E X E X E X E X

2X X V X s