CALCULUS / 4. PARTIAL DERIVATIVES & GRADIENTS
Partial Derivatives & Gradients
Derivatives for multivariable functions — the direction of steepest ascent
EXPLANATION
Most ML functions take many inputs (all the weights of a network). Partial derivatives extend the concept of derivatives to multivariable functions. Partial derivative ∂f/∂xᵢ: derivative of f with respect to xᵢ while treating all other variables as constants. The gradient ∇f is a vector of all partial derivatives: ∇f(x₁,...,xₙ) = [∂f/∂x₁, ∂f/∂x₂, ..., ∂f/∂xₙ]ᵀ The gradient points in the direction of steepest ascent. Negative gradient points toward steepest descent — that's gradient descent! Gradient descent update rule: θ = θ - lr · ∇_θ L(θ) For a neural network with millions of parameters, the gradient is a vector with millions of entries — one per parameter. PyTorch computes all of these with a single call to loss.backward() using the chain rule recursively. From Raschka's notation: ∂f/∂x means "differentiate f with respect to x, hold everything else constant." The symbol ∂ (curly d) distinguishes partial from ordinary derivatives.
DIAGRAM
f(x,y) = x²y + y (from Raschka's example) Partial w.r.t. x (treat y as constant): ∂f/∂x = 2xy Partial w.r.t. y (treat x as constant): ∂f/∂y = x² + 1 Gradient: ∇f(x,y) = [2xy, x²+1]ᵀ At point (2,3): ∂f/∂x = 2(2)(3) = 12 ∂f/∂y = 4 + 1 = 5 ∇f(2,3) = [12, 5] ← direction of steepest ascent Gradient descent at (2,3), lr=0.1: x_new = 2 - 0.1 * 12 = 0.8 y_new = 3 - 0.1 * 5 = 2.5
CODE