Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Agreeing which way the table goes
Suppose you write down how each of 3 outputs changes when each of 2 inputs is nudged. That’s 6 numbers in a table. But does each row belong to an output, or to an input? Both choices work, like driving on the left or on the right, as long as everyone agrees.
The two choices are called numerator and denominator layout. Swapping rows and columns turns one into the other. That swap is called a transpose.
| -0.300 |
| 0.500 |
| -0.800 | 1.800 |
| -1.700 | 0.600 |
| -1.100 | 1.600 |
| -0.800 | 1.800 |
| -1.700 | 0.600 |
| -1.100 | 1.600 |
A robot-learning engineer might copy one formula from a textbook that uses one convention and another formula from a paper that uses the other. Multiplied together, they give nonsense, and the robot learns nothing. Knowing both conventions, and checking shapes, prevents this.
- 1. 3 outputs, 2 inputs: how many numbers in the table?
- 2. Swapping rows and columns is called…
- 3. Do both layouts describe the same derivative?
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.The two layouts
For depending on :
| Layout | Shape of | Entry | gives |
|---|---|---|---|
| numerator (Jacobian) | |||
| denominator (gradient) |
For a scalar , the numerator layout gives a row () and the denominator layout gives a column (). In this course, is a column (the same shape as ), and Jacobians are numerator layout (A3.2-5).
Example. gives .
- 1. Numerator layout ∂y/∂x for y ∈ ℝ⁴, x ∈ ℝ² has how many rows?
- 2. Denominator layout for the same?
- 3. ∇(aᵀx) = ?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.The chain rule in each layout
For :
Numerator layout multiplies left to right. Denominator layout multiplies transposes in reverse order. Backpropagation (A3.3-5) is exactly the denominator form, read from the loss backwards.
The shape test
Before trusting a derivation, check the shapes. For with , the gradient must be a 2-vector. The rule is , which passes. A wrong guess like fails to multiply.
| Derivative of | with respect to | shape (this course) |
|---|---|---|
| scalar | vector | (like ) |
| vector | vector | (Jacobian) |
| scalar | matrix | (like ) |
- 1. ∇ of ‖Ax − b‖² w.r.t. x is…
- 2. Denominator-layout chain rule multiplies…
- 3. The gradient of a scalar w.r.t. X ∈ ℝ^(3×4) has how many entries?
Level 3: Advanced
★★★★☆ Advanced⏱ 35 minGraduate level, with full derivations and proofs.The derivative is layout-free: use differentials
The derivative itself is a linear map . Layouts are just two ways of writing its matrix. The differential method (Magnus and Neudecker, 1988) avoids the choice entirely:
- Compute the differential with ordinary rules: , , .
- Rearrange into .
- Then , with the same shape as .
Example. For : , so .
Example. For : , so .
Why the reversal in denominator layout
Transposing the numerator chain rule gives , because . ∎
Exercise 3.1: Use differentials to find ∂f/∂W for f = ½‖WX − Y‖_F²
Let . Then . So , which has the same shape as .
- 1. ∂tr(AX)/∂X = ?
- 2. Is the derivative (as a linear map) layout-dependent?
- 3. The reversal in denominator layout comes from…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Conventions in real software
- Autodiff frameworks.
torch.autograd.functional.jacobianandjax.jacrev/jacfwdreturn arrays of shape(output shape…, input shape…), which is numerator layout. But.grad/jax.gradof a scalar loss has the same shape as the parameter, the denominator-like convention used throughout this course. - References differ. The Matrix Cookbook (Petersen and Pedersen, 2012) mostly uses numerator layout. Many ML papers use denominator layout. Always check a source’s convention before combining formulas.
- Shape bugs are a leading cause of silent errors in research code. They can broadcast without crashing. Assertions on shapes,
einops-style named dimensions, and gradient checks (A3.1-2) catch them.
References
- J. Magnus, H. Neudecker (1988; 3rd ed. 2019). Matrix Differential Calculus with Applications in Statistics and Econometrics. Wiley.
- K. B. Petersen, M. S. Pedersen (2012). The Matrix Cookbook. Technical University of Denmark.
- T. Minka (2000). “Old and new matrix algebra useful for statistics.” MIT Media Lab note.
- A. G. Baydin, B. Pearlmutter, A. Radul, J. Siskind (2018). “Automatic differentiation in machine learning: a survey.” JMLR, 18.
- J. Bradbury et al. (2018). JAX: composable transformations of Python+NumPy programs. (Documentation of jacfwd/jacrev conventions.)