Agent, environment, state, action, reward
5.1.1· AI-ML › Reinforcement Learning Foundations
Overview
Agent-environment interaction loop reinforcement learning ki foundation hai. Supervised learning mein hume bataya jaata hai ki sahi answer kya hai, lekin RL agents ko achha behavior trial and error se discover karna padta hai — unhe sirf itna feedback (rewards) milta hai ki unke actions kitne achhe the.

The Five Components
Key insight: Agent mein "brain" hota hai — policy (action-choosing strategy) aur possibly ek model ki duniya kaise kaam karti hai.
Key insight: Environment boundary ek design choice hai. Ek robot ke liye, hum robot ki body ko environment mein include kar sakte hain aur sirf control algorithm ko agent maan sakte hain. Ya motor controllers ko agent mein rakh sakte hain aur sirf baaki duniya ko environment mein.
Ye kyun matter karta hai: Fully observable environment mein (jaise chess), agent sahi state dekhta hai. Partially observable environments mein (jaise poker ya limited sensors wale robot), agent ko incomplete information se decisions lene padte hain.
Actions kyun first-class hain: Agent SIRF apne actions control karta hai. Woh directly state ya reward control nahi kar sakta — wo interaction se emerge hote hain.
Critical insight: Rewards SIRF ek hi tarika hain goal communicate karne ka. Agar tum chahte ho ki RL agent aage chale, toh forward distance reward karo. Agar galti se "na girna" reward kiya, toh agent lait jaana seekh sakta hai!
The Interaction Loop: Deriving the Dynamics
Chalo formalize karte hain ki ye components time ke saath kaise interact karte hain.
Step 1: Initial state par, environment state mein hai (kisi initial distribution se drawn).
Step 2: Agent observes Agent observation receive karta hai (fully observable case mein, ).
Step 3: Agent acts Agent ki policy states/observations ko actions pe map karti hai. Ye ho sakta hai:
- Deterministic: — same state hamesha same action deta hai
- Stochastic: — probability distribution se action sample karo
Step 4: Environment responds Environment action receive karta hai aur:
- Naye state mein transition karta hai: jahan state transition probability hai
- Reward emit karta hai: ya agar stochastic hai
Step 5: Loop repeats Isse ek trajectory produce hoti hai (episode ya rollout bhi kaha jaata hai):
Ye formulation kyun? Ye ek Markov Decision Process (MDP) hai. "Markov" part ka matlab hai: current state diya ho toh future past se independent hai. Formally:
Isse hum decisions sirf current state ke basis par le sakte hain, poori history ke basis par nahi.
Finite horizon (episode time par khatam hota hai):
Kyun? Simple sum tab kaam karta hai jab episodes ka ek clear end ho (game over, task complete).
Infinite horizon with discounting:
jahan discount factor hai.
Discount kyun?
- Mathematical: Infinite sum ko converge karta hai (agar rewards bounded hain)
- Practical: Ye reflect karta hai ki near-term rewards distant rewards se zyada certain/valuable hain
- Control: 0 ke close = myopic (greedy), 1 ke close = far-sighted
Ye kyun converge hota hai, derivation: Maano rewards bounded hain: sab ke liye.
Geometric series ka sum hai:
Isliye: jo finite hai. ✓
Recursive form (bootstrapping):
Ye recursion Bellman equation ka beej hai.
Trajectory example:
t=0: s₀=(1,1), agent observes (1,1), chooses a₀=North
Environment: valid move, s₁=(1,2), r₀=-1
t=1: s₁=(1,2), agent chooses a₁=East
Environment: valid move, s₂=(2,2), r₁=-1
t=2: s₂=(2,2), agent chooses a₂=North
Environment: hits wall, s₃=(2,2), r₂=-5
t=3: s₃=(2,2), agent chooses a₃=East
Environment: valid move, s₄=(3,2), r₃=-1
... continues until reaching goal at (5,5)
t=12: s₁₂=(5,5), r₁₂=+10, episode ends
Return calculation ( ke saath):
Step penalty kyun? Iske bina ( non-goal states ke liye), agent ko jaldi goal reach karne ki koi zaroorat nahi. Woh hamesha ke liye ghoom sakta hai aur kabhi achhi policy nahi seekhega.
Ye reward structure kyun?
- Pehla term: Negative squared error → target se deviation penalize karta hai (comfortable temperature)
- Doosra term: Energy use par small penalty → efficiency encourage karta hai
- Dono terms negative hain → reward maximize karna matlab deviations aur energy minimize karna
Trajectory step:
t=0: s₀=(18°C, 10°C), agent chooses a₀=0.8 (80% heater)
Environment physics: Q = heater_power × max_heating
Heat_loss = k × (T_inside - T_outside)
T_new = T_old + (Q - Heat_loss) × dt
Result: s₁=(19.5°C, 10°C), r₀=-(19.5-21)² - 0.01×0.8² = -2.256
Continuous actions kyun? Temperature control naturally continuous scale par kaam karta hai. {off, low, medium, high} mein discretize karne se precision kho jaati.
Common Mistakes
Ye sahi kyun lagta hai: Rewards batate hain kya achha hai, toh har reward maximize karna logical lagta hai.
Fix: Agent ko cumulative discounted reward (return) maximize karna hota hai, na ki immediate reward. Example: Chess mein ek piece sacrifice karna (negative immediate reward) checkmate set up karne ke liye (bada future reward) optimal hai.
Formal: Agent ek policy seekhta hai jaise ki: Na ki: har par independently.
Ye sahi kyun lagta hai: Losses aur rewards dono performance measure karte hain, aur hum ML mein minimization ke aadat hain.
Fix: RL rewards maximize karne ke liye design hote hain. Agar tumhare task mein naturally loss hai (tracking error, energy waste), toh define karo taaki reward maximize karna matlab loss minimize karna ho.
Example: Goal se distance ke liye, use karo na ki .
Ye sahi kyun lagta hai: Simple states = smaller state space = faster learning.
Fix: Agar tum future predict karne ke liye zaroori information chod dete ho, toh Markov property toot jaati hai. Agent same state dekhega lekin hidden history ki wajah se alag outcomes experience karega, jo learning impossible bana deta hai.
Example: Pong mein, ek single frame ball velocity nahi dikhata. Tumhe 2+ frames chahiye ya explicitly state mein velocity include karni padegi. Warna, agent predict nahi kar sakta ball kahan jaayegi.
Ya ek feedback loop imagine karo: Agent → Action → Environment → State+Reward → Agent (loop close hota hai)
Recall Ek 12-Saal ke Bacche ko Samjhao
Socho tum ek naya video game seekh rahe ho, lekin controls labeled nahi hain. Tum buttons dabaate ho aur dekhte ho kya hota hai. Jab tum ek coin uthate ho, game tumhe points deta hai (woh reward hai). Jab tum ek hole mein girte ho, toh points kho dete ho (negative reward).
Tum (agent) screen dekh sakte ho (state) — tum kahan ho, enemies kahan hain. Tum choose karte ho kaun sa button dabao (action). Game ki duniya (environment) tumhare button ke hisaab se update hoti hai: tumhara character move karta hai, enemies move karti hain, aur decide hota hai tumne kitne points kamaaye.
Pehle tum random buttons try karte ho. Lekin time ke saath tum patterns notice karte ho: "Jab main cliff ke paas hoon aur right dabaata hoon, toh main girta hoon aur points kho deta hoon. Jab main cliff ke upar jump karta hoon, toh safely paar ho jaata hoon." Tum seekh rahe ho kaun se actions kaun si situations mein kaam karte hain. RL agents exactly yahi karte hain, sirf button mashing ki jagah math ke saath!
"Return" waise hai jaise pure game ka total score. Tum sirf sabse paas ka coin pakadna nahi chahte (immediate reward) — kabhi kabhi ek coin skip karna smarter hota hai khatre se bachne ke liye, taaki end mein total score better ho.
Connections
- Markov Decision Process (MDP) — formal mathematical framework
- Policy and Value Functions — agents apni strategy kaise encode karte hain
- Bellman Equations — optimal returns ke liye recursive relationship
- Exploration vs Exploitation — agents naye actions try karne aur jaane-maane achhe actions use karne mein balance kaise karte hain
- Partial Observability (POMDP) — jab agent poora state nahi dekh sakta
- Multi-Armed Bandits — simplified RL sirf ek state ke saath
- Model-Free vs Model-Based RL — agent environment dynamics seekhta hai ya nahi
#flashcards/ai-ml