Midterm 1

Midterm 1

CS 188 Spring 2014 Introduction to Artificial Intelligence Midterm 1 • You have approximately 2 hours and 50 minutes. • The exam is closed book, cl...

501KB Sizes 3 Downloads 16 Views

Recommend Documents

Midterm 1
Oct 20, 2014 - Britain, then the United States will: A) export both airplanes and ... Economists in general agree that r

ACT4000 MIDTERM 1
Feb 8, 2007 - (i) (5 points) Compute the price of a European put option on the stock which expires in 4 periods and has

Midterm 1 - Fall 2013
Oct 21, 2013 - If the price of Raclette cheese decreased, we would expect to see: B ... In the market shown in the figur

Midterm 1 - HKN
Jul 17, 2014 - Summer 2014 James Cook. Midterm 1 .... Pandu was silly and picked numbers far too small to make RSA secur

midterm
Oct 31, 2011 - A: Managerial accounting focuses on information for internal decision making. ... How do these withdrawal

Midterm
(i) [5 Points] Find the marginal utility for goods 1 and 2, MU1 and MU2. .... (ii) [6 Points] Find the price the buyers

Practice Questions for Midterm 1
What is the “Big Mac Index” and why is it useful? j. What did Solow find to be the most important contribution to ec

Midterm Solutions
(I) A bullet of mass m moving at horizontal velocity v strikes and sticks to the rim of a wheel (a solid disc) of mass.

Midterm 2
(a) What is the exact expected number of collisions? (b) Estimate ... Adjacent plazas are connected by gates, which have

Solutions to Question 1 from midterm
X is neither normal nor inferior in this case. e.) For Marshallian demand to slope up, the good must be a Giffen good. T

CS 188 Spring 2014

Introduction to Artificial Intelligence

Midterm 1

• You have approximately 2 hours and 50 minutes. • The exam is closed book, closed notes except your one-page crib sheet. • Mark your answers ON THE EXAM ITSELF. If you are not sure of your answer you may wish to provide a brief explanation. All short answer sections can be successfully answered in a few sentences AT MOST.

First name Last name SID edX username

First and last name of student to your left First and last name of student to your right

Q1. Q2. Q3. Q4. Q5. Q6. Q7. Q8.

For staff use only: All Searches Lead to the Same Destination Dynamic A∗ Search CSPs Variants of Trees More Games and Utilities Faulty Keyboard Deep inside Q-learning Bellman Equations for the Post-Decision State Total

1

/10 /18 /16 /15 /10 /9 /8 /14 /100

THIS PAGE IS INTENTIONALLY LEFT BLANK

Q1. [10 pts] All Searches Lead to the Same Destination For all the questions below assume : • All search algorithms are graph search (as opposed to tree search). • cij > 0 is the cost to go from node i to node j. • There is only one goal node (as opposed to a set of goal nodes). • All ties are broken alphabetically. • Assume heuristics are consistent. Definition: Two search algorithms are defined to be equivalent if and only if they expand the same nodes in the same order and return the same path. In this question we study what happens if we run uniform cost search with action costs dij that are potentially different from the search problem’s actual action costs cij . Concretely, we will study how this might, or might not, result in running uniform cost search (with these new choices of action costs) being equivalent to another search algorithm. (a) [2 pts] Mark all choices for costs dij that make running Uniform Cost Search algorithm with these costs dij equivalent to running Breadth-First Search.

#

#

# #

dij = 0 dij = α, α > 0 dij = α, α < 0 dij = 1 dij = −1 None of the above

Beadth First search expands the node at the shallowest depth first. Assigning a constant positive weight to all edges allows to weigh the nodes by their depth in the search tree. (b) [2 pts] Mark all choices for costs dij that make running Uniform Cost Search algorithm with these costs dij equivalent to running Depth-First Search.

# #

#

#

dij = 0 dij = α, α > 0 dij = α, α < 0 dij = 1 dij = −1 None of the above

Depth First search expands the nodes which were most recently added to the fringe first. Asssigning a constant negative weight to all edges essentially allows to reduce the value of the most recently nodes by that constant, making them the nodes with the minimum value in the fringe when using uniform cost search.

3

(c) [2 pts] Mark all choices for costs dij that make running Uniform Cost Search algorithm with these costs dij equivalent to running Uniform Cost Search with the original costs cij .

# #

dij = c2ij dij = 1/cij

# # #

dij = α cij ,

