Module 1 · Reinforcement Learning · Lesson 3 of 34

Learning from rewards

Agent, environment, actions and rewards. Exploration against exploitation, and Q-learning in a grid world.

In this lesson · about 18 minutes

  • Name the parts of a reinforcement-learning problem: agent, environment, state, action, reward, policy
  • Explain the explore-or-exploit trade-off and the discount factor
  • Work through one Q-learning update by hand

Most machine learning learns from examples with the right answer attached ("this photo is a cat"). Reinforcement learning (RL) is different: nobody gives the right answer. An agent tries things, and the world tells it afterwards how well that went, as a number called a reward. It is how you learned to ride a bicycle.

  • Environment: the world the agent acts in (a game, a robot's room, a conversation).
  • State: what the situation is right now.
  • Action: a move the agent can make.
  • Reward: a number after each action. Positive is good, negative is bad.
  • Policy: the agent's rule for picking an action in each state. Learning means improving the policy.

The goal is not the biggest reward right now but the biggest total reward over time. Sometimes you take a small loss (a step that costs −1) to reach a big win later (+10 at the goal).

Q-learning in one line

Q-learning keeps a table of scores, Q(state, action): "how much total reward do I expect if I take this action here and play well afterwards?" After every step it nudges the score towards what it just saw:

new Q = old Q + α × (reward + γ × best Q of the next state − old Q)

  • α (alpha), the learning rate: how big a nudge. 0.5 means "move halfway towards the new evidence".
  • γ (gamma), the discount: how much future reward counts. 0.9 means a reward one step away is worth 90% of the same reward now.
  • The part in brackets is the surprise: how much better or worse things went than expected.

Worked example

One Q-learning update

The agent is one square from a good area. Its table says Q(here, right) = 2.0. It moves right, pays the step cost of −1, and its table says the best action in the new square is worth 6.0. Use α = 0.5 and γ = 0.9.

    Step 0 of 5

    Try it · simulator

    Grid world: Q-learning

    An agent starts knowing nothing. It gets +10 at the goal, −10 in a pit and −1 for every step. Train it and watch it learn a route by trial and error.

    GOAL +10
    PIT −10
    PIT −10
    PIT −10
    START

    Episodes

    0

    Avg reward, last 10

    0.0

    Learned route

    –

    Route reward

    –

    Each square shows the move the agent currently thinks is best (arrow) and how good it thinks the square is (green good, red bad). The pink outline is the route it would take now. Train with ε = 0 from scratch and see whether it ever finds the goal.

    Check your understanding0 of 4 correct

    Question 1

    1.In reinforcement learning, what tells the agent how well it is doing?

    Question 2

    2.An agent with ε = 0 starts with an empty table. What is the risk?

    Question 3

    3.Old Q = 1.0, reward = 0, γ = 0.5, best next Q = 4.0, α = 0.25. What is the new Q?

    Question 4

    4.A cleaning robot is rewarded for “no mess visible to its camera”. It learns to face a wall. What is this?

    Quiz score: 0 of 4

    Tip: answer every quiz question correctly first.

    Written by Noviq Academy in its own words. The simulators are small teaching models that keep the real idea and leave out the scale; their numbers (prices, speeds, scores) are illustrative. Model names, prices and features change quickly, so check your provider's current documentation before you build. Read-aloud uses your device's built-in voices.