## Description

Consider the simple n-state MDP shown in Figure 1. Starting from state s1, the agent can move to the right (a0) or left (a1) from any state si. Actions are deterministic and always succeed (e.g. going left from state s2 goes to state s1, and going left from state s1 transitions to itself). Rewards are given upon taking an action from the state. Taking any action from the goal state G earns a reward of r = +1 and the agent stays in state G. Otherwise, each move has zero reward (r = 0). Assume a discount factor Ξ³ < 1.

π”,π = 0 π”,π = 0

”

π = 1

π),π = 0 π),π = 0 π),π = 0

Figure 1: n-state MDP

(a) The optimal action from any state si is taking a0 (right) until the agent reaches the goal state G. Find the optimal value function for all states si and the goal state G. [5 pts]

(b) Does the optimal policy depend on the value of the discount factor Ξ³? Explain your answer. [5 pts]

(c) Consider adding a constant c to all rewards (i.e. taking any action from states si has reward c and any action from the goal state G has reward 1 + c). Find the new optimal value function for all states si and the goal state G. Does adding a constant reward c change the optimal policy? Explain your answer. [5 pts]

(d) After adding a constant c to all rewards now consider scaling all the rewards by a constant a (i.e. rnew = a(c + rold)). Find the new optimal value function for all states si and the goal state G. Does that change the optimal policy? Explain your answer, If yes, give an example of a and c that changes the optimal policy. [5 pts]

2 Running Time of Value Iteration [20 pts]

In this problem we construct an example to bound the number of steps it will take to find the optimal policy using value iteration. Consider the infinite MDP with discount factor Ξ³ < 1 illustrated in Figure 2. It consists of 3 states, and rewards are given upon taking an action from the state. From state s0, action a1 has zero immediate reward and causes a deterministic transition to state s1 where there is reward +1 for every time step afterwards (regardless of action). From state s0, action a2 causes a deterministic transition to state s2 with immediate reward of Ξ³2/(1 β Ξ³) but state s2 has zero reward for every time step afterwards (regardless of action).

Figure 2: infinite 3-state MDP

(a) What is the total discounted return ( ) of taking action a1 from state s0 at time step t = 0? [5 pts]

(b) What is the total discounted return ( ) of taking action a2 from state s0 at time step t = 0? What is the optimal action? [5 pts]

(c) Assume we initialize value of each state to zero, (i.e. at iteration n = 0, βs : Vn=0(s) = 0). Show that value iteration continues to choose the sub-optimal action until iteration nβ where,

Thus, value iteration has a running time that grows faster than 1/(1 β Ξ³). (You just need to show the first inequality) [10 pts]

3 Approximating the Optimal Value Function [35 pts]

Consider a finite MDP M = hS,A,T,R,Ξ³i, where S is the state space, A action space, T transition probabilities, R reward function and Ξ³ the discount factor. Define Qβ to be the optimal state-action value Qβ(s,a) = QΟβ(s,a) where Οβ is the optimal policy. Assume we have an estimate QΛ of Qβ, and QΛ is bounded by lβ norm as follows:

||QΛ β Qβ||β β€ Ξ΅

Where ||x||β = maxs,a|x(s,a)|.

Assume that we are following the greedy policy with respect to QΛ, Ο(s) = argmaxaβAQΛ(s,a). We want to show that the following holds:

Where VΟ(s) is the value function of the greedy policy Ο and V β(s) = maxaβAQβ(s,a) is the optimal value function. This shows that if we compute an approximately optimal state-action value function and then extract the greedy policy for that approximate state-action value function, the resulting policy still does well in the real MDP.

(a) Let Οβ be the optimal policy, V β the optimal value function and as defined above Ο(s) = argmaxaβAQΛ(s,a). Show the following bound holds for all states s β S. [10 pts]

V β(s) β Qβ(s,Ο(s)) β€ 2Ξ΅

(b) Using the results of part 1, prove that

Now we show that this bound is tight. Consider the 2-state MDP illustrated in figure 3. State s1 has two actions, “stay” self transition with reward 0 and “go” that goes to state s2 with reward 2Ξ΅. State s2 transitions to itself with reward 2Ξ΅ for every time step afterwards.

βπ π‘ππ¦β, π = 0 π = 2π

Figure 3: 2-state MDP

(c) Compute the optimal value fucntion V β(s) for each state and the optimal state-action value function Qβ(s,a) for state s1 and each action. [5 pts]

4 Frozen Lake MDP [25 pts]

Now you will implement value iteration and policy iteration for the Frozen Lake environment from OpenAI Gym. We have provided custom versions of this environment in the starter code.

(a) (coding) Read through vi_and_pi.py and implement policy_evaluation, policy_improvement and policy_iteration. The stopping tolerance (defined as maxs |Vold(s) β Vnew(s)|) is tol =

10β3 . Use Ξ³ = 0.9. Return the optimal value function and the optimal policy. [10pts]

(b) (coding) Implement value_iteration in vi_and_pi.py. The stopping tolerance is tol =

10β3 . Use Ξ³ = 0.9. Return the optimal value function and the optimal policy. [10 pts]

(c) (written) Run both methods on the Deterministic-4×4-FrozenLake-v0 and

Stochastic-4×4-FrozenLake-v0 environments. In the second environment, the dynamics of the world are stochastic. How does stochasticity affect the number of iterations required, and the

resulting policy? [5 pts]

## Reviews

There are no reviews yet.