Week 12 · Capstone · Test a controller under changed conditions

Compare a learned route and a heuristic across seeds, then shift the environment.

← Week 11 · Subject contents

Compare a learned route and a heuristic across seeds, then shift the environment.

Work through the problem

Choose a route for each delivery. The direct route pays 5 when clear and −5 when blocked. The detour always pays 2. With blockage probability b, direct has expected reward 5−10b. Its break-even blockage rate is 0.3.

Train action values with exploration at b=0.15. Evaluate the selected action against the detour on the same random outcomes, then raise b to 0.45. Report the paired reward differences and how many training seeds chose each action. This isolates one operational shift with a known expected effect.

Run the Python lab

import numpy as np
decisions = []
for seed in range(20):
    rng = np.random.default_rng(seed)
    value,count = np.zeros(2),np.zeros(2)
    for step in range(700):
        a = step if step<2 else (rng.integers(2) if rng.random()<.15 else value.argmax())
        r = 2 if a else (-5 if rng.random()<.15 else 5)
        count[a]+=1
        value[a]+=(r-value[a])/count[a]
    decisions.append(value.argmax())
print("Seeds choosing direct:",decisions.count(0))
rng = np.random.default_rng(44)
outcomes = rng.random((len(decisions),1000))
for blocked in [.15,.45]:
    direct = np.where(outcomes<blocked,-5,5)
    learned = np.where(np.array(decisions)[:,None]==0,direct,2)
    delta = learned.mean(axis=1)-2
    print(blocked,"mean advantage",round(delta.mean(),2),"range",np.quantile(delta,[.05,.95]).round(2))
    assert (delta.mean()>0)==(blocked<.3)

Output from the lab

Seeds choosing direct: 20
0.15 mean advantage 1.47 range [1.3  1.66]
0.45 mean advantage -1.51 range [-1.84 -1.21]

Practice

  1. What would let a trained controller adapt online?

Check your reasoning

  1. Detect the blockage change, collect fresh outcomes with controlled exploration, and reevaluate before relying on the new policy.

← Week 11 · Subject contents

Further reading · Sutton and Barto · Reinforcement Learning