5.1.9 · HinglishReinforcement Learning Foundations

Dynamic programming (value - policy iteration)

3,168 words14 min readRead in English

5.1.9 · AI-ML › Reinforcement Learning Foundations

Overview

Dynamic programming (DP) methods Markov Decision Processes (MDPs) ko subproblems mein todkar aur solutions cache karke solve karte hain. Ye optimal value functions aur optimal policies ko iterative updates ke zariye compute karte hain jo Bellman optimality equations ka use karte hain.

DP kyun important hai: DP modern RL algorithms ki theoretical foundation hai. Bhaleki pure DP ke liye ek perfect model chahiye (transition probabilities aur rewards), ise samajhna model-free methods jaise Q-learning aur actor-critic ko unlock karta hai, jo model ke bina DP ko approximate karte hain.

Figure — Dynamic programming (value - policy iteration)

Core Concepts


The Two Bellman Equations

Bellman Expectation Equation (ek given policy ke liye)

First principles se derivation:

Value ki definition se shuru karo:

jahan return hai.

Pehle reward ko baaki se alag karo:

Parentheses wala term bas hai, yaani next state se return:

Value function ki definition se, :

Actions (policy se) aur next states (dynamics se) par expectation expand karo:

WHY har component:

  • : State mein action lene ki policy probability
  • : Environment dynamics (transition probability)
  • : Immediate reward jo hum actually receive karte hain
  • : Jahan hum pahunchte hain uska discounted value

Bellman Optimality Equation

Derivation:

Optimal value sabhi possible policies par maximum hai:

Optimal policy ke liye, use wo action choose karna chahiye jo expected return maximize kare:

jahan

Expectation expand karo:

WHY max operator: Optimal policy hamesha best action pick karti hai, isliye hum policy distribution par average lene ki jagah actions par maximize karte hain.


Algorithm 1: Policy Iteration

Policy iteration do steps ke beech alternate karta hai: policy evaluation (current policy ke liye compute karo) aur policy improvement (policy ko greedy banao).

Step 1: Policy Evaluation

Goal: Current policy ke under sabhi states ke liye compute karo.

Algorithm:

  1. ko arbitrarily initialize karo (e.g., sabhi ke liye 0)
  2. Convergence tak repeat karo (change < ):
    • Har state ke liye:

WHY this works: Har iteration Bellman expectation equation apply karta hai. Kyunki yeh ek contraction mapping hai ( ki wajah se), repeated applications unique fixed point par converge hoti hain.

WHY this step: "Yeh update true value function se distance ko har sweep mein factor se shrink karta hai, isliye yeh zaroor converge hoga."

Step 2: Policy Improvement

Goal: Current value function ke w.r.t. greedily act karke policy ko better banao.

Algorithm: Har state ke liye:

WHY this policy improve karta hai (Policy Improvement Theorem):

Greedy action ke liye:

Agar hum follow karein phir ke saath continue karein, toh hume kam se kam utni hi value milegi:

Kyunki yeh sabhi states ke liye hold karta hai, kam se kam jitni acchi hai. Agar strictly better nahi hai, toh already optimal hai.

Full Policy Iteration Loop

1. Initialize π arbitrarily
2. Repeat:
   a. V ← PolicyEvaluate(π)  // converge to V^π
   b. π' ← Gredy(V)
   c. If π' = π, stop (optimal!)
   d. π ← π'

Convergence: Policy iteration finite number of steps mein converge hoti hai (zyada se zyada policies, lekin usually bahut faster). Har iteration policy ko strictly improve karti hai jab tak optimality na aa jaaye.


Algorithm 2: Value Iteration

Value iteration policy evaluation aur improvement ko ek single update step mein combine karta hai. Kisi policy ko fully evaluate karne ki jagah, hum ek backup per state karte hain aur use immediately next iteration ke liye use karte hain.

Algorithm:

  1. ko arbitrarily initialize karo (e.g., sabhi ke liye 0)
  2. Convergence tak repeat karo (change < ):
    • Har state ke liye:
  3. Optimal policy extract karo:

WHY this works: Har update Bellman optimality equation apply karta hai. Hum directly compute kar rahe hain bina iteration ke dauran explicit policy maintain kiye. Max operator implicitly har step policy improve karta hai.

Key insight: Value iteration, policy iteration hai jisme truncated policy evaluation hai (fully converge karne ki jagah bas ek sweep). Yeh aksar zyada efficient hota hai kyunki policy fully converge hone se pehle improve ho sakti hai.


Policy vs Value Iteration: The Tradeoff

Aspect Policy Iteration Value Iteration
Update Full policy evaluation + improvement Single optimality backup
Iterations Kam policy changes (typically 3-5) Zyada backups (10-100s) lekin sasta
Per-iteration cost High (many sweeps to converge ) Low (ek sweep)
Total cost Chhote ke liye aksar similar ya better Bade ke liye aksar better
Intermediate policy Hamesha well-defined policy hoti hai End tak koi explicit policy nahi

Kab kya use karein:

  • Policy iteration: Jab policy evaluate karna fast ho (chhota state space, high ), ya jab computation ke dauran intermediate policies chahiye hon.
  • Value iteration: Jab policy evaluation expensive ho, ya jab sirf final optimal policy chahiye.
  • Asynchronous DP: States ko kisi bhi order mein update karo (high-error states par focus karo), practice mein faster converge hoti hai.