α>0

dij = cij + α,

α>0

dij = α cij + β, α > 0, β > 0 None of the above

P Uniform cost search expands the node with the lowest cost-so-far = ij cij on the fringe. Hence, the relative P ordering between two nodes is determined by the value of ij cij for a given node. Amongst the above given choices, = α cij , α > 0, canP we conclude, P P only for dij P dij ≥ dij ⇐⇒ cij ≥ cij , for some nodes n and m. ij∈ path(n)

ij∈ path(m)

ij∈ path(n)

ij∈ path(m)

(d) Let h(n) be the value of the heuristic function at node n. (i) [2 pts] Mark all choices for costs dij that make running Uniform Cost Search algorithm with these costs dij equivalent to running Greedy Search with the original costs cij and heuristic function h.

#

# # # #

dij = h(i) − h(j) dij = h(j) − h(i) dij = α h(i), α>0 dij = α h(j), α>0 dij = cij + h(j) + h(i) None of the above

Greedy search expands the node with the lowest heuristic function value h(n). P If dij = h(j) − h(i), then the cost of a node n on the fringe when running uniform-cost search will be ij dij = h(n) − h(start). As h(start) is a common constant subtracted from the cost of all nodes on the fringe, the relative ordering of the nodes on the fringe is still determined by h(n), i.e. their heuristic values.

(ii) [2 pts] Mark all choices for costs dij that make running Uniform Cost Search algorithm with these costs dij equivalent to running A* Search with the original costs cij and heuristic function h.

# # # # #



#

dij = α h(i), α > 0 dij = α h(j), α > 0 dij = cij + h(i) dij = cij + h(j) dij = cij + h(i) − h(j) dij = cij + h(j) − h(i) None of the above

P A search expands the node with the lowest f (n) + h(n) value, where f (n) = ij cij is the cost-so-far and h is the heuristic value. If dP h(j) − h(i), then the cost of a node n on the fringe when running ij = cij +P uniform-cost search will be ij dij = ij cij + h(n) − h(start) = f (n) + h(n) − h(start). As h(start) is a common constant subtracted from the cost of all nodes on the fringe, the relative ordering of the nodes on the fringe is still determined by f (n) + h(n).

4

Q2. [18 pts] Dynamic A∗ Search After running A∗ graph search and finding an optimal path from start to goal, the cost of one of the edges, X → Y , in the graph changes. Rather than re-running the entire search, you want to find a more efficient way of finding the optimal path for this new search problem. You have access to the fringe, the closed set and the search tree as they were at the completion of the initial search. In addition, you have a closed node map that maps a state, s from the closed set to a list of nodes in the search tree ending in s which were not expanded because s was already in the closed set. For example, after running A∗ search with the null heuristic on the following graph, the data structures would be as follows:

Fringe:

{}

Closed Node Map:

{A:[ ], B:[ ], C:[ ], D:[(A-C-D, 6)]}

Closed Set:

{A, B, C, D}

Search Tree:

{A A-B A-C A-B-D A-B-D-E

: : : : :

[(A-B, 1), (A-C, 4)], [(A-B-D, 2)], [ ], [(A-B-D-G, 7)], [ ]}

For a general graph, for each of the following scenarios, select the choice that finds the correct optimal path and cost while expanding the fewest nodes. Note that if you select the 4th choice, you must fill in the change, and if you select the last choice, you must describe the set of nodes to add to the fringe. In the answer choices below, if an option states some nodes will be added to the fringe, this also implies that the final state of each node gets cleared out of the closed set (indeed, otherwise it’d be rather useless to add something back into the fringe). You may assume that there are no ties in terms of path costs. Following is a set of eight choices you should use to answer the questions on the following page. i. ii. iii. iv. v. vi. vii. viii.

The optimal path does not change, and the cost remains the same. The optimal path does not change, but the cost increases by n The optimal path does not change, but the cost decreases by n The optimal path does not change, but the cost changes by The optimal path for the new search problem can be found by adding the subtree rooted at X that was expanded in the original search back onto the fringe and re-starting the search. The optimal path for the new search problem can be found by adding the subtree rooted at Y that was expanded in the original search back onto the fringe and re-starting the search. The optimal path for the new search problem can be found by adding all nodes for each state in the closed node map back onto the fringe and re-starting the search. The optimal path for the new search problem can be found by adding some other set of nodes back onto the fringe and re-starting the search. Describe the set below.

