Maths · Module 4
Calculus and Optimisation
Take each lesson, answer its quiz, then do its practice. After the last lesson come the module quiz, the project and the interview questions.
Lessons
- 4.1Derivatives: Rate of Change and the TangentSay what a derivative measures, and read its sign and size off a graph.
- 4.2Derivative Rules and the Chain RuleDifferentiate the functions ML uses, including functions of functions.
- 4.3Maxima, Minima and Setting the Derivative to ZeroFind where a function is lowest or highest, and know when that cannot be done by solving an equation.
- 4.4Partial Derivatives and the GradientDifferentiate a function of several variables, and read the gradient as the direction of steepest increase.
- 4.5Curvature: Second Derivatives, Taylor and NewtonUse the second derivative to see how a function bends, and step straight to the bottom of a local quadratic.
- 4.6Integrals as AreaRead an integral as accumulated area, enough for densities and AUC.
- 4.7Convexity, Local Minima and Saddle PointsTell a convex function from a non-convex one, and know what a zero gradient does and does not guarantee.
- 4.8The Chain Rule Through a ComputationCompute the gradient of a loss that is built from many steps, by passing derivatives backwards through a graph of operations.
- 4.9Constrained Optimisation and Lagrange MultipliersMinimise a function subject to a constraint, and read the multiplier.
Module material
Take these after the last lesson, in this order. Next on each page leads through them.
- Module quiz15 questions across the whole module. Take it after the last lesson; your first pick on each question is the one that counts.
- PracticeStated as a problem, with no template and no step-by-step instructions. Working out the steps is the point.
- NotebooksOpen them in Google Colab. Each answer is checked as you go: correct, wrong with the expected value, or not answered yet.
- Cheat sheetOne page of the module’s terms, rules and gotchas, with the output each rule produces.
- Interview questions15 questions interviewers ask on this module’s topics, from first principles to the follow-ups. Each comes with a model answer.
Glossary
Every term the module introduces, with the lesson that introduces it.
- rate of change
Δy/Δx, the change in the output per unit change in the input |x²from 1 to 2:34.1- secant
- a line through two points of a curve | through
(1, 1)and(2, 4), slope34.1 - limit
- the value a quantity approaches as
hgoes to zero |2 + h → 24.1 - tangent
- the line that touches the curve at a point with the curve's slope there |
y = 2x − 1atx = 14.1 - derivative
- the slope of the tangent, the limit of
Δy/Δx|2forx²at 1 4.1 f′(x)- the derivative of
f, a function ofx|x² → 2x4.1 dy/dx- the same derivative, written as a ratio of small changes |
d(x²)/dx = 2x4.1 - power rule
- the derivative of
xⁿisn xⁿ⁻¹|x³ → 3x²,12at 2 4.2 - chain rule
- the derivative of
f(g(x))isf′(g(x)) · g′(x)|(3 − 2x)² → 2(3 − 2x)(−2)4.2 - partial derivative
- the derivative with respect to one variable, the others held fixed |
∂/∂w (y − wx − b)² = −9.6for the 4-year-old car 4.2 - stationary point
- a point where the derivative is zero |
x² − 3x + 2at1.54.3 - minimum
- the derivative changes from negative to positive |
f′(1) = −1,f′(2) = 14.3 - maximum
- the derivative changes from positive to negative |
x⁴ − 4x² + xat0.1264.3 - local minimum
- lower than every nearby point |
1.347, value−2.61864.3 - global minimum
- lower than every point |
−1.473, value−5.44424.3 - bisection
- halve an interval that contains a zero, keeping the half where the sign changes |
2x + eˣ = 0on[−1, 0]4.3 - iterative method
- a method that improves an answer step by step | bisection, gradient descent 4.3
- median
- the middle value; it minimises the sum of absolute errors |
13.2for the six hero prices 4.3 - partial derivative
- the derivative with respect to one variable, with every other variable held fixed |
∂(x² + 3y²)/∂x = 4at(2, 1)4.4 - gradient
- the vector of all the partial derivatives |
(4, 6)4.4 - contour
- a curve joining points where the function has the same value | the ellipse
x² + 3y² = 74.4 - directional derivative
- the slope of
fin the direction of a unit vectoru,∇f · u|6.4641at 30° 4.4 - second derivative
- the derivative of the derivative,
f″(x)|x³ − 3x → 6x4.5 - curvature
- how sharply a curve bends; its sign says up or down |
+6at 1,−6at−14.5 - Hessian
- the matrix of all second partial derivatives |
diag(2, 6)forx² + 3y²4.5 - Taylor approximation
- a polynomial built from a function's derivatives at one point, matching it nearby |
1 + x + 1.5x²forx² + eˣat 0 4.5 - Newton's method
- repeatedly jump to the minimum of the local parabola,
x − f′/f″| three steps to−0.3517344.5 - strip sum
- the total area of thin rectangles under a curve |
0.46875with four right-edge strips 4.6 - integral
- the limit of the strip sums as the strips get thinner |
∫₀¹ x² dx = 1/34.6 - antiderivative
- a function whose derivative is the given function |
x³/3forx²4.6 - fundamental theorem of calculus
- the area's rate of growth is the curve's height |
A′(x) = x²4.6 - density
- a curve with total area 1, whose area over an interval is the probability of landing there |
2xon[0, 1]4.6 - ROC curve
- the true positive rate against the false positive rate as the threshold moves | the tiny ward's seven points 4.6
- AUC
- the area under the ROC curve |
0.7656on the tiny ward 4.6 - chord
- a straight line between two points of a curve |
x²from−2to14.7 - convex function
- every chord lies on or above the curve |
x²,log(1 + eˣ)4.7 - strictly convex
- every chord lies strictly above the curve; at most one minimiser |
x²(one),log(1 + eˣ)(none) 4.7 - saddle point
- a point with zero gradient that is neither a minimum nor a maximum | the origin of
x² − y²4.7 - computation graph
- a calculation drawn as nodes, one operation each, joined by the values they pass |
u = 3a,v = u + b,f = v²4.8 - forward pass
- compute each node's value from its inputs, in order |
3,5,254.8 - local derivative
- the derivative of one node with respect to its own input |
∂f/∂v = 2v = 104.8 - backward pass
- start from the output and multiply local derivatives back along each edge |
∂f/∂a = 10 · 1 · 3 = 304.8 - backpropagation
- the backward pass on a computation graph, each local derivative used once | how deep learning libraries compute gradients 4.8
- constraint
- a condition the answer must satisfy, such as
g(x, y) = c|x + y = 14.9 - Lagrange multiplier
λin∇f = λ∇gat a constrained optimum |λ = −24.9- Lagrangian
L = f − λ(g − c); its stationary point gives the constrained optimum | three equations forx,y,λ4.9- active constraint
- an inequality that holds with equality at the optimum |
x + y ≤ 1at(1, 0)4.9 - complementary slackness
- either the constraint is tight or its multiplier is zero |
x + y ≤ 4: multiplier04.9 - KKT conditions
- the conditions for an optimum with inequality constraints | gradient condition, feasibility,
μ ≥ 0, slackness 4.9