1. Home
  2. Explore
  3. Computer Science
  4. Reinforcement Learning Basics

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Reinforcement Learning Basics

Reinforcement Learning: Markov Decision Processes, Value Iteration, and Policy Iteration

1. Reinforcement Learning Versus Supervised Learning

In supervised learning, each training example contains an input and a corresponding target output:

(x,y)(x,y)(x,y)

The learning algorithm attempts to learn a hypothesis hhh that maps inputs to outputs:

h:x↦yh:x\mapsto yh:x↦y

The correct output is supplied directly for each input. Training examples are generally treated as independent and identically distributed, or i.i.d. The objective is to learn a function that performs well on unseen examples.

In reinforcement learning, the learner is called an agent and interacts with an environment over time. Instead of being told the correct action for every situation, the agent:

  1. Observes its current state.

  2. Chooses an action.

  3. Transitions to a new state.

  4. Receives a numerical reward.

The reward may be positive or negative and measures how desirable the recent outcome was. Unlike a supervised-learning label, a reward does not directly specify the correct action.

Reinforcement learning learns how to make a sequence of decisions that maximizes long-term accumulated reward.

Key differences

  • Supervised learning: The correct output is provided for each input.

  • Reinforcement learning: The agent receives feedback in the form of a reward after acting.

  • Supervised learning: Examples are typically independent.

  • Reinforcement learning: Decisions influence future states and future rewards.

  • Supervised learning: The objective is usually to minimize loss on unseen examples.

  • Reinforcement learning: The objective is to maximize the expected sum of future rewards.

The sequential nature of reinforcement learning is central. An action that produces a small immediate reward may be preferable if it leads to much larger rewards later. Conversely, an action with a large immediate reward may be poor if it causes bad future outcomes.

Examples of reinforcement-learning agents

  • A robot learning to walk.

  • A game-playing program for chess or Go.

  • An automated trading system making a sequence of financial decisions.

  • A navigation system choosing movements through an environment.

  • A control system operating a simulated or physical machine.


2. Markov Decision Processes

The standard mathematical framework for reinforcement learning is the Markov decision process, abbreviated MDP.

An MDP is represented by the five-tuple

(S,A,P,γ,R)(\mathcal{S},\mathcal{A},P,\gamma,R)(S,A,P,γ,R)

where each component describes one part of the decision problem.

2.1 State space

S\mathcal{S}S is the set of all possible states of the environment.

A state contains the information needed to describe the agent’s current situation. For example, in a grid-world environment, a state may specify the grid square currently occupied by the agent.

If the grid contains eleven accessible squares, then the state space has eleven elements:

∣S∣=11|\mathcal{S}|=11∣S∣=11

Blocked locations are not included in the state space because the agent cannot occupy them.

2.2 Action space

A\mathcal{A}A is the set of possible actions available to the agent.

In a grid-world example, the actions might be:

  • Move north.

  • Move south.

  • Move east.

  • Move west.

The available actions can, in general, depend on the state. For simplicity, many introductory examples assume that every action is available in every state.

2.3 Transition probabilities

The transition model describes how the environment changes after the agent takes an action. It is commonly written as

