CS662 Assignment 9 Solutions



Question 1. Utility. (5 points)
(from R & N, pp610): Tickets to a lottery cost $1. There are two possible prizes: a $10 payoff, with probability 1/50, and a $1,000,000 payoff with probability 1/2,000,000. What is the expected value of a lottery ticket? What is the optimal number of tickets to buy, assuming your utility for money is linear?


To begin, calculate the expected utility for one ticket:

EU = ( 1/50 ∗ 10 + 1/2000000 ∗ 1000000) − 1 = −0.3

So if we buy a lottery ticket, we lose 30 cents in expectation. Since each ticket is independent, we will not improve our winnings by buying more tickets - our loss will be 0.3 * the number of tickets purchased, so we should buy zero tickets. We can also see this directly - let’s write the equation for the EU of buying n tickets:

EU (N tickets) = (n ∗ 1 50 ∗ 10 + n ∗ 1/2000000 ∗ 1000000) − n = n(1/50 ∗ 10 + 1/2000000 ∗ 1000000) − 1 = n ∗ −0.3.

If we want to find the n that maximizes this, we can differentiate and find that EU' is maxmized when n = 0, or just notice that the function is a downward-sloping line.

Question 2. Value of information. (10 points total)

Suppose that our route-finding agent is trying to suggest a route for us to get from USF to Oakland. We want to minimize the expected travel time. We know that, when the Bay Bridge is busy, it takes 1 hour to drive there, and when the Bay Bridge is not busy, it takes 30 minutes to drive there. We know that taking BART always takes 40 minutes. We also know that the Bay Bridge is busy 40% of the time.

a. (2 points) Without any other information, should we drive or take BART? Show all necessary work.

Remember that we want to minimize the time needed here.

EU(BART) = 40
EU(Bridge) = 0.4 * 60 + 0.6 * 30 = 42
BART is quicker, so we should take that.

b. (2 points) Suppose that we can spend five minutes checking a traffic website to see if the bridge is actually busy. We know that 90% of the time when the bridge is actually busy, the site will say it's busy. (P(site | busy) = 0.9) We also know that 20% of the time the site will say the bridge is busy when it actually isn't. (P(site | !busy) = 0.2)

Use Bayes' rule to determine the probability that the bridge is actually busy if the site says it is. (P(busy | site)).

P(busy | site) = P(site | busy) P(busy) / P(site) = 0.9 * 0.4 / P(site) = 0.36 / P(site)
P(!busy | site) = P(site | !busy)P(!busy) / P(site) = 0.2 * 0.6 P(site) = 0.12 / P(site)
P(busy | site) = 0.36 / (0.36 + 0.12) = 0.75
P(!busy | site) = 0.12 / (0.36 + 0.12) = 0.25

Note: P(site) = 0.48, and P(!site) is 0.52
c. (3 points) If the site says the Bridge is busy, what should we do? What if the site says the bridge is not busy? Show all work.

We want to know the EU of driving, given that the site says the bridge is busy.

EU(driving | site) = P(busy|site)*60 + P(!busy|site) * 30 = 0.75 * 60 + 0.25 * 30 = 52.5
EU(driving | !site) = P(busy|!site) * 60 + P(!busy|!site) *30

P(busy | !site) = P(!site | busy)P(busy) / P(!site) = 0.1 * 0.4 / 0.52 = 0.07
P(!busy | !site) = P(!site | !busy) P(!busy) / P(!site) = 0.8 * 0.6 / 0.52 = 0.93

so, EU(driving | !site) = P(busy|!site) * 60 + P(!busy|!site) *30 = 0.07 * 60 + 0.93 * 30 = 32 minutes.

d. (3 points) Use a value of information calculation to determine whether it is worth it for us to spend five minutes checking the traffic website.

So we know that if the site says the bridge is busy, we should take BART, which costs 40 minutes. We also know that if the site says the bridge is busy, we should drive, which takes 32 minutes. Since it costs 5 minutes to check the site, our net costs for each choice would be 45 minutes and 37 minutes, respectively.

Now we just need to compute the EU for this, given the prior probability P(site)
EU(site) = P(site) * 45 + P(!site) * 37 = 0.48 * 45 + 0.52 * 37 = 40.8 minutes.

This is a greater time than just choosing to take BART, so the cost of checking the website is too high; the information we gain is not worth the cost required to acquire it. We should just take BART and not bother with the website.


Question 3. Perceptrons. (5 points)