Computational Complexity

Per iteration:

  • Policy evaluation: per sweep (har state ke liye, actions aur next states par sum)
  • Value iteration backup: per sweep

Total iterations:

  • Policy iteration: worst case (har policy), lekin typically 3-10 in practice
  • Value iteration: error threshold tak pahunchne ke liye

WHY convergence affect karta hai: Contraction factor hai. Har iteration error ko kam se kam factor se reduce karta hai, isliye chhota (kam far-sighted) faster converge karta hai.

Space complexity: aur store karne ke liye .


Connections to Other RL Methods

Temporal-difference learning se relationship:

  • DP: Model-based (needs ), sabhi states ko sweep karta hai
  • TD learning: Model-free (samples se seekhta hai), ek state at a time update karta hai
  • TD essentially DP hai jisme full expectation ki jagah sampled backups hain

Generalized Policy Iteration (GPI): Sabhi RL methods ko GPI ke roop mein dekha ja sakta hai: policy evaluation (value function ko policy ke consistent banana) aur policy improvement (policy ko value ke w.r.t. greedy banana) ko interleave karna. DP yeh exact computation se karta hai; TD/Q-learning ise samples se approximate karte hain.

Monte Carlo methods:

  • DP: Bootstrap karta hai (updates mein estimated use karta hai)
  • Monte Carlo: Bootstrap nahi (actual return ka wait karta hai)
  • Tradeoff: DP ki variance lower hai lekin model chahiye

Modern deep RL:

  • AlphaZero: aur ke liye neural networks ke saath policy iteration, evaluation ke liye Monte Carlo tree search
  • Actor-critic: Policy gradient (improvement) + TD learning (evaluation)

Connections


Recall Ek 12-saal ke bachche ko samjhao

Socho tum ek board game khel rahe ho jahan finish tak jitni jaldi ho sake pahunchna chahte ho. Abhi best strategy pata nahi hai, toh tum yeh try karte ho:

Plan 1 (Policy Iteration):

  1. Random strategy se shuru karo: "Main bas dice roll karunga aur jo mann kare move karunga."
  2. Ab pretend karo ki tum us strategy ko kai games ke liye follow karte ho aur calculate karo "Har square se average mein kitne turns lagte hain?"
  3. Apni strategy dobara dekho: "Ruko, agar main square 10 par hun, meri strategy kehti hai left jao, lekin agar main right jaaun, toh finish zyada jaldi pahunchunga!"
  4. Apni strategy update karo ki hamesha wo move choose karo jo kam-turns wale squares par le jaaye.
  5. Steps 2-4 repeat karo jab tak strategy change karna band na ho jaaye.

Plan 2 (Value Iteration):

  1. Guess karke shuru karo "Har square se 0 turns."
  2. Har square update karo: "Agar main yahan hun, toh main kitni jaldi finish kar sakta hun?" Sabhi possible moves dekho aur best pick karo.
  3. Step 2 repeat karo jab tak numbers change karna band na ho jaayein.
  4. Teri final strategy: hamesha sabse kam number wale square ki taraf move karo.

Dono plans perfect strategy dhundh lete hain! Pehla wala ek strategy try karne, use test karne, phir fix karne jaisa hai. Doosra wala har square ke liye best possible score calculate karne aur use follow karne jaisa hai.


Flashcards

MDPs solve karne ke liye do main DP algorithms kaun se hain? :: Policy iteration aur value iteration.

Policy evaluation aur value iteration updates mein key difference kya hai?
Policy evaluation policy par expectation use karta hai: . Value iteration actions par max use karta hai: .
Bellman expectation equation kya hai?
Bellman optimality equation kya hai?
Policy improvement theorem kyun guarantee karta hai ki greedy policy better hai?
Kyunki sabhi states ke liye hai, isliye .
DP convergence mein contraction factor kya hai?
(discount factor). Har iteration mein error factor se shrink hoti hai.
Value iteration ke liye tolerance diye stopping criterion kya hai?
implies .
Generalized policy iteration (GPI) kya hai?
Policy evaluation aur policy improvement ko interleave karne ka framework, jo sabhi RL algorithms ke underlying hai.
Value iteration policy iteration se wall-clock time mein aksar faster kyun converge karta hai?
Har iteration sasti hai (full convergence ki jagah ek backup), aur truncated evaluation aksar policy improvement ke liye sufficient hoti hai.
Wo key requirement kya hai jo DP ko large real-world RL problems ke liye infeasible banati hai?
DP ko full MDP model chahiye: sabhi states aur actions ke liye transition probabilities .
Policy iteration ko value iteration par kab prefer karna chahiye?
Jab state space chhota ho aur policy evaluation fast ho, ya jab high ho (1 ke karib).
In-place/asynchronous DP kya hai aur ise kyun use karein?
States ko kisi bhi order mein update karna (high-error states par bhi focus karna) latest values use karke. Synchronous sweeps se practice mein faster converge hota hai.

Concept Map

solves

leverages

defines

related to

computes

feeds into

greedy w.r.t.

loops back to

converges to

yields

foundation for

approximates without model

Markov Decision Process

Dynamic Programming

Bellman Equations

Policy Evaluation

Policy Improvement

State Value V-pi

Action Value Q-pi

Optimal Value V-star

Optimal Policy pi-star

Model-Free Methods