5

(a) [3 pts] Cost of X → Y is increased by n, n > 0, the edge is on the optimal path, and was explored by the first search. # i # ii # iii # iv, Change: # v # vi # vii viii, Describe the set below: The combination of all the nodes from the closed node map for the final state of each node in the subtree rooted at Y plus the node ending at Y that was expanded in the initial search. This means that you are re-exploring every path that was originally closed off by a path that included the edge X → Y . (b) [3 pts] Cost of X → Y is decreased by n, n > 0, the edge is on the optimal path, and was explored by the first search. # i # ii iii # iv, Change: # v # vi # vii # viii, Describe the set below: The original optimal path’s cost decreases by n because X → Y is on the original optimal path. The cost of any other path in the graph will decrease by at most n (either n or 0 depending on whether or not it includes X → Y ). Because the optimal path was already cheaper than any other path, and decreased by at least as much as any other path, it must still be cheaper than any other path. (c) [3 pts] Cost of X → Y is increased by n, n > 0, the edge is not on the optimal path, and was explored by the first search. i # ii # iii # iv, Change: # v # vi # vii # viii, Describe the set below: The cost of the original optimal path, which is lower than the cost of any other path, stays the same, while the cost of any other path either stays the same or increases. Thus, the original optimal path is still optimal. (d) [3 pts] Cost of X → Y is decreased by n, n > 0, the edge is not on the optimal path, and was explored by the first search. # i # ii # iii # iv, Change: # v # vi # vii # viii, Describe the set below: The combination of the previous goal node and the node ending at X that was expanded in the initial search. There are two possible paths in this case. The first is the original optimal path, which is considered by adding the previous goal node back onto the fringe. The other option is the cheapest path that includes X → Y , because that is the only cost that has changed. There is no guarantee that the node ending at Y , and thus the subtree rooted at Y contains X → Y , so the subtree rooted at X must be added in order to find the cheapest path through X → Y . (e) [3 pts] Cost of X → Y is increased by n, n > 0, the edge is not on the optimal path, and was not explored by the first search. i # ii # iii # iv, Change: # v # vi # vii # viii, Describe the set below: This is the same as part (c). (f ) [3 pts] Cost of X → Y is decreased by n, n > 0, the edge is not on the optimal path, and was not explored by the first search. i # ii # iii # iv, Change: # v # vi # vii # viii, Describe the set below: Assuming that the cost of X → Y remains positive, because the edge was never explored, the cost of the path to X is already higher than the cost of the optimal path. Thus, the cost of the path to Y through X can only be higher, so the optimal path remains the same. If you allow edge weights to be negative, it is necessary to find the optimal path to Y through X separately. Because the edge was not explored, a node ending at X was never expanded, so the negative edge would still never be seen unless the path was found separately and added onto the fringe. In this case, adding this path and the original goal path, similar to (d), would find the optimal path with the updated edge cost.

6

Q3. [16 pts] CSPs (a) The graph below is a constraint graph for a CSP that has only binary constraints. Initially, no variables have been assigned. For each of the following scenarios, mark all variables for which the specified filtering might result in their domain being changed.

(i) [1 pt] A value is assigned to A. Which domains might be changed as a result of running forward checking for A? # A B C D # E # F Forward checking for A only considers arcs where A is the head. This includes B → A, C → A, D → A. Enforcing these arcs can change the domains of the tails. (ii) [1 pt] A value is assigned to A, and then forward checking is run for A. Then a value is assigned to B. Which domains might be changed as a result of running forward checking for B? # A # B C # D E # F Similar to the previous part, forward checking for B enforces the arcs A → B, C → B, and E → B. However, because A has been assigned, and a value is assigned to B, which is consistent with A or else no value would have been assigned, the domain of A will not change. (iii) [1 pt] A value is assigned to A. Which domains might be changed as a result of enforcing arc consistency after this assignment? # A B C D E F Enforcing arc consistency can affect any unassigned variable in the graph that has a path to the assigned variable. This is because a change to the domain of X results in enforcing all arcs where X is the head, so changes propagate through the graph. Note that the only time in which the domain for A changes is if any domain becomes empty, in which case the arc consistency algorithm usually returns immediately and backtracking is required, so it does not really make sense to consider new domains in this case. (iv) [1 pt] A value is assigned to A, and then arc consistency is enforced. Then a value is assigned to B. Which domains might be changed as a result of enforcing arc consistency after the assignment to B? # A # B C # D E F After assigning a value to A, and enforcing arc consistency, future assignments and enforcing arc consistency will not result in a change to As domain. This means that Ds domain won’t change because the only arc that might cause a change, D → A will never be enforced. (b) You decide to try a new approach to using arc consistency in which you initially enforce arc consistency, and then enforce arc consistency every time you have assigned an even number of variables. You have to backtrack if, after a value has been assigned to a variable, X, the recursion returns at X without a solution. Concretely, this means that for a single variable with d values remaining, it is possible to backtrack up to d times. For each of the following constraint graphs, if each variable has a domain of size d, how many times would you have to backtrack in the worst case for each of the specified orderings? (i) [6 pts]

