Reinforcement Learning
An agent that learns through trial and reward: the state, the action, the policy and the value function.
The interaction loop
At each time step \(t\): the agent observes the state \(s_t\) and chooses an action \(a_t\), and the environment returns a reward \(r_{t+1}\) and a new state \(s_{t+1}\).
The goal is to maximize the discounted return:
$$G_t = r_{t+1} + \gamma r_{t+2} + \gamma^2 r_{t+3} + \dots = \sum_{k=0}^{\infty} \gamma^k r_{t+k+1}, \quad 0 \le \gamma < 1$$
Key concepts
- The policy \(\pi(a \mid s)\): the probability of choosing the action in the state.
- The value function \(V^\pi(s)\): the expected return starting from the state and following the policy.
- The action-value function \(Q^\pi(s, a)\): the expected return after taking the action in the state.
Q-learning
An algorithm that learns \(Q\) directly with an estimated update:
$$Q(s,a) \leftarrow Q(s,a) + \alpha\big[r + \gamma \max_{a’} Q(s’,a’) – Q(s,a)\big]$$
import numpy as np
Q = np.zeros((n_states, n_actions))
alpha, gamma, eps = 0.1, 0.99, 0.1
rng = np.random.default_rng(0)
# inside the loop over training episodes:
a = rng.integers(n_actions) if rng.random() < eps else int(Q[s].argmax())
# after taking the action and getting r and s_next:
Q[s, a] += alpha * (r + gamma * Q[s_next].max() - Q[s, a])The ε-greedy strategy balances exploration and exploitation.
Where is it used?
- Games: DQN combined Q-learning with deep networks and achieved human-level performance in a number of Atari games (Mnih et al., 2015).
- Robotics and control.
- Tuning language models with human feedback (RLHF).
Challenges
Delayed rewards, the need for a large number of interactions, and the difficulty of designing a reward function that is not exploited in unintended ways (reward hacking).
Lesson terms
- Exploration and exploitation
- Balancing trying new actions to discover better rewards against exploiting the best action currently known.
- Reinforcement Learning
- Learning behaviour that maximizes cumulative reward through trial-and-error interaction with an environment.
- Policy
- A rule that determines the action the agent chooses in each state.
Abstract
In reinforcement learning an agent interacts with an environment: it observes a state, takes an action, and receives a reward and a new state. The goal is to learn a policy that maximizes the sum of discounted rewards over the long run. The problem is usually formulated as a Markov decision process (MDP), and its algorithms include Q-learning and policy gradient methods.
Review questions
-
What are the elements of the interaction loop in reinforcement learning?
The state, the action, the reward and the next state.
-
What is the role of the discount factor γ?
It determines the weight of future rewards compared with immediate rewards.
Sources and references
Complete the lesson
You have completed all the lessons in the track! You can now request the track completion certificate.
Request the certificate