P(s′∣s,a)P(s' \mid s,a)P(s′∣s,a)

This quantity is the probability that the agent moves to successor state s′s's′ given that:

  • The current state is sss.

  • The chosen action is aaa.

For every fixed state-action pair (s,a)(s,a)(s,a), the transition probabilities form a probability distribution over possible successor states:

∑s′∈SP(s′∣s,a)=1\sum_{s'\in\mathcal{S}}P(s'\mid s,a)=1∑s′∈S​P(s′∣s,a)=1

The transition is generally stochastic, meaning that the same action does not necessarily produce the same next state every time.

For example, suppose the agent is in state (1,3)(1,3)(1,3) and chooses “move north.” Because of uncertainty in the environment, the outcomes might be:

  • Move to (2,3)(2,3)(2,3) with probability 0.80.80.8.

  • Move to (1,2)(1,2)(1,2) with probability 0.10.10.1.

  • Move to (1,4)(1,4)(1,4) with probability 0.10.10.1.

All other successor states have probability zero for that state-action pair.

Stochasticity may arise from:

  • Imperfect robot movement.

  • Slippery or uncertain terrain.

  • Unmodeled physical effects.

  • An opponent’s actions in a game.

  • Randomness deliberately built into a simulator.

2.4 The Markov property

An MDP assumes the Markov property: the distribution of the next state depends only on the current state and current action, not on the full history of previous states and actions.

Formally,

P(st+1∣st,at,st−1,at−1,…)=P(st+1∣st,at)P(s_{t+1}\mid s_t,a_t,s_{t-1},a_{t-1},\ldots) = P(s_{t+1}\mid s_t,a_t)P(st+1​∣st​,at​,st−1​,at−1​,…)=P(st+1​∣st​,at​)

This assumption allows the agent to make decisions based on the current state without retaining the entire trajectory.

2.5 Discount factor

The discount factor γ\gammaγ satisfies

0≤γ≤10\leq \gamma \leq 10≤γ≤1

It determines how much future rewards matter relative to immediate rewards.

A reward received one step in the future is multiplied by γ\gammaγ, a reward received two steps in the future is multiplied by γ2\gamma^2γ2, and so on.

  • If γ\gammaγ is close to 000, the agent is strongly focused on immediate rewards.

  • If γ\gammaγ is close to 111, the agent places substantial importance on long-term rewards.

  • The same γ\gammaγ is typically used at every time step.

The discount factor can be interpreted in several ways:

  • Time preference: A reward received sooner is preferred to the same reward received later.

  • Financial discounting: Future income and costs are discounted in a manner analogous to interest rates.

  • Stability: Discounting helps ensure that an infinite sum of rewards remains finite under suitable conditions.

2.6 Reward function

The reward function specifies the numerical feedback received by the agent.

A simple state-based reward function is

R:S→RR:\mathcal{S}\to\mathbb{R}R:S→R

where R(s)R(s)R(s) is the reward associated with entering or occupying state sss.

For example:

  • Reaching a goal state may produce reward +1+1+1.

  • Reaching an undesirable terminal state may produce reward −1-1−1.

  • Ordinary states may produce a small negative reward such as −0.02-0.02−0.02.

A state-action reward function may instead be used:

R:S×A→RR:\mathcal{S}\times\mathcal{A}\to\mathbb{R}R:S×A→R

This form is useful when actions have different costs. For example, two actions may lead to the same state but have different energy, time, or financial costs.

The introductory treatment primarily uses state-based rewards, assuming that actions themselves have equal cost unless otherwise stated.


3. Grid-World Example

Consider an agent moving through a grid-like environment.

  • Each accessible square is a state.

  • A blocked square is not a valid state.

  • The agent can move in one of the cardinal directions.

  • Some states are desirable terminal states.

  • Some states are undesirable terminal states.

  • Ordinary states may have small negative rewards to encourage the agent to reach a terminal state quickly.

For example:

  • Goal state: reward +1+1+1.

  • Failure state: reward −1-1−1.

  • Ordinary state: reward −0.02-0.02−0.02.

A solution is not merely a single action. It is a strategy for deciding what to do from every possible state. The agent must account for uncertainty in movement and for the long-term consequences of its choices.


4. Trajectories, Episodes, and Accumulated Reward

Suppose the agent begins in an initial state s0s_0s0​. It selects action a0a_0a0​, and the environment produces a new state s1s_1s1​ according to the transition model:

s1∼P(⋅∣s0,a0)s_1\sim P(\cdot\mid s_0,a_0)s1​∼P(⋅∣s0​,a0​)

The agent then selects a1a_1a1​, producing

s2∼P(⋅∣s1,a1)s_2\sim P(\cdot\mid s_1,a_1)s2​∼P(⋅∣s1​,a1​)

This process continues:

s0,a0,s1,a1,s2,a2,…s_0,a_0,s_1,a_1,s_2,a_2,\ldotss0​,a0​,s1​,a1​,s2​,a2​,…

A sequence of states and actions is called a trajectory, episode, or trial. These terms are often used interchangeably.

At every step, the agent receives a reward. Using a state-based reward convention, the discounted return beginning at s0s_0s0​ is

R(s0)+γR(s1)+γ2R(s2)+γ3R(s3)+⋯R(s_0)+\gamma R(s_1)+\gamma^2R(s_2)+\gamma^3R(s_3)+\cdotsR(s0​)+γR(s1​)+γ2R(s2​)+γ3R(s3​)+⋯

More generally, the return from time ttt is

Gt=∑k=0∞γkR(st+k)G_t=\sum_{k=0}^{\infty}\gamma^k R(s_{t+k})Gt​=∑k=0∞​γkR(st+k​)

The agent’s objective is to choose actions that maximize the expected value of this discounted return.

Immediate reward versus long-term return

  • Reward: The immediate feedback obtained from the current transition or state.

  • Return: The accumulated, discounted sequence of current and future rewards.

  • Value: The expected return obtained from a state when actions are selected according to a specified policy.

This distinction is fundamental. Reinforcement learning is difficult because maximizing immediate reward does not necessarily maximize long-term value.


5. Policies

A policy specifies how the agent chooses an action in each state.

A deterministic policy is a function

π:S→A\pi:\mathcal{S}\to\mathcal{A}π:S→A

where π(s)\pi(s)π(s) is the action chosen when the agent is in state sss.

For example, a policy might specify:

  • Move east in state s1s_1s1​.

  • Move north in state s2s_2s2​.

  • Move west in state s3s_3s3​.

The policy is applied repeatedly throughout a trajectory. If the agent reaches the same state multiple times, it takes the action prescribed by the policy each time, regardless of how it arrived there or how many times it has previously visited that state.

A policy does not necessarily give the best possible behavior. It is simply a rule for choosing actions. The goal is to find an optimal policy that maximizes expected long-term reward.


6. Value Functions

Given a policy π\piπ, the value function VπV^\piVπ assigns a numerical long-term value to every state.

For a starting state sss, the value function is

Vπ(s)=Eπ[R(s0)+γR(s1)+γ2R(s2)+⋯∣s0=s]V^\pi(s) = \mathbb{E}_\pi \left[ R(s_0)+\gamma R(s_1)+\gamma^2R(s_2)+\cdots \mid s_0=s \right]Vπ(s)=Eπ​[R(s0​)+γR(s1​)+γ2R(s2​)+⋯∣s0​=s]

The subscript π\piπ indicates that actions are selected according to policy π\piπ.

In words, Vπ(s)V^\pi(s)Vπ(s) is the expected sum of discounted future rewards when:

  1. The agent starts in state sss.

  2. The agent follows policy π\piπ at every step.

  3. The environment transitions stochastically according to PPP.

The expectation is necessary because future states—and therefore future rewards—are random when the transition model is stochastic.

Reward and value are different

Reward is immediate feedback; value is the expected long-term benefit of following a policy from a state.

For example, an ordinary state might have a small negative immediate reward because the agent has not yet reached its goal. Nevertheless, that state may have high value if it provides a reliable path to a large positive reward.

Likewise, an action leading to an immediately positive reward may have low value if it places the agent in a situation with poor future outcomes.

Policies and value functions as related objects

A policy determines a value function:

π⟶Vπ\pi\longrightarrow V^\piπ⟶Vπ

Given a value function, one can construct a policy by choosing actions that lead, in expectation, to states with high value:

V⟶πV\longrightarrow \piV⟶π

These two concepts are central to reinforcement learning. Some algorithms primarily improve value estimates, while others primarily improve the policy.


7. The Bellman Equation for a Fixed Policy

The value function can be decomposed into:

  1. The immediate reward obtained from the current state.

  2. The discounted expected value of future states.

Starting from state sss, the first reward is R(s)R(s)R(s). The policy chooses action π(s)\pi(s)π(s), and the environment transitions to successor state s′s's′ with probability P(s′∣s,π(s))P(s'\mid s,\pi(s))P(s′∣s,π(s)).

