Joyous Brands

Artificial Intelligence: A Visual Learner's Series

Part 8: Reinforcement learning

No right answers, just a score that often arrives late. The agent has to work out which actions earned it.

Learning from reward

In one line: Try actions, receive rewards or penalties, and gradually discover which behavior pays off over time.

Act, get a reward and a new state, repeatThe goal is the largest total reward over time, not the biggest next rewardAgentPolicy: what to doin each stateEnvironmentResponds with a newstate and a rewardActionNew state+ reward
  • A dog learning to fetch gets the treat at the end, so it must figure out which earlier moves mattered: the credit assignment problem.

Key terms: state, action, reward, return (total discounted reward), policy, value function V(s), action value Q(s, a).

Watch out: The agent optimizes the reward you wrote, loopholes included.

Explore or exploit?

In one line: Balance using what you know works with trying things that might work better.

  Your favorite taco place   ████████░░  pretty good, well known
  Restaurant never tried     ░░░░?░░░░░  could be better, could be worse

  ε-greedy: go to the favorite 90% of the time, try something random 10%
  UCB:      prefer options whose best plausible score is highest

Key terms: multi-armed bandit, ε-greedy, upper confidence bound (UCB), Thompson sampling, regret.

Watch out: Never exploring locks in early luck.

Learning values from experience

In one line: Compare your prediction with what happened a moment later and correct the difference, without waiting for the end.

  Leave work: "30 min"  ──▶  5 min in, traffic jam: "now 45 min"
                            update right away (TD error = +15 min)
  • The bracket is the TD error: how surprised the agent was. Q-learning nudges Q(s, a) a fraction α toward the better-informed guess.

Watch out: Learning guesses from guesses can become unstable, especially with neural networks.

Learning behavior directly

In one line: Do more of what led to high reward and less of what led to low reward, adjusting the behavior itself.

The critic tells the actor whether it did better than expectedActorthe policy: picks actionsEnvironmentreturns reward + stateCriticestimates valueactionreward, state“Better or worse than expected?” (the TD error)
  • Like free-throw practice: keep the motions that went in, drop the ones that clanked, faster with a coach saying "better than your average."

  • Policy gradient methods (REINFORCE, PPO) handle continuous actions like steering angles.

Watch out: Big updates can wreck a good policy, so methods like PPO limit each step.

Deep and model-based RL

In one line: Neural networks let agents learn from raw pixels; a learned model of the world lets them plan ahead.

ApproachHow it worksExample
Deep Q-networkNetwork estimates Q from screen pixels; replay memory and target network keep it stableClassic video games
Model-based RLLearn how the world responds, then plan or simulateFar fewer real trials needed
Search + learningLearned value and policy guide tree search, trained by self-playAlphaZero-style board games
RLHFReward model learned from human preferencesFine-tuning language models

Watch out: Policies learned in simulation often stumble on real hardware.

Self-test

  1. Draw the agent–environment loop for a thermostat that learns to save energy.

  2. Walk through one Q-learning update with numbers you choose.

  3. Redraw the actor–critic diagram and say what each arrow carries.