5.6.7 · D4 · HinglishMachine Learning (Aerospace Applications)

ExercisesFeedforward network — forward pass

2,992 words14 min read↑ Read in English

5.6.7 · D4 · Coding › Machine Learning (Aerospace Applications) › Feedforward network — forward pass

Yeh page ek self-test ladder hai forward pass ke liye. Pehle har problem paper par karo, phir collapsible solution kholo. Yahan use kiye gaye har symbol ko parent note mein build kiya gaya tha — lekin hum essentials ko re-anchor karte hain taaki tum kabhi notation par stuck na ho.

Recall Shuru karne se pehle 3 zaroori cheezein (definitions yaad kar lo)

Neeche har problem mein yahi teen cheezein use hoti hain. Ek stack of layers imagine karo, jisme information bottom-to-top flow kar rahi hai.

  • ::: neeche wali layer ke activations (outputs) — ek column of numbers, ek number har neuron ke liye.
  • ::: pre-activation: ek weighted sum plus ek bias. Layer mein har neuron ke liye ek number.
  • ::: activation: har ko nonlinearity se element-by-element pass karo.

Figure 1 — chaar scalar activation shapes. Neeche, orange ReLU flat-then-rising hai jisme par ek sharp corner (the "kink") hai; blue sigmoid aur green tanh smooth S-curves hain jo horizontal ceilings/floors ke beech pin hain (dotted lines par); gray dashed line do-nothing identity hai. Yeh picture mind mein rakho: "squashing" ka matlab literally ek curve hai jo ke ki taraf jaane par un dotted rails ki taraf flatten ho jata hai.

Figure — Feedforward network — forward pass

Level 1 — Recognition

Worked example Solution 1.1

pichli layer ke activation (length ) ko is layer (length ) mein map karta hai. Toh iske rows aur columns hain.

  • : layer 1 mein neurons hain, layer 0 mein inputs hain shape .
  • : layer 1 mein har neuron ke liye ek bias length .

Multiplication check karo: , aur jis ki length hai use add karna kaam karta hai. ✓

Worked example Solution 1.2

ReLU positives ko unchanged pass karta hai aur har cheez ko par clamp karta hai — Figure 1 mein orange curve trace karo: kink se left flat hai, uske right ek straight ramp hai.


Level 2 — Application

Worked example Solution 2.1

Step (a) pre-activation — ek single dot product (row · column) plus bias: Step (b) activation: kyun? Weighted evidence net negative nikla, aur kink se left (Figure 1) ReLU ka output zero par flat hai. Neuron "fire nahi kiya" — iska matlab hai ki usne ek aise pattern ko detect kiya jo is input ke liye absent hai.

Worked example Solution 2.2

Sigmoid element-by-element apply hota hai: .

Yeh values kyun? par term hai, toh top aur bottom balance hote hain aur hum S-curve ke midpoint par exactly baith jaate hain, — yahi wajah hai ki sigmoid par centred hota hai. Jaise badhta hai, shrink hokar ki taraf jata hai, toh fraction ki taraf climb karta hai (par kabhi reach nahi karta); isliye high hai lekin ceiling se neeche hai. Dono outputs ke andar aate hain — woh "squashing" jo Figure 1 mein blue curve karte dikhai deta hai.

Worked example Solution 2.3

Layer 1 pre-activation ( ki har row ko se dot karo): Layer 1 activation (ReLU): dono entries positive hain, toh hum kink ke ramp side par hain aur ReLU unhe unchanged chhod deta hai: . Layer 2 pre-activation: Layer 2 activation (linear): . End mein linear kyun? Ek regression output ko koi bhi real value lene ki freedom honi chahiye; identity (Figure 1 mein gray dashed line) koi squashing apply nahi karta, toh raw score seedha prediction ke roop mein pass ho jaata hai.


Level 3 — Analysis

Worked example Solution 3.1

ko mein substitute karo: Toh aur . Matlab: linear maps stack karne se ek linear map milta hai — extra layer ne hume kuch nahi diya. Yahi wajah hai ki nonlinearity essential hai.

