PROJECTENGRAM

Q LEARNING

10_Q_Learning

Tags: #◇CSINTSY #◇Computational Thinking #◇Computer Science #◇Artificial Intelligence #◇Machine Learning #◇Intelligent Systems #◇Probability #◇Data Analysis


◇Overview

Q-Learning is a model-free reinforcement learning algorithm.

◇Details / Theory

10. Q-Learning Reviewer

◇Overview

Q-Learning is a model-free reinforcement learning algorithm.
Model-Free: It does not need to know the Transition Probability (TT) or Reward Function (RR) of the environment beforehand. It learns by trial and error. Goal: To learn the Q-Function (Quality Function), which estimates the value of taking a specific action in a specific state.

◇The Q-Function: Q(s,a)Q(s, a)

Represents the expected cumulative future reward of taking action aa in state ss, and then acting optimally afterwards. Once we know Q(s,a)Q(s, a) for all states and actions, the optimal policy is simply to pick the action with the highest Q-value in each state:
π\*(s)=argmax_aQ(s,a)\pi^\*(s) = \text{argmax}\_a Q(s, a)

◇The Q-Table

A table (matrix) where rows are States and columns are Actions. Each cell contains the value Q(s,a)Q(s, a). Initialized to 0 (or random values). Updated iteratively as the agent interacts with the environment.

◇Q-Learning Update Rule (Bellman Update)

When the agent is in state ss, takes action aa, receives reward RR, and lands in new state s′s', we update the Q-value:

Q(s,a)←Q(s,a)+α[R+γmax⁡a′Q(s′,a′)⏟Target−Q(s,a)⏟Current]Q(s, a) \leftarrow Q(s, a) + \alpha [ \underbrace{R + \gamma \max_{a'} Q(s', a')}_{\text{Target}} - \underbrace{Q(s, a)}_{\text{Current}} ]

Components:

  1. Q(s,a)Q(s, a): The current estimated value (Old Value).
  2. α\alpha (Alpha): Learning Rate (0<α≤10 < \alpha \le 1).
    Determines how much new information overrides old information.
    High α\alpha: Learn fast, but volatile.
    Low α\alpha: Learn slow, but stable.
  3. RR: Immediate reward received.
  4. γ\gamma (Gamma): Discount Factor (0≤γ≤10 \le \gamma \le 1). Importance of future rewards.
  5. max⁡a′Q(s′,a′)\max_{a'} Q(s', a'): The estimate of optimal future value from the next state s′s'. We assume we will take the best action from there.
  6. Temporal Difference (TD) Error: The term in the brackets [Target−Current][Target - Current]. It represents the difference between what we expected and what actually happened.

◇Exploration vs. Exploitation

How does the agent choose actions while learning?
Exploration: Trying new or random actions to discover their rewards. Necessary to find better paths. Exploitation: Choosing the action currently known to be the best (highest Q-value) to maximize reward.

Epsilon-Greedy Strategy (ϵ\epsilon-greedy)

A common method to balance exploration and exploitation.
With probability ϵ\epsilon (epsilon): Explore (choose a random action). With probability 1−ϵ1 - \epsilon: Exploit (choose the best action from Q-table). Usually, ϵ\epsilon starts high (explore a lot) and decays over time (exploit more as we learn).

◇Solved Example: Q-Value Update

Scenario:
Current State (ss): Room A. Action (aa): Move to Room B. Reward (RR): +10 (Found a coin). Next State (s′s'): Room B. Current Q-Value Q(A,Move B)Q(A, \text{Move B}): 5. Best Q-Value in Next State max⁡Q(B,a′)\max Q(B, a'): 20 (Maybe Room B is close to exit). Learning Rate (α\alpha): 0.1. Discount Factor (γ\gamma): 0.9.

Calculation:

  1. Target Value:
    R+γmax⁡Q(s′,a′)R + \gamma \max Q(s', a')
    10+0.9(20)=10+18=2810 + 0.9(20) = 10 + 18 = 28

  2. Difference (TD Error):
    Target−Current\text{Target} - \text{Current}
    28−5=2328 - 5 = 23

  3. New Q-Value:
    Q(s,a)+α[Difference]Q(s, a) + \alpha [\text{Difference}]
    5+0.1[23]5 + 0.1 [23]
    5+2.3=7.35 + 2.3 = 7.3

Result: The Q-value for moving from A to B increased from 5 to 7.3 because the outcome was better than expected.


◇Common Pitfalls

Confusing the learning rate α\alpha (how much to update) with the discount factor γ\gamma (how much to value future rewards). Forgetting that Q-Learning is model-free — it does not need transition probabilities; it learns from experience. Using pure exploitation (ϵ=0\epsilon = 0) too early — sufficient exploration is needed for the Q-table to converge.

◇Summary

TL;DR — Q-Learning updates Q-values via Q(s,a)←Q(s,a)+α[r+γmax⁡a′Q(s′,a′)−Q(s,a)]Q(s,a) \leftarrow Q(s,a) + \alpha[r + \gamma \max_{a'} Q(s',a') - Q(s,a)]. It’s model-free, uses ϵ\epsilon-greedy for exploration/exploitation balance, and converges to optimal Q-values with sufficient exploration.

Related: Source / Reference:


Made by 2ru17

Please contact me through discord or my the university email for any problems regarding the reviewer. Thanks!

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

What does it mean for Q-Learning to be a "model-free" algorithm?

Q2

In Q-Learning, what does the Q-Function Q(s,a)Q(s, a) represent?

Q3

How are the values in a Q-Table typically initialized before the agent starts learning?

Q4

What is the role of the Learning Rate (α\alpha) in the Q-Learning update rule?

Q5

In the Q-Learning update rule, what does the term max⁡a′Q(s′,a′)\max_{a'} Q(s', a') represent?

Q6

What does the Temporal Difference (TD) Error represent?

Q7

In the context of reinforcement learning, what is "Exploration"?

Q8

What is the purpose of the Epsilon-Greedy (ϵ\epsilon-greedy) strategy?

Q9

How does the parameter ϵ\epsilon (epsilon) typically change over time in a Q-Learning implementation?

Q10

What happens if an agent uses pure exploitation (ϵ=0\epsilon = 0) too early in the learning process?