1.2.14 · HinglishCalculus & Optimization Basics

Chain rule for multivariate functions (backprop foundation)

2,838 words13 min readRead in English

1.2.14 · AI-ML › Calculus & Optimization Basics

What Is the Multivariate Chain Rule?

WHY does this work? Kyunki jab ek tiny amount se change hota hai:

  1. Isse mein ka change aata hai
  2. mein yeh change mein ka change laata hai
  3. Saath hi, ko bhi affect karta hai, jo doosre path se ko affect karta hai
  4. mein total change dono pathway contributions ka sum hota hai

Derivation from First Principles

Chalo ise limits aur differentials ki ground truth se build karte hain.

Step 1: Single-variable chain rule se shuru karo aur ke liye, hum jaante hain:

WHY? Kyunki aur , isliye:

se divide karke aur limit lete hue chain rule milta hai.

Step 2: Multiple intermediate variables tak generalize karo Ab maano jahan dono aur par depend karte hain.

Partial derivatives ki definition se:

Yeh ka total differential hai. Iska matlab hai: " mein ek tiny change ke through aur ke through contributions se aata hai."

Step 3: aur ko ke terms mein express karo

Step 4: Substitute karo aur terms collect karo

ke coefficients collect karte hue:

Definition ke anusaar, ka coefficient hai:

WHAT does this mean? Sum mein har term ek "pathway" hai input se intermediate ke through output tak. Hum har path ke along multiply karte hain aur sabhi paths ko sum karte hain.

Figure — Chain rule for multivariate functions (backprop foundation)

Worked Examples

Connection to Backpropagation

Neural networks mein, ek computational graph hota hai jahan:

  • Nodes = intermediate values (activations, weighted sums)
  • Edges = operations (matrix multiply, activation functions)
  • Goal = har parameter ke liye compute karna

Backprop algorithm IS the chain rule:

  1. Forward pass: Sabhi intermediates store karte hue se compute karo
  2. Backward pass: Graph ke through gradients backward propagate karke compute karo

Har node par, agar par depend karta hai:

Ise local gradient () times upstream gradient () kaha jaata hai.

WHY is this efficient? Har independently compute karne ki jagah (expensive), hum ek backward pass compute karte hain jo humein SABHI parameter gradients deta hai. Yeh reverse-mode automatic differentiation hai.

Recall Ek 12-Saal-Ke Bachche Ko Samjhao

Socho tum smoothie bana rahe ho. Tum daali strawberries aur kele, blend kiya, milk dala, phir blend kiya, phir shahad dala. Final taste har ingredient par depend karta hai.

Ab tumhara dost kehta hai "yeh bahut meetha hai!" Tum figure out karna chahte ho: mujhe shahad kitna kam karna chahiye? Lekin ruko—meethas bhi is baat par depend karti hai ki kele kitne pakke the. Aur kele thickness ko affect karte hain, jo affect karta hai ki tum shahad kitna taste karte ho.

Chain rule "taste detective" bonne jaisa hai. Tum backward kaam karte ho:

  1. "Meethas 70% shahad se hai, 30% kele se"
  2. "Kele ki ripeness sweetness ko affect karti hai is through ki unme kitna sugar hai"
  3. "Toh meethas 10% kam karne ke liye, mujhe shahad 7% kam karna hai aur kam pakke kele use karne hain" Math mein, jab ek cheez doosri ko affect kare, jo teesri ko affect kare, hum chain ke along "effect sizes" multiply karte hain. Agar multiple chains hain (jaise shahad→meethas aur kele→meethas), hum unhe saara add kar lete hain. Yahi chain rule hai!

Why This Matters for AI/ML

  1. Backpropagation sirf repeated chain rule application hai. Har neural network training isi par rely karti hai.

  2. Computational graphs ise visual banate hain. Modern frameworks (PyTorch, TensorFlow) ek graph build karte hain aur automatically chain rule apply karte hain.

  3. Efficiency: Chain rule ke bina, gradients compute karne ke liye parameters ke liye forward passes chahiye honge. Iske saath, ek backward pass sabhi gradients deta hai.

  4. Vanishing/exploding gradients tab hote hain jab chain rule products kai layers mein bahut chhote/bade ho jaate hain: Agar har , toh product exponentially shrink karta hai (vanishing). Agar , toh explode karta hai.

Connections

  • Gradient Descent - In gradients ko parameters update karne ke liye use karta hai
  • Backpropagation Algorithm - Neural nets mein chain rule ki practical implementation
  • Computational Graphs - Visual representation jo automatic differentiation enable karti hai
  • Automatic Differentiation - Software jo chain rule automatically compute karta hai
  • Jacobian and Hessian Matrices - Multivariate derivatives ke matrix forms
  • Vanishing and Exploding Gradients - Long chains se aane wale problems
  • Activation Functions - Har ek ka ek derivative hota hai jo chain mein use hota hai
  • Loss Functions - Backprop ke liye starting point ()

#flashcards/ai-ml

ke liye jahan aur ho, ka multivariate chain rule formula kya hai? :: . se tak sabhi paths par sum karo, har path ke along derivatives multiply karte hue.

Multivariate chain rule mein hum terms KYU SUM karte hain? :: Kyunki input variable (e.g., ) output ko MULTIPLE intermediate variables ke through affect kar sakta hai (multiple paths). Har path independently total change mein contribute karta hai, isliye hum unhe add karte hain.

Backpropagation mein kisi node par "local gradient" kya hota hai?
Us node ke operation ka apne immediate inputs ke saath derivative: . Upstream gradient ke saath combine karke, yeh deta hai.

aur mein kya difference hai? :: partial derivative hai jo doosre variables ko constant rakhta hai. total derivative hai jo un sabhi tareekon ko account karta hai jisse ko affect karta hai, including doosre variables ke through indirect paths.

Backpropagation ko "reverse mode" automatic differentiation KYU kaha jaata hai?
Kyunki yeh computational graph ko REVERSE order mein (output se input) traverse karta hai, chain rule ko backward apply karke gradients compute karta hai. Yeh ek pass mein sabhi parameter gradients deta hai.
Agar , , ho, toh kya hai?
.
Deep networks mein vanishing gradients kis cheez se hote hain?
Chain rule mein multiplication ki long chains se. Agar har layer ka gradient ho, toh kai layers mein ka product exponentially shrink karta hai.
Chain rule mein pehle kaun sa derivative aata hai: input ke kareeb wala ya output ke kareeb wala?
OUTPUT ke kareeb wala. Hum backward kaam karte hain: . "Outside-in" order.

Concept Map

affects

affects

contributes

contributes

generalizes to

derives

dz/dx = sum of paths

each path is

foundation of

traces error backward

error signal

Input x

Intermediate u

Intermediate v

Output z

Single-var chain rule

Multivariate chain rule

Total differential dz

Sum over paths

Product of derivatives

Backpropagation

Neural network neurons