Do 20.15a on pp 761 of Russell & Norvig. You may assume that alpha = 0.1 and w0 = 0.

I wrote a program to solve this problem. You find the solution much more quickly with a bias of -0.1, so either answer is fine with me.
Here's the output:

shanti:solutions brooks$ python perceptron.py Iteration 1 Example 1: Expected: 1 Actual: 0 Inputs: [1, 0, 1, 0, 0, 0] New weights: [0.10,0.00,0.10,0.00,0.00,0.00] Example 2: Expected: 1 Actual: 1 no change to weights Example 3: Expected: 1 Actual: 1 no change to weights Example 4: Expected: 1 Actual: 1 no change to weights Example 5: Expected: 1 Actual: 1 no change to weights Example 6: Expected: 1 Actual: 1 no change to weights Example 7: Expected: 0 Actual: 1 Inputs: [1, 0, 0, 0, 1, 0] New weights: [0.00,0.00,0.10,0.00,-0.10,0.00] Example 8: Expected: 1 Actual: 1 no change to weights Example 9: Expected: 0 Actual: 0 no change to weights Example 10: Expected: 0 Actual: 0 no change to weights Example 11: Expected: 0 Actual: 0 no change to weights Example 12: Expected: 0 Actual: 0 no change to weights Example 13: Expected: 0 Actual: 0 no change to weights Example 14: Expected: 0 Actual: 1 Inputs: [0, 1, 1, 1, 0, 0] New weights: [0.00,-0.10,0.00,-0.10,-0.10,0.00] Iteration 2 Example 1: Expected: 1 Actual: 0 Inputs: [1, 0, 1, 0, 0, 0] New weights: [0.10,-0.10,0.10,-0.10,-0.10,0.00] Example 2: Expected: 1 Actual: 1 no change to weights Example 3: Expected: 1 Actual: 1 no change to weights Example 4: Expected: 1 Actual: 0 Inputs: [1, 1, 0, 0, 1, 1] New weights: [0.20,0.00,0.10,-0.10,0.00,0.10] Example 5: Expected: 1 Actual: 1 no change to weights Example 6: Expected: 1 Actual: 1 no change to weights Example 7: Expected: 0 Actual: 1 Inputs: [1, 0, 0, 0, 1, 0] New weights: [0.10,0.00,0.10,-0.10,-0.10,0.10] Example 8: Expected: 1 Actual: 1 no change to weights Example 9: Expected: 0 Actual: 1 Inputs: [0, 1, 1, 0, 1, 1] New weights: [0.10,-0.10,0.00,-0.10,-0.20,0.00] Example 10: Expected: 0 Actual: 0 no change to weights Example 11: Expected: 0 Actual: 0 no change to weights Example 12: Expected: 0 Actual: 0 no change to weights Example 13: Expected: 0 Actual: 0 no change to weights Example 14: Expected: 0 Actual: 0 no change to weights Iteration 3 Example 1: Expected: 1 Actual: 1 no change to weights Example 2: Expected: 1 Actual: 0 Inputs: [1, 0, 1, 1, 0, 0] New weights: [0.20,-0.10,0.10,0.00,-0.20,0.00] Example 3: Expected: 1 Actual: 1 no change to weights Example 4: Expected: 1 Actual: 0 Inputs: [1, 1, 0, 0, 1, 1] New weights: [0.30,0.00,0.10,0.00,-0.10,0.10] Example 5: Expected: 1 Actual: 1 no change to weights Example 6: Expected: 1 Actual: 1 no change to weights Example 7: Expected: 0 Actual: 1 Inputs: [1, 0, 0, 0, 1, 0] New weights: [0.20,0.00,0.10,0.00,-0.20,0.10] Example 8: Expected: 1 Actual: 1 no change to weights Example 9: Expected: 0 Actual: 0 no change to weights Example 10: Expected: 0 Actual: 0 no change to weights Example 11: Expected: 0 Actual: 1 Inputs: [0, 1, 0, 1, 0, 1] New weights: [0.20,-0.10,0.10,-0.10,-0.20,0.00] Example 12: Expected: 0 Actual: 0 no change to weights Example 13: Expected: 0 Actual: 0 no change to weights Example 14: Expected: 0 Actual: 0 no change to weights Iteration 4 Example 1: Expected: 1 Actual: 1 no change to weights Example 2: Expected: 1 Actual: 1 no change to weights Example 3: Expected: 1 Actual: 1 no change to weights Example 4: Expected: 1 Actual: 0 Inputs: [1, 1, 0, 0, 1, 1] New weights: [0.30,0.00,0.10,-0.10,-0.10,0.10] Example 5: Expected: 1 Actual: 1 no change to weights Example 6: Expected: 1 Actual: 1 no change to weights Example 7: Expected: 0 Actual: 1 Inputs: [1, 0, 0, 0, 1, 0] New weights: [0.20,0.00,0.10,-0.10,-0.20,0.10] Example 8: Expected: 1 Actual: 1 no change to weights Example 9: Expected: 0 Actual: 0 no change to weights Example 10: Expected: 0 Actual: 0 no change to weights Example 11: Expected: 0 Actual: 0 no change to weights Example 12: Expected: 0 Actual: 0 no change to weights Example 13: Expected: 0 Actual: 0 no change to weights Example 14: Expected: 0 Actual: 0 no change to weights Iteration 5 Example 1: Expected: 1 Actual: 1 no change to weights Example 2: Expected: 1 Actual: 1 no change to weights Example 3: Expected: 1 Actual: 1 no change to weights Example 4: Expected: 1 Actual: 1 no change to weights Example 5: Expected: 1 Actual: 1 no change to weights Example 6: Expected: 1 Actual: 1 no change to weights Example 7: Expected: 0 Actual: 0 no change to weights Example 8: Expected: 1 Actual: 1 no change to weights Example 9: Expected: 0 Actual: 0 no change to weights Example 10: Expected: 0 Actual: 0 no change to weights Example 11: Expected: 0 Actual: 0 no change to weights Example 12: Expected: 0 Actual: 0 no change to weights Example 13: Expected: 0 Actual: 0 no change to weights Example 14: Expected: 0 Actual: 0 no change to weights For bias = -0.1: shanti:solutions brooks$ python perceptron.py Iteration 1 Example 1: Expected: 1 Actual: 0 Inputs: [1, 0, 1, 0, 0, 0] New weights: [0.10,0.00,0.10,0.00,0.00,0.00] Example 2: Expected: 1 Actual: 1 no change to weights Example 3: Expected: 1 Actual: 1 no change to weights Example 4: Expected: 1 Actual: 0 Inputs: [1, 1, 0, 0, 1, 1] New weights: [0.20,0.10,0.10,0.00,0.10,0.10] Example 5: Expected: 1 Actual: 1 no change to weights Example 6: Expected: 1 Actual: 1 no change to weights Example 7: Expected: 0 Actual: 1 Inputs: [1, 0, 0, 0, 1, 0] New weights: [0.10,0.10,0.10,0.00,0.00,0.10] Example 8: Expected: 1 Actual: 1 no change to weights Example 9: Expected: 0 Actual: 1 Inputs: [0, 1, 1, 0, 1, 1] New weights: [0.10,0.00,0.00,0.00,-0.10,0.00] Example 10: Expected: 0 Actual: 0 no change to weights Example 11: Expected: 0 Actual: 0 no change to weights Example 12: Expected: 0 Actual: 0 no change to weights Example 13: Expected: 0 Actual: 0 no change to weights Example 14: Expected: 0 Actual: 0 no change to weights Iteration 2 Example 1: Expected: 1 Actual: 0 Inputs: [1, 0, 1, 0, 0, 0] New weights: [0.20,0.00,0.10,0.00,-0.10,0.00] Example 2: Expected: 1 Actual: 1 no change to weights Example 3: Expected: 1 Actual: 1 no change to weights Example 4: Expected: 1 Actual: 0 Inputs: [1, 1, 0, 0, 1, 1] New weights: [0.30,0.10,0.10,0.00,0.00,0.10] Example 5: Expected: 1 Actual: 1 no change to weights Example 6: Expected: 1 Actual: 1 no change to weights Example 7: Expected: 0 Actual: 1 Inputs: [1, 0, 0, 0, 1, 0] New weights: [0.20,0.10,0.10,0.00,-0.10,0.10] Example 8: Expected: 1 Actual: 1 no change to weights Example 9: Expected: 0 Actual: 1 Inputs: [0, 1, 1, 0, 1, 1] New weights: [0.20,0.00,0.00,0.00,-0.20,0.00] Example 10: Expected: 0 Actual: 0 no change to weights Example 11: Expected: 0 Actual: 0 no change to weights Example 12: Expected: 0 Actual: 0 no change to weights Example 13: Expected: 0 Actual: 0 no change to weights Example 14: Expected: 0 Actual: 0 no change to weights