Functions

Read f(x) notation, define a domain, and see how the parameters w and b turn the rule wx + b into a tiny model, with a Python version.

Give a rule the number 2. It doubles the number, adds 1, and returns 5. Give it 3 and it returns 7.

That rule is a function: for each allowed input, it gives one output. The letter f is just a name for our rule.

$$f(x) = 2x + 1$$

Read f(x) as “the output of f when its input is x.” It does not mean f multiplied by x. The expression 2x does mean 2 multiplied by x.

Before moving the input below, predict the output for x = −1.

The answer is −1: double −1 to get −2, then add 1. Negative inputs follow exactly the same rule.

Inputs can share an output

Try a different rule: g(x) = x². Both 2 and −2 produce 4. This is still a function. Each input has one answer; different inputs are allowed to have the same answer.

Predict: Could “take x and return either x + 1 or x − 1, without specifying which” define an ordinary function of x alone?

We also need to say which inputs are allowed. The rule 1/x works for real numbers except zero. That allowed collection is the domain.

A small model is also a function

Our first rule can be written as f(x) = wx + b. Here w and b are numbers we choose, called parameters. With w = 2 and b = 1, it is exactly the rule above. Learning will mean adjusting parameters using examples. For now, keep them fixed.

If you know a little Python, this is the same calculation:

The outputs are 7 and 13. The input stayed at 3; changing a parameter changed the rule.

A straight-line rule with an added offset, such as 2x + 1, is called affine in linear algebra. A linear map has no offset: 2x is an example. You may hear both called “linear functions” in introductory algebra.

Neural networks compose many functions. Some bend the relationship rather than drawing a straight line: x² is one example. The useful question is still what output a particular input produces.

Try on a graph: Open the free Desmos calculator. Enter y = 2x + 1 and y = x^2. Inspect x = −2 and x = 2. Which rule gives the same output at both inputs?

If the Python syntax is unfamiliar, the Python tutorial’s section on defining functions explains def and return.

  • A function assigns one output to each allowed input. Different inputs can share an output.
  • In f(x) = 2x + 1, f(x) means the output at input x. At x = 3, the output is 7.
  • The domain is the set of allowed inputs. For 1/x over real numbers, exclude zero.
  • In wx + b, w and b are parameters. Changing them changes the rule.
  • In linear algebra, wx + b is affine; with b = 0 it is linear.