Maths for AI
Topic 3 · Refreshers: school maths you will need

Refresher: Functions & Graphs

What a function is (a rule from inputs to outputs), reading and sketching graphs, straight lines and their slope, curves such as x², exponential growth and decay, and logarithms as the reverse of powers.

Show:
In this topic
Beginner

A function is a rule

A function takes an input and gives exactly one output, following a rule. We write f(x)=2x+1f(x) = 2x + 1: "f of x equals two x plus one". The input xx goes in, 2x+12x + 1 comes out: f(3)=7f(3) = 7, f(0)=1f(0) = 1, f(−2)=−3f(-2) = -3.

This is exactly the idea of a machine learning model: a function from inputs (a house's size, an image's pixels) to an output (a price, the word "cat"). Training is finding the rule's numbers.

Beginner

Graphs: pictures of functions

A graph plots every input on the horizontal axis (xx) against its output on the vertical axis (y=f(x)y = f(x)). The point (3,7)(3, 7) means "when xx is 3, yy is 7". Reading a graph means asking: when xx grows, does yy grow, shrink, or turn around? How fast?

Beginner

Straight lines: slope and intercept

The simplest functions are straight lines: y=mx+by = mx + b.

  • mm is the slope (or gradient): how much yy changes when xx increases by 1. Positive slopes go up, negative ones go down, zero is flat.
  • bb is the intercept: the value of yy when x=0x = 0, where the line crosses the vertical axis.

The slope between two points is "rise over run": m=y2−y1x2−x1m = \dfrac{y_2 - y_1}{x_2 - x_1}. Between (1,3)(1, 3) and (4,9)(4, 9) the slope is 6/3=26/3 = 2. Linear regression, the first model in machine learning, is finding the best mm and bb for some data.

Try it

Try it: move a line, then a curve

Change the slope and intercept and watch the line move. Then switch to the other functions and see their shapes.

Interactive: this part runs in your browser.

Beginner

Curves: squares and other powers

y=x2y = x^2 is a U-shaped curve (a parabola): it is never negative, it is lowest at x=0x = 0, and it grows faster and faster. Squared errors in ML have this shape, which is why "find the lowest point of a U" is the central job of training. y=x3y = x^3 keeps its sign, and y=xy = \sqrt{x} grows ever more slowly.

Beginner

Exponential growth and decay

In an exponential function the input is in the exponent: y=2xy = 2^x doubles every time xx goes up by 1. Exponential growth starts slowly and then explodes (compound interest, viral spread). y=0.5xy = 0.5^x halves each step: exponential decay (a learning rate schedule that shrinks each epoch). The most important base is the number e≈2.718e \approx 2.718, giving exe^x, written exp(x) in code. It appears in the sigmoid and softmax functions.

Beginner

Logarithms: the reverse of powers

A logarithm answers "what power do I need?": log⁡28=3\log_2 8 = 3 because 23=82^3 = 8, and log⁡101000=3\log_{10} 1000 = 3. The natural log ln⁡x\ln x (written log(x) in NumPy) uses base ee. Logs turn multiplication into addition: log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b. That is why models add up log-probabilities instead of multiplying tiny probabilities. Logs of numbers between 0 and 1 are negative, and log⁡1=0\log 1 = 0. The notation lesson goes further.

Beginner

Practice: check yourself

Work each question out (on paper, in your head, or in Python), type the answer and press ✔ Check. Fractions like 1/4 are fine. Hints and a worked answer are there when you need them.

Question 1.
For f(x)=4x−3f(x) = 4x - 3, what is f(2.5)f(2.5)?
Question 2.
What is the slope of the line through (2,5)(2, 5) and (6,17)(6, 17)?
Question 3.
What is log⁡232\log_2 32?
Question 4.
An investment doubles every year, starting at $100. How much is it after 6 years?
Beginner

Summary

Key words

function f(x)f(x)
a rule that turns each input into one output
graph
a picture of inputs (x) against outputs (y)
slope mm
change in y per 1 step in x: rise over run
intercept bb
the value of y when x is 0
parabola
the U shape of y=x2y = x^2
exponential
the input is the power: 2x2^x, exe^x
logarithm
the power needed: log⁡28=3\log_2 8 = 3

Common mistakes

  • Mixing up slope and intercept in y=mx+by = mx + b.
  • Rise over run upside down: it is change in y divided by change in x.
  • log⁡(a+b)≠log⁡a+log⁡b\log(a + b) \ne \log a + \log b. Only products split: log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b.
  • Taking the log of zero or a negative number: it is undefined.
  • Thinking exponential means "fast" from the start: it begins slowly.
Check yourself

Quiz

1. If f(x)=3x−2f(x) = 3x - 2, what is f(4)f(4)?

2. What is the slope between (0,1)(0, 1) and (2,7)(2, 7)?

3. In y=−2x+5y = -2x + 5, where does the line cross the y-axis?

4. What is log⁡10100\log_{10} 100?

5. Which grows fastest for large x?

Ready