5.2.13 · HinglishDeep & Advanced RL

Reward shaping and sparse rewards

1,919 words9 min readRead in English

5.2.13 · AI-ML › Deep & Advanced RL


Sparse reward KYA hota hai?

YEH mushkil kyun hai: RL return se seekhta hai. Agar almost sab hain, toh har jagah jahan agent actually gaya ho, isliye koi bhi action dusre se behtar nahi lagta → koi policy improvement nahi jab tak goal luck se na mile. Luck se goal milne ki probability steps ki sankhya ke saath exponentially decay hoti hai.


Reward shaping KYA hai?

Danger yeh hai: ek naïve reward hacking create kar sakta hai — agent ek aisa loop dhundh leta hai jo ko milkify kare bina task solve kiye.


Safe tarike se shape kaise karein: Potential-Based Reward Shaping (PBRS)

First principles se derivation — Optimal policy kyun preserve hoti hai

Hum ise derive karenge, memorize nahi karenge.

Step 1 — Shaped return likho. Ek trajectory ke liye shaped return hai Yeh step kyun? By definition return shaped reward ka discounted sum hai.

Step 2 — Sum ko split karo. Kyun? Sum of a sum linearly split hota hai.

Step 3 — Shaping part ko telescope karo. Maano . Ise likhte hain: wale terms group karo: coefficient . Similarly ke liye: . Sab kuch cancel ho jaata hai sirf chhodkar. Kyun? Har ek term se ke saath appear hota hai aur agle term se ke saath — yeh annihilate ho jaate hain. Yeh ek telescoping series hai.

Step 4 — Collect karo.

Step 5 — Interpret karo. Shaped value true value se ek aisi constant se different hai jo sirf start state pe depend karti hai, actions pe nahi: Yeh punchline kyun hai: kyunki ek constant offset over hai. Toh greedy/optimal policy identical rehti hai. ∎

Figure — Reward shaping and sparse rewards

Sparse rewards ke liye aur tools (80/20)

  • Intrinsic motivation / curiosity: ya count bonus add karo taaki agent ko novel states visit karne ka reward mile → explore karta rehta hai jab tak real reward na mile.
  • Hindsight Experience Replay (HER): agar agent goal ke liye gaya tha lekin tak pahuncha, toh episode ko relabel karo jaise hi goal tha. Ab ek "failure" ek "success" ban jaata hai → dense synthetic learning signal, koi reward hacking nahi.
  • Curriculum learning: agent ke paas wale goals se shuru karo (dense success), phir dheere dheere unhe door karte jao.

Worked examples


Common mistakes (unhe Steel-man karo)


Flashcards

Sparse reward se seekhna mushkil kyun hai?
Almost sab , toh visited states par flat hai → koi action better nahi lagta → policy improve nahi ho sakti jab tak goal rare chance se na mile.
Reward shaping kya hai?
Reward mein ek extra term add karna, , taaki learning goal ki taraf guide ho.
Potential-based shaping formula batao.
kisi bhi potential ke liye.
PBRS optimal policy kyun unchanged rakhta hai?
Shaping telescope karti hai toh ; par constant hai, toh unchanged rehta hai.
Potential ka ideal choice kya hai?
, jo good actions ko pehle step se hi distinguishable banata hai.
PBRS ke under loops free reward kyun nahi dete?
Ek state mein enter karne ka bonus use chhodne se cancel ho jaata hai; ek closed loop par sum telescope hokar zero ho jaata hai.
Hindsight Experience Replay (HER) kya hai?
Ek failed episode ke goal ko actually reach kiye gaye state se relabel karo, failures ko successful (dense) learning examples mein badlo.
Curiosity/intrinsic bonus kya hai aur kab use karte hain?
Novel states visit karne ka reward (jaise prediction error ya ); tab use karte hain jab banane ke liye koi goal heuristic na ho.
PBRS formula mein drop karne par kya hota hai?
Telescoping residual terms chhodti hai → discounted MDPs mein policy invariance toot jaati hai.

Recall Feynman: ek 12-saal ke bachche ko explain karo

Tum "hot or cold" khel rahe ho lekin aankhon par patti bandhi hai aur dost sirf "mil gaya!" tab chillata hai jab tum chhupe hue khilaune ko chhute ho — baaki silence. Tum hamesha bhatakte rehoge. Reward shaping matlab ab tumhara dost whisper kar raha hai "warm... warm... thanda." Yeh help karta hai! Lekin ek rule hai: jab bhi tum kareeb jaate ho toh wo ek candy deta hai, aur jab bhi peeche jaate ho toh — exactly wahi candy waapis le leta hai. Toh circles mein ghoomne par kuch nahi milta; sirf asal khilauna milne par reward milta hai. Isliye hum tumhari help bhi kar sakte hain aur tumhe kabhi candy ke liye aage-peeche pace karne pe trick bhi nahi kar sakte.

Connections

Concept Map

almost always zero

Q near zero everywhere

hit goal by luck

adds helper term F

fixes

naive F

example

safe form of

F equals gamma Phi s' minus Phi s

loops sum to zero

prevents

Ng Harada Russell 1999

Sparse reward

No learning signal

No policy improvement

Exponentially rare exploration

Reward shaping

Shaped reward R plus F

Reward hacking

Boat spins on checkpoints

Potential-based shaping

Potential function Phi

Policy invariance