In the Gridworld example of the policy iteration section, you saw that you may not need to reach the optimal state value function v∗(s) to obtain an optimal policy. The value function at iteration k=3 already gives the same policy as a far more accurate value function at large k.We could have stopped early, and taking the argument to the limit, we can question the need to start from a policy at all. Instead of letting the policy π dictate which actions are selected, we select the actions that maximize the expected return: the immediate reward plus the discounted value of the successor state. We therefore do the improvement step in each iteration, computing the optimal value function without a policy.In this section we look at an algorithm called value iteration that does that.Value iteration.The basic principle behind value iteration is the principle that underlies dynamic programming, called the principle of optimality, as applied to policies. According to this principle an optimal policy can be divided into two components.
An optimal first action a∗.
An optimal policy from the successor state s′.
More formally, for a discount factor γ>0, a policy π(a∣s) achieves the optimal value from state s, vπ(s)=v∗(s), if and only if it selects only optimal actions at s and achieves the optimal value, vπ(s′)=v∗(s′), from every successor state s′ that it reaches from s with positive probability.Effectively this principle allows us to decompose the problem into two sub-problems, one of them straightforward to determine, and to use the Bellman optimality equation, which provides the one-step backup induction at each iteration.v∗(s)=maxa(Rsa+γ∑s′∈SPss′av∗(s′))As an example, if I want to move optimally towards a location in the room, I can make an optimal first step and at that point follow the optimal policy, which I was magically given, towards the desired final location. Think of making that optimal first step by walking backwards from the goal state. We start at the end of the problem, where we know the final rewards, and work backwards to all the states that connect to it in our look-ahead tree.One-step look-ahead tree representation of the value iteration algorithm.The “start from the end” intuition behind the equation is usually applied with no consideration of whether we are at the end or not. We just do the backup inductive step for each state. In value iteration with synchronous backups, we start at k=0 from the value function v0(s)=0.0, and at each iteration k+1, for all states s∈S, we update vk+1(s) from vk(s). For a discounted problem with 0≤γ<1 and bounded rewards, the update is a contraction, and the value function converges to v∗ from any starting point. With γ=1 convergence needs further assumptions, for example an episodic problem in which every policy eventually reaches a terminal state; without them the values can grow without bound.The equation of value iteration is taken straight from the Bellman optimality equation, by turning the latter into an update rule called the Bellman update.vk+1(s)=maxa(Rsa+γ∑s′∈SPss′avk(s′))Value iteration can be written in vector form asvk+1=maxa(Ra+γPavk)Notice that we are not building an explicit policy at every iteration, and the intermediate value functions may not correspond to a feasible policy.
Initial value estimates for iteration 2 (A). States with next state positive value (B).v2(s33)=−0.04+P(s43∣s33,→)v1(s43)+P(s33∣s33,→)v1(s33)+P(s32∣s33,→)v1(s32)v2(s33)=−0.04+0.8×1+0.1×0.76+0.1×0=0.836v2(s23)=−0.04+P(s33∣s23,→)v1(s23)+P(s23∣s23,→)v1(s23)=−0.04+0.8×0.76=0.568v2(s32)=−0.04+P(s33∣s32,↑)v1(s33)+P(s42∣s32,↑)v1(s42)+P(s32∣s32,↑)v1(s32)v2(s32)=−0.04+0.8×0.76+0.1×−1+0.1×0=0.468
Initial value estimates for iteration 3 (A). States with next state positive values (B)
Notice how information propagates outward from terminal states and eventually all states have correct value estimates. s32 has a lower value compared to s23 due to the red oval state with negative reward next to s32
After many iterations, the value estimates converge to the optimal value function v∗(s) and a policy π∗ can be derived from the value function using the following equation:π∗(s)=argmaxa[∑s′P(s′∣s,a)v∗(s′)]Optimal value function and optimal policy π∗ for the maze problem.
The rate of convergence depends mainly on the discount factor γ, and also on the maximum reward value. The policy that we get from coarse estimates is close to the optimal policy long before v has converged. This means that after a reasonable number of iterations, we could extract the policy in a greedy fashion and use it to guide the agent’s actions.Convergence of value for the maze problem. For this problem, convergence is reached within 5 to 10 iterations.Key references: (Mansour & Singh, 2013; Tamar et al., 2016; Tamar et al., 2016)