Math for AILoading progress…

Reading a graph

Evaluate functions, compare growth rates and read a loss curve without confusing inputs and outputs.

A graph is a table that never ends

A graph draws every pair (input, output) as a point. The horizontal axis holds the input x. The vertical axis holds the output f(x). To read a value, find the input on the bottom, go straight up to the curve, then straight across to the side. That height is the output. Nothing in the picture says the output must grow when x grows: the curve goes wherever the rule sends it.

-4-3-2-10123456-6-4-202468
f(x) = 0.5x² − x − 1.5
height at x = 1: -2
height at x = 2: -1.5
slope = rise / run = (-1.5 − (-2)) / 1 = 0.5
crosses the vertical axis at -1.5
crosses the horizontal axis at -1 and 3

Rising between these two points: the output went up.

Orange dot: the probe. Purple dot and dashed line: the point one gap to the right and the straight line through both. Green rings: where the curve meets the axes.

Pick a curve and move the probe. The second point is one gap to the right. Watch the slope turn negative where the curve falls.

Three things you can read off a graph

  • A value: the height of the curve above a chosen x. For the valley curve, the height at x = 4 is 0.5·16 − 4 − 1.5 = 2.5.
  • Where it crosses the axes: the vertical crossing is f(0), the output when the input is 0. A horizontal crossing is an input whose output is 0.
  • Its direction: the slope between two points is rise over run, (change in output) / (change in input). Positive slope: rising. Negative slope: falling. Slope 0: level.

For a straight line the slope is the same everywhere. For a curve it changes from place to place, which is why we say "between these two points". A line is written y = m·x + b, where m is the slope and b the height at x = 0.

Predict first. A line passes through (0, 3) and (2, −1). What is its slope?

The common mistake: reading the shape as a trend

Beginners often assume "moving right means going up". On the hill-and-valley curve, between x ≈ −1.4 and x ≈ 1.4 the output falls while the input rises. Another trap: reading a height off the wrong axis, or mixing up "the output is 0" (a horizontal crossing) with "the input is 0" (a vertical crossing). Say the question out loud before you read: which quantity am I given, and which one am I looking for?

Chapter context

A function maps an input to an output under a stated rule. Graphs let us see the same rule at many inputs; formulas let us calculate a particular output exactly. Both views should describe the same quantity and units.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

f:X→Y,y=f(x),log⁡b(bx)=x.f:X\to Y,\quad y=f(x),\quad \log_b(b^x)=x.

For the illustrative loss:

L(θ)=(θ−1.2)2≥0.L(\theta)=(\theta-1.2)^2\ge0.

Theta is a tunable scalar, 1.2 is the target, and L is a nonnegative output. An exponent and its logarithm undo each other only on their valid domains.

Worked example

Evaluate L(0)=1.44, L(2)=0.64 and L(1.2)=0. The parameter 2 gives a larger input than 0 but a smaller loss. Squaring makes positive and negative distances contribute the same penalty. This is a synthetic landscape, not a claim that real models have one simple valley.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import isclose, log2
loss = lambda theta: (theta - 1.2) ** 2
assert isclose(loss(0), 1.44)
assert isclose(loss(2), 0.64)
assert loss(1.2) == 0
assert log2(8) == 3
assert sum(i*i for i in range(1, 4)) == 14

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

The output of a loss function is not its input parameter. Larger inputs do not always produce larger outputs. Logarithms require an explicit base when comparing information quantities.