Calculus & Optimization Basics
Level 3 — Production (from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60
Show all working. Where "explain out loud" is requested, write the reasoning as if narrating to a peer. Code may be written in plain Python/NumPy pseudocode from memory.
Question 1 — Gradient, Hessian, and critical-point classification (12 marks)
Consider .
- Derive the gradient from first principles of the partial-derivative rules. (2)
- Find all critical points. (3)
- Derive the Hessian . (2)
- Classify each critical point (min / max / saddle) using the Hessian, and explain out loud the test you use and why the sign of the determinant and leading minor matter. (5)
Question 2 — Taylor approximation from scratch (10 marks)
Let .
- Derive the second-order Taylor expansion of about , showing the derivative computations. (4)
- Use it to approximate and give the absolute error vs the true value. (3)
- Write the general multivariate second-order Taylor formula for about and state what each term (gradient, Hessian) contributes. (3)
Question 3 — Gradient descent: derive and code (12 marks)
For :
- State the gradient descent update rule and derive the closed-form recurrence for in terms of and learning rate . (3)
- Show algebraically the condition on for convergence to , and explain what happens for too large. (4)
- Write from memory a NumPy function
gradient_descent(w0, eta, steps)that returns the final . (5)
Question 4 — Lagrange multipliers derivation (10 marks)
Minimize subject to .
- Set up the Lagrangian and derive the stationarity conditions. (4)
- Solve for . (4)
- Explain out loud the geometric meaning of and why at the optimum. (2)
Question 5 — Chain rule for backprop (10 marks)
A tiny network computes: , where , and loss .
- Derive and using the multivariate chain rule, listing each intermediate derivative. (6)
- Given , compute the numeric value of . (4)
Question 6 — Convexity & directional derivative (6 marks)
- Prove is convex using the second-derivative test, and state why convexity guarantees any local minimum is global. (3)
- For at point , compute the directional derivative in the direction (unit-normalize first). (3)
Answer keyMark scheme & solutions
Question 1 (12)
1. Gradient (2) (1 mark each partial.)
2. Critical points (3) Set both to zero: and . Substitute into : or .
- : point .
- : point . (1 for equations, 1 each point.)
3. Hessian (2)
4. Classification (5) Det .
- At : saddle point. (2)
- At : , and leading minor local minimum. (2)
Explain out loud (1): The second-derivative test uses the Hessian as a local quadratic model. A negative determinant means the two curvature eigenvalues have opposite signs → surface curves up in one direction and down in another → saddle. A positive determinant with positive means both eigenvalues positive → bowl → local min. The leading minor sign disambiguates min vs max when det>0.
Question 2 (10)
1. Taylor derivation (4) ; , ; , .
2. Approximate (3) : . True ; absolute error . (2 for approx, 1 for error.)
3. Multivariate formula (3) Gradient term = linear (first-order slope); Hessian term = quadratic curvature correction.
Question 3 (12)
1. Update rule & recurrence (3) . Update: .
2. Convergence condition (4) Error . Subtract 4: , so . Converges iff . (3) For : → error grows, diverges (oscillating with increasing amplitude). At it oscillates without decaying. (1)
3. Code (5)
import numpy as np
def gradient_descent(w0, eta, steps):
w = w0
for _ in range(steps):
grad = w - 4 # f'(w)
w = w - eta * grad
return w(2 loop, 1 correct gradient, 1 update, 1 return.)
Question 4 (10)
1. Lagrangian (4) . Stationarity:
2. Solve (4) From first two: , . Constraint: . So . Minimum value .
3. Explain (2) is the sensitivity of the optimal objective to relaxing the constraint (shadow price): . At the optimum along the constraint, moving without violating cannot decrease , which requires have no component tangent to the constraint curve — i.e. is parallel to , giving .
Question 5 (10)
1. Chain rule (6) Intermediates:
- ,
(2 per intermediate group + assembly.)
2. Numeric (4) ; . . . .
Question 6 (6)
1. Convexity (3) for all → convex. For a convex function the epigraph is a convex set and any local minimum satisfies everywhere, so the local minimum is global (no other lower valley can exist).
2. Directional derivative (3) at . Unit vector: , . .
[
{"claim":"Q1 Hessian det at (1,1) is 27 -> local min", "code":"x,y=1,1; det=36*x*y-9; result=(det==27 and 6*x>0)"},
{"claim":"Q2 Taylor approx of ln(1.2) = 0.18", "code":"x=Rational(2,10); approx=x-x**2/2; result=(approx==Rational(18,100))"},
{"claim":"Q4 Lagrange solution x=1,y=2,lambda=2 satisfies constraint and stationarity", "code":"x,y,lam=1,2,2; result=(2*x-lam==0 and 2*y-2*lam==0 and x+2*y-5==0)"},
{"claim":"Q5 dL/dw approx -0.08872", "code":"z=Rational(1,2); a=1/(1+exp(-z)); dLdw=(a-1)*a*(1-a)*1; result=(abs(float(dLdw)-(-0.088722))<1e-4)"},
{"claim":"Q6 directional derivative equals 6.0", "code":"gx,gy=2,6; ux,uy=Rational(6,10),Rational(8,10); D=gx*ux+gy*uy; result=(D==6)"}
]