Free preview

146 lessons

Essential Calculus for ML

Free preview

Essential Calculus for ML · 146 lessons

Master the fundamentals

No surprise gaps

Actually remember it

Skip what you know

One subscription. All learning paths included.

Our content is best on a larger screen

Level curves and contour plots

Level curves

Explanation

To picture a surface z=f(x,y)z = f(x,y) we have so far cut it with vertical planes, holding one of the inputs, xx or yy, fixed. A horizontal plane also cuts it: the plane z=cz = c meets the surface wherever the height is exactly cc, and directly beneath that intersection, in the xyxy-plane, lies a curve.

Level curve and contour plot

Definition

The level curve of ff at level cc is the set of points (x,y)(x,y) of the xyxy-plane with f(x,y)=cf(x,y)=c.

Level curves at several levels, drawn together in the xyxy-plane and each labelled with its level, form the contour plot of ff. Each labelled curve on the plot is a contour.

Toggle the views below. The first view shows three horizontal planes cutting one surface, each intersection drawn again in the xyxy-plane beneath it. The second view shows those same curves on their own in the xyxy-plane, each labelled with its level.

x
y
z
The planes z=1 (teal), z=2 (orange) and z=3 (red) cut the surface z=12(x2+y2). Each cut is drawn once on the surface and once in the xy-plane below it. Drag the scene to rotate it.

Finding the level curve at level cc therefore means solving the single equation f(x,y)=cf(x,y)=c.

If no pair (x,y)(x,y) satisfies f(x,y)=cf(x,y)=c, then ff has no level curve at that level and nothing is drawn for it.

Level curve and contour curve

Details

Example

The surface z=x2+y2z=x^2+y^2 is cut by the horizontal planes z=9z=9 and z=1z=-1. Find the level curve of f(x,y)=x2+y2f(x,y)=x^2+y^2 at each level, and describe what it looks like in the xyxy-plane.

Solution

The level curve at level cc is the set of points with f(x,y)=cf(x,y)=c, so at level 99 we solve

x2+y2=9x^2+y^2=9

This equation is the level curve: the curve consists of exactly the pairs (x,y)(x,y) satisfying it. To see what it looks like, we match it against a form we know: x2+y2=r2x^2+y^2=r^2 is the circle of radius rr about the origin, and here r2=9r^2=9, so the level curve at c=9c=9 is the circle of radius 33. Checking one of its points, f(3,0)=32+02=9f(3,0)=3^2+0^2=9, the level we set.

At level 1-1 the equation is

x2+y2=1x^2+y^2=-1

Matching the form now asks for r2=1r^2=-1, and no real radius has a negative square. Nor does any point satisfy the equation, since x2+y2x^2+y^2 is a sum of two squares and is never negative. There is no level curve at c=1c=-1, and nothing is drawn for that level.

Practice questions

4 questions

Which curve is the level curve of f(x,y)=yx2f(x,y)=y-x^2 at level c=3c=3?

Select the correct answer:

+ 3 more questions

Reading a contour plot

Explanation

A contour plot is a flat picture that carries everything we need to know about the shape of a surface: without ever seeing it in 3D, the labels and spacing tell us where it is high and low, where it climbs steeply, and where its peaks and basins sit.

Every point of a contour shares its label's value, so f(x,y)f(x,y) is constant along a contour, and each step across a contour changes f(x,y)f(x,y) by one label. The contour plot below shows one surface, drawn without axes: none of the readings needs a coordinate, only the labels. Step through the five readings.

22
16
10
4
T
Reading 1 of 5: Along a contour
Every point of the highlighted contour has f(x,y)=16: moving along a contour leaves f(x,y) unchanged.

The last two readings named what nested contours surround; precisely:

Peak and basin

Definition

Nested closed contours whose levels increase towards the innermost contour surround a peak, a high point of the surface. Nested closed contours whose levels decrease towards the innermost contour surround a basin, a low point of the surface.

The steepness reading holds on any plot with equally spaced levels:

Key Point

On a plot whose levels rise in equal steps, contours packed close together mark a steep part of the surface, and contours spread far apart a shallow part.

ML Context

A model with two parameters has a loss value for every pair of settings, and those values form a surface above the plane of settings. Fitting the model, adjusting its two parameters to shrink the loss, is pictured on a contour plot of that surface.

Practice questions

4 questions

The contour plot below shows one surface, with four points marked on it. The levels rise in equal steps of 66.

4
10
16
22
P
Q
S
T

At which of the marked points is the surface steepest?

Select the correct answer:

+ 3 more questions