Therefore,

Vπ(s)=R(s)+γ∑s′∈SP(s′∣s,π(s))Vπ(s′)V^\pi(s) = R(s) + \gamma \sum_{s'\in\mathcal{S}} P(s'\mid s,\pi(s))V^\pi(s')Vπ(s)=R(s)+γ∑s′∈S​P(s′∣s,π(s))Vπ(s′)

This is the Bellman equation for a fixed policy.

The equation is recursive because the value of the current state is defined in terms of the values of successor states.

Interpretation

  • R(s)R(s)R(s) is the immediate reward.

  • γ\gammaγ discounts future outcomes.

  • P(s′∣s,π(s))P(s'\mid s,\pi(s))P(s′∣s,π(s)) gives the probability of reaching s′s's′.

  • Vπ(s′)V^\pi(s')Vπ(s′) is the future value after reaching s′s's′.

  • The summation computes the expected value over all possible successor states.

The Bellman equation can also be understood as

current value=immediate reward+discounted expected future value\text{current value} = \text{immediate reward} + \text{discounted expected future value}current value=immediate reward+discounted expected future value

8. Computing the Value of a Given Policy

Assume the MDP has a finite number of states. Then VπV^\piVπ can be represented as a vector with one component per state:

Vπ=[Vπ(s1)Vπ(s2)⋮Vπ(s∣S∣)]V^\pi= \begin{bmatrix} V^\pi(s_1)\\ V^\pi(s_2)\\ \vdots\\ V^\pi(s_{|\mathcal{S}|}) \end{bmatrix}Vπ=​Vπ(s1​)Vπ(s2​)⋮Vπ(s∣S∣​)​​

Similarly, define the reward vector

R=[R(s1)R(s2)⋮R(s∣S∣)]R= \begin{bmatrix} R(s_1)\\ R(s_2)\\ \vdots\\ R(s_{|\mathcal{S}|}) \end{bmatrix}R=​R(s1​)R(s2​)⋮R(s∣S∣​)​​

For a fixed policy π\piπ, define the policy transition matrix PπP^\piPπ by

Pijπ=P(sj∣si,π(si))P^\pi_{ij}=P(s_j\mid s_i,\pi(s_i))Pijπ​=P(sj​∣si​,π(si​))

Each row describes the transition probabilities from one current state when the action prescribed by π\piπ is taken.

The Bellman equations for all states can then be written in vector form:

Vπ=R+γPπVπV^\pi=R+\gamma P^\pi V^\piVπ=R+γPπVπ

Rearranging gives

(I−γPπ)Vπ=R(I-\gamma P^\pi)V^\pi=R(I−γPπ)Vπ=R

Assuming the matrix is invertible,

Vπ=(I−γPπ)−1RV^\pi=(I-\gamma P^\pi)^{-1}RVπ=(I−γPπ)−1R

This provides a direct method for calculating the value function of a known policy.

Why this works

For a fixed policy:

  • The reward vector RRR is known.

  • The transition matrix PπP^\piPπ is known.

  • The discount factor γ\gammaγ is known.

  • The unknown values Vπ(s)V^\pi(s)Vπ(s) appear linearly.

Thus, evaluating a fixed policy reduces to solving a system of linear equations.

This is the policy evaluation step used in policy iteration.


9. Optimal Value Function

The optimal value function gives the highest achievable value from every state.

It is defined as

V∗(s)=max⁡πVπ(s)V^*(s)=\max_\pi V^\pi(s)V∗(s)=maxπ​Vπ(s)

Thus, V∗(s)V^*(s)V∗(s) is the maximum expected discounted return obtainable from state sss, considering all possible policies.

The optimal value function satisfies the Bellman optimality equation:

V∗(s)=R(s)+max⁡a∈A[γ∑s′∈SP(s′∣s,a)V∗(s′)]V^*(s) = R(s) + \max_{a\in\mathcal{A}} \left[ \gamma \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V^*(s') \right]V∗(s)=R(s)+maxa∈A​[γ∑s′∈S​P(s′∣s,a)V∗(s′)]

The agent chooses the action whose expected successor value is greatest.

Difference from the fixed-policy Bellman equation

For a fixed policy, the action is already determined:

π(s)\pi(s)π(s)

For the optimal value function, the best action must be selected by maximizing over all possible actions:

max⁡a∈A\max_{a\in\mathcal{A}}maxa∈A​

This maximization makes the optimality equation nonlinear and prevents it from being solved as one ordinary linear system in the same direct way as the fixed-policy Bellman equation.


10. Optimal Policy

Once the optimal value function is known, the optimal policy can be recovered by choosing the action that maximizes expected future value:

π∗(s)=arg⁡max⁡a∈A[∑s′∈SP(s′∣s,a)V∗(s′)]\pi^*(s) = \arg\max_{a\in\mathcal{A}} \left[ \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V^*(s') \right]π∗(s)=argmaxa∈A​[∑s′∈S​P(s′∣s,a)V∗(s′)]

The discount factor γ\gammaγ can be included inside the maximization without changing the selected action because it is the same positive constant for every action:

π∗(s)=arg⁡max⁡a∈A[γ∑s′∈SP(s′∣s,a)V∗(s′)]\pi^*(s) = \arg\max_{a\in\mathcal{A}} \left[ \gamma \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V^*(s') \right]π∗(s)=argmaxa∈A​[γ∑s′∈S​P(s′∣s,a)V∗(s′)]

The optimal policy is therefore obtained by acting greedily with respect to the optimal value function.

The optimal policy selects, in each state, the action with the greatest expected long-term value.


11. Value Iteration

Value iteration computes the optimal value function by repeatedly applying the Bellman optimality update.

Algorithm

  1. Initialize the value of every state, commonly to zero:

V(s)←0V(s)\leftarrow 0V(s)←0
  1. Repeatedly update every state according to

V(s)←R(s)+max⁡a∈A[γ∑s′∈SP(s′∣s,a)V(s′)]V(s) \leftarrow R(s) + \max_{a\in\mathcal{A}} \left[ \gamma \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V(s') \right]V(s)←R(s)+maxa∈A​[γ∑s′∈S​P(s′∣s,a)V(s′)]
  1. Continue until the values converge.

  2. Extract the policy using

π(s)=arg⁡max⁡a∈A[∑s′∈SP(s′∣s,a)V(s′)]\pi(s) = \arg\max_{a\in\mathcal{A}} \left[ \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V(s') \right]π(s)=argmaxa∈A​[∑s′∈S​P(s′∣s,a)V(s′)]

The update uses the current value estimates on the right-hand side to produce improved value estimates on the left-hand side.

Bellman backup operator

Define the Bellman backup operator BBB by

(BV)(s)=R(s)+max⁡a∈A[γ∑s′∈SP(s′∣s,a)V(s′)](BV)(s) = R(s) + \max_{a\in\mathcal{A}} \left[ \gamma \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V(s') \right](BV)(s)=R(s)+maxa∈A​[γ∑s′∈S​P(s′∣s,a)V(s′)]

Value iteration repeatedly applies this operator:

Vk+1=BVkV_{k+1}=BV_kVk+1​=BVk​

The operator is called a backup operator because it updates the value of a state using information about possible successor states.

Why value iteration converges

For discounted MDPs, the Bellman optimality operator is a contraction mapping. Informally, applying the operator brings value functions closer together.

For two value functions V1V_1V1​ and V2V_2V2​, the contraction property has the form

∥BV1−BV2∥∞≤γ∥V1−V2∥∞\|BV_1-BV_2\|_\infty \leq \gamma\|V_1-V_2\|_\infty∥BV1​−BV2​∥∞​≤γ∥V1​−V2​∥∞​

Since γ<1\gamma<1γ<1 in the usual discounted setting, repeated application of BBB moves value estimates toward a unique fixed point.

A fixed point V∗V^*V∗ satisfies

BV∗=V∗BV^*=V^*BV∗=V∗

This fixed point is the optimal value function because it satisfies the Bellman optimality equation.

The initialization does not need to be zero. Under the contraction property, a suitable initialization will converge toward the same fixed point.

Synchronous and asynchronous variants

Synchronous value iteration

  • Compute updated values for all states using the old value vector.

  • Replace all old values simultaneously after the full update.

Asynchronous value iteration

  • Update one state at a time or update states in sequence.

  • Use newly updated values immediately when computing later updates.

Both approaches are based on the same Bellman backup idea, although their implementation and convergence behavior can differ.

Approximation versus exact convergence

Value iteration approaches V∗V^*V∗ increasingly closely. In practice, it is stopped when the changes become smaller than a chosen tolerance.

Depending on the implementation and stopping criterion, the algorithm may produce an arbitrarily accurate approximation rather than explicitly reaching the exact mathematical fixed point.


12. Policy Iteration

Policy iteration alternates between evaluating a policy and improving that policy.

Algorithm

  1. Initialize a policy π\piπ arbitrarily or randomly.

  2. Policy evaluation: Compute VπV^\piVπ for the current policy.

  3. Policy improvement: For every state, replace the current action with the action that maximizes expected value under the current value function.

  4. Repeat until the policy no longer changes.

Policy evaluation

For the current policy, calculate

Vπ=(I−γPπ)−1RV^\pi=(I-\gamma P^\pi)^{-1}RVπ=(I−γPπ)−1R

This evaluates the expected long-term return obtained by following the current policy.

Policy improvement

Using the current value function, update the policy at each state:

πnew(s)=arg⁡max⁡a∈A[R(s)+γ∑s′∈SP(s′∣s,a)Vπ(s′)]\pi_{\text{new}}(s) = \arg\max_{a\in\mathcal{A}} \left[ R(s) + \gamma \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V^\pi(s') \right]πnew​(s)=argmaxa∈A​[R(s)+γ∑s′∈S​P(s′∣s,a)Vπ(s′)]

If R(s)R(s)R(s) is independent of the action, it does not affect which action maximizes the expression and may be omitted from the arg⁡max⁡\arg\maxargmax:

πnew(s)=arg⁡max⁡a∈A[∑s′∈SP(s′∣s,a)Vπ(s′)]\pi_{\text{new}}(s) = \arg\max_{a\in\mathcal{A}} \left[ \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V^\pi(s') \right]πnew​(s)=argmaxa∈A​[∑s′∈S​P(s′∣s,a)Vπ(s′)]

The improved policy is greedy with respect to the current value function.

Stopping condition

Policy iteration stops when

πnew(s)=π(s)for every s∈S\pi_{\text{new}}(s)=\pi(s) \quad\text{for every }s\in\mathcal{S}πnew​(s)=π(s)for every s∈S

Once the policy stops changing, it is the optimal policy under the standard finite discounted MDP assumptions. Evaluating that final policy yields the exact optimal value function.


13. Value Iteration Versus Policy Iteration

Value iteration

  • Directly updates value estimates.

  • Uses the Bellman optimality equation at every update.

  • Does not require solving a full linear system at each iteration.

  • Approaches the optimal value function progressively.

  • The optimal policy is extracted after or during convergence.

Policy iteration

  • Alternates between policy evaluation and policy improvement.

  • Policy evaluation solves a system of linear equations.

  • Each policy-improvement step chooses actions greedily with respect to the current value function.

  • Converges to the optimal policy after a finite number of policy changes under standard finite-MDP assumptions.

  • Once the optimal policy is obtained, its value function is the exact V∗V^*V∗.

Computational considerations

Let

  • ∣S∣|\mathcal{S}|∣S∣ be the number of states.

  • ∣A∣|\mathcal{A}|∣A∣ be the number of actions.

A value-iteration sweep considers each state-action pair and possible successor states. For a dense transition representation, its rough cost is on the order of

O(∣S∣2∣A∣)O\left(|\mathcal{S}|^2|\mathcal{A}|\right)O(∣S∣2∣A∣)

Policy evaluation requires solving or inverting a matrix of size ∣S∣×∣S∣|\mathcal{S}|\times|\mathcal{S}|∣S∣×∣S∣. A dense matrix inversion has rough cubic cost:

O(∣S∣3)O\left(|\mathcal{S}|^3\right)O(∣S∣3)

Policy improvement itself requires evaluating the actions and is roughly on the order of

O(∣S∣2∣A∣)O\left(|\mathcal{S}|^2|\mathcal{A}|\right)O(∣S∣2∣A∣)

Therefore:

  • Policy iteration may be more expensive per iteration for large state spaces because of policy evaluation.

  • Value iteration may require many updates because it gradually approaches the optimum.

  • Policy iteration can reach the exact optimal policy after a finite number of policy changes.

  • Value iteration is often stopped after reaching a desired numerical precision.

The best method depends on the size and structure of the state and action spaces.


14. Relationship Between the Main Quantities

The central relationships in an MDP can be summarized as follows.

Policy to value

A policy determines a transition matrix PπP^\piPπ, which determines the corresponding value function:

π⟶Pπ⟶Vπ\pi \longrightarrow P^\pi \longrightarrow V^\piπ⟶Pπ⟶Vπ

The value is found using

Vπ=(I−γPπ)−1RV^\pi=(I-\gamma P^\pi)^{-1}RVπ=(I−γPπ)−1R

Value to policy

A value function induces a greedy policy by choosing the action with the best expected successor value:

V⟶πV \longrightarrow \piV⟶π

using

π(s)=arg⁡max⁡a∈A[∑s′∈SP(s′∣s,a)V(s′)]\pi(s) = \arg\max_{a\in\mathcal{A}} \left[ \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V(s') \right]π(s)=argmaxa∈A​[∑s′∈S​P(s′∣s,a)V(s′)]

Optimal quantities

The optimal value function and optimal policy satisfy

V∗(s)=max⁡πVπ(s)V^*(s)=\max_\pi V^\pi(s)V∗(s)=maxπ​Vπ(s)

and

π∗(s)=arg⁡max⁡a∈A[∑s′∈SP(s′∣s,a)V∗(s′)]\pi^*(s) = \arg\max_{a\in\mathcal{A}} \left[ \sum_{s'\in\mathcal{S}} P(s'\mid s,a)V^*(s') \right]π∗(s)=argmaxa∈A​[∑s′∈S​P(s′∣s,a)V∗(s′)]

Value iteration searches for V∗V^*V∗ through repeated Bellman backups. Policy iteration searches for π∗\pi^*π∗ by repeatedly evaluating and improving policies.


15. Bias–Variance Trade-Off: Relevant Background

Before reinforcement learning, the learning objective was analyzed through the bias–variance trade-off.

Machine learning systems are evaluated primarily by their generalization error, meaning performance on unseen data rather than performance only on the training set.

The expected test error can be conceptually decomposed into:

  1. Irreducible error

  2. Bias

  3. Variance

Irreducible error

Irreducible error comes from noise in the data, including noise in test examples and labels. It cannot be eliminated merely by choosing a better model.

Bias

Bias is systematic error caused by assumptions that are too restrictive or by a model that is insufficiently flexible.

Examples include:

  • Consistently underpredicting.

  • Consistently overpredicting.

  • Using a model whose parameters are systematically pulled toward inappropriate values.

  • Failing to represent the true relationship between inputs and outputs.

Variance

Variance measures sensitivity to noise in the training data. A high-variance model changes substantially when trained on different training sets.

Model capacity and regularization

Increasing model capacity generally:

  • Reduces bias.

  • May increase variance.

Increasing regularization generally:

  • Reduces variance.

  • May increase bias.

Consequently, the correct intervention depends on which problem is dominant.

  • If the model has high bias, increasing capacity or reducing regularization may help.

  • If the model has high variance, increasing regularization or obtaining more data may help.

  • Increasing capacity when variance is already high can worsen generalization.

  • Increasing regularization when bias is already high can make the model even less flexible.

Training and cross-validation error

A practical heuristic is:

  • Training error approximates the contribution of bias.

  • The gap between cross-validation error and training error approximates the contribution of variance.

Thus, model development should examine both errors simultaneously:

  • Low training error and substantially higher cross-validation error: likely high variance.

  • High training error and similarly high cross-validation error: likely high bias.

Cross-validation provides a practical estimate of how well the current model generalizes and helps determine which corrective action is most appropriate.


16. Broader Machine-Learning Context

Supervised learning

Supervised learning uses noisy input-output pairs and learns a function

h:x↦yh:x\mapsto yh:x↦y

The target variable determines the problem type:

  • Classification: yyy is discrete, such as a binary label or one of ten digit classes.

  • Regression: yyy is continuous.

Generalized linear models

Generalized linear models extend ordinary linear and logistic regression by allowing the conditional distribution

p(y∣x)p(y\mid x)p(y∣x)

to belong to the exponential family.

This framework can include:

  • Binary outcomes.

  • Multiclass outcomes.

  • Continuous outcomes.

  • Count-valued outcomes such as Poisson variables.

  • Other distributions with suitable structure.

Discriminative and generative models

Discriminative models directly model

p(y∣x)p(y\mid x)p(y∣x)

or directly learn a decision rule for predicting yyy from xxx.

Generative models model how complete examples are generated. Using the chain rule, a joint distribution can be decomposed as

p(x,y)=p(y)p(x∣y)p(x,y)=p(y)p(x\mid y)p(x,y)=p(y)p(x∣y)

Examples include:

  • Naive Bayes for discrete input variables.

  • Gaussian discriminant analysis for real-valued input variables.

When p(x∣y)p(x\mid y)p(x∣y) belongs to the exponential family, the resulting conditional distribution p(y∣x)p(y\mid x)p(y∣x) often has a generalized linear or logistic-regression form.

Nonlinear models

Nonlinearity can be introduced through:

  • Hand-designed feature maps.

  • Kernel methods.

  • Neural networks with learned feature representations.

Kernel methods use symmetric positive-definite functions that implicitly correspond to feature maps. Examples include:

  • Support vector machines for classification.

  • Gaussian processes for regression.

For ordinary parameterized models, computational complexity often depends on the number of features. Kernel methods instead tend to depend heavily on the number of training examples. They can represent very rich or effectively infinite-dimensional feature spaces, but may become expensive on very large datasets.

Support vector machines can scale better in some cases because their learned coefficients are often sparse: many training examples receive zero coefficients.

Neural networks can be viewed conceptually as:

  • A generalized linear model at the final layer.

  • A learned nonlinear feature map in the preceding layers.

Learning theory

Learning theory provides a more formal understanding of:

  • Regularization.

  • Bayesian interpretations of regularized estimation.

  • Bias and variance.

  • Uniform convergence.

Regularization can be interpreted in a Bayesian setting as imposing a prior over model parameters and performing maximum a posteriori estimation. Uniform convergence provides theoretical tools for relating empirical performance to expected performance across a class of models.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent