Level 4 — ApplicationCalculus & Optimization Basics

Calculus & Optimization Basics

60 minutes60 marksprintable — key stays hidden on paper

Level: 4 (Application — novel problems, no hints) Time limit: 60 minutes Total marks: 60


Question 1 — Gradients, Hessians, and critical points (14 marks)

Consider the function f(x,y)=x33xy2+y4.f(x,y) = x^3 - 3xy^2 + y^4.

(a) Compute f(x,y)\nabla f(x,y). (3 marks)

(b) Find all critical points of ff. (4 marks)

(c) Compute the Hessian H(x,y)H(x,y) and classify the critical point at the origin. (4 marks)

(d) A model uses gradient descent with learning rate η\eta starting at (1,0)(1,0). Write the coordinates after one update step in terms of η\eta. (3 marks)


Question 2 — Directional derivative and steepest ascent (10 marks)

Let g(x,y)=exsin(y)g(x,y) = e^{x}\sin(y) evaluated near the point P=(0,π2)P=(0,\tfrac{\pi}{2}).

(a) Compute the directional derivative of gg at PP in the direction of the vector v=(3,4)\mathbf{v} = (3,4). (5 marks)

(b) State the unit vector along which gg increases most rapidly at PP, and give the maximum rate of increase. (5 marks)


Question 3 — Constrained optimization via Lagrange multipliers (14 marks)

A neural network's regularization forces the weight vector (x,y)(x,y) onto the constraint x2+2y2=6x^2 + 2y^2 = 6. We wish to optimize the objective f(x,y)=xy.f(x,y) = xy.

(a) Set up the Lagrangian and derive the stationarity equations. (4 marks)

(b) Solve for all candidate points (x,y)(x,y) satisfying the conditions. (6 marks)

(c) Identify which candidates give the maximum and minimum of ff on the constraint, and state those extreme values. (4 marks)


Question 4 — Taylor approximation & convexity (12 marks)

Let h(x)=ln(1+ex)h(x) = \ln(1 + e^{x}) (the softplus function).

(a) Compute h(x)h'(x) and h(x)h''(x). (4 marks)

(b) Using a second-order Taylor expansion about x=0x=0, write the quadratic approximation h~(x)\tilde h(x). (4 marks)

(c) Prove that hh is convex on all of R\mathbb{R}. (4 marks)


Question 5 — Chain rule / backprop and learning-rate reasoning (10 marks)

A tiny network computes, for scalar input xx: u=wx+b,a=tanh(u),L=12(at)2,u = wx + b,\qquad a = \tanh(u),\qquad L = \tfrac{1}{2}(a - t)^2, where tt is a fixed target and w,bw,b are parameters.

(a) Using the multivariate chain rule, derive Lw\dfrac{\partial L}{\partial w} and Lb\dfrac{\partial L}{\partial b}. (6 marks)

(b) Explain in 2–3 sentences what happens to gradient-descent convergence if the learning rate η\eta is (i) far too large, (ii) far too small. (4 marks)


End of paper.

Answer keyMark scheme & solutions

Question 1 (14 marks)

(a) Partial derivatives (3): f=(3x23y2, 6xy+4y3).\nabla f = \big(3x^2 - 3y^2,\ -6xy + 4y^3\big).

  • fx=3x23y2f_x = 3x^2-3y^2 (1.5), fy=6xy+4y3f_y = -6xy+4y^3 (1.5).

(b) Critical points: set both to zero (4). From fx=0f_x=0: x2=y2x=±yx^2=y^2 \Rightarrow x=\pm y. From fy=0f_y=0: 6xy+4y3=02y(3x+2y2)=0-6xy+4y^3=0 \Rightarrow 2y(-3x+2y^2)=0, so y=0y=0 or 2y2=3x2y^2=3x.

  • If y=0y=0: then x2=0x=0x^2=0 \Rightarrow x=0. Point (0,0)(0,0). (1)
  • If y0y\neq0, x=±yx=\pm y and 2y2=3x2y^2=3x:
    • x=yx=y: 2x2=3xx=3/22x^2=3x \Rightarrow x=3/2, so (3/2,3/2)(3/2,3/2). (1.5)
    • x=yx=-y: 2y2=3x=3y2y2+3y=0y=3/22y^2=3x=-3y \Rightarrow 2y^2+3y=0\Rightarrow y=-3/2 (y≠0), x=3/2x=3/2, so (3/2,3/2)(3/2,-3/2). (1.5)

Critical points: (0,0), (3/2,3/2), (3/2,3/2)(0,0),\ (3/2,3/2),\ (3/2,-3/2).

(c) Hessian (4): H=(6x6y6y6x+12y2).H=\begin{pmatrix} 6x & -6y \\ -6y & -6x+12y^2\end{pmatrix}. (2 for correct entries.) At origin H=(0000)H=\begin{pmatrix}0&0\\0&0\end{pmatrix} — the Hessian is the zero matrix, so the second-derivative test is inconclusive (2). (Higher-order analysis needed; origin is a degenerate critical point.)

(d) GD update: (x,y)(x,y)ηf(x,y) \leftarrow (x,y) - \eta\nabla f (3). At (1,0)(1,0): f=(310, 0)=(3,0)\nabla f = (3\cdot1 - 0,\ 0) = (3,0). New point =(13η, 0)= (1 - 3\eta,\ 0).


Question 2 (10 marks)

(a) (5) gx=exsinyg_x = e^x\sin y, gy=excosyg_y=e^x\cos y. At P=(0,π/2)P=(0,\pi/2): gx=11=1g_x=1\cdot1=1, gy=10=0g_y=1\cdot0=0, so g=(1,0)\nabla g=(1,0) (2). Unit vector of (3,4)(3,4): magnitude 55, v^=(3/5,4/5)\hat v=(3/5,4/5) (1.5). Dv^g=gv^=135+0=35=0.6D_{\hat v}g = \nabla g\cdot\hat v = 1\cdot\tfrac35 + 0 = \tfrac35 = 0.6 (1.5).

(b) (5) Steepest ascent is along g/g=(1,0)\nabla g/\|\nabla g\| = (1,0) (unit vector) (2.5). Maximum rate =g=12+02=1=\|\nabla g\| = \sqrt{1^2+0^2}=1 (2.5).


Question 3 (14 marks)

(a) (4) Lagrangian: L=xyλ(x2+2y26).\mathcal L = xy - \lambda(x^2+2y^2-6). Stationarity:

  • x:y2λx=0\partial_x: y - 2\lambda x = 0 (1.5)
  • y:x4λy=0\partial_y: x - 4\lambda y = 0 (1.5)
  • constraint: x2+2y2=6x^2+2y^2=6 (1)

(b) (6) From eqs: y=2λxy=2\lambda x, x=4λy=8λ2xx=4\lambda y = 8\lambda^2 x. If x0x\neq0: 1=8λ2λ=±1221=8\lambda^2 \Rightarrow \lambda=\pm\tfrac{1}{2\sqrt2} (2). Then y=2λx=±x2y=2\lambda x=\pm\tfrac{x}{\sqrt2}, i.e. y2=x2/2y^2 = x^2/2 (1). Constraint: x2+2(x2/2)=62x2=6x2=3x=±3x^2+2(x^2/2)=6 \Rightarrow 2x^2=6\Rightarrow x^2=3\Rightarrow x=\pm\sqrt3 (1.5). Then y=±3/2=±1.5y=\pm\sqrt{3/2}=\pm\sqrt{1.5}. Four candidate points: (3,1.5), (3,1.5), (3,1.5), (3,1.5).(\sqrt3,\sqrt{1.5}),\ (\sqrt3,-\sqrt{1.5}),\ (-\sqrt3,\sqrt{1.5}),\ (-\sqrt3,-\sqrt{1.5}). (1.5) (If x=0x=0 then y=0y=0, which violates constraint — rejected.)

(c) (4) f=xy=±31.5=±4.5=±32±2.121f=xy=\pm\sqrt3\cdot\sqrt{1.5}=\pm\sqrt{4.5}=\pm\tfrac{3}{\sqrt2}\approx\pm2.121.

  • Maximum f=32f=\tfrac{3}{\sqrt2} at (3,1.5)(\sqrt3,\sqrt{1.5}) and (3,1.5)(-\sqrt3,-\sqrt{1.5}) (same-sign product). (2)
  • Minimum f=32f=-\tfrac{3}{\sqrt2} at the opposite-sign pairs. (2)

Question 4 (12 marks)

