339. Bellman Equation

The recursion at the heart of dynamic programming. Defines the optimal cost-to-go 𝐽𝑡(𝑠) — minimum cost to complete the problem from stage 𝑡 in state 𝑠 — as a function of cost-to-go from the next stage.

339.1. Principle of optimality (Bellman, 1957)

> “An optimal policy has the property that whatever the initial state and initial decision, the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision.”

Restated: if (𝑎0,𝑎1,,𝑎𝑇1) is optimal from 𝑠0, then (𝑎1,,𝑎𝑇1) is optimal from 𝑠1=𝑓0(𝑠0,𝑎0).

Why true (contradiction): if the suffix weren’t optimal, swap it for the better one → strictly lower total cost → contradicts optimality of the full plan. ∎

339.2. Deriving the recursion

The total cost decomposes:

𝐽𝜋(𝑠0)=𝑐0(𝑠0,𝑎0)stage 0+𝑡=1𝑇1𝑐𝑡(𝑠𝑡,𝑎𝑡)+𝑐𝑇(𝑠𝑇)sub-problem of same kind, from 𝑠1

The bracketed remainder is the same problem starting from 𝑠1. By the principle of optimality, the optimal remainder is 𝐽1(𝑠1) — the optimal cost-to-go from 𝑠1.

So at stage 𝑡 in state 𝑠, you pay 𝑐𝑡(𝑠,𝑎) now and face the optimal-remaining problem from 𝑓𝑡(𝑠,𝑎):

𝐽𝑡(𝑠)=min𝑎𝒜︀(𝑠){𝑐𝑡(𝑠,𝑎)+𝐽𝑡+1(𝑓𝑡(𝑠,𝑎))}

This is the Bellman equation — direct consequence of additivity + principle of optimality.

339.3. Base case

𝐽𝑇(𝑠)=𝑐𝑇(𝑠)

(no decisions left; the only cost is the terminal one.)

339.4. Optimal action

𝑎𝑡(𝑠)=argmin𝑎{𝑐𝑡(𝑠,𝑎)+𝐽𝑡+1(𝑓𝑡(𝑠,𝑎))}

The optimal total cost from 𝑠0 is 𝐽0(𝑠0).

339.5. Worked example: shortest path through a layered graph

Stages 0123, states {𝑆},{𝐴,𝐵},{𝐶,𝐷},{𝐺}. Edge costs:

from\toABCDG
S42
A53
B16
C2
D4

Stage 3 (base case): 𝐽3(𝐺)=0.

Stage 2:

Stage 1:

Stage 0:

Optimal path: 𝑆𝐵𝐶𝐺, cost 5.

339.6. Two variants

Both compute the same optimum — choose whichever fits the data flow.

339.7. Stochastic case

When transitions are random (𝑠𝑡+1𝑃𝑡(|𝑠𝑡,𝑎𝑡)), the Bellman equation becomes:

𝐽𝑡(𝑠)=min𝑎{𝑐𝑡(𝑠,𝑎)+𝑠𝑃𝑡(𝑠|𝑠,𝑎)𝐽𝑡+1(𝑠)}

— expectation over the next state replaces the deterministic transition. See Stochastic DP.

339.8. See also