5.6.9 · D4 · HinglishMachine Learning (Aerospace Applications)

ExercisesOptimization — SGD, momentum, Adam — derivations

3,057 words14 min read↑ Read in English

5.6.9 · D4 · Coding › Machine Learning (Aerospace Applications) › Optimization — SGD, momentum, Adam — derivations

Poore note mein symbols ka wahi matlab hai jo parent note ne define kiya hai. Ek naming warning pehle se: is chapter mein letter do alag cheezein ke liye use hota hai, aur unhe mix karna confusion ka #1 source hai — isliye hum yahan dono ko apna alag naam dete hain aur kabhi bhi bare nahi likhenge.


Level 1 — Recognition

L1.1 Kaunsi direction?

Aap par khade ho aur gradient hai (loss upar jaata hai jab badhta hai). ke saath, kya plain gradient descent ko left (chhota) ya right (bada) move karega, aur se kaunsi value par jaayega?

Recall Solution

WHAT: update hai . WHY: downhill point karta hai; positive matlab uphill right ki taraf hai, toh hum left step karte hain. Left move karta hai (chhota), tak. ✔

L1.2 Term ka naam batao

mein jahan , ko kya kaha jaata hai aur se kya collapse hota hai?

Recall Solution

ko momentum coefficient (ek decay/memory factor) kehte hain. ke saath: jo plain SGD hai. Toh bina memory ke momentum hai hi SGD. ✔


Level 2 — Application

L2.1 Quadratic par ek SGD step

, toh . , se aur calculate karo.

Recall Solution

WHAT: apply karo jahan . WHY : differentiate karne par milta hai — position par parabola ka slope exactly hai, toh gradient literally wahi hai jahan aap khade ho. : . WHY exactly shrink hua: substitute karne par rule banta hai — har step ko same factor se scale karta hai. : . Toh ki valley ki taraf ek clean geometric decay. ✔

L2.2 Do momentum steps

Same , , , , . aur compute karo, aur ko SGD ke se compare karo.

Recall Solution

WHAT: chalao phir . Step 0: , , . WHY step 0 SGD se match karta hai: ke saath koi stored velocity nahi hai, toh pehli velocity bas hai — momentum ke paas pehli move mein kuch extra add karne ko nahi hai. Step 1: , , . WHY step 1 aage nikal jaata hai: purani velocity ka () aur fresh gradient () add karta hai, toh velocity raw gradient se almost double hai — ball consistent downhill direction mein speed pakad chuka hai. Momentum pahuncha vs SGD ka faster, kyunki ne pehla gradient accumulate kiya. ✔

L2.3 Ek Adam step

Same , , , . compute karo.

Recall Solution

WHAT: do moments compute karo, bias-correct karo, phir step lo. . , bias-correct: . WHY correction: se shuru hota hai, toh ek single update sirf tak pahunchta hai — true gradient ka ek shrunken version. se divide karne par woh exact shrink undo hota hai aur honest estimate milta hai. , bias-correct: , toh . WHY se divide karte hain: estimates karta hai ko, toh — isse divide karne par gradient ka size cancel ho jaata hai, sirf uska sign bachta hai. Adam ka pehla step hai — magnitude-independent. ✔

Neeche wali figure padhna. Horizontal axis parameter hai, vertical axis loss hai (woh pale chalk parabola). Teeno optimizers se start karte hain (top right). Teen coloured dotted-with-dots tracks successive positions dikhate hain: blue = SGD, pink = Momentum, yellow = Adam. Har track ko true parabola se thoda upar draw kiya gaya hai taaki aap inhe alag kar sako — vertical offset sirf cosmetic hai, real ke liye horizontal position padho. Takeaway: dekho pink Momentum dots kaise aage pull karte hain (har step mein zyada left land karte hain) jabki blue SGD peeche rehta hai, aur yellow Adam deliberately ek modest, evenly-scaled pehla stride leta hai — teeno L2 answers visual form mein.

Figure — Optimization — SGD, momentum, Adam — derivations

Level 3 — Analysis

L3.1 amplification

Steady slope par gradient constant hai. Dikhao ki momentum velocity tak converge karti hai aur ke liye evaluate karo.

Recall Solution

WHAT: ko se unroll karo: WHY woh sum: har step purani velocity ka -fraction rakhta hai aur fresh add karta hai — ek geometric series (dekho Exponential Moving Average). ke saath, (kyunki ), toh . ke liye: — steady directions par 10× effective learning rate. ✔

L3.2 Oscillation cancellation

Maano ek coordinate ka gradient alternate karta hai: (steep ravine wall bouncing). , , ke saath compute karo, aur explain karo ki same-sign case ki tulna mein running velocity ka kya hota hai.

Recall Solution

. Pehle entry ke baad, velocity magnitude chhoti rehti hai ( se yeh approximately aur ke beech bounce karti hai) kyunki opposite-sign gradients baar baar cancel ho jaate hain. Same-sign case mein yeh badhkar ki taraf jaati. Yahi hai kaise momentum oscillations ko damp karta hai aur consistent directions mein accelerate karta hai. ✔

L3.3 Kyun SGD saddle se escape karta hai

Saddle point par , toh full-batch GD ka update hai — woh kabhi move nahi karta. use karke explain karo ki SGD mini-batch step generally kyun move karta hai.

Recall Solution

Mini-batch gradient unbiased hai: saddle par . Lekin unbiased ka matlab sirf average zero hai — actual mein nonzero variance hoti hai, toh ek typical draw mein hoga. Woh random kick ko saddle se kisi direction mein push karta hai; agar woh downhill escape direction par land kare (saddle par hamesha ek hoti hai) toh loss drop ho jaata hai. Dekho Saddle Points and Loss Landscapes. Isliye SGD ka noise ek feature hai, bug nahi.


Level 4 — Synthesis

L4.1 Adam ki bias correction derive karo

aur mean ke stationary gradients ke saath, dikhao ki aur isliye hum se kyun divide karte hain.

Recall Solution

WHAT: ko se unroll karo: WHY: har naya gradient weight ke saath aata hai aur purane se decay karte hain. ke saath expectation lo:

=(1-\beta_1)\,g\cdot\frac{1-\beta_1^{t}}{1-\beta_1}=g\,(1-\beta_1^{t}).$$ Kyunki chhote $t$ ke liye $1-\beta_1^{t}<1$ hai, raw $m_t$ $g$ ko **underestimate** karta hai (0 ki taraf biased). Divide karne par: $$\hat m_t=\frac{m_t}{1-\beta_1^{t}} \;\Rightarrow\; \mathbb{E}[\hat m_t]=g.$$ Same algebra $\hat s_t=s_t/(1-\beta_2^{t})$ deta hai. ✔

L4.2 Bias-correction shrink factor

ke liye bias correction pehle-step first moment ko kitna inflate karta hai (matlab factor )? Aur par ke saath second moment ke liye?

Recall Solution

First moment, : . Second moment, : . Yeh exactly wahi inflations hain jo humne L2.3 mein use kiye: () aur (). ✔

Neeche wali figure padhna. Horizontal axis step counter hai; vertical axis (log scale par, toh equal spacing equal multiplying factor matlab hai) bias correction ka inflation factor hai. Pink first-moment factor hai; blue second-moment factor hai. Yellow dashed line at 1 matlab "koi correction ki zaroorat nahi." Takeaway: par pink factor hai aur blue ek bada — wildly different — lekin dono curves yellow line ki taraf slide karte hain jab badhta hai, toh correction training shuru hone ke baad quietly khud ko switch off kar leta hai. Isliye ise skip karna sirf pehle kuch steps ko hurt karta hai.

Figure — Optimization — SGD, momentum, Adam — derivations

