40
1 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

Embed Size (px)

Citation preview

Page 1: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

1

461191 Discrete MathLecture 6: Discrete Probability

San RatanasanyaCS, KMUTNB

Page 2: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

2

Today’s topics Basic of Counting Review Administrivia Probability Baye’s Theorem Expected Value and Variance

Page 3: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

3

Basic Counting Tools Basic rules of counting

Sum rule: either task 1 or task 2 have to be done Product rule: both task 1 and task 2 have to be done Task 1 and Task 2 are independent

Inclusion and Exclusion Principle Exclude one that count more than once or irrelevant count Include one that miss

Pigeonhole Principle If there are k nest for at least k+1 pigeons, then there must be at

least one nest that has more than one pigeons

Page 4: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

4

Example How many strings of five ASCII character

contain the ‘@’ character at least once? (ASCII has 128 characters)

1285 - 1275

Page 5: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

5

Example A computer company receives 350 applications from

computer graduates for a job planning a line of new Web servers. Suppose that 220 of these people majored in CS, 147 majored in business, and 51 majored both in CS and business. How many of these applications majored in CS nor in business?

|A B| = 220 + 147 - 51 = 316 U - |A B| = 350 – 316 = 34

Page 6: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

6

Example g pigeonhole A drawer contains a dozen brown socks and a dozen black socks,

all un matched. A man takes socks out at random in the dark. How many socks must he take out to be sure that he has at least

two socks of the same color?

How many socks must he take out to be sure that he has at least two black socks?

3

14

Page 7: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

7

Binomial Coefficient THEOREM 1: The Binomial Theorem

Let x,y,n be positive integer

THEOREM 2: PASCAL’S IDENTITY Let n and k be positive integer with n > k then

THEOREM 3: Let n be positive integer, then

Page 8: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

8

Example How many terms are therein the expansion of

(x + y)15?

What is the difference between the coefficient of the term x8y3 and x5y6?

215

|C(11, 8) – C(11, 5)| = |165 – 462| = 297

Page 9: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

9

Permutations and Combinations Permutations

Ordered arrangement of a set of distinct objects. An ordered arrangement of rr elements of a set is r-r-

permutationpermutation

Combinations An unordered selection of rr elements from the set

is r-combinationr-combination

P(n, r) = n! (n - r)!

C(n, r) = P(n, r) = n! r! r!(n – r)!

Page 10: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

10

Example A group contain n men and n women. How

many ways are there to arrange these people in a row if the men and women alternate?

In how many ways can a set of five letters be selected from the English alphabet?

C(26, 5) = 65780

2(n!)2

Page 11: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

11

Generalized Permutations and Combinations

Permutations and Combinations with repetition

Permutations with Indistinguishable Objects

Distributing Objects into Boxes (4 cases) Distinguishable objects and distinguishable boxes Distinguishable objects and indistinguishable boxes Indistinguishable objects and distinguishable boxes Indistinguishable objects and indistinguishable boxes

Page 12: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

12

Example General PC How many string of six letter are there?

How many ways are there to select three unordered elements from a set with five elements when repetition is allowed?

266

C(5+3-1, 3) = C(7, 3) = 35

Page 13: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

13

Generating Permutations and Combinations Counting permutations or combinations

can solve many problems Counting is sometimes not enough. We

need to generate either one of them to find the solution.

Page 14: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

14

Example Generate PC What is the next permutation in lexicographic order

after 362541? Count number of permutations = n! -1 = 6! – 1 = 719 Lexicogrphic: aj < aj+1. Therefore, the next number is 364125

(KakuroKakuro) Let S = {1, 2, …, 9}. What are the subset that has 3 elements of S and their sum is 15? Count number of combinations = 9! / 3!6! = 84 Generate subset: {1, 5, 9}, {1, 6, 8}, {2, 4, 9}, {2, 5, 8} ,{2, 6, 7},

{3, 4, 8}, {3, 5, 7}, {4, 5, 6}

Page 15: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

15

Administrivia Midterm Exam is in next 2 weeks. Please be

prepared! All assignments MUST be submitted before

Midterm.

Page 16: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

16

Discrete Probability and Probability Theory

Page 17: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

17

Finite Probability Laplace’s definitions:

ExperimentExperiment – a procedure that yields one of a given set of possible outcomes.

Sample spaceSample space – the set of possible outcomes from the experiment.

EventEvent – a subset of the sample space.

