Q-Learning: Teaching an Agent by Trial and Error
Q-Learning teaches an agent the 'quality' of an action in a given state through trial and error, like training a pet with treats. It's used in robotics for navigation or in games where an AI learns optimal moves.
WHY IT EXISTS How do you teach a machine to make optimal decisions in an environment when you don't have a perfect model of that environment? Q-Learning was developed to solve this by allowing an agent to learn from direct interaction and experience, rather than from a pre-written rulebook. It answers the question: "What is the best action to take right now to get the best results in the long run?"
THE MENTAL MODEL Imagine you're in a dark room with many doors (states) and you can take certain actions (open door A, open door B). Behind some doors are rewards. Q-Learning is like slowly building a mental map of expected rewards. You try a door, get a result, and update your belief about that door's value. The "Q" stands for Quality—a score for how good an action is in a particular state, considering not just the immediate reward but all future rewards that follow.
HOW IT WORKS The agent maintains a "Q-table," a spreadsheet with rows for every state and columns for every action. Each cell, Q(s, a), holds the expected future reward for taking action 'a' in state 's'. The agent starts with a table of zeros and explores the environment. When it takes an action and receives a reward, it updates the corresponding Q-value. This update incorporates the immediate reward and a discounted estimate of the best future reward from the new state. Over many iterations, the Q-values converge, giving the agent a policy for how to act.
WHEN TO USE IT Q-Learning is ideal for problems with a discrete, manageable number of states and actions. Think of classic grid-world problems (a robot navigating a maze), simple board games (Tic-Tac-Toe), or optimizing simple processes like inventory management. It shines when the environment's rules are unknown or stochastic (unpredictable).
WHEN NOT TO USE IT It struggles with continuous or very large state spaces. A Q-table for a self-driving car, where the state includes precise positions of all nearby objects, would be impossibly large. In these cases, Deep Q-Networks (DQNs), which approximate the Q-table with a neural network, are used instead. It can also be less sample-efficient than other methods.
ONE CANONICAL EXAMPLE A simple robot cleaner in a 4-room house. The state is the robot's current room. The actions are moving to an adjacent room. The goal is to reach a room with a charging station (positive reward). The robot starts randomly, builds a Q-table for each (Room, Action) pair, and after many trips, the table's values will guide it to take the shortest path to the charger from any room.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.