Unit 1 of 6 · about 3 hours · derive
Limits, partial and directional derivatives, and gradients
Every later gradient is a stack of directional derivatives. If you cannot compute one by hand and check it numerically, no backward pass output will mean anything to you.
You'll be able to
- Compute partial and directional derivatives from the limit definition and evaluate them at a point by hand.
- Explain the gradient as the steepest-ascent direction and relate every directional derivative to it through .
- Convert between row-vector (MML) and column-vector (18.S096) gradient conventions without dropping a transpose.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Univariate derivatives, partials and gradientsMathematics for Machine Learning - Ch. 5
Section 5.1, Differentiation of Univariate Functions (pp. 141-145): difference quotient (5.3), derivative as a limit (5.4), polynomial derivation (5.5)-(5.6), product, quotient, sum and chain rules (5.29)-(5.32). Section 5.2, Partial Differentiation and Gradients (pp. 146-149): partial derivatives, gradient as a row vector, the chain rule as matrix multiplication (5.48)-(5.53)
- Derivatives as linear operatorsMIT 18.S096 - Matrix Calculus for ML
Lecture 1, Part 2 notes (course notes Chapter 2, Sections 2.1-2.3): as a linear operator, scalar-valued case with the gradient as the transpose of the derivative
- Gradient geometry and directional derivativesMIT 18.02SC - Multivariable Calculus Unit 2
Sessions 35 to 38 (Part B): gradient definition and perpendicularity to level curves, the proof, a worked example, directional derivatives
Refresher only. Open only if partial derivatives or gradients are weak; it does not replace the MML derivations.
Focus on
- The derivative is the limit of the difference quotient; each partial derivative holds all other variables constant.
- For unit , , and the maximum over is at by Cauchy-Schwarz.
- MML writes gradients as row vectors and 18.S096 as column vectors; the two differ by a transpose and the chain rule changes shape with the choice.
- Existing partials do not imply differentiability; continuous partials do.
Common mistakes · 3
- Reading as a partial derivative. A partial fixes an axis; a directional derivative moves along and needs the full gradient dot product.
- Assuming equal partials imply a smooth function. With off the origin and , both partials at the origin are 0, yet equals 1/2 along , so is discontinuous and not differentiable there.
- Mixing gradient conventions across sources and silently dropping a transpose, which flips every later matrix shape.
Try it yourself
Closed-book, before checking anything
float64 NumPy centered differences at : both components agree within 3e-10 absolute (measured 1.0e-11 and 2.2e-10).Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.State the difference quotient and the assumption that turns it into the derivative.Answer
. The two-sided limit as must exist. Uses: is defined near for the quotient, and differentiability at for the limit.
2.For , give at (1, 2) and for .Answer
Partial derivatives are and , so and = 17.67766953.
3.Give a function with both partials zero at the origin that is not differentiable there, and the curve that exposes it.Answer
with . Both partials at the origin are 0, but along the value is constantly 1/2, so is discontinuous and hence not differentiable at the origin.
4.MML gives a gradient where 18.S096 gives for the same . Which is right?Answer
Both, by stated convention. MML uses numerator layout (row); 18.S096 uses column gradients with . Convert with a transpose and never mix the two inside one derivation.
Practice
- MML Chapter 5, Exercise 5.5 (partial derivatives and Jacobians)
Exercises (pp. 170-171), Exercise 5.5: dimensions of each partial derivative in part (a), then the Jacobians in part (b)
Do part (a) before part (b); the predicted dimensions fix the Jacobian shapes.
- TrenTorch: Directional derivatives
Implement
directional_derivative(f, x, direction)as a centered difference along the normalized direction, andsteepest_ascent_direction(f, x)as the unit gradientThen run both on the Reproduce cubic at (1, 2): the derivative along (1, 1) must land within 1e-9 of 17.67766953, and the steepest-ascent value must equal = 17.69180601.
You're done when
You compute and any for a new quadratic or cubic by hand, and a float64 centered-difference check at agrees to 1e-9 absolute.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 3 more in the section
- MIT 18.S096 - Matrix Calculus for MLMIT OpenCourseWare · primary
Use lectures 1-5, the Hessian portion of lecture 7 and computational-graph portion of lecture 8; do the supplied problems and notebooks.
- Mathematics for Machine Learning - Ch. 5Deisenroth, Faisal & Ong · reference
Use Chapter 5 as the compact derivative, Jacobian, chain-rule and backpropagation reference.
- MIT 18.02SC - Multivariable Calculus Unit 2MIT OpenCourseWare · optional
Use sessions 24-38 only if partial derivatives, gradients, Hessians or the multivariable chain rule are weak.
Also in this section
- Hands-On ML - Autodiff notebookAurelien Geron · required
Work through numerical differentiation and both AD modes, then rebuild the essential reverse-mode engine independently.
- PyTorch Autograd mechanicsPyTorch documentation · required
Consult after the handwritten engine for accumulation, graph behavior, disabled tracking and vector-Jacobian products.
- CS231n - Linear ClassificationStanford University · support
Read the Softmax classifier section for the cross-entropy loss formula with both the information-theory and MLE views, and Practical issues: Numeric stability for the max-subtraction trick. Derive the softmax gradient by hand; do not implement the course assignment here.