Definition 1:If S is a finite sample space of equally likely outcomes, and E is an event, that is , a subset of S, then the probability of E is p(E) = |E| |S|

Page 18: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

18

The Probability of Combinations of Events

Theorem 1:Let E be an event in a sample space S. The probability of the event E, the complementary event of E, is given by p(E) = 1 – p(E)p(E) = 1 – p(E)

Theorem 2:Let E1 and E2 be events in sample space S. Thenp(Ep(E11 E E22) = p(E) = p(E11) + p(E) + p(E22) – p(E) – p(E11 E E22))

Page 19: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

19

Example There are many lotteries now that award enormous prizes to

people who correctly choose a set of six numbers out of the first n positive integers, where n is usually between 30 and 60. What is the probability that a person picks the correct numbers out of 40?

What is the probability that a positive integer selected at random from the set of positive integers not exceeding 100 is divisible by either 2 or 5?

1 / C(40, 6) = 1 / 3838380 = 0.00000026

0.5 + 0.2 – 0.1 = 0.6

Page 20: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

20

Probabilistic Reasoning The Monty Hall Three-door Puzzle

You are asked to select one of the 3 doors to win the price.

Once you select the door, the host, who knows what is behind each door, he opens one of the other two doors that he know is a losing door.

Then he ask you whether you would like to switch doors.

Should you change doors or keep your original selection?

You should change the door whenever you have chance!The probability of wining will change from 1/3 to 2/3

Page 21: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

21

Assigning Probabilities Let SS be the sample space of an experiment with a

finite or countable number of outcomes. We assign a probaility p(s)p(s) to each outcome ss such that these 2 conditions must be met 0 p(s)p(s) 1 for each ss SS

The function p()p() is called a probability distribution

Ss

