Policy value and Bellman equations
Quick answer
A value function estimates expected future discounted reward. State value V describes following a policy from a state; action value Q describes taking a particular first action and then following that policy. Bellman equations express these values recursively. Examples are static Python snippets tested locally on CPU; Only Python standard-library modules are required. ByteMind execution is unverified.
Expected Bellman backup
from fractions import Fraction as Fprint(F(1,4)*(2+F(1,2)*8)+F(3,4)*(-2+F(1,2)*4))Expected output (locally tested): 3/2. Each outcome is weighted by its transition probability.
How it works
For policy pi, V_pi(s)=sum_a pi(a|s) Q_pi(s,a). Q_pi(s,a)=E[r+gamma V_pi(s_next) | s,a], with zero continuation at terminal states. Optimal values use max over legal actions instead of policy averaging. Example: an action gives immediate 2 and goes to a state valued 6; gamma=0.5 gives Q=5. A stochastic transition must average each possible next reward plus discounted continuation, not choose the best outcome. Value iteration repeatedly applies the Bellman optimality backup to all states using known transition probabilities. Synchronous updates read old values and write new ones; asynchronous updates differ in order. In a finite discounted MDP with bounded rewards, the Bellman optimality operator contracts sup-norm differences by gamma < 1; this supports convergence of exact value iteration. Terminal values are zero when rewards are received on entry. A greedy policy chooses an action maximizing Q with an explicit tie rule. Expected discounted return and success probability are different quantities. Model-free TD learning instead samples transitions; it does not require the full model. Use the known model for a tiny planning reference, not as a hidden input to a model-free learner.
Value iteration on one live state
v=0.0for _ in range(50):v=max(2,1+0.75*v)print(round(v,5))Expected output (locally tested): 4.0. The repeating action approaches 1/(1-0.75), which exceeds the terminal reward.
Common mistakes
Do not maximize over random next states, add terminal reward twice, or treat a single noisy sample as the exact expectation. Check the legal-action set and tie rule.
Practice and next steps
Write a two-state MDP where action a terminates with reward 2 and action b gives reward 1 and returns to the same state. At gamma=0.75, solve the optimal fixed point and identify the greedy action.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Policy value and Bellman equations — knowledge check
Apply policy value and bellman equations to small examples and debugging scenarios.
How is V_pi related to Q_pi?
What does the optimal Bellman backup maximize over?
What is continuation after true termination?
What does value iteration use?
Why use gamma below one in a continuing discounted task?