AI foundations

Reinforcement learning: definition, how it works and examples

Train a dog and you never hand it a manual. You let it try things, you reward the ones you like, and over a few weeks it works out what earns a treat. Reinforcement learning runs on that same idea, except the learner is a piece of software and the treats are numbers. An agent acts, the environment answers with a reward or a penalty, and slowly the agent settles on a strategy that pays off. Nobody scripts the right answer. It gets found.

That trial-and-error quality is what sets reinforcement learning apart from the machine learning most people meet first. There is no dataset of correct answers to copy. The system has to work out what good looks like by acting in the world and living with the consequences. We build data and AI systems at Shipshape Data, and reinforcement learning is one of the approaches clients ask about most and understand least, usually because the headlines are all about beating grandmasters at Go while the everyday uses are quieter and closer to home.

This guide walks through what reinforcement learning is, the handful of concepts you actually need, the main families of algorithms, where it earns its keep in real businesses, and how to start without a doctorate. Read the parts that match where you are and skip the rest.

Why reinforcement learning earns its place

Most machine learning you have seen learns from a stack of labelled examples. Show it thousands of photos tagged cat or dog and it learns to tell them apart. That works beautifully when someone can hand you the right answer for every case. It falls apart the moment the right answer depends on what you did three steps ago.

Reinforcement learning is built for exactly that situation: sequential decisions where each choice narrows or widens what you can do next, and where nobody knows the best move in advance. You are not matching inputs to known outputs. You are learning a way of behaving that pays off over a whole sequence, not just the next click. That is a different problem, and it is the one a lot of real business decisions actually are.

The problems other methods cannot touch

Rule-based systems need you to spell out what to do in every situation. That is fine until the situations outnumber anything you could write down. Picture a warehouse robot picking a route through a floor whose layout, stock and stray obstacles change by the hour. You cannot enumerate every arrangement, so you cannot pre-write the rules. Reinforcement learning sidesteps the problem by learning from what happens: try a path, see how long it took, adjust. The agent keeps getting better as it goes, which is precisely the property you want when the environment refuses to sit still.

The kind of value it drives

The payoff is not academic. Energy operators use reinforcement learning to balance loads across a grid and shave real money off waste. Data centre teams have used it to tune cooling and cut the energy that pulls, without letting the kit overheat. Manufacturers schedule maintenance around learned patterns of wear instead of a fixed calendar, so lines stop less often. The common thread is a decision that unfolds over time with money riding on getting the sequence right, not just the next step.

Reinforcement learning suits the messy middle where the rules are too tangled to write down but the feedback is real enough to learn from.

A word of caution before you get excited. Reinforcement learning is powerful and it is also fussy. It needs a way to simulate or safely rehearse the decisions it is learning, a reward it will not accidentally game, and patience while it explores a lot of bad ideas on the way to good ones. When those things are missing, a plainer method usually wins. Knowing when not to reach for it is as useful as knowing how it works.

The core ideas you actually need

Strip away the maths and reinforcement learning rests on five words: agent, environment, state, action, reward. Get comfortable with those and most papers and tutorials stop feeling like a foreign language. They are the grammar of the whole field, and everything from a toy grid to a robot arm is built from them.

The loop between agent and environment

The agent is the thing that decides and learns. The environment is everything it acts on and gets feedback from. They talk in a loop. At each step the agent looks at the current state, picks an action from what its experience suggests, and the environment hands back a new state plus a number: the reward. Round and round until the task ends. The agent is not chasing the biggest reward right now. It is after the largest total reward across the whole run, which is why reinforcement learning can happily accept a small loss early for a bigger gain later.

A trading algorithm is a clean example. The environment is the market, the cash it holds and the positions it is carrying. Every few seconds it reads prices and indicators (the state), decides to buy, sell or sit tight (the action), and books a profit or loss (the reward). Then the market moves, the portfolio updates, and the loop turns again. Nobody ever tells it the correct trade. It learns which behaviour pays by living through thousands of them.

States, actions and rewards

A state is a snapshot of everything relevant right now. In chess the state is where every piece sits. For a delivery robot it might be its location, battery level, nearby obstacles and the drops still outstanding. Actions are the choices open in that state: the chess player can move any legal piece, the robot can turn, roll forward or stop. Rewards are the signal that steers behaviour. You hand out positive numbers for outcomes you want and negative ones for mistakes.