sp 1)(

Page 22: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

22

Definition 1:Suppose that SS is a set with nn elements. The uniform distributionuniform distribution assigns the probability 1/nn to each element of SS.

Definition 2:The probability of the event E is the sum of the probabilities of the outcomes in E. That is,

(Note that when E is an infinite set, is a convergent infinite series.)

Es

spEp )()(

Es

sp )(

Page 23: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

23

Example Suppose that a die is biased so that 3 appears twice as

often as each number but that the other five outcomes are equally likely. What is the probability that an odd number appears when we roll this die?

Let E = {1, 3, 5}p(1) = p(2) = p(4) = p(5) = p(6) = 1/7; p(3) = 2/7Then p(E) = 4/7

Page 24: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

24

Conditional Probability and Independence

Definition 3:Let EE and FF be events with p(F)p(F) > 0. The conditional probability of EE given FF, denoted by p(E | F)p(E | F), is defined as p(E | F) = p(E p(E | F) = p(E F) F) p(F)p(F)

Definition 4:The events EE and FF are independent if and only if p(E p(E F) = p(E) p(F)∙ F) = p(E) p(F)∙

Page 25: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

25

Example What is the conditional probability that a family with two

kids has two boys, given they have at least one boy?

Are the events E, that a family with three kids has of both sexes, and F, that this family has at most one boy, independent?

Let E = {BB}, F = {BB, GB, BG} then E F = {BB}p(E|F) = (1/4)/(3/4) = 1/3

Yes. Because p(E F) = p(E)p(F) = 3/8

Page 26: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

26

Bernoulli Trials and the Binomial Distribution

An experiment with only 2 outcomes either SuccessSuccess or FailureFailure is called Bernoulli TrialsBernoulli Trials.

Let pp and qq be a probability of success and failure, respectively. Then, it follows that p + q = 1p + q = 1

Bernoulli TrailsBernoulli Trails are mutually independentmutually independent.

Theorem 2:The probability of exactly kk successes in nn independent Bernoulli trials, with probability of success pp and probability of failure q = 1 – pq = 1 – p, is

b(k; n, p)b(k; n, p) = C(n, k)pC(n, k)pkkqqn-kn-k

If we consider it as a function of kk, we call this function the Binomial DistributionBinomial Distribution. 1)(),(

0

n

k

nknk qpqpknC

Page 27: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

27

Random variable

Definition 5:A random variablerandom variable is a function fro the sample space of an experiment to the set of real numbers. That is, a random variable assigns a real number to each possible outcome.

Definition 6:The distributiondistribution of random variable XX on a sample space SS is the set of pairs (r, p(X = r))(r, p(X = r)) for all r r X(S)X(S), where p(X = r)p(X = r) is the probability that XX takes the value r. A distribution is usually described by specifying p(X = r)p(X = r) fro each r r X(S) X(S).

Page 28: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

28

Example Suppose that a coin is flipped three times. Let X(t) be

the random variable that equals the number of heads that appear when t is the outcome. Find X(t).

X(HHH) = 3, X(HHT) = X(HTH) = X(THH) = 2, X(TTH) = X(THT) = X(HTT) = 1, X(TTT) = 0

Because each of the eight possible outcomesHas probability of 1/8, the distribution of X(t) is given byP(X=3) = 1/8, P(X=2)=3/8, P(X=1) = 3/8, P(X=0) = 1/8

Page 29: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

29

More Examples Birthday Problem. What is the minimum number of people who

need to be in a room so that the probability that at least two of them have the same birthday is greater than 1/2?

Example 14 - 16

1- pn = 1- 365 364 363 … 367-n 366 366 366 366n = 22

Page 30: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

30

Monte Carlo Algorithms Deterministic Algorithms

Always proceed in the same way whenever given the same input.

Probabilistic Algorithms Make random choices at one or more step for its efficiency in

a huge number of possible case. Mote Carlo Algorithms

The probability that the algorithm give the correct answer increases as more test carried out.

Details in Section 6.2 page 411

Page 31: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

31

The Probabilistic Method

is used as existence proof to proof results about set S.

See Theorem 4 for example

Theorem 3:If the probability that an element of a set S does not have a particular property is less than 1, there exists an element in S with this property.

Page 32: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

32

Baye’s Theorem

Page 33: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

33

Bayes’ Theorem The probability that a particular event occurs on the basis of partial evidence,

i.e., it is like conditional probability

Theorem 1:Suppose that EE and FF are events from a sample space S S such that p(E) p(E) 0 0 and p(F) p(F) 0 0. Then P(F | E) = p(E | F)p(F)P(F | E) = p(E | F)p(F)

p(E | F)p(F) + p(E | F)p(F)p(E | F)p(F) + p(E | F)p(F)

Theorem 2: Suppose that EE is an event from a sample space S S and that FF11, F, F22, …, , …, FFnn are mutually exclusive events such that Assume that p(E) p(E) 0 0 and p(Fp(Fii) ) 0 0 for i = 1, 2, .., n. Then

n

i ii

jjj

FpFEp

FpFEpEFp

0)()|(

)()|()|(

n

i i SF0

Page 34: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

34

Example We have 2 boxes. The first box contains two green balls and seven red balls;

the second box contains four green balls and three red balls. Bob selects a ball by first choosing one of the two boxes at random. He then selects one of the balls in this box at random. If Bob has selected a red ball, what is the probability that he selected a ball from the first box?

Details in Section 6.3 on page 417

Page 35: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

35

Example: Bayesian Spam Filter Uses information about previously seen e-mail

messages whether an incoming e-mail message is spam.

Look for occurrences of particular word in messages.

See details in Section 6.3 on page 421

Page 36: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

36

Expected Value and Variance

Page 37: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

37

Definition 1: The expected value (or expectation) of the random variable X(s) on the sample space S is equal to

Expected Value (of Random Variable)

is a weighted average of the values of a random variable. provides central point for the distribution of values of the

random variable.

Ss

sXspXE )()()(

Theorem 1: If X is a random variable and p(X = r) is the probability that X = r, so that p(X = r) = , then

rsXSs

sp)(,

)(

)(

)()(SXr

rrXpXE

Page 38: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

38

Variance

Theorem 6: If X is a random variable on sample space S, then V(X) = E(X2) – E(X)2

rsXSs

sp)(,

)(

)(

)()(SXr

rrXpXE

Definition 4: Let X be a random variable on a sample space S. The variance of X, denoted by V(X), is

The standard deviation of X is defined to be

Ss

spXEsXXV )())()(()( 2

)()( XVX

Page 39: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

39

Average-case Computational Complexity

See Example 8-9 on page 431-432

Page 40: 461191 Discrete Math Lecture 6: Discrete Probability San Ratanasanya CS, KMUTNB

40

Homework Section 6.1

8, 20, 35, 38, 41 Section 6.2

18, 22, 36, 37, 39, 40 Section 6.3

5, 10, 15, 18, 23 Section 6.4

2, 7, 9, 10, 22, 23 Supplementary

2, 3, 15, 16, 21, 22