LearnQuestion bank

Define a convex function. Why does convexity matter for optimisation? Compare gradient descent with Newton’s method, including cost and when Newton fails.

ML engineeringTechnicalMedium

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Convex: f(theta x + (1-theta)y) <= theta f(x) + (1-theta)f(y); twice differentiable iff Hessian PSD; every local minimum is global.
  • Matters because it removes spurious local minima and gives global optimality certificates and convergence guarantees.
  • Gradient descent: first-order, cheap per step, step size limited by smoothness, rate degrades with conditioning.
  • Newton: uses Hessian, quadratic local convergence, O(d^3) factorisation per step, fails with indefinite/singular Hessian, saddles, or far from optimum.
  • Quasi-Newton/L-BFGS approximates curvature cheaply; deep learning still favours first-order methods for scale, stochasticity, and memory.

In full

A convex function satisfies f(theta x + (1-theta)y) <= theta f(x) + (1-theta)f(y) for all x, y and theta in [0,1], equivalently Jensen’s inequality f(E[X]) <= E[f(X)], and for twice-differentiable functions this is equivalent to a positive semidefinite Hessian everywhere; a key consequence is that every local minimum is global. Convexity matters because it removes spurious local minima, turns stationarity into a global optimality certificate, and gives clean convergence guarantees. Gradient descent uses only the gradient, x_{k+1} = x_k - eta grad f(x_k), is cheap per iteration, needs eta at most about 1/L, where L is the smoothness (gradient Lipschitz) constant, and converges slowly when the problem is ill-conditioned, with rates that depend on the condition number. Newton’s method uses the Hessian, x_{k+1} = x_k - H^{-1} grad f(x_k), and converges quadratically near a well-conditioned optimum, but it costs about O(d^3) per step for factorisation plus O(d^2) storage and struggles with non-convexity, indefinite or singular Hessians, saddle points, and starts far from the optimum. Quasi-Newton methods such as L-BFGS approximate the inverse Hessian from gradients to get much better-than-GD behaviour without full Hessian cost, but deep learning still relies mostly on first-order methods because d is huge, gradients are stochastic and noisy, memory is limited, and the landscape is non-convex.

Corrected by an independent AI reviewer.

What a strong answer covers

  • Definition via Jensen’s inequality or a PSD Hessian; every local minimum is global.
  • GD: first order, step size, convergence rate depends on conditioning.
  • Newton: uses the Hessian, converges quadratically near the optimum, costs O(d³) per step, struggles with non-convexity and saddle points.
  • Mentions quasi-Newton methods (L-BFGS) and why deep learning uses first-order methods.

Common mistakes

  • claiming neural-net losses are convex
  • ignoring the cost of forming and inverting the Hessian.