1.2.5 · AI-ML › Calculus & Optimization Basics
Intuition Badi picture (WHY)
Ek single-input, single-output function f ( x ) ka EK derivative f ′ ( x ) hota hai — ek number jo slope batata hai. Lekin ML mein hum constantly aise functions se deal karte hain jo vector andar lete hain aur vector bahar dete hain: f : R n → R m . Ab "slope" ek number nahi hai — balki partial derivatives ki poori table hai, har ek (output, input) pair ke liye. Woh table Jacobian matrix hai. Yeh kisi bhi point ke paas ek vector-valued function ki sabse achhi linear approximation hai — f ′ ( x ) ka multi-dimensional generalization.
Definition Jacobian matrix
f : R n → R m ke liye jiske components hain
f ( x ) = f 1 ( x 1 , … , x n ) ⋮ f m ( x 1 , … , x n ) ,
Jacobian J (jo J f ya ∂ x ∂ f bhi likha jaata hai) ==m × n == matrix hai
J ij = ∂ x j ∂ f i .
Row i = output f i ka gradient. Column j = input x j ke badle mein har output ka response.
J = ∂ x 1 ∂ f 1 ⋮ ∂ x 1 ∂ f m ⋯ ⋱ ⋯ ∂ x n ∂ f 1 ⋮ ∂ x n ∂ f m
Intuition Shape mnemonic — "rows are outputs, columns are inputs"
Jacobian mein ==m rows hain (ek har output ke liye) aur n columns== hain (ek har input ke liye). Toh J ∈ R m × n . Check karo: isko ek input-direction vector Δ x ∈ R n se multiply karna hoga aur output-change Δ f ∈ R m milega. ( m × n ) ( n × 1 ) = ( m × 1 ) . ✔
Intuition Derivation idea
f ka x par derivative woh number hai jo linear approximation ko kaam karta banata hai:
f ( x + h ) ≈ f ( x ) + f ′ ( x ) h .
Hum vectors ke liye bilkul SAME cheez demand karte hain: woh linear map J dhundho jisse
f ( x + h ) ≈ f ( x ) + J h .
Jacobian ke baare mein sab kuch isi ek requirement se nikalta hai.
Step 1 — Ek output ek waqt dekho. Component f i lo. Yeh ek vector ka scalar function hai, toh iska first-order Taylor expansion hai
f i ( x + h ) ≈ f i ( x ) + j = 1 ∑ n ∂ x j ∂ f i h j .
Yeh step kyun? Yeh sirf multivariable Taylor / total-differential rule hai: har input x j ko h j se perturb karne par f i mein ∂ f i / ∂ x j rate se change aata hai, aur chhote effects add ho jaate hain.
Step 2 — Sum ko dot product samjho.
j ∑ ∂ x j ∂ f i h j = row i [ ∂ x 1 ∂ f i ⋯ ∂ x n ∂ f i ] h = ( ∇ f i ) ⊤ h .
Yeh step kyun? h j ka weighted sum exactly ek matrix row times h hota hai. Woh row f i ka gradient hai.
Step 3 — Saare m rows stack karo. Yeh har output ke liye simultaneously karte hue:
f ( x + h ) ≈ f ( x ) + J h , J = ( ∇ f 1 ) ⊤ ⋮ ( ∇ f m ) ⊤ .
Yeh step kyun? Row-approximations ko stack karna ek matrix equation ke barabar hai. Jis matrix ki rows gradients hain wahi Jacobian hai. ∎
Worked example Example 1 — ek
2 → 2 map
f ( x , y ) = [ x 2 y x + sin y ] . J nikalo aur ( 1 , 0 ) par evaluate karo.
Partials:
∂ f 1 / ∂ x = 2 x y , ∂ f 1 / ∂ y = x 2
∂ f 2 / ∂ x = 1 , ∂ f 2 / ∂ y = cos y
J ( x , y ) = [ 2 x y 1 x 2 cos y ] , J ( 1 , 0 ) = [ 0 1 1 1 ] .
Har step kyun? Har entry "output i , input j ke w.r.t. differentiate karo, baaki input ko constant maano" hai. ( 1 , 0 ) plug karne se symbolic slopes concrete numbers ban jaate hain — local linear map.
Worked example Example 2 — Jacobians se chain rule (backprop se match karta hai)
Maano z = W x (linear layer, W ∈ R m × n ) phir a = σ ( z ) elementwise.
J z = ∂ x ∂ z = W . Kyun? z i = ∑ j W ij x j , toh ∂ z i / ∂ x j = W ij .
J σ = ∂ z ∂ a = diag ( σ ′ ( z 1 ) , … , σ ′ ( z m ) ) . Kyun? a i = σ ( z i ) sirf z i par depend karta hai, toh off-diagonal partials zero ho jaate hain — ek diagonal Jacobian.
Poora map x ↦ a : J = J σ J z = diag ( σ ′ ( z )) W .
Yeh kyun matter karta hai: Jacobians ka yeh product hai hi neural net ka forward-mode differentiation.
Worked example Example 3 — polar → Cartesian & determinant
f ( r , θ ) = ( r cos θ , r sin θ ) .
J = [ cos θ sin θ − r sin θ r cos θ ] , det J = r cos 2 θ + r sin 2 θ = r .
Determinant kyun? Square Jacobian ke liye, ∣ det J ∣ local area/volume scaling factor hai — ek chhota patch f ke under kitna expand hota hai. Yahi polar integration mein r d r d θ factor hai.
Common mistake "Jacobian aur gradient same cheez hain."
Kyun sahi lagta hai: scalar function ke liye dono mein same numbers hote hain. Fix: gradient ∇ f ek column vector hai; m = 1 ke liye Jacobian iska transpose hai (ek row). Isse bhi important, "gradient" tabhi meaningful hai jab output scalar ho (m = 1 ); m > 1 ke liye koi single gradient nahi, sirf Jacobian hota hai.
n × m hai."
Kyun sahi lagta hai: log aadat se pehle inputs likhte hain. Fix: yeh m × n hai — rows = outputs, columns = inputs — kyunki isko R n → R m map karna hai: J h ke liye right mein h ∈ R n chahiye.
Common mistake "Jacobians ke liye chain rule
J f J g hai."
Kyun sahi lagta hai: scalar chain rule d x d h = d g d h d x d g order-free lagta hai. Fix: matrix multiplication commutative NAHI hai. h = g ∘ f ke liye, outer function ka Jacobian left mein lagao: J h = J g J f . Shapes sirf usi order mein fit hote hain.
det J kisi bhi Jacobian ke liye exist karta hai."
Kyun sahi lagta hai: hum har waqt determinants lete hain. Fix: determinant ke liye square matrix chahiye, yaani m = n . Non-square J ke liye (ML ke zyaadatar layers) koi determinant nahi hota.
Recall Feynman: ek 12-saal ke bacche ko explain karo
Ek aisi machine socho jo input mein kuch dials leti hai aur output mein kuch bulbs jalati hai. Agar tum ek dial ko thoda sa nudge karo, toh har bulb thoda aur bright ya dim ho jaata hai. Jacobian bas un saare "kitna bright per nudge" numbers ki table hai — har (bulb, dial) pair ke liye ek number. Agar tumhe yeh table pata hai, toh tum bina machine chalaye kisi bhi chhoti twist ka result predict kar sakte ho: apni twist ko bas table se multiply karo.
"ROC — Rows are Outputs, Columns are inputs." Aur: gradient Jacobian mein stack hota hai — har output ke gradient-rows stack karo.
f : R n → R m ke Jacobian ki shape kya hai?m × n — rows = outputs, columns = inputs.
Jacobian ki ( i , j ) entry define karo. J ij = ∂ f i / ∂ x j .
Jacobian ki row i kya hai? Output f i ke gradient ka transpose, yaani ( ∇ f i ) ⊤ .
Scalar function (m = 1 ) ke liye Jacobian aur gradient mein kya relation hai? Jacobian ek row vector hai jo ( ∇ f ) ⊤ ke barabar hai; gradient iska transpose hai (ek column).
Jacobian use karke first-order linear approximation likhо. f ( x + h ) ≈ f ( x ) + J h .
h = g ∘ f ke liye Jacobian form mein chain rule?J h = J g J f (outer left mein; order matter karta hai).
∣ det J ∣ ka kya matlab hai, aur yeh kab defined hai?Map ka local volume-scaling factor; sirf tab defined hai jab J square ho (m = n ).
z = W x ka x ke w.r.t. Jacobian?W khud.
Elementwise a = σ ( z ) ka z ke w.r.t. Jacobian? diag ( σ ′ ( z 1 ) , … , σ ′ ( z m )) .
Polar map ( r cos θ , r sin θ ) ke liye det J ? r .
Scalar derivative f prime x
Vector function f R^n to R^m
Partial derivatives dfi dxj
Column j is input xj response
Linear approximation requirement
Per-output first order expansion
Row times h equals grad fi dot h
ML backprop and optimization