Worked example Solution 3.2

Layer by layer: , phir . Collapsed: ; . Phir . ✓ Same answer.

Worked example Solution 3.3

Neuron output karta hai. Yeh dead hota hai jab bhi , yaani .

  • Dead region: (output exactly ).
  • Active region: , jahan output slope se badhta hai.
  • Kink (corner) par hai, jahan .

Yeh wahi corner hai jo Figure 1 mein orange curve par dikhti hai, bas shifted: ReLU ke andar linear part kink ko se par shift kar deta hai. Woh hinge hi woh tarika hai jisse networks curved aerospace dynamics ke piecewise-linear approximations banate hain.


Level 4 — Synthesis

Worked example Solution 4.1

Step 1 — har logit ko exponentiate karo: Step 2 — sum: . Step 3 — divide karo: Pehle exponentiate kyun? Raw logits negative ho sakte hain, lekin probabilities nahi ho sakti — har score ko ek positive number mein map karta hai aur saath mein order preserve karta hai (bada logit → bada ). Sum se divide karne par total ho jaata hai ✓. Sabse bada class 0 hai, jise index→name table Nominal (probability ) padhta hai.

Worked example Solution 4.2

Layer 1 pre-activation (teen dot products): Layer 1 activation (tanh, element-wise): almost kyun hai? tanh saturate karta hai: jab zero se kuch units dur ho jaata hai tab Figure 1 mein green curve apni ceiling ke against already flatten ho chuki hoti hai, toh nearly maxed out hai, jabki aur abhi bhi sloped middle par hain aur symmetric rehte hain (). Layer 2 pre-activation: Softmax: ; sum . Coin-flip ke itna kareeb kyun? Dono logits sirf se differ karte hain; kyunki chhote gaps ke liye ek gentle multiplier hai, ek chhota sa logit lead sirf ek modest probability lead ban jaata hai. Predicted class: 1 = Degraded (probability ).


Level 5 — Mastery

Worked example Solution 5.1

Pura point yahi hai: ek matrix multiply poore batch ko handle kar leti hai. compute karo (bias har column mein broadcast hota hai). har column mein add karo: ReLU element-wise apply karo: Dono samples ke liye ek multiply kyun? Har column usi se independently process hota hai, toh inputs ko side-by-side stack karne se hardware dono passes ek single matrix product mein compute kar leta hai — exactly yahi tarika hai jisse real inference ek saath sensor frames ka poora batch run karta hai. Column 1 sample 1 ka activation hai ; column 2 sample 2 ka hai.

Worked example Solution 5.2

Claim: softmax invariant hai jab har logit mein constant add karo, kyunki top aur bottom cancel ho jaata hai. Toh hum pick kar sakte hain taaki exponents rahein (koi overflow nahi). Shifted logits: . Phir ; sum . Yeh safe aur exact kyun hai: upar wala cancellation algebraic hai, approximation nahi — probabilities literally unchanged hain, lekin har exponent ab hai toh hai aur kabhi overflow nahi kar sakta.

Worked example Solution 5.3

Step 1 — hidden pre-activations ( ki har row ko se dot karo, plus bias): Step 2 — activation (ReLU): dono hain, toh hum orange curve ke flat left side par hain (Figure 1) aur har ek zero par clamp hota hai: Step 3 — output. Jab har hidden activation zero ho, toh output pre-activation hai Weighted-sum term zero vector hai chahe mein koi bhi numbers hon, toh prediction sirf output bias ke barabar hoti hai. Yeh kyun matter karta hai ("dying ReLU" failure): zyada negative biases har neuron ko uske kink se neeche push kar dete hain; jab ek neuron saare realistic inputs ke liye output karta hai toh woh stuck ho jaata hai (uske weights output ko influence karna band kar dete hain), aur agar puri layer mar jaaye toh network ek constant par freeze ho jaata hai aur apne sensors ko bilkul ignore karta hai. Fix in practice: careful bias initialisation, input normalisation, ya leaky-ReLU jo negative side par ek small slope rakhta hai.