Chapter 4: Probability - programming tutorials exercises

Download Report

Transcript Chapter 4: Probability - programming tutorials exercises

Chapter 4: Probability
What is probability?
 A value between zero and one that describe the
relative possibility(change or likelihood) an event
occurs.
 The MEF announces that in 2012 the change
Cambodia economic growth rate is equal to 7% is
80%.
 The weather forecast announces that there is a
70 % change of rain for Phnom Penh Saturday.
The 3 keywords used in probability:
Experiment: A process that leads to the
occurrence of one and only one of possible
outcomes.
In probability, an experiment has two or more
results/outcomes and it is uncertain which will
occur.
Outcome: A particular result of an experiment
Event: A subset or collection of one ore more
outcomes of experiment
Example: Rolling a die
Experiment
Roll a die
a1
a2
a3
All possible outcomes
a4
a5
a6
Get an even number
Get a 3 or less
Some possible events
Get A number greater than 5
Types of Probability
Types of
Probability
Objective
Probability
Classical
Probability
Subject
Probability
Empirical
Probability
 Classical Probability: The probability that is based
on the assumption that the outcomes of an
experiments are equally likely.
 Example: Consider the experiment of rolling a sixsided die. What is the probability of the event “an
odd number of spots face up”?
Solution: Possible outcomes are:
a 1-spot
a 2-spot
a 3-spot
a 4-spot
a 5-spot
a 6-spot
The favorable(odd number of spots) outcomes
are: a 1-spot a 3-spot a 5-spot
Therefore, the probability of an odd number
of spots face up is:
Probability=3/6=0.5
Mutually excusive: The occurrence of any one
event means that none of other events can
occur at the same time. In rolling a die
experiment, the event of “an odd number of
spots face up” and the event of “an even
number of spots face up” can not occur at the
same time.
 Empirical Probability: The probability that is
based on the empirical conception of probability.
 It is much influenced by the similar events
happened in the past.
Example: A study of 800 information technology
graduates at the IIC university revealed that 235
of the 800 were not employed in their major area
of study in college. For example, a person who
majored in computer network is now the
marketing manager of a Luxury company.
What is the probability that a particular
information technology graduate will be
employed in the area other than his or her
college major?
Solution:
Probability=P(A)=235/800=0.29
P(A) means the probability of an event A that a
particular information technology graduate
will be employed in the area other than
his/her college major.
Subjective Probability: The probability that is
based on evaluating available opinions and
other information.
It is not or little influenced by the past
experience.
Example:
-Estimating the change that you will earn an A
in this course.
-What is the probability that the Honda
company will exceed the value 24000 in the
next year?
Some rules of Probability:
 Rules of Addition
 The events must be mutually exclusive
 If two events A and B are mutually exclusive, the
special rule of addition is:
P(A or B)=P(A)+P(B)
Example: An automatic Shaw machine fills plastic
bags with a mixture of beans, broccoli, and other
vegetables. Most of the bags contain the correct
weight, but because of the slight variation in the
size of beans and other vegetables, a package
might be slightly underweight or overweight. A
check of 4,000 bags filled in the past month
revealed:
Weight
Event
Underweight A
Satisfy
B
Overweight
C
Number of Probability of
Bags
Occurrences
100
3,600
0.025
0.900
300
0.075
What is the probability that a particular bag will be underweight or
overweight?
Solution:
P(A or C)=P(A)+P(C)
=0.025+0.075=0.10
A Ven diagram is a useful tool to depict addition
and multiplication rules.
Event B
Event A
Event C
Complement Rule: P(A)+P(~A)=1
General Rule of Addition
The outcomes of experiment may not be
mutually exclusive.
P(A or B)=P(A)+P(B)-P(A and B)
Example: What is the probability of randomly
chosen card from a card deck will be either
the king or the heart?
Solution:
P(A or B)=P(A)+P(B)-P(A and B)
=4/52+13/52-(1/52)
=0.3077
A
A and B
B
Rules of Multiplication
Special Rule of Multiplication
 Event A and B are independent—The occurrence
of event A does not alter the probability of event
B.
P(A and B)=P(A)P(B)
Example:
Two dies are rolled. What is the probability that
both display the odd number?
Solution:
P(A and B)=P(A)P(B)
=3/6*3/6=1/4=0.25
General Rule of Probability
 The joint probability of events A and B that both
