Starting from:

$30

Assignment 1 Solution

Optimal Policy for Simple MDP [20 pts] Consider the simple n-state MDP shown in Figure 1. Starting from state s 1 , the agent can move to the right (a 0 ) or left (a 1 ) from any state s i . Actions are deterministic and always succeed (e.g.

going left from state s 2 goes to state s 1 , and going left from state s 1 transitions to itself). Rewards are given upon taking an action from the state. Taking any action from the goal state G earns areward of r = +1 and the agent stays in state G. Otherwise, each move has zero reward (r = 0).




Assume a discount factor γ < 1.




Figure 1: n-state MDP







(a) The optimal action from any state s i is taking a 0 (right) until the agent reaches the goal state

G. Find the optimal value function for all states s i 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 s i has reward c

and any action from the goal state G has reward 1 + c). Find the new optimal value function

for all states s i 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. r new = a(c + r old )). Find the new optimal value function for all states s i 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 s 0 , action a 1 has zero immediate reward and causes a deterministic transition to state s 1 where

there is reward +1 for every time step afterwards (regardless of action). From state s 0 , action a 2 causes a deterministic transition to state s 2 with immediate reward of γ 2 /(1 − γ) but state s 2 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 a 1 from state s 0 at time step




(b) What is the total discounted return of taking action a 2 from state s 0 at time step




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




n ∗ ≥

log(1 − γ) 111 ≥ log( ) log 1(/1 − γ) 1/(1 − γ)




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|| ∞ = max s,a |x(s, a)|.







Assume that we are following the greedy policy with respect to Q̃, π(s) = argmax a∈A Q̃(s, a). We

want to show that the following holds:

V π (s) ≥ V ∗ (s) − 2ε1 − γ




Where V π (s) is the value function of the greedy policy π and V ∗ (s) = max a∈A Q ∗ (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) = argmax a∈A Q̃(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 V π (s) ≥ V ∗ (s) −

2ε 1−γ . [10 pts]




Now we show that this bound is tight. Consider the 2-state MDP illustrated in figure 3. State s 1 has two actions, "stay" self transition with reward 0 and "go" that goes to state s 2 with reward 2ε.

State s 2 transitions to itself with reward 2ε for every time step afterwards.




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

(d) Show that there exists an approximate state-action value function Q̃ with ε error (measured 2ε with l ∞ norm), such that V π (s 1 ) − V ∗ (s 1 ) = − 1−γ , where π(s) = argmax a∈A Q̃(s, a). (You may need to define a consistent tie break rule) [10 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 max s |V old (s) − V new (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-4x4-FrozenLake-v0 and Stochastic-4x4-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]

More products