5.6.9 · D3 · HinglishMachine Learning (Aerospace Applications)

Worked examplesOptimization — SGD, momentum, Adam — derivations

2,368 words11 min read↑ Read in English

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

Yahan = gradient (loss ka slope), = learning rate (step-size knob), = decay/memory of running average, aur ek tiny number hai taaki zero se divide na ho.


Scenario matrix

Neeche har worked example us cell ke saath tagged hai jo woh cover karta hai. Matrix har case class list karta hai jo yeh topic aap par throw kar sakta hai.

# Cell (scenario class) Kya special hai Example
A Positive gradient, plain step , basic SGD walk Ex 1
B Negative gradient / sign flip aur ka zero cross karna Ex 2
C Consistent direction → momentum builds same-sign , speed-up Ex 3
D Oscillating direction → momentum cancels alternating-sign (ek ravine) Ex 4
E Zero / degenerate gradient (saddle) : kaun move karta hai, kaun stall karta hai Ex 5
F Exploding gradient huge : Adam ka rescue Ex 6
G Pure-noise direction (mean 0) , , step Ex 7
H Limiting behaviour bias correction fade hoti hai, EMA saturate hoti hai Ex 8
I Real-world word problem CFD surrogate LR schedule Ex 9
J Exam twist target speed-up ke liye derive karo Ex 10

Example 1 — Cell A: positive gradient, ek plain SGD step

  1. Gradient compute karo. . Yeh step kyun? SGD ko wahan slope chahiye jahan hum khade hain; ke liye derivative exactly hai.
  2. Rule apply karo . Yeh step kyun? Positive slope matlab loss badhti hai jab barhta hai, toh hum left move karte hain (bowl ke neeche), ki taraf.

Verify: ka minimum pe hai, aur , se zyada ke paas hai — loss se tak giri. Units: dimensionless, dimensionless. ✓


Example 2 — Cell B: negative gradient aur ek sign flip

  1. Step 1 gradient: (negative — loss decrease hoti hai jab barhta hai). Yeh step kyun? ka sign direction batata hai: matlab right jao ( badhao).
  2. Update: . Yeh step kyun? Negative subtract karna add karne jaisa hai — hum sahi tarah se ki taraf left se move karte hain.
  3. Step 2 gradient: , abhi bhi negative → right move karte raho. .

Verify: shrink hua ; har step se multiply hota hai. Wakai aur . ✓ Koi overshoot nahi kyunki .


Example 3 — Cell C: consistent direction, momentum builds

  1. Velocity unroll karo. ; ; . Yeh step kyun? Momentum recent gradients ko sum karta hai (ek exponentially weighted sum); same-sign terms add up hote hain.
  2. Limit. Constant ek geometric series deta hai . Yeh step kyun? jab ; yahi famous speed-up ka source hai.
  3. Effective step , yaani raw ka 10× amplification.

Verify: partial geometric sum ke against. ✓ Aur . ✓


Example 4 — Cell D: oscillating direction, momentum cancels

  1. .
  2. . Yeh step kyun? Purani velocity almost cancel ho jaati hai flipped se; alternating signs destructively interfere karte hain.
  3. ; .

Verify: SGD ki velocity exactly hoti har step (swing amplitude ). Momentum ka swing / ke paas settle hota hai — cross-ravine wobble roughly damped hoti hai cancelling part pe. Ex 3 (consistent → tak badhta hai) ko is se (oscillating → chota rehta hai) compare karo: same rule, opposite outcome, exactly design goal. ✓


Example 5 — Cell E: saddle pe zero gradient

  1. Plain SGD: step . Instantly stall karta hai. Yeh step kyun? SGD ki zero memory hai; koi slope nahi → koi motion nahi. Isliye deterministic full-batch GD saddles pe stuck ho jaata hai.
  2. Momentum: , step . Rolling rehta hai. Yeh step kyun? Stored velocity ise flat spot ke across carry karti hai — jaise ek ball coasting kare.
  3. Adam: , . Step . Yeh bhi coast karta hai.

