Functions
A function is a relationship that defines how one quantity depends on another.
A function takes an input from a set and maps it to an output from another set. The input set is known as the domain and the output set is known as the codomain or target set of the function. There are many ways to denote functions in machine learning literature, or in Mathematics. Here's the more popular ones.
\begin{aligned}
& f: \sX \rightarrow \sY \\
& y = f(x), x \in \sX, y \in \sY \\
& f: x \mapsto y, x \in \sX, y \in \sY \\
\end{aligned}
In these, \( \sX \) is the domain, \( \sY \) is the codomain, \( x \) is the input variable and \( y \) is the output variable.
Note that the codomain provides a set of possible values for the output of the function.
The function may not actually realize all possible values in the codomain.
For example, consider the square function \( y = x^2 \) defined over the set of natural numbers, \( x \in \natural \). In this case, the domain and the codomain are both \( \natural \).
However, for the input sequence \( 1, 2, 3, 4 \ldots \), the output sequence is \( 1, 4, 9 , 16, \ldots \).
The natural numbers \(2, 3, 5, 6, 7, \ldots \) are missing from the outputs of the function. In other words, all natural numbers are not realized by the square function.
This restricted set of output values that are actually generated by the function is known as its range or the image of the function. Remember this subtle difference between range and codomain of a function. Succinctly, \( \text{image of } f \subseteq \text{codomain of } f \). Note that some texts use range interchangeably to mean codomain or image, rendering it ambiguous. To be precise, it is better to stick with codomain and image and avoid using range, which might be misinterpreted.
Example functions