Project 3 of 12, for Aaesha
Gridworld Solver
For Aaesha, planning the way a mind with a map does: the worth of every tile on the crab's racing grid, without a single race. Policy evaluation, value iteration and policy iteration.
Sign up free to open itLog in
Act 8 needs a free account, so your work is saved as you go. Act 1 is open to everyone.
The brief
- AaeshaA thousand races say the traditional line is worth about minus eight, but that's only about.
- AaeshaRats in a maze learn a map of it in their heads, then plan with it.
- AaeshaYou've already got the map, with every tile and every chance on it, which is enough to work it out exactly.
- NeilI'd like to know, exactly, whether I've been racing it wrong all term.
- PaulThen work it out instead of racing it.
Write dp.py, using your racing grid in track.py. Values and policies are dictionaries keyed by tile; gamma is 0.9 unless you're told otherwise.
q_value(values, tile, action, gamma=0.9): what an action is worth on a tile, given the values of the tiles it can lead to.evaluate(policy, gamma=0.9, theta=1e-6): the value of every tile under a policy, by sweeping until no value changes by more thantheta. The finish and the pool stay at 0.greedy(values, gamma=0.9): the best action on every tile still racing, looking one step ahead.value_iteration(gamma=0.9, theta=1e-6): the best values.policy_iteration(policy, gamma=0.9): evaluate and improve until the policy stops changing; returns(policy, values).
Run as a program, it prints the traditional line's values, the best values, the best line, and whether policy iteration agrees.
The traditional line 4.5 6.7 9.1 0.0 2.7 # 5.1 0.0 -7.6 -8.6 -8.4 -9.8 The best line 4.5 6.7 9.1 0.0 2.7 # 5.1 0.0 1.2 1.2 2.8 0.1 > > > F ^ # ^ P ^ > ^ < Policy iteration agrees: True
What you learn
What's in it
- How good a tile is to stand on
- One step from the finish
- Sweep until nothing changes
- Two sweeps
- The best a tile can be worth
- Free seconds
- Evaluate, improve, repeat
- A longer corridor
- How Paul would do it
- Fix Riya's version
- Make the track known
- Three rounds
- Ship it