Docsity

Expected Value - Mathematics for Computer Science - Lecture Slides, Slides of Mathematics

Toggle sidebar
bg1
ļæ½
ļæ½ ļæ½
Expected Value I
The expectation or expected value of a random variable is a single number that tells
you a lot about the behavior of the variable. Roughly, the expectation is the average value,
where each value is weighted according to the probability that it comes up. Formally, the
expected value of a random variable R defined on a sample space S is:
Ex (R)= R(w) Pr (w)
w∈S
To appreciate its signficance, suppose S is the set of students in a class, and we select a
student uniformly at random. Let R be the selected student’s exam score. Then Ex (R)is
just the class average— the first thing everyone want to know after getting their test back!
In the same way, expectation is usually the first thing one wants to determine about any
random variable.
Let’s work through an example. Let R be the number that comes up on a fair, six-sided
die. Then the expected value of R is:
6
ļæ½ 1
Ex (R)= k 6
k=1
111111
= 1 Ā· +2Ā· +3Ā· +4Ā· +5Ā· +6Ā·
666666
7
= 2
This calculation shows that the name ā€œexpected valueā€ is a little misleading; the random
variable might never actually take on that value. You can’t roll a 31
2 on an ordinary die!
1 Betting on Coins
Dan, Eric, and Nick decide to play a fun game. Each player puts $2 on the table and
secretly writes down either ā€œheadsā€ or ā€œtailsā€. Then one of them tosses a fair coin. The
$6 on the table is divided evenly among the players who correctly predicted the outcome
of the coin toss. If everyone guessed incorrectly, then everyone takes their money back.
After many repetitions of this game, Dan has lost a lot of money— more than can be
explained by bad luck. What’s going on?
A tree diagram for this problem is worked out below, under the assumptions that
everyone guesses correctly with probability 1/2and everyone is correct independently.
Docsity.com
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Expected Value - Mathematics for Computer Science - Lecture Slides and more Slides Mathematics in PDF only on Docsity!

The expectation or expected value of a random variable is a single number that tells you a lot about the behavior of the variable. Roughly, the expectation is the average value, where each value is weighted according to the probability that it comes up. Formally, the expected value of a random variable R defined on a sample space S is:

Ex (R) = R(w) Pr (w) w∈S

To appreciate its signficance, suppose S is the set of students in a class, and we select a student uniformly at random. Let R be the selected student’s exam score. Then Ex (R) is just the class average— the first thing everyone want to know after getting their test back! In the same way, expectation is usually the first thing one wants to determine about any random variable.

Let’s work through an example. Let R be the number that comes up on a fair, sixsided die. Then the expected value of R is:

ļæ½^6 1 Ex (R) = k k=1^6 1 1 1 1 1 1 = 1 Ā· + 2 Ā· + 3 Ā· + 4 Ā· + 5 Ā· + 6 Ā· 6 6 6 6 6 6 7 = 2

This calculation shows that the name ā€œexpected valueā€ is a little misleading; the random variable might never actually take on that value. You can’t roll a 312 on an ordinary die!

1 Betting on Coins

Dan, Eric, and Nick decide to play a fun game. Each player puts $2 on the table and secretly writes down either ā€œheadsā€ or ā€œtailsā€. Then one of them tosses a fair coin. The $6 on the table is divided evenly among the players who correctly predicted the outcome of the coin toss. If everyone guessed incorrectly, then everyone takes their money back. After many repetitions of this game, Dan has lost a lot of money— more than can be explained by bad luck. What’s going on?

A tree diagram for this problem is worked out below, under the assumptions that everyone guesses correctly with probability 1 / 2 and everyone is correct independently.

1/

1/

1/

1/

1/

1/

1/

1/

probability

Dan right?

Eric right?

Nick right? Dan’s payoff

Y

N

Y

Y

Y

Y

Y

Y

N

N

N

N

N

N $

āˆ’$

āˆ’$

āˆ’$

$

$

$

$

1/

1/

1/ 1/ 1/

1/ 1/

1/ 1/

1/ 1/ 1/

