Gradient LabSign up free

Cheat sheets › Chapter 13

Reinforcement learning cheat sheet

Learn by acting and collecting rewards. Every lesson in one page: the key idea, the pseudocode and the terms.

Agents and rewards

Reinforcement learning has an agent (the learner) inside an environment (the world). The agent observes its state: here, which square it’s on.

loop forever:
    state = what the agent observes now
    action = agent.choose(state)
    reward, next_state = environment.respond(action)
    agent.learn(state, action, reward)

goal: collect as much total reward as possible over time

Terms: environment, state, action, discount

Markov decision processes

A markov decision process writes a decision problem down precisely. First, the states. A smart thermostat’s room can be cold, comfy or hot.

states  = [cold, comfy, hot]
actions = [heat, wait]
P(next state | state, action)    # e.g. heat when cold → comfy 80%
R(state)                         # comfy = +1, cold or hot = −1
policy = which action to take in each state

Terms: markov decision process

Q-learning

Q-learning keeps a q-value for every state and action: “how much total reward do I expect if I do this here?” Purple bars are “go left”, teal bars “go right”. Everything starts at 0.

Q[state][action] = 0 for everything
repeat many episodes:
    pick an action (usually the best known, sometimes random)
    reward, next = environment.step(action)
    target = reward + 0.9 × best Q[next]
    Q[state][action] += 0.1 × (target − Q[state][action])
# then simply follow the highest Q in each state

Terms: q-value, exploration

Policy gradients

Instead of a Q-table, a policy gradient method learns the policy directly: a network that gives a probability for each action. A robot arm starts out unsure what to do.

policy = network: state → probability of each action
play an episode, sampling actions from the policy
if the total reward was good:
    make the actions you took more likely
else:
    make them less likely
repeat over many episodes

Terms: policy gradient

Revise with flashcards and quizzes. Free practice for every lesson in this chapter.

Open in the app