5.6.9 · D2 · HinglishMachine Learning (Aerospace Applications)

Visual walkthroughOptimization — SGD, momentum, Adam — derivations

2,026 words9 min read↑ Read in English

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


Step 1 — Ek ball ek hill par: "descend" ka matlab kya hai

KYA HAI. Ek landscape imagine karo. Position par ground ki height ek number hai jise hum loss kehte hain. "Training" ka matlab hai: ball ko lowest point tak roll karo.

PEHLE PICTURE KYU. Kisi bhi formula se pehle, tumhe dekhna hoga ki optimization bas downhill chalna hai. Is page ke har optimizer ka ek rule hota hai — "kis taraf, kitna door?"

PICTURE. Figure mein, (parameter) left–right jaata hai. (loss) curve ki height hai. Ball par baithi hai; arrow wohi sensible move dikhata hai — valley ki taraf.

Figure — Optimization — SGD, momentum, Adam — derivations

Step 2 — Slope humein batata hai neeche kaun sa taraf hai

KYA HAI. Ball ki position par, woh line draw karo jo curve ko bas chhuti hai — yeh tangent hai. Iska steepness derivative hai, jise likhte hain, ya many-dimensions language mein gradient .

YEH TOOL KYU AUR KOI NAHI. Humein ek local jawab chahiye — "yahan abhi neeche kaun sa taraf hai?" — sirf woh use karke jo hum ek point par measure kar sakte hain. Derivative exactly wahi hai: tangent ka rise-over-run. Positive slope matlab ground right ki taraf chadhti hai, toh hum left jaayein; negative slope matlab right jaao. Dono taraf, hum slope ke khilaf step lete hain.

PICTURE. Green tangent line uphill jhuk rahi hai. Red arrow opposite direction mein point karta hai: downhill. Woh single sign-flip yahan ke har method ka seed hai.

Figure — Optimization — SGD, momentum, Adam — derivations

Anti-parallel kyun optimal hai (sirf "ek" downhill direction nahi) — yeh Taylor Expansion + Cauchy–Schwarz argument parent note mein hai; yahan hum picture par trust karte hain: slope ke opposite sabse fast girta hai.


Step 3 — Gradient noisy hai: SGD ka entry

KYA HAI. Real training mein hum true slope measure nahi kar sakte; hum ise ek chhote random mini-batch se estimate karte hain, jo ek wobbly arrow deta hai .

KYU. Millions of samples par exact slope compute karna bahut slow hai. Mini-batch sasta hai aur, average par, correct hai — iski expected value true slope ke barabar hoti hai (ek unbiased estimate). Backpropagation dekho ki har actually kaise compute hota hai.

PICTURE. True downhill arrow ek clean direction hai. Mini-batch arrows uske around scatter hote hain — kuch bahut lambe, kuch tilted. Inhe blindly follow karo aur tumhara path zig-zag karega.

Figure — Optimization — SGD, momentum, Adam — derivations

Step 4 — Ravine problem, aur momentum ka jawab

KYA HAI. Bahut saare loss surfaces ravines hote hain: across steep, along almost flat. SGD steep walls se bounce karta hai (fast oscillation) aur flat floor par creep karta hai (slow progress). Momentum ek running average rakhta hai jise velocity kehte hain, taaki consistent directions build up hon aur oscillating wale cancel ho jaayein.

AVERAGE KYU. Oscillation ka matlab hai across-arrows baar baar sign flip karte hain; unhe add karne se cancel hota hai. Along-arrows sab ek hi taraf point karte hain; unhe add karne se accumulate hota hai. Ek decaying running sum dono ek saath karta hai — yeh ek Exponential Moving Average hai.

PICTURE. Left: SGD ka saw-tooth path ravine ke across. Right: momentum ka smoothed path — sideways wiggles annihilate ho jaate hain, forward drive badhta hai.

Figure — Optimization — SGD, momentum, Adam — derivations

Step 5 — Momentum amplifier kyun hai

KYA HAI. Velocity unroll karo: . Steady slope par (constant), yeh geometric sum settle hota hai par.

YEH KYU MATTER KARTA HAI. ke saath, factor : momentum 10× faster sprint karta hai SGD se us kisi bhi direction mein jis par gradient agree karta rehta hai. Yahi "acceleration" hai.

PICTURE. Bars geometrically shrink karte hain (); unki heights par dashed ceiling tak sum hoti hain. Recent gradients sabse zyada count hote hain; purane fade ho jaate hain.