A-B-C-D-E:

0

A-E-B-D-C:

2d

C-B-D-E-A: 0 If no solution containing the current assignment exists on a tree structured CSP, then enforcing arc consistency will always result in an empty domain. This means that running arc consistency on a tree structured 7

CSP will immediately tell you whether or not the current assignment is part of a valid solution, so you can immediately start backtracking without further assignments. A − B − C − D − E and C − B − D − E − A are both linear orderings of the variables in the tree, which is essentially the same as running the two pass algorithm, which will solve a tree structured CSP with no backtracking. A − E − B − D − C is not a linear ordering, so while the odd assignments are guaranteed to be part of a valid solution, the even assignments are not (because arc consistency was not enforced after assigning the odd variables). This means that you may have to backtrack on every even assignment, specifically E and D. Note that because you know whether or not the assignment to E is valid immediately after assigning it, the backtracking behavior is not nested (meaning you backtrack on E up to d times without assigning further variables). The same is true for D, so the overall behavior is backtracking 2d times. (ii) [6 pts]

A-B-C-D-E-F-G:

d2

F-D-B-A-C-G-E:

d4 + d

C-A-F-E-B-G-D:

d2

A − B − C − D − E − F − G: The initial assignment of A, B might require backtracking on both variables, because there is no guarantee that the initial assignment to A is a valid solution. Because A is a cutset for this graph, the resulting graph consists of two trees, so enforcing arc consistency immediately returns whether the assignments to A and B are part of a solution, and you can begin backtracking without further assignments. F − D − B − A − C − G − E: Until A is assigned, there is no guarantee that any of the previous values assigned are part of a valid solution. This means that you may be required to backtrack on all of them, resulting in d4 times. Furthermore, the remaining tree is not assigned in a linear order, so further backtracking may be required on G (similar to the second ordering above) resulting in a total of d4 +d. C − A − F − E − B − G − D: This ordering is similar to the first one. except that the resulting trees are not being assigned in linear order. However, because each tree only has a single value assigned in between each run of arc consistency, no backtracking will be required (you can think of each variable as being the root of the tree, and the assignment creating a new tree or two where arc consistency has been enforced), resulting in a total of d2 times.

8

Q4. [15 pts] Variants of Trees (a) Pacman is going to play against a careless ghost, which makes a move that is optimal for Pacman time, and makes a move that that minimizes Pacman’s utility the other 23 of the time.

1 3

of the

(i) [2 pts] Fill in the correct utility values in the game tree below where Pacman is the maximizer:

Pacman

Ghost

3

1 0

-3

1

6

0

-3

9

(ii) [2 pts] Draw a complete game tree for the game above that contains only max nodes, min nodes, and chance nodes.

1

0 1/3

1 2/3

2/3

1/3

-3

-3 9

6

3

-3

6

3

-3

6

0

-3

9

0

-3

9

9

(b) Consider a modification of alpha-beta pruning where, rather than keeping track of a single value for α and β, you instead keep a list containing the best value, wi , for the minimizer/maximizer (depending on the level) at each level up to and including the current level. Assume that the root node is always a max node. For example, consider the following game tree in which the first 3 levels are shown. When the considering the right child of the node at level 3, you have access to w1 , w2 , and w3 .

(i) [1 pt] Under this new scenario, what is the pruning condition for a max node at the nth level of the tree (in terms of v and w1 ...wn )? v > mini (wi ), where i is even; (ii) [1 pt] What is the pruning condition for a min node at the nth level of the tree? v < maxi (wi ), where i is odd; (iii) [2 pts] What is the relationship between α, β and the list of w1 ...wn at a max node at the nth level of the tree?

# # # # # #

P

