A Markov Decision Process (MDP) models an agent that repeatedly chooses actions, receives rewards, and moves between states.
It is defined by the tuple:
(S,A,Psa,γ,R)
where:
S is the set of states.
A is the set of actions.
Psa are the state transition probabilities.
γ is the discount factor.
R is the reward function.
The reward may depend on both the state and action, R(s,a), or only on the state, R(s). We use R(s) below for simplicity.
The Markov assumption says that once we know the current state and action, the distribution of the next state does not depend on the earlier history.
We also assume the MDP is stationary, so the same transition probabilities and reward function apply at every time step.
For an infinite-horizon discounted problem, we use:
0≤γ<1
Values of γ close to 1 place more importance on future rewards.
At each step the agent takes an action at, and the environment responds with a new state st+1 and a reward R(st).
The discounted sum of future rewards is called the return:
R(s0)+γR(s1)+γ2R(s2)+⋯
Our goal is to find a policy that maximizes the expected return:
E[R(s0)+γR(s1)+γ2R(s2)+⋯]
A policy:
π:S→A
tells the agent which action to take in each state.
The value function Vπ(s) is the expected return when we start in state s and then follow policy π:
Vπ(s)=E[R(s0)+γR(s1)+γ2R(s2)+⋯∣s0=s,π]
We write:
Psa(s′)
for the probability of moving to state s′ after taking action a in state s.
Bellman Equations and Dynamic Programming
The value function can then be written recursively using the Bellman equation:
Vπ(s)=R(s)+γs′∈S∑Psπ(s)(s′)Vπ(s′)
The first term is the reward received now. The second term is the discounted expected value of the next state.
The optimal value function is the best value achievable over all policies:
V∗(s)=πmaxVπ(s)
It satisfies the Bellman optimality equation:
V∗(s)=R(s)+a∈Amax(γs′∈S∑Psa(s′)V∗(s′))
Once we know V∗, we can recover an optimal policy by choosing the best action in each state:
π∗(s)=arga∈Amax(γs′∈S∑Psa(s′)V∗(s′))
For finite state and action spaces with known transition probabilities, two standard ways to compute an optimal policy are value iteration and policy iteration.
Value IterationFor each state s, initialize V0(s)=0For t=0,1,…, repeat until convergence {For each state s, set {Vt+1(s)←R(s)+a∈Amax(γs′∈S∑Psa(s′)Vt(s′))}}
With bounded rewards and:
0≤γ<1
the Bellman operator is a γ-contraction, so value iteration converges to the unique optimal value function V∗.
Policy IterationInitialize π randomlyRepeat until convergence {Compute Vπtypically by solving a linear systemFor each state s, set {π(s)←arga∈Amax(γs′∈S∑Psa(s′)Vπ(s′))}}
Policy iteration often reaches an optimal policy in fewer outer iterations than value iteration on small MDPs, but it is not universally faster.
Each policy-evaluation step solves a system of linear equations for Vπ, so the total runtime depends on both the number and cost of the iterations.
The algorithms above assume that the transition model is known.
If it is unknown but we can collect transitions from the environment, we can estimate it from data:
Psa(s′)=# of times action a was taken in state s# of times action a was taken in state s and led to s′
This estimate is defined only when the data contain visits to the state-action pair (s,a).
A behavior policy with poor coverage cannot estimate transitions for actions that are never taken.
Value Function Approximation
Tabular methods become impractical when the state space is continuous.
If a d-dimensional state is discretized into k values per dimension, we already get:
kd
possible states.
Instead of storing one value for every state, we can approximate the value function with a parameterized function.
In a model-based approach, we first learn a model of the environment's dynamics from sampled trajectories.
Suppose we collect n trajectories, each containing T transitions:
To model stochastic transitions, we add Gaussian process noise:
st+1=Ast+Bat+ϵt
where:
ϵt∼IIDN(0,Σ)
This is a linear-Gaussian dynamics assumption: the process noise is independent of the current state and action, has zero mean, and has the same covariance at every transition.
Because:
ϵt∼N(0,Σ)
the transition model is:
st+1∣st,at∼N(Ast+Bat,Σ)
Therefore:
p(s′∣s,a)=N(s′;As+Ba,Σ)
where the right-hand side is the Gaussian density evaluated at the candidate next state s′.
Fitted Value Iteration
We now have a model for predicting the next state, but we still cannot store V(s) for every continuous state.
If the state space is continuous and the action space is small and discrete, we can combine the learned dynamics model with fitted value iteration.
The continuous-state Bellman update is:
V(s)←R(s)+γa∈Amax(∫p(s′∣s,a)V(s′)ds′)
The sum from the discrete Bellman equation has become an integral because the next state is now continuous.
Because there are infinitely many possible states, we cannot store a separate value for each one.
Instead, we approximate the value function using features ϕ(s):
V(s)=θTϕ(s)
The features ϕ(s) may be hand-designed or produced by a nonlinear model.
At iteration t, we first use the current value function Vt to compute a Bellman target for each sampled state:
yt(i)=R(s(i))+γa∈Amax(∫p(s′∣s(i),a)Vt(s′)ds′)
We then fit the next value function to these targets:
θt+1=argθmini=1∑n(yt(i)−θTϕ(s(i)))2
and set:
Vt+1(s)=θt+1Tϕ(s)
The targets are computed using the frozen previous approximation Vt and remain fixed while fitting Vt+1.
Unlike exact tabular value iteration, fitted value iteration is approximate, so convergence is not guaranteed in general.
The integral in the Bellman target may also be difficult to compute exactly.
A simple approach is to approximate it using Monte Carlo samples from the learned transition model.
Choose n representative states s(1),…,s(n)Initialize θ0←0 and V0(s)←θ0Tϕ(s)For t=0,1,…, repeat until convergence {For i=1 to n {For each action a∈A {Sample s1′,s2′,…,sm′∼p(⋅∣s(i),a)qt(a)←R(s(i))+γm1j=1∑mVt(sj′)}yt(i)←amaxqt(a)}θt+1←argθmini=1∑n(yt(i)−θTϕ(s(i)))2Vt+1(s)←θt+1Tϕ(s)}