Reward design is where reinforcement learning projects quietly live or die, and it catches people out more than any algorithm choice. Set the reward carelessly and the agent will find the loophole rather than solve your problem. Reward that delivery robot for saving battery without also rewarding completed drops, and it learns the most efficient behaviour of all: never leave the depot. The agent is doing exactly what you asked. You just asked for the wrong thing. We have seen versions of this on real projects, and the fix is almost never a cleverer model. It is a reward that actually describes success.

Where teams get it wrong: most reinforcement learning failures trace back to the reward, not the algorithm. If the agent is behaving oddly, assume it is optimising precisely what you told it to and read your reward function again before you touch anything else. Worth checking early: whether you can rehearse the decision safely, in a simulator or on historical data, before it acts on anything that costs money.

Policy and value functions

A policy is the agent's way of behaving: a mapping from states to actions. A deterministic policy always plays the same move in a given state. A stochastic one spreads probabilities across several moves, which builds in a bit of exploration so the agent keeps testing alternatives rather than settling too soon. The optimal policy is the one that earns the most reward over the long run across every state it might land in, and finding it is the whole game.

Value functions are how the agent judges its options. A state-value function estimates the total reward you can expect from a given state if you carry on with your current policy. An action-value function, usually called the Q-value, estimates the reward for taking one specific action in one specific state and then following the policy. Agents lean on these estimates to compare choices and nudge their policy in a better direction, edging towards optimal behaviour one update at a time.

The main families of algorithms

Reinforcement learning is not one method but a few related families, each pointed at a different sort of problem. Some learn straight from experience with no model of the world. Others build a model of how the environment behaves and plan against it. Which you pick comes down to your problem's shape, the compute you can spare, and whether the agent learns live or from a pile of past data. Here are the three you will run into first.

Q-learning and temporal difference methods

Q-learning is where most people start, and for good reason. It learns the value of taking a given action in a given state without needing any model of the environment. The agent keeps a Q-table holding an expected reward for every state-action pair. After each move it updates the relevant entry using the reward it just got plus the best value available in the state it landed in. That small update rule lets learning ripple backwards through a sequence, so a reward at the end eventually teaches the moves that led to it.

The catch is size. A Q-table is fine for a warehouse grid with a manageable set of squares and directions. It collapses the moment the states run to billions, because you cannot store or fill a table that big. Deep Q-Networks fix this by swapping the table for a neural network that approximates the Q-values instead of listing them. That single change is what put reinforcement learning within reach of video games and other problems with enormous state spaces, and it is the lineage behind a lot of the headline results.

Policy gradient methods

Policy gradient methods skip the value table and tune the policy directly. They adjust the probabilities the agent assigns to each action, pushing up the odds of moves that led to good rewards and pushing down the ones that did not. This is the family to reach for when the actions are continuous rather than a short menu: the angle of a robot joint, the opening of a valve, a steering input. Q-learning has to chop a continuous range into buckets and loses precision doing it. Policy gradients handle the smooth control naturally.

REINFORCE is the plain, foundational version. In practice teams tend to run something sturdier like Proximal Policy Optimisation, which adds guardrails so the policy cannot lurch too far in a single update and wreck what it had learned. That stability is why Proximal Policy Optimisation turns up so often in robotics and control work, where a wild update is not just a slower run but a broken machine.

Actor-critic approaches

Actor-critic methods take the useful half of each of the other two and bolt them together. The actor learns the policy and decides what to do. The critic learns a value function and judges how good those decisions were. The critic's steadier feedback beats raw reward signals for guiding the actor, so learning tends to be faster and less jumpy than either approach on its own.

You get the best of both sides. The critic cuts the noise in learning and helps the agent converge sooner. The actor keeps the ability to handle continuous control that pure value methods cannot. Modern variants such as Advantage Actor-Critic and Soft Actor-Critic sit behind a lot of current results, and they balance exploring new options against exploiting known-good ones well enough to hold up outside the lab, which is why they show up so much in real deployments.

Where it shows up in the real world

Reinforcement learning is already running in places you use without noticing, from the queue of shows a streaming service lines up for you to the robots sorting parcels overnight. The pattern is always the same: a system that adapts to changing conditions, learns from acting, and improves a sequence of decisions no fixed program could keep up with. Seeing where it fits elsewhere is often the fastest way to spot where it might fit for you.

Games and entertainment