i wi = α + β maxi wi = α, mini wi = β mini wi = α, maxi wi = β wn = α, wn−1 = β wn−1 = α, wn = β None of the above. The relationship is

β = min(w2 , w4 , w6 ...),

10

α = max(w1 , w3 , w5 ...)

(c) Pacman is in a dilemma. He is trying to maximize his overall utility in a game, which is modeled as the following game tree.

The left subtree contains a utility of 12. The right subtree contains an unknown utility value. An oracle has told you that the value of the right subtree is one of −3, −9, or 21. You know that each value is equally likely, but without exploring the subtree you do not know which one it is. Now Pacman has 3 options: 1. Choose left; 2. Choose right; 3. Pay a cost of c = 1 to explore the right subtree, determine the exact utility it contains, and then make a decision. (i) [3 pts] What is the expected utility for option 3? 12 ∗

2 3

+ 21 ∗

1 3

− 1 = 14

(ii) [4 pts] For what values of c (for example, c > 5 or −2 < c < 2) should Pacman choose option 3? If option 3 is never optimal regardless of the value for c, write None. According to the previous part, we have 15 − c > 12, then we will choose option 3. Therefore, c < 3

11

Q5. [10 pts] More Games and Utilities (a) Games. Consider the game tree below, which contains maximizer nodes, minimizer nodes, and chance nodes. For the chance nodes the probability of each outcome is equally likely. (i) [3 pts] Fill in the values of each of the nodes.

(ii) [4 pts] Is pruning possible? # No. Brief justification:

#

Yes. Cross out the branches that can be pruned.

(b) Utilities. Pacman’s utility function is U ($x) = Compute the following quantities:



x. He is faced with the following lottery: [0.5, $36 ; 0.5, $64].

(i) [1 pt] What is Pacman’s expected utility? EU ([0.5, $36 ; 0.5, $64]) = P The utility of a lottery can be computed via EU (L) = x∈L p(x)U (x) Hence, EU ([0.5, $36 ; 0.5, $64]) = 0.5U ($36) + 0.5U ($64) = 0.5(6) + 0.5(8) = 7 (ii) [1 pt] What is Equivalent Monetary Value for this lottery? EM V ([0.5, $36 ; 0.5, $64]) = The equivalent monetary value is the amount of money you would pay in exchange for the lottery. Since the utility of the lottery was calculated to be 7, then we just need to find the X such that U ($X) = 7 Answer: X = $49 (iii) [1 pt] What is the maximum amount Pacman would be willing to pay for an insurance that guarantees he gets $64 in exchange for giving his lottery to the insurance company? Solve for X in the equation: U (64 − $X) = U (Lottery) = 7 Answer: X = $15

12

Q6. [9 pts] Faulty Keyboard Your new wireless keyboard works great, but when the battery runs out it starts behaving strangely. All keys other than {a, b, c} stop working. The {a, b, c} keys work as intended with probability 0.8, but could also produce either of the other two different characters with probability 0.1 each. For example, pressing a will produce ‘A’ with probability 0.8, ‘B’ with probability 0.1, and ‘C’ with probability 0.1. After 11 key presses the battery is completely drained and no new characters can be produced. The na¨ıve state space for this problem consists of three states {A, B, C} and three actions {a, b, c}. For each of the objectives below specify a reward function on the na¨ıve state space such that the optimal policy in the resulting MDP optimizes the specified objective. The reward can only depend on current state, current action, and next state; it cannot depend on time. If no such reward function exist, then specify how the na¨ıve state space needs to be expanded and a reward function on this expanded state space such that the optimal policy in the resulting MDP optimizes the specified objective. The size of the extended state space needs to be minimal. You may assume that γ = 1. There are many possible correct answers to these questions. We accepted any reward function that produced the correct policy, and any state-space extension that produced a state-space of minimal asymptotic complexity. (Big O complexity of the state space size in terms on the horizon and the number of keys and characters available) (a) [3 pts] Produce as many B’s as possible before the first C.

For this part, we want to achieve the policy of always R(s, a, s0 ) = 1 if s0 = B, 0 otherwise taking action b. Many reward functions gave this policy (giving positive reward for taking action b achieved the same thing). Notice that we do not need a bit for whether C has been pressed or not, because it will not affect our optimal policy or transitions. Another correct reward function might be R(s, a, s0 ) = 1 if a=’b’, 0 otherwise.

#

The state-space needs to be extended to include: Reward function over extended state space:

13

(b) [3 pts] Produce a string where the number of B’s and the number of C’s are as close as possible.

#

R(s, a, s0 ) =

The state-space needs to be extended to include: a counter D for the difference between the number of B’s and the number of C’s. D = #B-#C = number of B’s minus number of C’s in s. New state-space size: 3 · 23 R(s, a, s0 ) = −|D(s0 )|

Reward function over extended state space:

For this part, you need to keep track of the difference between the number of B’s you have seen so far and the number of C’s you have seen so far. A significant number of people wrote that you can explicitly store both the counts of B and C. While this is a valid state space, it is not minimal, since it shouldn’t matter whether you are, say, in a situation where you pressed 4 B’s and 4 C’s, and a situation where you pressed 2 B’s and 2 C’s. The reward function above is one of many that can reproduce the behavior specified. This reward function basically assigns a score of 1 for any transition that decreases the counter, a score of 0 for any transition that doesn’t change the counter, and a score of -1 for any transition that increases the counter by 1. A significant number of people had the right idea for the reward function, but only wrote down an equation that relates number of B’s and number of C’s. (example: −|#B − #C|). While close, it’s ambiguous in the sense that it’s not clear if these numbers are referring to the state s or s0 , which are both parameters to the reward function. Another correct but non-minimal extension of the state space is one where we add both a counter for the number of B’ and a counter for the number of C’s. In this case the size of the state-space would be: 3 · 12 · 12. Another possible state space extension that leads to a smaller state space (but with the same complexity as our answer) can be obtained by noticing that once |D(s)| > 5 the policy for the remaining time steps is determined. Therefore we could augment the state space with max(−6, min(6, D)) instead of D(s).

(c) [3 pts] Produce a string where the first character re-appears in the string as many times as possible.

#

R(s, a, s0 ) =

The state-space needs to be extended to include: character produced after the first keypress The size of the state-space is now 3 · 3. first(s) = first character produced on the way to state s. Note that this new variable added to the state-space remains constant after the first character is produced. Reward function over extended state space:

R(s, a, s0 ) = 1

14

if

a = lowercase(first(s)),

0 otherwise

Q7. [8 pts] Deep inside Q-learning Consider the grid-world given below and an agent who is trying to learn the optimal policy. Rewards are only awarded for taking the Exit action from one of the shaded states. Taking this action moves the agent to the Done state, and the MDP terminates. Assume γ = 1 and α = 0.5 for all calculations. All equations need to explicitly mention γ and α if necessary.

(a) [3 pts] The agent starts from the top left corner and you are given the following episodes from runs of the agent through this grid-world. Each line in an Episode is a tuple containing (s, a, s0 , r). Episode 1 (1,3), S, (1,2), 0 (1,2), E, (2,2), 0 (2,2), E, (3,2), 0 (3,2), N, (3,3), 0 (3,3), Exit, D, +50

Episode 2 (1,3), S, (1,2), 0 (1,2), E, (2,2), 0 (2,2), S, (2,1), 0 (2,1), Exit, D, -100

Episode 3 (1,3), S, (1,2), 0 (1,2), E, (2,2), 0 (2,2), E, (3,2), 0 (3,2), S, (3,1), 0 (3,1), Exit, D, +30

Episode 4 (1,3), S, (1,2), 0 (1,2), E, (2,2), 0 (2,2), E, (3,2), 0 (3,2), N, (3,3), 0 (3,3), Exit, D, +50

Episode 5 (1,3), S, (1,2), 0 (1,2), E, (2,2), 0 (2,2), E, (3,2), 0 (3,2), S, (3,1), 0 (3,1), Exit, D, +30

Fill in the following Q-values obtained from direct evaluation from the samples: Q((3,2), N) =

50

Q((3,2), S) =

30

Q((2,2), E) =

40

Direct evaluation is just averaging the discounted reward after performing action a in state s. (b) [3 pts] Q-learning is an online algorithm to learn optimal Q-values in an MDP with unknown rewards and transition function. The update equation is: Q(st , at ) = (1 − α)Q(st , at ) + α(rt + γ max Q(st+1 , a0 )) 0 a

where γ is the discount factor, α is the learning rate and the sequence of observations are (· · · , st , at , st+1 , rt , · · · ). Given the episodes in (a), fill in the time at which the following Q values first become non-zero. Your answer should be of the form (episode#,iter#) where iter# is the Q-learning update iteration in that episode. If the specified Q value never becomes non-zero, write never. Q((1,2), E) =

(4,2)

Q((2,2), E) =

(3,3)

Q((3,2), S) =

(3,4)

This question was intended to demonstrate the way in which Q-values propagate through the state space. Q-learning is run in the following order - observations in ep 1 then observations in ep 2 and so on. (c) [2 pts] In Q-learning, we look at a window of (st , at , st+1 , rt ) to update our Q-values. One can think of using an update rule that uses a larger window to update these values. Give an update rule for Q(st , at ) given the window (st , at , rt , st+1 , at+1 , rt+1 , st+2 ). Q(st , at ) = (1 − α)Q(st , at ) + α(rt + γrt+1 + γ 2 maxa0 Q(st+2 , a0 )) (Sample of the expected discounted reward using rt+1 )

15

Q(st , at ) = (1 − α)Q(st , at ) + α(rt + γ((1 − α)Q(st+1 , at+1 ) + α(rt+1 + γ maxa0 Q(st+2 , a0 )))) (Nested Q-learning update) Q(st , at ) = (1−α)Q(st , at )+α(rt +γ max((1−α)Q(st+1 , at+1 )+α(rt+1 +γ maxa0 Q(st+2 , a0 )), maxa0 Q(st+1 , a0 ))) (Max of normal Q-learning update and one step look-ahead update)

16

Q8. [14 pts] Bellman Equations for the Post-Decision State Consider an infinite-horizon, discounted MDP (S, A, T, R, γ). Suppose that the transition probabilities and the reward function have the following form: T (s, a, s0 ) = P (s0 |f (s, a)) R(s, a, s0 ) = R(s, a) Here, f is some deterministic function mapping S × A → Y , where Y is a set of states called post-decision states. We will use the letter y to denote an element of Y , i.e., a post-decision state. In words, the state transitions consist of two steps: a deterministic step that depends on the action, and a stochastic step that does not depend on the action. The sequence of states (st ), actions (at ), post-decision-states (yt ), and rewards (rt ) is illustrated below. f

(s0 , a0 )

y0

P

(s1 , a1 )

r0

f

P

y1

(s2 , a2 )

r1

f

···

r2

You have learned about V π (s), which is the expected discounted sum of rewards, starting from state s, when acting according to policy π.   V π (s0 ) = E R(s0 , a0 ) + γR(s1 , a1 ) + γ 2 R(s2 , a2 ) + . . . given at = π(st ) for t = 0, 1, 2, . . . ∗

V (s) is the value function of the optimal policy, V ∗ (s) = maxπ V π (s). This question will explore the concept of computing value functions on the post-decision-states y.   W π (y0 ) = E R(s1 , a1 ) + γR(s2 , a2 ) + γ 2 R(s3 , a3 ) + . . .

1

We define W ∗ (y) = maxπ W π (y). (a) [2 pts] Write W ∗ in terms of V ∗ . W ∗ (y) = P 0 y)V ∗ (s0 ) s0 P (s P # s0 P (s0 y)[V ∗ (s0 ) + maxa R(s0 , a)] P # s0 P (s0 y)[V ∗ (s0 ) + γ maxa R(s0 , a)] P 0 # y)[γV ∗ (s0 ) + maxa R(s0 , a)] 0 P (s

#

s

None of the above

Consider the expected rewards under the optimal policy.   W ∗ (y0 ) = E R(s1 , a1 ) + γR(s2 , a2 ) + γ 2 R(s3 , a3 ) + . . . y0 X   = P (s1 y0 )E R(s1 , a1 ) + γR(s2 , a2 ) + γ 2 R(s3 , a3 ) + . . . s1 s1

=

X

P (s1 y0 )V ∗ (s1 )

s1

V



is time-independent, so we can replace y0 by y and replace s1 by s0 , giving X W ∗ (y) = P (s0 y)V ∗ (s0 ) s0

1 In some applications, it is easier to learn an approximate W function than V or Q. For example, to use reinforcement learning to play Tetris, a natural approach is to learn the value of the block pile after you’ve placed your block, rather than the value of the pair (current block, block pile). TD-Gammon, a computer program developed in the early 90s, was trained by reinforcement learning to play backgammon as well as the top human experts. TD-Gammon learned an approximate W function.

17

(b) [2 pts] Write V ∗ in terms of W ∗ . V ∗ (s) =

# #

# #

maxa [W ∗ (f (s, a))] maxa [R(s, a) + W ∗ (f (s, a))] maxa [R(s, a) + γW ∗ (f (s, a))] maxa [γR(s, a) + W ∗ (f (s, a))] None of the above

V ∗ (s0 ) = max Q(s0 , a0 ) a0   = max E R(s0 , a0 ) + γR(s1 , a1 ) + γ 2 R(s2 , a2 ) + . . . s0 , a0 a0     = max E R(s0 , a0 ) s0 , a0 + E γR(s1 , a1 ) + γ 2 R(s2 , a2 ) + . . . s0 , a0 a0   = max R(s0 , a0 ) + E γR(s1 , a1 ) + γ 2 R(s2 , a2 ) + . . . f (x0 , a0 ) a0

= max (R(s0 , a0 ) + γW ∗ (f (s0 , a0 ))) a0

Renaming variables, we get V ∗ (s) = max (R(s, a) + γW ∗ (f (s, a))) a

(c) [4 pts] Recall that the optimal value function V ∗ satisfies the Bellman equation: X T (s, a, s0 ) (R(s, a) + γV ∗ (s0 )) , V ∗ (s) = max a

s0

which can also be used as an update equation to compute V ∗ . Provide the equivalent of the Bellman equation for W ∗ .

W ∗ (y) =

P

s0

P (s0 |y) maxa (R(s0 , a) + γW ∗ (f (s0 , a)))

The answer follows from combining parts (a) and (b) (d) [3 pts] Fill in the blanks to give a policy iteration algorithm, which is guaranteed return the optimal policy π ∗ . • Initialize policy π (1) arbitrarily. • For i = 1, 2, 3, . . . (i)

– Compute W π (y) for all y ∈ Y . – Compute a new policy π (i+1) , where π (i+1) (s) = arg max a

– If

(2)

(i)

for all s ∈ S, return π .

Fill in your answers for blanks (1) and (2) below. (1)

# #

(i)

W π (f (s, a)) (i)

R(s, a) + W π (f (s, a)) (i)

R(s, a) + γW π (f (s, a)) 18

(1)

for all s ∈ S.

(2)

# #

(i)

γR(s, a) + W π (f (s, a)) None of the above

π (i) (s) = π (i+1) (s)

Policy iteration performs the following update: (i)

π (i+1) (s) = arg max Qπ (s, a) a

π

Next we express Q in terms of W

π

(similarly to part b):   Qπ (s0 , a0 ) = E R(s0 , a0 ) + γR(s1 , a1 ) + γ 2 R(s2 , a2 ) + . . . s0 , a0   = R(s0 , a0 ) + γE R(s1 , a1 ) + γR(s2 , a2 ) + . . . f (s0 , a0 ) = R(s0 , a0 ) + γW π (f (s0 , a0 ))

(e) [3 pts] In problems where f is known but P (s0 |y) is not necessarily known, one can devise reinforcement learning algorithms based on the W ∗ and W π functions. Suppose that an the agent goes through the following sequence of states, actions and post-decision states: st , at , yt , st+1 , at+1 , yt+1 . Let α ∈ (0, 1) be the learning rate parameter. Write an update equation analogous to Q-learning that enables one to estimate W ∗



 W (yt ) ← (1 − α)W (yt ) + α

max (R(st+1 , a) + γW (f (st+1 , a)) a

Recall the motivation for Q learning: the Bellman equation satisfied by the Q function is Q(s, a) = Es0 [R(s, a)+ γ maxa0 Q(s0 , a0 )]. Q learning uses an estimate of the right-hand side of this equation obtained from a single sample transition s, a, s0 . That is, we move Q(s, a) towards R(s, a) + γ maxa0 Q(s0 , a0 ). We have obtained a Bellman-like equation for W ∗ in part c. X W ∗ (y) = P (s0 |y) max (R(s0 , a0 ) + γW ∗ (f (s0 , a0 ))) 0 a

s0

h

i = Es0 max (R(s0 , a) + γW ∗ (f (s0 , a))) a

If we don’t know P (s0 |y), we can still estimate the expectation above from a single transition (y, s0 ) using the expression inside the expectation: maxa (R(s0 , a) + γW ∗ (f (s0 , a)). Doing a partial update with learning rate parameter α, we get W (yt ) ← (1 − α)W (yt ) + α max (R(st+1 , a) + γW (f (st+1 , a)) a

19