Week 08 · Linear value function approximation

Share information between states using a feature map.

← Week 7 · Subject contents · Week 9 →

Share information between states using a feature map.

Work through the problem

A tabular value function gives each state its own parameter. A linear approximation V(s)=wᵀφ(s) shares parameters. A TD error δ=r+γV(s′)−V(s) gives the semi-gradient update w ← w+αδφ(s). The gradient treats the bootstrapped target as fixed for that update.

With φ(s)=[1,s] and initial w=[0,0], a target of 4 at s=2 and α=0.1 changes w to [0.4,0.8]. The prediction at unseen s=3 becomes 2.8. This can speed learning or introduce bias when the features are wrong.

Run the Python lab

import numpy as np
states = np.arange(5)
phi = np.c_[np.ones(5),states]
w = np.zeros(2)
w += .1*(4-phi[2]@w)*phi[2]
print("One update:",w,"unseen state 3:",round(phi[3]@w,2))
for _ in range(300):
    for s in [0,2,4]:
        w += .03*(2*s-phi[s]@w)*phi[s]
print("Predictions:",(phi@w).round(2))
assert np.allclose(phi@w,2*states,atol=.02)

Output from the lab

One update: [0.4 0.8] unseen state 3: 2.8
Predictions: [0. 2. 4. 6. 8.]

Practice

  1. Can these features represent a value that jumps at s=3?

Check your reasoning

  1. Only approximately. Add an indicator or a nonlinear basis to capture the jump.

← Week 7 · Subject contents · Week 9 →

Further reading · Sutton and Barto · Reinforcement Learning