Figure — Optimization — SGD, momentum, Adam — derivations

Step 6 — Adam ka second moment: gradient size measure karna

KYA HAI. Adam do running averages rakhta hai har parameter ke liye: mean (momentum, "kaun sa taraf") aur mean square (magnitude, "kitna bada aur kitna noisy").

SQUARE KYU KARTE HAIN. Squaring sign throw away kar deta hai, toh raw strength measure karta hai direction se regardless. Bada matlab "is coordinate mein large ya noisy gradients hain"; chhota matlab "quiet." Isse har parameter apna khud ka step size pa sakta hai — vital jab early aur late network layers ke scales bilkul alag hon.

PICTURE. Do coordinates: ek mein large steady gradient, ek mein tiny. Unke (blue) aur (orange) EMAs direction aur magnitude ko alag alag track karte hain.

Figure — Optimization — SGD, momentum, Adam — derivations

Step 7 — Cold-start bias, aur uska fix

KYA HAI. Dono averages zero se start hote hain: . Shuruaat mein woh zero ki taraf drag hote hain — ek underestimate. Constant ke saath unroll karo toh milta hai, jo se chhota hota hai jab tiny ho. Fix yeh hai ki shrinkage divide kar do:

KYU. Correction ke bina Adam ke pehle steps absurdly small honge (empty memory se start karte hue), training stall ho jaayegi. se divide karna exactly cold-start undo karta hai.

PICTURE. Raw (dashed) se creep karta hai; corrected (solid) step one se hi true value par baith jaata hai. Jaise badhta hai, aur dono curves merge ho jaate hain — correction politely fade ho jaata hai.

Figure — Optimization — SGD, momentum, Adam — derivations

Step 8 — Sab kuch jodte hain: unit step (saare cases)

KYA HAI. Update assemble karo: Ab har regime check karo jo ratio hit kar sakta hai:

Regime ratio step liya
steady slope poora — confident
pure noise (mean 0) ~kuch nahi — noise ignore
dead coordinate divide bachata hai

KYU. Yahi Adam ka poora point hai: direction ko magnitude se divide karo taaki stride length ho chahe gradient kitna bhi bada ho. Confident directions clean unit step lete hain; noisy directions damp ho jaate hain; degenerate zeros se safe ho jaate hain (division by zero nahi).

PICTURE. Teen coordinates side by side, har ek ke saath raw gradient (grey) aur uska Adam step (magenta). Bade aur chhote raw gradients dono same-length magenta step produce karte hain; noisy wala almost kuch nahi produce karta.

Figure — Optimization — SGD, momentum, Adam — derivations

Ek-picture summary

Sab ek saath: ek ball ravine descend kar rahi hai. SGD zig-zag karta hai; momentum floor ke saath smooth aur speed karta hai; Adam har axis ko rescale karta hai taaki stride har jagah steady unit step ho. Boxed formula destination hai.

Figure — Optimization — SGD, momentum, Adam — derivations
Recall Feynman retelling (plain words)

Tum ek hill par blindfolded ho aur bottom chahte ho. Tum apne pair ke neeche slope feel kar sakte ho — yahi gradient hai; uske khilaf step lo (Step 2). Lekin tumhare pair kaanpte hain, toh har felt slope thoda galat hota hai — yahi SGD ka noise hai (Step 3). Staggering rokne ke liye, tum momentum banate ho: apni recent direction yaad rakho aur roll karte raho, toh honest directions add up hote hain (10× faster!) aur kaanpne wale sideways stumbles cancel ho jaate hain (Steps 4–5). Adam ek doosra trick add karta hai: har pair ke liye alag se, woh notice karta hai ki tumhare steps usually kitne bade hote hain aur use divide kar deta hai, taaki tum hamesha ek confident stride lete ho — bade-slope pair cliff se nahi kudte, tiny-slope pair phir bhi hilte hain, aur bilkul still pair rukhe rehte hain (Steps 6–8). Kyunki tumhari memory khaali se start hoti hai, pehle strides bahut timid honge, toh tum unhe scale up karte ho jab tak memory fill na ho jaaye (Step 7). Direction momentum se, stride-size magnitude se, safety se — yahi poora box hai.

Recall

Ek-line " kyun?" ::: Steady slope par aur , toh ratio hai aur step exactly hai. Ek-line "bias correction kyun?" ::: Zero-initialized EMAs factor se low padhte hain; usse divide karna step one se hi true value restore karta hai.