L4.3 Noise-only coordinate par Adam

Ek coordinate zero-mean noise receive karta hai: gradients jahan , . Argue karo ki long-run Adam step jaata hai, aur steady-gradient coordinate se contrast karo jahan step jaata hai.

Recall Solution

Noise case: lekin . Steady case (): , , toh Adam consistent directions par trust karta hai (unit step) aur pure noise ko ignore karta hai (zero step) — ek per-coordinate signal-to-noise filter. ✔


Level 5 — Mastery

L5.1 One-step descent guarantee

First-order Taylor Expansion use karke jahan , dikhao ki loss strictly decrease hota hai (first order tak) jab bhi aur . Guarantee kya tod deta hai?

Recall Solution

WHAT: GD update ko Taylor expansion mein substitute karo: Yahan ek vector ki squared length ki definition hai (ek identity, Cauchy–Schwarz inequality nahi — steepest-descent direction ne Cauchy–Schwarz parent note mein wahan use kiya tha; yeh step ek plain dot-product-with-itself hai). WHY decrease hota hai: aur tabhi hota hai jab . ke saath, change hai, toh drop karta hai. Kya tod deta hai guarantee: approximation sirf first-order hai; agar bada ho toh ignored second-order (curvature) term dominate kar sakta hai aur badh sakta hai — L1/L3 traps ka overshoot. ✔

L5.2 Quadratic par convergence rate

ke liye (toh ), SGD map hai . Kis ke liye hoga, aur kaunsa fastest convergence deta hai? Saare cases cover karo including , , aur non-positive .

Recall Solution

WHAT: linear map ko closed form mein iterate karo. Kyunki har step constant se multiply karta hai, steps ke baad WHY multiplier sab decide karta hai: exactly tab hoga jab powers shrink honge, matlab jab ho. Solve karo : Ab multiplier ka har case walk karo:

  • (non-positive rate): , toh aur kabhi nahi shrinks. Actually (uphill) direction mein step karta hai — pure gradient ascent, loss badhta hai. se milta hai: hamesha ke liye frozen. Toh mandatory hai.
  • : — smooth monotone shrink ki taraf (hamara L2.1 case, ).
  • : , toh one-step convergence, possible fastest.
  • : — converge phir bhi karta hai, lekin har step sign alternate karta hai (oscillating shrink).
  • : , toh hamesha bounce karta hai, magnitude kabhi nahi shrinks (marginal, no convergence).
  • : diverge karta hai, bina bound ke badhta hai.

Summary: converges ; fastest at ; frozen at ; ke liye ascent; marginal bounce at ; ke liye diverges. ✔

L5.3 Synthesize: optimizer chunno

Ek aerospace CFD surrogate net mein hai (a) noisy mini-batch gradient, (b) ek deep ravine loss valley, aur (c) layers jinke gradient magnitudes se differ karte hain. Kaunsa single optimizer teeno address karta hai aur har ek ka mechanism kya hai?

Recall Solution

Adam. Mechanism-by-mechanism:

  • (a) Noise → first moment (gradients ka Exponential Moving Average) zero-mean noise average out karta hai, bilkul momentum ki tarah.
  • (b) Ravine → same momentum-like averaging consistent along-valley direction mein accelerate karta hai aur oscillating across-valley direction cancel karta hai (L3.2).
  • (c) scale mismatch se divide karna har coordinate ko step tak rescale karta hai, toh -bade gradients explode nahi karte aur tiny wale stall nahi karte (L4.3). Ek optimizer, teen mechanisms. Woh combination isliye hai ki Adam aise nets ke liye default hai. ✔

Recall Self-test checklist

ke saath par one-step SGD ::: Momentum (same setup, ) ::: Adam (same setup) ::: ke liye Momentum steady-slope amplification ::: Adam first-step second-moment inflation, ::: SGD par kis ke liye converge karta hai? ::: , fastest at ; ya ke liye diverges/ascends