Gradient LabStart the lesson

Lessons › Chapter 13: Reinforcement learning

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.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

An app that learns by doing

Brightbank’s savings app could learn when a reminder actually helps people save, by trying and seeing what works.

Concept

An agent in a world

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

Build

It acts

Based on the state, the agent picks an action: move left or move right.

Build

The world responds

The environment answers with a new state and a reward: 0 for an ordinary square, +10 for reaching the goal. The agent learns from this, and the loop repeats.

Key idea

Think long-term

The goal isn’t the next reward but the total over time. Future rewards usually count a bit less (a discount), like money now vs money later. Sometimes taking a small loss now leads to a much bigger win later.

Real life

In real life: a robot vacuum

A robot vacuum is an agent: its state is what its sensors see, its actions are moves and turns, and it’s rewarded for covering floor without bumping or getting stuck. Robots, game-playing AIs and some recommendation systems are built around this same loop.

Quick check: What is a reinforcement learning agent trying to maximize?

The objective is the (discounted) sum of rewards, not just the next one.

Pseudocode

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

Key terms

environment
The world an agent acts in. It responds to each action with a new situation and a reward.
state
What the agent observes about its situation right now.
action
A choice the agent can make.
discount
How much less a future reward counts than an immediate one.

In the news

Recent models and papers that build on this idea: