Learning, and the capstone · University · about 35 min
The optimiser answers the question you asked, which is rarely the question you meant.
[1 mark]The reward is distance travelled towards a mark 60 cm ahead. What is it actually rewarding?
[1 mark]Four commands were each driven for 4 s from the same line. What does this print?
MARK = 60.0
travel = {55: 49.5, 70: 63.8, 85: 79.2, 100: 93.6}
by_progress = max(travel, key=lambda c: travel[c])
by_error = min(travel, key=lambda c: abs(travel[c] - MARK))
print(by_progress, by_error)100 70
Command 100 travels furthest, but command 70 ends 3.8 cm from the mark against 10.5 cm for 55. Two scores, two winners.
[1 mark]What is the name for a policy scoring well on its reward while the behaviour is not what was wanted?
[1 mark]A robot is rewarded for a small depth reading, meant to encourage parking close to its charger. What is the likely result?
[1 mark]Which form of shaping reward is guaranteed not to change the optimal policy?
[1 mark]Why does a sparse reward of 1 for arriving and 0 otherwise teach almost nothing, even though it specifies the task perfectly?
[1 mark]A search's best score has risen steadily for fifty trials. What should you do before believing it?
Try commands 55, 70, 85 and 100 for four seconds each from the same line, homing between trials. Print by progress:, the command that travelled furthest, and by error:, the command that finished nearest the mark 60 cm ahead. Then run the one the error score chose, and stop there.
from bugbot import * connect() DT = 0.1 MARK = 60.0 RUN_S = 4.0 COMMANDS = [55, 70, 85, 100]
The hint students can ask for: Try commands 55, 70, 85 and 100, each for four seconds from the same starting line, driving back between trials so every trial is fair. Score each one twice: how far it got, and how far it ended from the mark 60 cm ahead. The two scores do not pick the same command. Then run the one that the error score picked, and stop there.
from bugbot import *
connect()
DT = 0.1
MARK = 60.0 # the mark, in cm ahead of the starting line
RUN_S = 4.0
COMMANDS = [55, 70, 85, 100]
def home():
"""Back to the starting line between trials, so every trial starts the same."""
for i in range(200):
y = position()[1]
if y < 3.0:
break
drive(-max(20, min(80, 1.2 * y)), 0, 0)
wait(DT)
stop()
wait(0.5)
def trial(cmd):
"""Drive at this command for four seconds and report how far the robot got."""
y0 = position()[1]
drive(cmd, 0, 0)
wait(RUN_S)
stop()
wait(0.6)
return position()[1] - y0
rows = []
for cmd in COMMANDS:
travel = trial(cmd)
rows.append((cmd, travel, abs(travel - MARK)))
print("command", cmd, "travelled", round(travel, 1), "and finished", round(abs(travel - MARK), 1), "cm out")
home()
print("by progress:", max(rows, key=lambda r: r[1])[0])
best = min(rows, key=lambda r: r[2])[0]
print("by error:", best)
drive(best, 0, 0)
wait(RUN_S)
stop()
wait(0.5)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.