(a) (4) h(x)=ln(1+ex)h(x)=\ln(1+e^x). h(x)=ex1+ex=σ(x)h'(x)=\dfrac{e^x}{1+e^x}=\sigma(x) (sigmoid) (2). h(x)=ex(1+ex)exex(1+ex)2=ex(1+ex)2=σ(x)(1σ(x))h''(x)=\dfrac{e^x(1+e^x)-e^x\cdot e^x}{(1+e^x)^2}=\dfrac{e^x}{(1+e^x)^2}=\sigma(x)(1-\sigma(x)) (2).

(b) (4) At x=0x=0: h(0)=ln2h(0)=\ln 2; h(0)=12h'(0)=\tfrac12; h(0)=1212=14h''(0)=\tfrac12\cdot\tfrac12=\tfrac14. h~(x)=ln2+12x+1214x2=ln2+x2+x28.\tilde h(x)=\ln2 + \tfrac12 x + \tfrac12\cdot\tfrac14 x^2 = \ln 2 + \tfrac{x}{2} + \tfrac{x^2}{8}. (1 each for the three coefficients; 1 for correct 12\frac12 factor on quadratic term.)

(c) (4) h(x)=ex(1+ex)2h''(x)=\dfrac{e^x}{(1+e^x)^2}. For all real xx, ex>0e^x>0 and (1+ex)2>0(1+e^x)^2>0, so h(x)>0h''(x)>0 everywhere (3). A twice-differentiable function with strictly positive second derivative is (strictly) convex on R\mathbb{R} (1).


Question 5 (10 marks)

(a) (6) Chain rule. La=(at)\dfrac{\partial L}{\partial a}=(a-t); dadu=1tanh2(u)=1a2\dfrac{da}{du}=1-\tanh^2(u)=1-a^2; uw=x\dfrac{\partial u}{\partial w}=x, ub=1\dfrac{\partial u}{\partial b}=1.

Lw=(at)(1a2)x,Lb=(at)(1a2).\frac{\partial L}{\partial w}=(a-t)(1-a^2)\,x,\qquad \frac{\partial L}{\partial b}=(a-t)(1-a^2).

  • L/a\partial L/\partial a (1), da/duda/du (1.5), assembling L/w\partial L/\partial w with the xx factor (2), L/b\partial L/\partial b (1.5).

(b) (4) (i) Too large: updates overshoot the minimum, loss oscillates or diverges (weights blow up) — no convergence (2). (ii) Too small: steps are tiny, convergence is very slow and may stall / need many iterations; can get stuck near flat regions (2).


[
  {"claim":"Gradient of f at (1,0) is (3,0)","code":"x,y=symbols('x y'); f=x**3-3*x*y**2+y**4; g=[diff(f,x),diff(f,y)]; result = [gg.subs({x:1,y:0}) for gg in g]==[3,0]"},
  {"claim":"(3/2,3/2) is a critical point of f","code":"x,y=symbols('x y'); f=x**3-3*x*y**2+y**4; result = (diff(f,x).subs({x:Rational(3,2),y:Rational(3,2)})==0) and (diff(f,y).subs({x:Rational(3,2),y:Rational(3,2)})==0)"},
  {"claim":"Directional derivative of e^x sin y at (0,pi/2) along (3,4) equals 3/5","code":"x,y=symbols('x y'); g=exp(x)*sin(y); gx=diff(g,x).subs({x:0,y:pi/2}); gy=diff(g,y).subs({x:0,y:pi/2}); dv=gx*Rational(3,5)+gy*Rational(4,5); result = simplify(dv-Rational(3,5))==0"},
  {"claim":"Max of xy on x^2+2y^2=6 is 3/sqrt(2)","code":"val = sqrt(3)*sqrt(Rational(3,2)); result = simplify(val - 3/sqrt(2))==0"},
  {"claim":"softplus second-order Taylor coeffs are ln2, 1/2, 1/8","code":"x=symbols('x'); h=log(1+exp(x)); s=series(h,x,0,3).removeO(); result = (s.coeff(x,0)==log(2)) and (s.coeff(x,1)==Rational(1,2)) and (s.coeff(x,2)==Rational(1,8))"},
  {"claim":"softplus second derivative positive at x=0","code":"x=symbols('x'); h=log(1+exp(x)); result = diff(h,x,2).subs(x,0) > 0"}
]