---
title: "An Introduction to Q-Learning Part 1"
description: "Value-based reinforcement learning methods learn a state-value or action-value function and derive the policy from it, typically a greedy or epsilon-greedy policy, rather than training the policy directly."
url: "https://swe.quest/articles/an-introduction-to-q-learning-part-1-02c8621463858d6d"
canonical: "https://huggingface.co/blog/deep-rl-q-part1"
source: "Hugging Face"
published: "2022-05-18"
difficulty: "medium"
kind: "How-to"
reading_minutes: 13
tags: ["machine-learning","model-training","algorithms"]
---

# An Introduction to Q-Learning Part 1

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-05-18, 13 min read, How-to. Original: [https://huggingface.co/blog/deep-rl-q-part1](https://huggingface.co/blog/deep-rl-q-part1)

## Summary

Value-based reinforcement learning methods learn a state-value or action-value function and derive the policy from it, typically a greedy or epsilon-greedy policy, rather than training the policy directly. The Bellman equation makes value estimation recursive: a state's value is the immediate reward plus the discounted value of the next state. Monte Carlo methods update values only after a full episode using the actual return, while Temporal Difference learning (TD(0)) updates after each step by bootstrapping from the current estimate of the next state. Worked numeric examples with a mouse-and-cheese grid show both update rules, setting up Q-Learning in the next part.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)

## Prerequisites

- reinforcement learning basics ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- expected value and probability

## Keywords

Q-Learning, Bellman equation, Temporal Difference Learning, Monte Carlo, Hugging Face Deep RL Course

## Related posts

- [An Introduction to Q-Learning Part 2/2](https://swe.quest/articles/an-introduction-to-q-learning-part-2-2-2282a7e5e80bee59.md): Hugging Face · 2022-05-20 · Medium · 9 min read · Machine learning, Model training, Algorithms
  Q-Learning is an off-policy, value-based reinforcement learning algorithm that uses temporal-difference updates to train a Q-table of state-action values, from which the optimal policy follows directly.
- [An Introduction to Deep Reinforcement Learning](https://swe.quest/articles/an-introduction-to-deep-reinforcement-learning-d17541fa32bf28e1.md): Hugging Face · 2022-05-04 · Easy · 16 min read · Machine learning, Model training
  Deep reinforcement learning trains an agent to act in an environment through trial and error, using rewards as its only feedback, with the goal of maximizing expected cumulative (discounted) return.
- [Advantage Actor Critic (A2C)](https://swe.quest/articles/advantage-actor-critic-a2c-5b4f17254e3ab304.md): Hugging Face · 2022-07-22 · Medium · 7 min read · Machine learning, Model training, Algorithms
  Actor-Critic methods reduce the high variance of Monte-Carlo policy-gradient estimates in Reinforce by pairing a policy network (Actor) with a value network (Critic) that scores the actions taken.
- [Policy Gradient with PyTorch](https://swe.quest/articles/policy-gradient-with-pytorch-8cc397d15e17e5f8.md): Hugging Face · 2022-06-30 · Easy · 7 min read · Machine learning, Model training, Python
  Policy-gradient methods optimize a stochastic policy directly via gradient ascent on expected return, instead of deriving a policy from learned Q-values as in Deep Q-Learning.
- [Deep Q-Learning with Space Invaders](https://swe.quest/articles/deep-q-learning-with-space-invaders-f474bfcf35b2c89d.md): Hugging Face · 2022-06-07 · Medium · 10 min read · Machine learning, Model training, Games
  Deep Q-Learning replaces the tabular Q-table with a neural network that maps a state to Q-values for every action, making RL feasible for huge state spaces like Atari frames (256^100800 possible observations).

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