Verify: ✓; ✓. Degenerate case clearly separate karta hai memoryless SGD (stuck) ko memory-based methods (unstuck) se — yahi momentum/Adam ka poora practical argument hai. ✓


Example 6 — Cell F: exploding gradient, Adam rescues

  1. SGD step: . Ek catastrophic jump — likely diverge karega. Yeh step kyun? SGD ka step ke proportional hai; bada gradient matlab bada, dangerous leap.
  2. Adam step (settled): . Yeh step kyun? se divide karna magnitude ko normalize kar deta hai, ek unit step chodh ke. Yahi Adam ki famous per-coordinate rescaling hai.

Verify: , toh , times . Exploding-gradient scenario dikhata hai Adam ka step hai, scale se independent. ✓


Example 7 — Cell G: pure-noise direction, step dies

  1. First moment (mean tracker): ; ; ; . Yeh step kyun? estimate karta hai ; alternating signs ke saath yeh near 0 hover karta hai.
  2. Second moment (magnitude tracker), har step pe use karke: ; ; aur yeh ki taraf climb karta hai. Yeh step kyun? estimate karta hai regardless of sign — squaring flip erase kar deta hai.
  3. Settled step . Adam noisy directions ko freeze kar deta hai.

Verify: ✓; ✓. Chota bade ke upar ⇒ tiny step — signal-to-noise behaviour. Ex 6 (steady ) ko is se (noise → ) contrast karo. ✓


Example 8 — Cell H: limiting behaviour, bias correction fades

  1. Raw EMA at step : ke saath, . Yeh step kyun? se start karna average ko early zero ki taraf drag karta hai; parent ke series argument se.
  2. Correction factors: , , .
  3. Corrected: exactly, har pe. Yeh step kyun? Same se divide karna bias cancel karta hai — bias correction ka poora point yahi hai; yeh sabse zyada matter karta hai jab small ho (factor at ).

Verify: , toh ✓; corrected mean exactly hai. Jab factor hota hai, toh bias correction quietly khud ko switch off kar leta hai. ✓


Example 9 — Cell I: real-world CFD surrogate word problem

  1. : . Yeh step kyun? Early on hum bade exploratory steps chahte hain saddles escape karne ke liye.
  2. : . Halved.
  3. : . Yeh step kyun? Late training mein tiny steps chahiye taaki noisy path zig-zagging band kare aur minimum mein settle ho.

Verify: , toh ; ratio . Units: learning rate throughout dimensionless. ✓ Yeh parent ke schedule se match karta hai.


Example 10 — Cell J: exam twist, ke liye solve karo

  1. Set up: . Yeh step kyun? Momentum ki steady-state velocity hai (geometric sum, Ex 3); target ke liye invert karo.
  2. Default check: .
  3. Bump: — ek tiny change (0.9→0.99) speed-up ko 10-fold multiply kar deta hai, kyunki nonlinearly shrink hoti hai. Yeh step kyun? Map near blow up karta hai; wahi sensitivity hai isliye top decimals mein tune hoti hai.

Verify: ✓, ✓, ✓.


Recall Self-test: pehle cell ka naam lo, phir answer do

Kaun sa optimizer saddle pe move karta hai jahan abhi hai, aur kyun? ::: Momentum aur Adam (stored velocity / coast karta hai); SGD stall karta hai kyunki uski koi memory nahi (Cell E). Steady slope pe ke saath, momentum speed-up kya hai aur yeh kahan se aata hai? ::: , geometric sum se (Cell C). Adam aur dono ke liye step kyun deta hai? ::: Yeh se divide karta hai, magnitude cancel karta hai — ek per-coordinate normalization (Cell F). Pure-noise direction mein Adam ka step zero kyun ho jaata hai? ::: (mean gradient) lekin , toh ratio (Cell G). Bias correction chote pe sabse zyada kyun matter karta hai? ::: Factor early pe tiny hota hai ( pe 0.1), toh uncorrected badly underestimate karta hai ko (Cell H).

Parent derivations pe wapas jao parent derivations · Hinglish version: 5.6.09 Optimization — SGD, momentum, Adam — derivations (Hinglish)