Jacobians and Hessians
Quick answer
A Jacobian is a matrix of first partial derivatives for a vector-valued function. A Hessian is a matrix of second partial derivatives of a scalar-valued function. These matrices help explain how multiple outputs respond to inputs and how a loss curves. We use output rows and input columns for Jacobians, and a fixed parameter ordering for Hessians.
Jacobian of a two-output function
For F(a,b)=[a²+b, a−2b], J[i,j]=∂Fᵢ/∂xⱼ with x=[a,b]. The first row is [2a,1] and the second is [1,−2]. For a small change δx, Jδx approximates δF near the evaluation point.
def jacobian(a,b): return [[2*a,1],[1,-2]]J=jacobian(3,4)delta=[0.01,0.02]print(J)print([round(sum(x*y for x,y in zip(row,delta)),4) for row in J])Expected output:
[[6, 1], [1, -2]][0.08, -0.03]The true first output changes by 0.0801 because the quadratic contributes 0.0001 beyond the linear approximation. The second output is linear and matches exactly in real arithmetic.
Hessian of a scalar loss
For L(a,b)=a²+ab+2b², the gradient is [2a+b,a+4b]. Differentiate these two entries again: H=[[2,1],[1,4]]. Continuous second partial derivatives guarantee symmetry. The quadratic form dᵀHd measures curvature along direction d; for this loss it is positive for all nonzero d.
H=[[2,1],[1,4]]for d in [[1,0],[0,1],[1,-1]]: Hd=[sum(x*y for x,y in zip(row,d)) for row in H] print(sum(x*y for x,y in zip(d,Hd)))Expected output:
244Along the first and second unit axes, curvatures are 2 and 4. The third direction is not unit length; its normalized curvature is 4/2=2. Positive definiteness at a stationary point is sufficient for a strict local minimum under the usual twice continuously differentiable assumptions, not a universal global guarantee.
Common mistakes
Do not interchange a Jacobian and Hessian: one differentiates outputs once, the other differentiates a scalar loss twice. A vector-to-vector map may have a rectangular Jacobian. Never assume a Hessian is positive semidefinite for every loss. Computing a dense Hessian scales quadratically in the number of parameters just to store it.
Practice and next steps
Find the Jacobian of F(a,b)=[ab,a+b] at (2,3). Then differentiate L=a²−b² twice and explain why the curvature signs differ. Next, compare derivatives with numerical approximations.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Jacobians and Hessians — knowledge check
Apply calculus and differentiation to small original examples.
A function has 3 outputs and 2 inputs. What is its Jacobian shape here?
What is the Hessian of L=a²+3b²?
Which matrix contains second derivatives of a scalar loss?
What can Jδx approximate for small δx?
For L=a²−b², what does its Hessian indicate?