The best-known example is still DeepMind's AlphaGo, which beat world champions at Go, a game with more legal positions than there are atoms in the universe. It learned largely by playing itself, starting from near-random moves and grinding its way past centuries of accumulated human strategy. That same self-play idea now drives adaptive characters in games that react to how you play. Streaming services put reinforcement learning behind their recommendations too, learning which suggestions keep you watching rather than just serving up whatever looks superficially similar to your last pick.

Robotics and manufacturing

On the factory floor, reinforcement learning trains robotic arms to grip, move and assemble with a steadiness that is hard to hand-program. The robot learns grip force, movement paths and assembly order by trying them in simulation first, where a failure costs nothing, then carries the learned behaviour onto the real line. Large warehouse operators use it to coordinate fleets of robots, learning the traffic patterns that keep them out of each other's way and move orders faster. Because the systems keep improving on their own, running costs tend to drift down rather than up.

The robot learns to fail in simulation, cheaply and thousands of times, so it arrives on the real line already knowing what works.

Business operations and optimisation

The least glamorous uses are often the most valuable. Energy companies apply reinforcement learning to grid management, balancing supply and demand across thousands of nodes while weather, usage and equipment limits all shift at once. Financial firms use it for trading strategies that adapt as markets move. Large operators tune data centre cooling with it and cut real energy without risking the hardware. If your own operation has decisions that play out in sequence with uncertain outcomes, supply chain planning, dynamic pricing, how you allocate scarce resource, the same shape of problem is sitting there. The catch, and it is a big one, is that none of it works on shaky data. An agent learning from a state it cannot trust learns the wrong lesson faster, which is where the foundations come in.

Getting started without a PhD

You do not need a doctorate to get your hands dirty with reinforcement learning. Open-source libraries, cloud compute and a wave of practical tutorials have pulled the barrier a long way down. Where you begin depends on what you already know. New to both programming and machine learning, budget a few months on the basics first. Comfortable with Python and some machine learning already, you can jump in far sooner. Either way the trick is the same: start small, get a win, then add difficulty.

Pick your entry point

Your background decides the door. If you know Python and a little statistics, go straight to a hands-on introductory course and learn by building rather than by reading theory. You will absorb the ideas faster writing a simple agent that solves a grid world than working through equations. If programming is new to you, learn Python first. It runs the field, and its libraries and community are where the help is. There is no shortcut worth taking here that skips the coding.

Set up a workspace

A workable starter kit is short. The pieces most beginners land on are:

  • Python 3.8 or later as the base everything else sits on
  • A ready-made environment library so you can train agents without building worlds by hand
  • A deep learning framework such as PyTorch or TensorFlow for the neural network side
  • A library of reliable, pre-built algorithm implementations so you are not writing them from scratch on day one
  • Cloud compute for later, when a laptop stops keeping up and training slows to a crawl

Most people start entirely on their own machine and only move to the cloud once a project outgrows it. There is no need to rent a cluster to balance a pole on a cart.

Start with problems you can debug

Begin with tabular methods on small grid worlds where an agent learns to reach a goal. They run in seconds on any laptop and let you watch the mechanics work. A pole-balancing task like CartPole is a natural second step: it adds a continuous state space while staying simple enough to pick apart when it misbehaves. Steer clear of full 3D games at the start. Every extra dimension multiplies both the training time and the debugging pain, and there is no faster way to lose heart than to stare at an agent that will not learn and have no idea why. Build up through a ladder of harder but still tractable tasks and the intuition comes with it.

Where this fits for you

Reinforcement learning gives you a way to attack sequential decisions that ordinary programming cannot reach. The agent learns by trying and adjusting, the five core ideas describe how it thinks, and the algorithm families are just different routes to the same goal of a policy that pays off. It has moved well past the research lab and into places where it trims cost and lifts efficiency every day, quietly, in grids and warehouses and cooling plants.

Whether it is right for you is a narrower question, and it usually comes back to readiness rather than ambition. If you are early in your AI journey, the honest first move is not a reinforcement learning pilot. It is solid data and a clear problem worth solving, because an agent is only ever as trustworthy as the state it learns from. Get that foundation right and the interesting techniques have something real to stand on. Get it wrong and the cleverest algorithm just learns your bad data faster.

That first part, the foundation, is the work we do. If you want a straight read on whether reinforcement learning fits a real problem in your business, or on what your data needs before it could, talk to us and we will give you an honest answer rather than a demo.

Start at your core.

Tell us where your data is today and what you want AI to do. We will come back with a straight answer on what your foundation needs and where the quickest real win is.

Talk to us