1/

1/

In the ā€œpayoffā€ column, we’re accounting for the fact that Dan has to put in $2 just to play. So, for example, if he guesses correctly and Eric and Nick are wrong, then he takes all $ on the table, but his net profit is only $4. Working from the tree diagram, Dan’s expected payoff is:

Ex (payoff) = 0 Ā· + 1 Ā· + 1 Ā· + 4 Ā· + (āˆ’2) Ā· + (āˆ’2) Ā· + (āˆ’2) Ā· + 0 Ā· 8 8 8 8 8 8 8 8 = 0

So the game perfectly fair! Over time, he should neither win nor lose money.

The trick is that Nick and Eric are collaborating; in particular, they always make oppo site guesses. So our assumption everyone is correct independently is wrong; actually the events that Nick is correct and Eric is correct are mutually exclusive! As a result, Dan can never win all the money on the table. When he guesses correctly, he always has to split his winnings with someone else. This lowers his overall expectation, as the corrected tree diagram below shows:

  • The state divides 1 / 2 the money collected among the people who guessed correctly and spends the other half repairing the Big Dig.

This is a lot like our betting game, except that there are more players and more choices. Chernoff discovered that a small set of numbers was selected by a large fraction of the population— apparently many people think the same way. It was as if the players were collaborating to lose! If any one of them guessed correctly, then they’d have to split the pot with many other players. By selecting numbers uniformly at random, Chernoff was unlikely to get one of these favored sequences. So if he won, he’d likely get the whole pot! By analyzing actual state lottery data, he determined that he could win an average of 7 cents on the dollar this way!

2 Equivalent Definitions of Expectation

There are some other ways of writing the definition of expectation. Sometimes using one of these other formulations can make computing an expectation a lot easier. One option is to group together all outcomes on which the random variable takes on the same value.

Theorem 1. (^) � Ex (R) = x · Pr (R = x) x∈ range(R)

Proof. We’ll transform the left side into the right. Let [R = x] be the event that R = x.

Ex (R) = R(w) Pr (w) w∈S = R(w) Pr (w) x∈ range(R) w∈[R=x] = x Pr (w) x∈ range(R) w∈[R=x] āŽ›

= āŽx

Ā· Pr (w)āŽ  x∈ range(R) w∈[R=x] = x Ā· Pr (R = x) x∈ range(R)

On the second line, we break the single sum into two. The outer sum runs over all possible values x that the random variable takes on, and the inner sum runs over all outcomes taking on that value. Thus, we’re still summing over every outcome in the sample space exactly once. On the last line, we use the definition of the probability of the event [R = x].

Corollary 2. If R is a naturalvalued random variable, then:

āˆž Ex (R) = i Ā· Pr (R = i) i=

There is another way to write the expected value of a random variable that takes on values only in the natural numbers, N = { 0 , 1 , 2 ,... }.

Theorem 3. If R is a naturalvalued random variable, then:

āˆž Ex (R) = Pr (R > i) i=

Proof. Consider the sum:

Pr (R = 1) + Pr (R = 2) + Pr (R = 3) + Ā· Ā· Ā·

  • Pr (R = 2) + Pr (R = 3) + Ā· Ā· Ā·
  • Pr (R = 3) + Ā· Ā· Ā·
  • Ā· Ā· Ā·

The columns sum to 1 Ā· Pr (R = 1), 2 Ā· Pr (R = 2), 3 Ā· Pr (R = 3), etc. Thus, the whole sum is equal to: āˆž i Ā· Pr (R = i) = Ex (R) i=

Here, we’re using Corollary 2. On the other hand, the rows sum to Pr (R > 0), Pr (R > 1), Pr (R > 2), etc. Thus, the whole sum is also equal to:

āˆž Pr (R > i) i=

These two expressions for the whole sum must be equal, which proves the theorem.

2.1 Mean Time to Failure

Let’s look at a problem where one of these alternative definitions of expected value is particularly helpful. A computer program crashes at the end of each hour of use with probability p, if it has not crashed already. What is the expected time until the program crashes?