events will happen is found by multiplying the
probability of A will happen and the conditional
probability of event B will happen.
P(A and B)=P(A)P(B|A)
where P(B|A) means the probability B will occur
given A ready occurred.
Example: Suppose that in a bag there are 2 notes of
10$ and 3 notes of 20$. Two notes are to be
selected, one after the other. What is the
probability of selecting one note of 10$ followed
by one note of 20$?
Solution:
P(A and B)=P(A)P(B|A)
=2/5*3/4=0.3
Tree Diagrams
The tree diagram is a graph that is helpful in
organizing calculations that involve several
stages.
Each segment of the tree is one stage of the
problem
P(B1|A1)=1/4
2/5*1/4=0.1
P(B2|A1)=3/4
2/5*3/4=0.3
P(A1)=2/5
P(B1|A2)=2/4
3/5*2/4=0.3
P(B2|A2)=2/4
3/5*2/4=0.3
=1.0
P(A2)=3/5
Bayes’ Theorem
In the 18th century, Reverend Thomas Bayes,
and English Presbyterian minister, raised this
question: Does God really exist? Interested in
mathematics, he tried to develop a formula to
find the probability that God really exists
based on evidence that was available to him
on earth.
Example:
Suppose that 10 percent of people in Cambodia
has believed that the God really exists. We will let
A1 refer to the event that the God really exists
and A2 refer to the event that the God does not
exist. Thus, we know that if we select a person
from Cambodia randomly, the probability that
the individual chosen believes that the God really
exist is P(A1)=0.1 and the probability that the
individual chosen believes that the God does not
exist is P(A2)=1-0.1=0.9. These probabilities are
prior probabilities.
Now, let B denote the event “survey shows that
the God really exists”. Assume that historical
evidence shows that if a person believes the God
really exists, the probability that the survey
shows that the God really exists is 0.85(P(B|A1).
We also assume that if a person believes that the
God does not exist, the probability the survey
shows that the God really exists is 0.15(P(B|A2).
Now select a person from Cambodia randomly
and do the survey. The survey shows that his/her
believes that the God really exist. What is the
probability that the person actually believes that
the God really exist?
This probability can be calculated as below:
P(A1|B)=P(A1)P(B|A1)/(P(A1)P(B|A1)+P(A2)P(B|A2))
=0.1*0.85/(01*0.85+0.90*0.15)=0.086
=>P(A1|B) is called posterior probability
Principles of Counting
 Large number of outcomes
 Possible arrangements for two or more groups
 Multiplication Formula: if there are m ways of
doing one thing and n ways of doing anther thing,
there are m*n ways of doing both.
Total number of arrangements=(m)(n)
Example: There are 20 male students and 5 female
students. How many different arrangements of
male and female students to form a group of
two(one male and anther female)?
Number of arrangements=20*5=100
The Permutation Formula
Possible arrangements for only one group of
objects
Any arrangement of r objects selected from a
single group of n possible objects can be
expressed by the following formula:
nPr=n!/(n-r)!
Example: The 10 numbers from 0 to 9 are to be
used in code groups of four to identify an item of
clothing. Code 1023 might identify a blue blouse
and size small. Code 2051 might identify a Tshort, and size medium and so on. The same
number can not be used twice or more in each
group.
Solution:
nPr=10!/(10-4)!=10!/6!
=10*9*8*7=5040
Note: in Permutation, ab and ba are not the same.
The Combination Formula
 For permutation, the order of objects in their
group makes the group different from all
other groups.
If the order of objects in their group does not
make the group different from all other
groups, the total number of arrangements is
called combination.
Combination is the number of ways to choose
r objects from a group of n object without
regard to order.
Combination Formula:
nCr=n!/r!(n-r)!
Example: How many different ways to choose 5
students from 10 students to form a group of
five students?
Solution:
nCr=10!/5!(10-5)!
=10*9*8*7*6/5*4*3*2*1
=252
Note: in Combination ab and ba are same.
Exercises
1. Before a nationwide survey, 30 persons were
selected to test a questionnaire. One question
about whether NGOs management law is
applicable in Cambodia required yes and no
answer.
a. What is the experiment?
b. List one possible event.
c. Twenty of 30 say yes. What is the probability
that a particular person say yes?
d. What is the concept of this probability?
(Classical, Empirical or subjective probability)
2. The events A and B are mutually exclusive. Suppose
P(A)=0.20 and P(B)=.10. What is the probability that
either A or B occur?
3. Suppose the probability you will get a grade A in this
IT class is 0.30 and the probability that you will get
grade B is 0.35. What is the probability that you will
get a grade above C? and What is the probability that
you will get a grade below B?
4. Mr. Sok is taking two courses, C++ programming and
Software Engineering. The probability Sok will pass
C++ programming is 0.65 and the probability of
passing Software Engineering is 0.70. The probability
Sok will pass both is 0.50. What is the probability
that Sok will pass at least one course?
5. Suppose P(A)=0.25 and P(B)=0.50. What is the joint
probability of A and B?
6. In tossing 3 coins at the same time, what is the
probability that the three coin show tails?
7. In the experiment of select two cards( one after another
without inserting in to the deck again) from a cards deck.
What is the probability that both are kings.
8. Three defective eggs were accidentally sold (pick one
after another) at a small shop near Olympic market along
with 50 non-defective eggs.
a.
b.
c.
What is the probability that the first two eggs were sold are
defective?
What is the probability that the first two eggs were nondefective?
Draw a Ven’ diagram to illustrate these probabilities.
9. The board of directors of Luxury company
consists of 10 persons in which 3 persons are
female. 3 of the board are selected
randomly to form a committee.
a. What is the probability that the committee
consists of 3 women?
b. What is the probability that the committee
consists of at least 1 man?
10.For the daily lottery game in Phnom Penh, each
game participant needs to buy at least one
ticket. Every ticket contains three numbers
between 0 and 9. A number(1 digit) can not be
appeared twice or more in the ticket. The
winning tickets are announced in CTN TV
station every night at 7:30 pm.
a. How many different outcomes(3 digits) are
possible?
b. If you purchase 1 ticket tonight, what is the
change that you will win?
c. If you purchase 2 tickets to night, what is the
change that one of your tickets will win?