If we let R be the number of hours until the crash, then the answer to our problem is Ex (R). This is a naturalvalued variable, so we can use the formula:

āˆž Ex (R) = Pr (R > i) i=

Proof. Let S be the sample space.

Ex (R 1 + R 2 ) = (R 1 (w) + R 2 (w)) · Pr (w) w∈S = R 1 (w) · Pr (w) + R 2 (w) · Pr (w) w∈S w∈S = Ex (R 1 ) + Ex (R 2 )

Linearity of expectation generalizes to any finite collection of random variables by induction:

Corollary 5. For any random variables R 1 , R 2 ,... , Rk,

Ex (R 1 + R 2 + Ā· Ā· Ā· + Rk) = Ex (R 1 ) + Ex (R 2 ) + Ā· Ā· Ā· + Ex (Rk)

The reason linearity of expectation is so wonderful is that, unlike many other probabil ity rules, the random variables are not required to be independent. This probably sounds like a ā€œyeah, whateverā€ technicality right now. But when you give an analysis using linearity of expectation, someone will almost invariably say, ā€œNo, you’re wrong. There are all sorts of complicated dependencies here that you’re ignoring.ā€ But that’s the magic of linearity of expectation: you can ignore such dependencies!

3.1 Expected Value of Two Dice

What is the expected value of the sum of two fair dice?

Let the random variable R 1 be the number on the first die, and let R 2 be the number on the second die. At the start of these Notes, we showed that the expected value of one die is 312. We can find the expected value of the sum using linearity of expectation:

Ex (R 1 + R 2 ) = Ex (R 1 ) + Ex (R 2 ) 1 1 = 3 + 3 2 2 = 7

Notice that we did not have to assume that the two dice were independent. The expected sum of two dice is 7, even if they are glued together! (This is provided that gluing some how does not change weights to make the individual dice unfair.)

Proving that the expected sum is 7 with a tree diagram would be hard; there are 36 cases. And if we did not assume that the dice were independent, the job would be a nightmare!

3.2 The HatCheck Problem

There is a dinner party where n men check their hats. The hats are mixed up during dinner, so that afterward each man receives a random hat. In particular, each man gets his own hat with probability 1 /n. What is the expected number of men who get their own hat?

Without linearity of expectation, this would be a very difficult question to answer. We might try the following. Let the random variable R be the number of men that get their own hat. We want to compute Ex (R). By the definition of expectation, we have:

āˆž Ex (R) = k Ā· Pr(R = k) k=

Now we’re in trouble, because evaluating Pr(R = k) is a mess and we then need to substitute this mess into a summation. Furthermore, to have any hope, we would need to fix the probability of each permutation of the hats. For example, we might assume that all permutations of hats are equally likely.

Now let’s try to use linearity of expectation. As before, let the random variable R be the number of men that get their own hat. The trick is to express R as a sum of indicator variables. In particular, let Ri be an indicator for the event that the ith man gets his own hat. That is, Ri = 1 is the event that he gets his own hat, and Ri = 0 is the event that he gets the wrong hat. The number of men that get their own hat is the sum of these indicators: R = R 1 + R 2 + Ā· Ā· Ā·+ Rn

These indicator variables are not mutually independent. For example, if n āˆ’ 1 men all get their own hats, then the last man is certain to receive his own hat. But, since we plan to use linearity of expectation, we don’t have worry about independence!

Let’s take the expected value of both sides of the equation above and apply linearity of expectation:

Ex (R) = Ex (R 1 + R 2 + Ā· Ā· Ā· + Rn) = Ex (R 1 ) + Ex (R 2 ) + Ā· Ā· Ā· + Ex (Rn)

All that remains is to compute the expected value of the indicator variables Ri. We’ll use an elementary fact that is worth remembering in its own right:

Fact 1. The expected value of an indicator random variable is the probability that the indicator is

  1. In symbols: Ex (I) = Pr (I = 1)

Proof.

Ex (I) = 1 Ā· Pr (I = 1) + 0 Ā· Pr (I = 0) = Pr (I = 1)